USGS

Isis 3.0 Object Programmers' Reference

Home

Isis.h
Go to the documentation of this file.
1 
24 #ifdef __GTHREADS
25 #error *****Isis.h MUST be included before any other files!*****
26 #endif
27 
28 #include "IsisDebug.h"
29 
30 #include <signal.h>
31 
32 #include <QCoreApplication>
33 
34 #include "Application.h"
35 #include "UserInterface.h" // this is an unnecessary include
36 
37 #ifndef APPLICATION
38 #define APPLICATION IsisMain
39 #endif
40 
85 std::map<QString, void *> GuiHelpers();
86 #ifndef GUIHELPERS
87 std::map<QString, void *> GuiHelpers() {
88  std::map<QString, void *> empty;
89  return empty;
90 }
91 #endif
92 
93 void APPLICATION();
94 
95 void startMonitoringMemory();
96 void stopMonitoringMemory();
97 void SegmentationFault(int);
98 void Abort(int);
99 void InterruptSignal(int);
100 
109 int main(int argc, char *argv[]) {
110 #ifdef CWDEBUG
111  startMonitoringMemory();
112  signal(SIGSEGV, SegmentationFault);
113  signal(SIGABRT, Abort);
114  signal(SIGINT, InterruptSignal);
115 #endif
116 
117  Isis::Application::p_applicationForceGuiApp = false;
118 
119 #ifdef USE_GUI_QAPP
120  Isis::Application::p_applicationForceGuiApp = true;
121 #endif
122 
123  Isis::Application *app = new Isis::Application(argc, argv);
125  int status = app->Run(APPLICATION);
126  delete app;
127  delete QCoreApplication::instance();
128  return status;
129 }
130 
131 #ifdef CWDEBUG
132 void startMonitoringMemory() {
133 #ifndef NOMEMCHECK
134  MyMutex *mutex = new MyMutex();
135  std::fstream *alloc_output = new std::fstream("/dev/null");
136  Debug(make_all_allocations_invisible_except(NULL));
137  ForAllDebugChannels(if(debugChannel.is_on()) debugChannel.off());
138  Debug(dc::malloc.on());
139  Debug(libcw_do.on());
140  Debug(libcw_do.set_ostream(alloc_output));
141  Debug(libcw_do.set_ostream(alloc_output, mutex));
142  atexit(stopMonitoringMemory);
143 #endif
144 }
145 
146 
147 void stopMonitoringMemory() {
148 #ifndef NOMEMCHECK
149  Debug(
150  alloc_filter_ct alloc_filter;
151  std::vector<std::string> objmasks;
152  objmasks.push_back("libc.so*");
153  objmasks.push_back("libstdc++*");
154  std::vector<std::string> srcmasks;
155  srcmasks.push_back("*new_allocator.h*");
156  srcmasks.push_back("*set_ostream.inl*");
157  alloc_filter.hide_objectfiles_matching(objmasks);
158  alloc_filter.hide_sourcefiles_matching(srcmasks);
159  alloc_filter.hide_unknown_locations();
160  delete libcw_do.get_ostream();
161  libcw_do.set_ostream(&std::cout);
162  list_allocations_on(libcw_do, alloc_filter);
163  dc::malloc.off();
164  libcw_do.off()
165  );
166 #endif
167 }
168 
169 
170 void SegmentationFault(int) {
171  std::vector<std::string> currentStack;
172  StackTrace::GetStackTrace(&currentStack);
173 
174  std::cerr << "Segmentation Fault" << std::endl;
175  for(unsigned int i = 1; i < currentStack.size(); i++) {
176  std::cerr << currentStack[i] << std::endl;
177  }
178 
179  exit(1);
180 }
181 
182 void Abort(int) {
183  std::vector<std::string> currentStack;
184  StackTrace::GetStackTrace(&currentStack);
185 
186  std::cerr << "Abort" << std::endl;
187  for(unsigned int i = 1; i < currentStack.size(); i++) {
188  std::cerr << currentStack[i] << std::endl;
189  }
190 
191  exit(1);
192 }
193 
194 
195 void InterruptSignal(int) {
196  exit(1);
197 }
198 
199 #endif