Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArSignalHandler_WIN.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
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   //ourSigMap[SigIOT]="SIGIOT";
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   //ourSigMap[SigSTKFLT]="SIGSTKFLT";
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 }

Generated on Tue Feb 20 10:51:41 2007 for Aria by  doxygen 1.4.0