cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : AppUtil.hpp 00003 // 00004 // Purpose : This file represents the Cubit application itself. 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : Darryl Melander 00009 // 00010 // Date : 06/08/98 00011 // 00012 // Owner : Darryl Melander 00013 //------------------------------------------------------------------------- 00014 00015 #ifndef APP_UTIL_HPP 00016 #define APP_UTIL_HPP 00017 00018 #include "CubitDefines.h" 00019 #include "CubitString.hpp" 00020 #include "CGMUtilConfigure.h" 00021 #include "CubitEventDispatcher.hpp" 00022 #ifdef BUILD_WITH_CONCURRENT_SUPPORT 00023 #include "CubitConcurrentApi.h" 00024 #endif 00025 #include <time.h> 00026 00027 #ifndef _WIN32 00028 #include <sys/resource.h> 00029 #endif 00030 00031 class ProgressTool; 00032 class CubitString; 00033 class CubitThreadPool; 00034 00035 class CUBIT_UTIL_EXPORT AppUtil 00036 { 00037 public: 00038 static AppUtil* instance_no_create(); 00039 00040 static AppUtil* instance(); 00041 //- Access to the application object 00042 00043 static void delete_instance(); 00044 00045 void report_resource_usage() const; 00046 //- Prints out information about the session 00047 00048 bool get_terminal_size( int& rows, int& cols ); 00049 //- Get the size of the terminal, if known. 00050 00051 #ifdef CAT 00052 int days_to_expire(int year, int month, int day) const; 00053 //- Returns number of days until the app expires 00054 #endif 00055 ~AppUtil(); 00056 00057 00058 // Signal handing code. The signal handler provided by 00059 // AppUtil sets the flag cubit_intr to CUBIT_TRUE when 00060 // an interrupt (SIGINT) is detected. See the comments 00061 // with the declaration of cubit_intr in AppUtil.cpp 00062 // for more information. 00063 00064 // returns whether the interupt flag has been set 00065 CubitBoolean interrupt(); 00066 void set_interrupt(CubitBoolean); 00067 00068 // clears the interrupt flag 00069 void clear_interrupt(); 00070 00071 static CubitBoolean catch_interrupt() { return catching_sigint_; } 00072 //- Check if the signal handler provided in AppUtil 00073 //- is being used. 00074 00075 static void catch_interrupt( CubitBoolean yesno ); 00076 //- yesno: 00077 //- CUBIT_TRUE: Set signal handler for SIGINT to the 00078 //- handler provided by AppUtil. 00079 //- CUBIT_FALSE: Set the signal hander for SIGINT to 00080 //- the system default. 00081 00082 void startup(); 00083 //- Contains startup code for cubit 00084 00085 int shutdown(); 00086 //- Contains shutdown code for cubit 00087 00088 void apputil_getrusage(struct rusage &r_usage) const; 00089 //- fill the r_usage with data from getrusage; implements special code to 00090 //- find memory usage when you don't get that from the system call getrusage 00091 00092 void set_terminal_size( int rows, int cols ); 00093 //- This function sets the values returned from 00094 //- get_terminal_size(). It has no effect on 00095 //- the actual terminal size. 00096 00097 ProgressTool *progress_tool(); 00098 void progress_tool(ProgressTool* pTool); 00099 // pass in a pointer to a progress tool - the lifetime of the tool will be 00100 // controlled by AppUtil 00101 00106 CubitString get_app_dir(); 00107 // get the cubit dir variable 00108 00109 static void initialize_settings(); 00110 // initialize settings 00111 00112 CubitEventDispatcher& event_dispatcher() { return mEventDispatcher; } 00113 00115 template <class T> 00116 void send_event(const T& event) 00117 { 00118 CubitObservable* obs = dynamic_cast<CubitObservable*>(event.get_entity()); 00119 this->send_event(obs, event); 00120 } 00121 00122 bool concurrent_enabled() 00123 { 00124 return concurrentSupport; 00125 } 00126 00127 CubitThreadPool* thread_pool(); 00128 00129 private: 00130 00131 void send_event(CubitObservable* obs, const CubitEvent& event); 00132 00133 static CubitBoolean catching_sigint_; 00134 //- Signal handler registered for SIGINT? 00135 00136 int term_width, term_height; 00137 00138 static AppUtil* instance_; 00139 CubitBoolean mAppStarted; 00140 00141 CubitString cubitDir; 00142 //- directory of the cubit executable 00143 00144 ProgressTool *mProgressTool; 00145 00146 CubitEventDispatcher mEventDispatcher; 00147 00148 clock_t mInterruptThrottle; 00149 00150 CubitBoolean concurrentSupport; 00151 #ifdef BUILD_WITH_CONCURRENT_SUPPORT 00152 CubitConcurrent *mConcurrentInstance; 00153 #endif 00154 00155 CubitThreadPool* mThreadPool; 00156 00157 AppUtil(); 00158 }; 00159 00160 // returns the directory where cubit binaries reside, 00161 // or more correctly, the path of the library/executable that contains this AppUtil code. 00162 inline CubitString AppUtil::get_app_dir() 00163 { 00164 return cubitDir; 00165 } 00166 00167 #endif 00168