Update of /cvsroot/pclasses/pclasses2/src/App
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3902/src/App
Modified Files:
BackgroundApp.cpp CmdLine.cpp
Log Message:
Move background forking into BackgroundApp::daemonize().
More CmdLine work.
Index: BackgroundApp.cpp
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/src/App/BackgroundApp.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- BackgroundApp.cpp 18 Jan 2005 17:50:05 -0000 1.1
+++ BackgroundApp.cpp 24 Jan 2005 22:58:39 -0000 1.2
@@ -19,8 +19,10 @@
***************************************************************************/
#include "pclasses/App/BackgroundApp.h"
+#include <iostream>
#include <signal.h>
+
#ifndef WIN32
# include <sys/types.h>
# include <sys/stat.h>
@@ -32,7 +34,7 @@
namespace App {
BackgroundApp::BackgroundApp(const AppDetails& details) throw()
-: SimpleApp(details)
+: SimpleApp(details), _cmdLineParser()
{
}
@@ -149,6 +151,16 @@
}
#endif
+void BackgroundApp::setCommandLineOpts(CmdLineOption* opts[])
+{
+ _cmdLineParser.setOptions(opts);
+}
+
+void BackgroundApp::showCommandLineHelp()
+{
+ _cmdLineParser.dumpHelp(std::cout);
+}
+
int BackgroundApp::init(int argc, char* argv[])
{
int ret = SimpleApp::init(argc, argv);
@@ -158,6 +170,21 @@
::signal(SIGHUP, SimpleApp::signalHandler);
#endif
+ try
+ {
+ _cmdLineParser.parse(argc, argv);
+ }
+ catch(CmdLineError& err)
+ {
+ showCommandLineHelp();
+ return 1;
+ }
+
+ return 0;
+}
+
+void BackgroundApp::daemonize()
+{
#ifdef WIN32
{
// connect to the service controller ...
@@ -187,8 +214,6 @@
dup2(nullfd, 2);
}
#endif
-
- return 0;
}
void BackgroundApp::cleanup()
Index: CmdLine.cpp
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/src/App/CmdLine.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CmdLine.cpp 21 Jan 2005 09:21:07 -0000 1.5
+++ CmdLine.cpp 24 Jan 2005 22:58:42 -0000 1.6
@@ -131,10 +131,15 @@
{
}
+void CmdLineParser::setOptions(CmdLineOption* opts[])
+{
+ _opts = opts;
+}
+
CmdLineOption* findOptShort(CmdLineOption* opts[], std::string& shortOpt)
{
int i = 0;
- while(opts[i])
+ while(opts && opts[i])
{
if(opts[i]->shortName() == shortOpt)
return opts[i];
@@ -148,7 +153,7 @@
CmdLineOption* findOptLong(CmdLineOption* opts[], std::string& longOpt)
{
int i = 0;
- while(opts[i])
+ while(opts && opts[i])
{
if(opts[i]->longName() == longOpt)
return opts[i];
@@ -172,6 +177,8 @@
void CmdLineParser::parse(int argc, char* argv[]) throw(CmdLineError)
{
_unnamedValues.clear();
+ if(!_opts)
+ return;
CmdLineOption* opt = 0;
std::list<CmdLineOption*> foundOpts;
|