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