From: Christian P. <cp...@us...> - 2005-04-23 17:51:02
|
Update of /cvsroot/pclasses/pclasses2/src/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5601/src/App Modified Files: SimpleApp.cpp BackgroundApp.cpp Log Message: - Use new signal handling code Index: BackgroundApp.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/BackgroundApp.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- BackgroundApp.cpp 24 Jan 2005 22:58:39 -0000 1.2 +++ BackgroundApp.cpp 23 Apr 2005 17:50:53 -0000 1.3 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005 by Christian Prochnow * + * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * @@ -20,19 +20,32 @@ #include "pclasses/App/BackgroundApp.h" #include <iostream> -#include <signal.h> - #ifndef WIN32 # include <sys/types.h> # include <sys/stat.h> # include <fcntl.h> +# include "../System/SignalListener.h" #endif namespace P { namespace App { +#ifndef WIN32 +class ReloadSignalHandler: public System::SignalListener { + public: + ReloadSignalHandler() + : SignalListener(SIGHUP) { } + + void onSignal(const sigval& sv) + { + BackgroundApp& app = static_cast<BackgroundApp&>(theApp()); + app.reload(); + } +}; +#endif + BackgroundApp::BackgroundApp(const AppDetails& details) throw() : SimpleApp(details), _cmdLineParser() { @@ -166,9 +179,9 @@ int ret = SimpleApp::init(argc, argv); if(ret) return ret; - #ifdef SIGHUP - ::signal(SIGHUP, SimpleApp::signalHandler); - #endif +#ifndef WIN32 + new ReloadSignalHandler(); +#endif try { @@ -224,16 +237,6 @@ { } -void BackgroundApp::signal(int sig) -{ - SimpleApp::signal(sig); - - #ifdef SIGHUP - if(sig == SIGHUP) - reload(); - #endif -} - void BackgroundApp::reload() { } Index: SimpleApp.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/SimpleApp.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SimpleApp.cpp 27 Feb 2005 17:19:10 -0000 1.5 +++ SimpleApp.cpp 23 Apr 2005 17:50:53 -0000 1.6 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004 by Christian Prochnow * + * Copyright (C) 2004,2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * @@ -20,10 +20,11 @@ #include "pclasses/System/EventQueue.h" #include "pclasses/App/SimpleApp.h" -#include <signal.h> +#include <iostream> #ifndef WIN32 # include "../System/FdListener.h" +# include "../System/SignalListener.h" #endif namespace P { @@ -66,26 +67,31 @@ return ret; } +#ifndef WIN32 +class TermSignalHandler: public System::SignalListener { + public: + TermSignalHandler(int sig) + : SignalListener(sig) { } + + void onSignal(const sigval& sv) + { + theApp().stop(1); + } +}; +#endif + int SimpleApp::init(int argc, char* argv[]) { - #ifdef WIN32 - { - //SetConsoleCtrlHandler((PHANDLER_ROUTINE)SIGTERM_handler, TRUE); - } - #endif - -// System::EventQueue& evq = System::EventQueue::instance(); -// System::FdListenerList& lst = System::FdListenerList::instance(evq); + // these calls create the main-thread instance of EventQueue and + // the file-descriptor listeners list + System::EventQueue& evq = System::EventQueue::instance(); + System::FdListenerList::instance(evq); - #ifdef SIGTERM - ::signal(SIGTERM, &signalHandler); - #endif - #ifdef SIGQUIT - ::signal(SIGQUIT, &signalHandler); - #endif - #ifdef SIGINT - ::signal(SIGINT, &signalHandler); - #endif +#ifndef WIN32 + new TermSignalHandler(SIGQUIT); + new TermSignalHandler(SIGINT); + new TermSignalHandler(SIGTERM); +#endif return 0; } @@ -121,44 +127,9 @@ { } -PCLASSES_RETSIGTYPE SimpleApp::signalHandler(int sig) -{ - #ifdef WIN32 - { - _theApp->signal(sig); - } - #else - { - ::signal(sig, SIG_IGN); - _theApp->signal(sig); - ::signal(sig, &signalHandler); - } - #endif -} - -void SimpleApp::signal(int sig) -{ - switch(sig) - { - #ifdef SIGTERM - case SIGTERM: - #endif - #ifdef SIGQUIT - case SIGQUIT: - #endif - #ifdef SIGINT - case SIGINT: - stop(1); - break; - #endif - default: - break; - } -} - -SimpleApp* theApp() throw() +SimpleApp& theApp() throw() { - return SimpleApp::_theApp; + return *SimpleApp::_theApp; } } // !namespace App |