Library: Net Responsibility
Package: Core
Header: MainApplication.h
MainApplication is the skeleton of Net Responsibility. This is where all Options are processed, the Database loaded, the Logger set up, the signals handled and the Subsystems called.
MainApplication is derived from Poco::Util::ServerApplication, which also takes care of making the instance a daemon or service, if requested.
Direct Base Classes: Poco::Util::ServerApplication
All Base Classes: Poco::RefCountedObject, Poco::Util::Application, Poco::Util::ServerApplication, Poco::Util::Subsystem
Member Functions: checkForRoot, defineOptions, displayHelp, getDatabase, getOptions, handleHelp, initialize, instance, main, setOption, setupLogger, signalHandler, terminateNicely, uninitialize
Inherited Functions: addSubsystem, commandName, config, defineOptions, duplicate, findFile, getSubsystem, handleOption, init, initialize, initialized, instance, isInteractive, loadConfiguration, logger, main, name, options, referenceCount, reinitialize, release, run, setLogger, setUnixOptions, startTime, stopOptionsProcessing, terminate, uninitialize, uptime, waitForTerminationRequest
Default constructor. Sets some class variables and registers the Subsystems that are to be invoked.
~MainApplication();
static Database & getDatabase();
A public static method to access the Database from any class.
static Options & getOptions();
A public static method to access the Options object from any class.
static MainApplication & instance();
A public static method to access this very instance from any class.
static void terminateNicely(
bool deletePidfile = false
);
Terminate Net Responsibility nicely. This unmasks all singals, deleted the pidfile if told to, and tells the instance to shut down.
void checkForRoot();
Checks if the user who started the program is having enough priviligues. In Linux you'll need to be running Net Responsibility as root.
void defineOptions(
OptionSet & options
);
Defines all arguments that are accepted. These must be entered the Unix style: —argument=value or -avalue.
void displayHelp();
void handleHelp(
const string & name,
const string & value
);
This method is called if the —help argument is specified. It will only print out all available arguments with displayHelp() and exit.
void initialize(
Application & self
);
Invokes a set of methods and constructs Options and Database. A short glimpse of the actual code will reveal pretty much what it does.
See also: Poco::Util::Application::initialize()
int main(
const vector < string > & args
);
The main method invoked after the Subsystems are run. At this moment it is more or less redundent, since all the actual code is run inside the Subsystems.
void setOption(
const string & name,
const string & value
);
The default way that Poco handles configurations is not ideal for our purposes. It's way to flexible for accountability softwares. Therefor the options are processed in Options. However, some global values are specified in the default config system. This is because they're easliy reached from any class. setOption() is used to store these global values.
void setupLogger();
Sets up the Logger. This is done differently on on different platforms. Unix platforms will talk to syslog by default. If the instance is not running as a daemon/service, all messages will be sent to stdout instead. If a specific logfile is specified, the messages will go there.
static void signalHandler(
int sig = - 1
);
The signal handler. Masks all possible signals, and catches them properly, by logging the shutdown in the Database.
void uninitialize();
See also: Poco::Util::Application::uninitialize()