Overview
Features
Download
Documentation
Community
Add-Ons & Services

Poco Subsystem, Application etc.

A general discussion forum.

Poco Subsystem, Application etc.

Postby gtbasher » 17 Sep 2012, 02:31

Hi there,

I have been looking at the Subsystem, Application and ServerApplication code and it is a little confusing. There is also a problem with the logic. Look at the following example:

Code: Select all
...

void Controller::initialize(Application &self)
{
   logger().information(std::string(name()) + " starting up.");
   ServerApplication::initialize(self);
}

void Controller::uninitialize()
{
   logger().information(std::string(name()) + " shutting down.");
   ServerApplication::uninitialize();
}

void Controller::reinitialize(Application &self)
{
   logger().information(std::string(name()) + " restarting.");
   ServerApplication::reinitialize(self);
}

int Controller::main(const std::vector<std::string> &args)
{
   if(!m_helpRequested)
   {
      //do application processing
      logger().information(std::string(name()) + " running.");
   }
   return Application::EXIT_OK;
}

void Controller::defineOptions(OptionSet &options)
{
   //stuff
}

void Controller::_handleHelp(const std::string &name,const std::string &value) {}
void Controller::_handleConfig(const std::string &name,const std::string &value) {}


Using the help flag on the command line ie:

Code: Select all
Controller -h


Prints

Code: Select all
usage: Controller OPTIONS
The controller application.

--daemon                    Run application as a daemon.
--pidfile=path              Write the process ID of the application to given
                            file.
-h, --help                  display help information
-cpath, --config_file=path  load configuration data from an XML file
Controller starting up.
Controller shutting down.


It doesn't make sense for the application to initialize if you only want to get help information. What if the initialization takes a long time. Reading through the docs says that the initialization is done like so in the Application class:

Runs the application by performing additional initializations and calling the main() method.
First calls initialize(), then calls main(), and finally calls uninitialize(). The latter will be called even if main() throws an exception. If initialize() throws an exception, main() will not be called and the exception will be propagated to the caller.


Which is a problem because when using the ServerApplication as a base class as that class itself has a run(int argc,char **argv) method.

As far as I can tell the only workaround is to use the m_helpRequested member variable to control whether the initialization code runs or not, which is obviously not a good idea.

I'm confused, there is an init method and an initialize method. Surely that's not helpful? Am I perhaps looking at this thing the wrong way?

There is also a slight problem with the arguments, the short argument (eg. -c) should have an '=' character between itself and it's argument type (ie. cpath should be c=path).
gtbasher
 
Posts: 8
Joined: 15 Sep 2012, 14:23

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron