Isis 3 Developer Reference
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 
97 void SegmentationFault(int);
98 void Abort(int);
99 void InterruptSignal(int);
100 
109 int main(int argc, char *argv[]) {
110  // Verify ISISROOT was set
111  // Note: as printing and logging IExceptions requires ISISROOT to be set (for preferences),
112  // The case below cannot be handled with IExceptions
113  if (getenv("ISISROOT") == NULL || QString(getenv("ISISROOT")) == "") {
114  std::cerr << "Please set ISISROOT before running any Isis applications" << std::endl;
115  exit(1);
116  }
117 
118 #ifdef CWDEBUG
120  signal(SIGSEGV, SegmentationFault);
121  signal(SIGABRT, Abort);
122  signal(SIGINT, InterruptSignal);
123 #endif
124 
126 
127 #ifdef USE_GUI_QAPP
129 #endif
130 
131  Isis::Application *app = new Isis::Application(argc, argv);
133  int status = app->Run(APPLICATION);
134  delete app;
135  delete QCoreApplication::instance();
136  return status;
137 }
138 
139 #ifdef CWDEBUG
140 void startMonitoringMemory() {
141 #ifndef NOMEMCHECK
142  MyMutex *mutex = new MyMutex();
143  std::fstream *alloc_output = new std::fstream("/dev/null");
144  Debug(make_all_allocations_invisible_except(NULL));
145  ForAllDebugChannels(if(debugChannel.is_on()) debugChannel.off());
146  Debug(dc::malloc.on());
147  Debug(libcw_do.on());
148  Debug(libcw_do.set_ostream(alloc_output));
149  Debug(libcw_do.set_ostream(alloc_output, mutex));
150  atexit(stopMonitoringMemory);
151 #endif
152 }
153 
154 
155 void stopMonitoringMemory() {
156 #ifndef NOMEMCHECK
157  Debug(
158  alloc_filter_ct alloc_filter;
159  std::vector<std::string> objmasks;
160  objmasks.push_back("libc.so*");
161  objmasks.push_back("libstdc++*");
162  std::vector<std::string> srcmasks;
163  srcmasks.push_back("*new_allocator.h*");
164  srcmasks.push_back("*set_ostream.inl*");
165  alloc_filter.hide_objectfiles_matching(objmasks);
166  alloc_filter.hide_sourcefiles_matching(srcmasks);
167  alloc_filter.hide_unknown_locations();
168  delete libcw_do.get_ostream();
169  libcw_do.set_ostream(&std::cout);
170  list_allocations_on(libcw_do, alloc_filter);
171  dc::malloc.off();
172  libcw_do.off()
173  );
174 #endif
175 }
176 
177 
178 void SegmentationFault(int) {
179  std::vector<std::string> currentStack;
180  StackTrace::GetStackTrace(&currentStack);
181 
182  std::cerr << "Segmentation Fault" << std::endl;
183  for(unsigned int i = 1; i < currentStack.size(); i++) {
184  std::cerr << currentStack[i] << std::endl;
185  }
186 
187  exit(1);
188 }
189 
190 void Abort(int) {
191  std::vector<std::string> currentStack;
192  StackTrace::GetStackTrace(&currentStack);
193 
194  std::cerr << "Abort" << std::endl;
195  for(unsigned int i = 1; i < currentStack.size(); i++) {
196  std::cerr << currentStack[i] << std::endl;
197  }
198 
199  exit(1);
200 }
201 
202 
203 void InterruptSignal(int) {
204  exit(1);
205 }
206 
207 #endif
Definition: Application.h:117
#define APPLICATION
Definition: Isis.h:38
void stopMonitoringMemory()
static void GetStackTrace(const void *)
Definition: IsisDebug.h:115
std::map< QString, void * > GuiHelpers()
Base include file for all Isis applications.
Definition: Isis.h:87
int main(int argc, char *argv[])
The programmer supplied main function.
Definition: Isis.h:109
void SegmentationFault(int)
static bool p_applicationForceGuiApp
Definition: Application.h:133
void Abort(int)
void startMonitoringMemory()
int Run(void(*funct)())
Runs the program defined in the function funct.
Definition: Application.cpp:193
void RegisterGuiHelpers(std::map< QString, void *> helpers)
Definition: Application.h:138
void InterruptSignal(int)