00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArSignalHandler.h"
00030 #include "ArLog.h"
00031
00032
00033 ArSignalHandler *ArSignalHandler::ourSignalHandler=0;
00034 ArStrMap ArSignalHandler::ourSigMap;
00035 std::list<ArFunctor1<int>*> ArSignalHandler::ourHandlerList;
00036
00037
00038 AREXPORT void ArSignalHandler::signalCB(int sig)
00039 {
00040 std::list<ArFunctor1<int>*>::iterator iter;
00041
00042 for (iter=ourHandlerList.begin(); iter != ourHandlerList.end(); ++iter)
00043 (*iter)->invoke(sig);
00044 if (ourHandlerList.begin() == ourHandlerList.end())
00045 ArLog::log(ArLog::Terse, "ArSignalHandler::runThread: No handler function. Unhandled signal '%s'", ourSigMap[sig].c_str());
00046 }
00047
00048 AREXPORT void ArSignalHandler::createHandlerNonThreaded()
00049 {
00050 }
00051
00052 AREXPORT void ArSignalHandler::createHandlerThreaded()
00053 {
00054 getHandler()->create(false);
00055 }
00056
00057 AREXPORT void ArSignalHandler::blockCommon()
00058 {
00059 }
00060
00061 AREXPORT void ArSignalHandler::unblockAll()
00062 {
00063 }
00064
00065 AREXPORT void ArSignalHandler::block(Signal sig)
00066 {
00067 }
00068
00069 AREXPORT void ArSignalHandler::unblock(Signal sig)
00070 {
00071 }
00072
00073 AREXPORT void ArSignalHandler::handle(Signal sig)
00074 {
00075 }
00076
00077 AREXPORT void ArSignalHandler::unhandle(Signal sig)
00078 {
00079 }
00080
00081 AREXPORT void ArSignalHandler::addHandlerCB(ArFunctor1<int> *func,
00082 ArListPos::Pos position)
00083 {
00084 if (position == ArListPos::FIRST)
00085 ourHandlerList.push_front(func);
00086 else if (position == ArListPos::LAST)
00087 ourHandlerList.push_back(func);
00088 else
00089 ArLog::log(ArLog::Terse,
00090 "ArSignalHandler::addHandler: Invalid position.");
00091 }
00092
00093 AREXPORT void ArSignalHandler::delHandlerCB(ArFunctor1<int> *func)
00094 {
00095 ourHandlerList.remove(func);
00096 }
00097
00101 AREXPORT void ArSignalHandler::delAllHandlerCBs(void)
00102 {
00103 ourHandlerList.clear();
00104 }
00105
00106
00107 AREXPORT ArSignalHandler * ArSignalHandler::getHandler()
00108 {
00109 if (!ourSignalHandler)
00110 ourSignalHandler=new ArSignalHandler;
00111
00112 return(ourSignalHandler);
00113 }
00114
00115 AREXPORT void ArSignalHandler::blockCommonThisThread()
00116 {
00117 }
00118
00119 AREXPORT void ArSignalHandler::blockAllThisThread()
00120 {
00121 }
00122
00123 ArSignalHandler::ArSignalHandler()
00124 {
00125 setThreadName("ArSignalHandler");
00126 initSigMap();
00127 }
00128
00129 ArSignalHandler::~ArSignalHandler()
00130 {
00131 }
00132
00133 AREXPORT void * ArSignalHandler::runThread(void *arg)
00134 {
00135 threadStarted();
00136 return(0);
00137 }
00138
00139 void ArSignalHandler::initSigMap()
00140 {
00141 ourSigMap[SigHUP]="SIGHUP";
00142 ourSigMap[SigINT]="SIGINT";
00143 ourSigMap[SigQUIT]="SIGQUIT";
00144 ourSigMap[SigILL]="SIGILL";
00145 ourSigMap[SigTRAP]="SIGTRAP";
00146 ourSigMap[SigABRT]="SIGABRT";
00147
00148 ourSigMap[SigBUS]="SIGBUS";
00149 ourSigMap[SigFPE]="SIGFPE";
00150 ourSigMap[SigKILL]="SIGKILL";
00151 ourSigMap[SigUSR1]="SIGUSR1";
00152 ourSigMap[SigSEGV]="SIGSEGV";
00153 ourSigMap[SigUSR2]="SIGUSR2";
00154 ourSigMap[SigPIPE]="SIGPIPE";
00155 ourSigMap[SigALRM]="SIGALRM";
00156 ourSigMap[SigTERM]="SIGTERM";
00157
00158 ourSigMap[SigCHLD]="SIGCHLD";
00159 ourSigMap[SigCONT]="SIGCONT";
00160 ourSigMap[SigSTOP]="SIGSTOP";
00161 ourSigMap[SigTSTP]="SIGTSTP";
00162 ourSigMap[SigTTIN]="SIGTTIN";
00163 ourSigMap[SigTTOU]="SIGTTOU";
00164 ourSigMap[SigURG]="SIGURG";
00165 ourSigMap[SigXCPU]="SIGXCPU";
00166 ourSigMap[SigXFSZ]="SIGXFSZ";
00167 ourSigMap[SigVTALRM]="SIGVTALRM";
00168 ourSigMap[SigPROF]="SIGPROF";
00169 ourSigMap[SigWINCH]="SIGWINCH";
00170 ourSigMap[SigIO]="SIGIO";
00171 ourSigMap[SigPWR]="SIGPWR";
00172 }
00173
00174 AREXPORT const char * ArSignalHandler::nameSignal(int sig)
00175 {
00176 return(ourSigMap[sig].c_str());
00177 }
00178
00179 AREXPORT void ArSignalHandler::logThread(void)
00180 {
00181 if (ourSignalHandler != NULL)
00182 ourSignalHandler->logThreadInfo();
00183 else
00184 ArLog::log(ArLog::Normal, "No signal handler thread running");
00185 }