USGS

Isis 3.0 Object Programmers' Reference

Home

Isis.h

Go to the documentation of this file.
00001 
00024 #ifdef __GTHREADS
00025 #error *****Isis.h MUST be included before any other files!*****
00026 #endif
00027 
00028 #include "IsisDebug.h"
00029 
00030 #include <signal.h>
00031 
00032 #include <QCoreApplication>
00033 
00034 #include "Application.h"
00035 #include "UserInterface.h" // this is an unnecessary include
00036 
00037 #ifndef APPLICATION
00038 #define APPLICATION IsisMain
00039 #endif
00040 
00085 std::map<std::string,void*> GuiHelpers();
00086 #ifndef GUIHELPERS
00087 std::map<std::string,void*> GuiHelpers() {
00088   std::map<std::string,void*> empty;
00089   return empty;
00090 }
00091 #endif
00092 
00093 void APPLICATION ();
00094 
00095 void startMonitoringMemory();
00096 void stopMonitoringMemory();
00097 void SegmentationFault(int);
00098 void Abort(int);
00099 void InterruptSignal(int);
00100 
00109 int main (int argc, char *argv[]) {
00110 #ifdef CWDEBUG
00111   startMonitoringMemory();
00112   signal(SIGSEGV, SegmentationFault);
00113   signal(SIGABRT, Abort);
00114   signal(SIGINT, InterruptSignal);
00115 #endif
00116 
00117   Isis::Application *app = new Isis::Application(argc,argv);
00118   app->RegisterGuiHelpers(GuiHelpers());
00119   int status = app->Exec(APPLICATION);
00120   delete app;
00121   delete QCoreApplication::instance();
00122   return status;
00123 }
00124 
00125 #ifdef CWDEBUG
00126 void startMonitoringMemory() {
00127 #ifndef NOMEMCHECK
00128   MyMutex *mutex = new MyMutex();
00129   std::fstream *alloc_output = new std::fstream("/dev/null");
00130   Debug( make_all_allocations_invisible_except(NULL) );
00131   ForAllDebugChannels( if (debugChannel.is_on()) debugChannel.off() );
00132   Debug( dc::malloc.on() );
00133   Debug( libcw_do.on() );
00134   Debug( libcw_do.set_ostream(alloc_output) );
00135   Debug( libcw_do.set_ostream(alloc_output, mutex) );
00136   atexit(stopMonitoringMemory);
00137 #endif
00138 }
00139 
00140 
00141 void stopMonitoringMemory() {
00142 #ifndef NOMEMCHECK
00143   Debug(
00144     alloc_filter_ct alloc_filter;
00145     std::vector<std::string> objmasks;
00146     objmasks.push_back("libc.so*");
00147     objmasks.push_back("libstdc++*");
00148     std::vector<std::string> srcmasks;
00149     srcmasks.push_back("*new_allocator.h*");
00150     srcmasks.push_back("*set_ostream.inl*");
00151     alloc_filter.hide_objectfiles_matching(objmasks);
00152     alloc_filter.hide_sourcefiles_matching(srcmasks);
00153     alloc_filter.hide_unknown_locations();
00154     delete libcw_do.get_ostream();
00155     libcw_do.set_ostream(&std::cout);
00156     list_allocations_on(libcw_do, alloc_filter);
00157     dc::malloc.off();
00158     libcw_do.off()
00159   );
00160 #endif
00161 }
00162 
00163 
00164 void SegmentationFault(int) {
00165   std::vector<std::string> currentStack;
00166   StackTrace::GetStackTrace(&currentStack);
00167 
00168   std::cerr << "Segmentation Fault" << std::endl;
00169   for(unsigned int i = 1; i < currentStack.size(); i++) {
00170     std::cerr << currentStack[i] << std::endl;
00171   }
00172 
00173   exit(1);
00174 }
00175 
00176 void Abort(int) {
00177   std::vector<std::string> currentStack;
00178   StackTrace::GetStackTrace(&currentStack);
00179 
00180   std::cerr << "Abort" << std::endl;
00181   for(unsigned int i = 1; i < currentStack.size(); i++) {
00182     std::cerr << currentStack[i] << std::endl;
00183   }
00184 
00185   exit(1);
00186 }
00187 
00188 
00189 void InterruptSignal(int) {
00190   exit(1);
00191 }
00192 
00193 #endif