class MainApplication

Library: Net Responsibility
Package: Core
Header: MainApplication.h

Description

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.

Inheritance

Direct Base Classes: ServerApplication

All Base Classes: ServerApplication

Member Summary

Member Functions: checkForRoot, defineOptions, displayHelp, getDatabase, getOptions, handleHelp, initialize, instance, main, setOption, setupLogger, signalHandler, terminateNicely, uninitialize

Constructors

MainApplication

MainApplication();

Default constructor. Sets some class variables and registers the Subsystems that are to be invoked.

Destructor

~MainApplication

~MainApplication();

Member Functions

getDatabase static

static Database & getDatabase();

A public static method to access the Database from any class.

getOptions static

static Options & getOptions();

A public static method to access the Options object from any class.

instance static

static MainApplication & instance();

A public static method to access this very instance from any class.

terminateNicely static

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.

checkForRoot protected

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.

defineOptions protected

void defineOptions(
    OptionSet & options
);

Defines all arguments that are accepted. These must be entered the Unix style: —argument=value or -avalue.

displayHelp protected

void displayHelp();

handleHelp protected

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.

initialize protected

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.

main protected

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.

setOption protected

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.

setupLogger protected

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.

signalHandler protected static

static void signalHandler(
    int sig = - 1
);

The signal handler. Masks all possible signals, and catches them properly, by logging the shutdown in the Database.

uninitialize protected

void uninitialize();