1 /* Copyright (C) 2021-2023 Free Software Foundation, Inc.
2 Contributed by Oracle.
3
4 This file is part of GNU Binutils.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21 /*
22 * The Application class is the base class for all C++ executables
23 * in the Performance Tools Suite
24 *
25 * It determines the directory from which the running binary came,
26 * sets up the I18N catalog, the program name, and initializes
27 * an instance of the Settings class to manage all user preferences
28 * and settings. It also manages usage tracking.
29 *
30 * Applications which read experiments are derived from a subclass
31 * named DbeApplication (q.v.)
32 */
33
34 #ifndef _APPLICATION_H
35 #define _APPLICATION_H
36
37 #include "dbe_types.h"
38
39 class Settings;
40 class Emsg;
41 class Emsgqueue;
42
43 // Application object
44 class Application
45 {
46 public:
47 Application (int argc, char *argv[], char *_run_dir = NULL);
48 virtual ~Application ();
49 void set_name (const char *_name);
50 char *get_cur_dir ();
51
52 // Control the settings of a progress bar, used for GUI applications
53 // this function also detects cancel requests and returns 1
54 // if yes, 0 otherwise
55 static int set_progress (int percentage, const char *proc_str);
56 static char *get_realpath (const char *_name);
57
58 // queue for messages (from reading er.rc files, ...)
59 void queue_comment (Emsg *m); // queue for messages
60 Emsg *fetch_comments (void); // fetch the queue of comment messages
61 void delete_comments (void); // delete the queue of comment messages
62
63 // worker threads (currently used in dbe_stat() for stat() calls)
64 int get_number_of_worker_threads ();
65
66 char *get_version () { return prog_version; }
67 char *get_name () { return prog_name; }
68 char *get_run_dir () { return run_dir; }
69 Emsgqueue *get_comments_queue () { return commentq; };
70
71 protected: // methods
72 void set_run_dir (char *fdhome = NULL);
73 typedef int (*ProgressFunc)(int, const char *);
74
75 // Write a usage message; to be defined in derived class
76 virtual void usage () = 0;
77
78 // Ruud
79 // Write a version message; to be defined in derived class
80 void print_version_info ();
81
82 // Can be overridden in derived class
83 virtual int check_args (int argc, char *argv[]);
84
85 void read_rc ();
86 static void set_progress_func (ProgressFunc func) { progress_func = func; }
87
88 protected:
89 Emsgqueue *commentq;
90 Settings *settings;
91 char *prog_version;
92 char *prog_name;
93 char *whoami;
94 char *run_dir;
95 char *run_dir_with_spaces; // used in case there are spaces
96 char *cur_dir;
97 int lic_found;
98 char *lic_err;
99
100 private:
101 void set_ut_email (int argc, char *argv[]);
102 int number_of_worker_threads;
103 static ProgressFunc progress_func;
104 };
105
106 extern Application *theApplication;
107
108 #endif /* _APPLICATION_H */