Changeset 2344 for code/branches/objecthierarchy2/src/util
- Timestamp:
- Dec 4, 2008, 8:28:14 PM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/util/SignalHandler.cc
r2171 r2344 35 35 #include "Debug.h" 36 36 37 #include <cassert>38 37 #include <iostream> 39 38 #include <cstdlib> … … 42 41 namespace orxonox 43 42 { 44 SignalHandler * SignalHandler::singletonRef= NULL;43 SignalHandler* SignalHandler::singletonRef_s = NULL; 45 44 } 46 45 … … 133 132 void SignalHandler::sigHandler( int sig ) 134 133 { 135 for ( SignalCallbackList::iterator it = SignalHandler::getInstance() ->callbackList.begin(); it != SignalHandler::getInstance()->callbackList.end(); it++ )134 for ( SignalCallbackList::iterator it = SignalHandler::getInstance().callbackList.begin(); it != SignalHandler::getInstance().callbackList.end(); it++ ) 136 135 { 137 136 (*(it->cb))( it->someData ); … … 184 183 if ( sigPid == 0 ) 185 184 { 186 getInstance() ->dontCatch();185 getInstance().dontCatch(); 187 186 // wait for message from parent when it has attached gdb 188 187 int someData; … … 237 236 238 237 char cmd[256]; 239 snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance() ->appName.c_str(), sigPid );238 snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance().appName.c_str(), sigPid ); 240 239 write( gdbIn[1], cmd, strlen(cmd) ); 241 240 … … 331 330 bt.insert(0, timeString); 332 331 333 FILE * f = fopen( getInstance() ->filename.c_str(), "a" );332 FILE * f = fopen( getInstance().filename.c_str(), "a" ); 334 333 335 334 if ( !f ) 336 335 { 337 perror( ( std::string( "could not append to " ) + getInstance() ->filename ).c_str() );336 perror( ( std::string( "could not append to " ) + getInstance().filename ).c_str() ); 338 337 exit(EXIT_FAILURE); 339 338 } … … 341 340 if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() ) 342 341 { 343 COUT(0) << "could not write " << bt.length() << " byte to " << getInstance() ->filename << std::endl;342 COUT(0) << "could not write " << bt.length() << " byte to " << getInstance().filename << std::endl; 344 343 exit(EXIT_FAILURE); 345 344 } -
code/branches/objecthierarchy2/src/util/SignalHandler.h
r2171 r2344 37 37 #include "UtilPrereqs.h" 38 38 39 #include <cassert> 39 40 #include <list> 40 41 #include <string> … … 68 69 class SignalHandler 69 70 { 70 private:71 SignalHandler();72 71 public: 73 inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; } 74 ~SignalHandler(){ SignalHandler::singletonRef = NULL; } 72 SignalHandler() { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; } 73 ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; } 74 inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; } 75 75 76 76 void registerCallback( SignalCallback cb, void * someData ); … … 87 87 SignalCallbackList callbackList; 88 88 89 static SignalHandler * singletonRef;89 static SignalHandler* singletonRef_s; 90 90 91 91 std::string appName; … … 104 104 { 105 105 public: 106 inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }; 107 void doCatch( const std::string & appName, const std::string & filename ) {}; 108 void dontCatch() {}; 109 void registerCallback( SignalCallback cb, void * someData ) {}; 106 SignalHandler() { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; } 107 ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; } 108 inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; } 109 void doCatch( const std::string & appName, const std::string & filename ) {} 110 void dontCatch() {} 111 void registerCallback( SignalCallback cb, void * someData ) {} 110 112 111 113 private: 112 static SignalHandler * singletonRef;114 static SignalHandler* singletonRef_s; 113 115 }; 114 116 }
Note: See TracChangeset
for help on using the changeset viewer.