MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
Public Member Functions | Static Public Attributes | Static Private Member Functions | Private Attributes
Util::Config Class Reference

Deals with parsing configuration from commandline options. More...

#include <config.h>

Public Member Functions

 Config ()
 
 Config ()
 
 Config (std::string cmd)
 Creates a new configuration manager. More...
 
 Config (std::string cmd)
 
void activate ()
 Activated the stored config. More...
 
void activate ()
 
void addBasicConnectorOptions (JSON::Value &capabilities)
 
void addBasicConnectorOptions (JSON::Value &capabilities)
 Adds the default connector options. Also updates the capabilities structure with the default options. More...
 
void addConnectorOptions (int port, JSON::Value &capabilities)
 Adds the default connector options. More...
 
void addConnectorOptions (int port, JSON::Value &capabilities)
 
void addOption (std::string optname, JSON::Value option)
 
void addOption (std::string optname, JSON::Value option)
 Adds an option to the configuration parser. More...
 
int forkServer (Socket::Server &server_socket, int(*callback)(Socket::Connection &S))
 
int forkServer (Socket::Server &server_socket, int(*callback)(Socket::Connection &S))
 
bool getBool (std::string optname)
 Returns the current value of an option or default if none was set as a bool. More...
 
bool getBool (std::string optname)
 
long long int getInteger (std::string optname)
 Returns the current value of an option or default if none was set as a long long int. More...
 
long long int getInteger (std::string optname)
 
JSON::ValuegetOption (std::string optname, bool asArray=false)
 Returns a reference to the current value of an option or default if none was set. More...
 
JSON::ValuegetOption (std::string optname, bool asArray=false)
 
std::string getString (std::string optname)
 
std::string getString (std::string optname)
 Returns the current value of an option or default if none was set as a string. More...
 
bool parseArgs (int &argc, char **&argv)
 Parses commandline arguments. More...
 
bool parseArgs (int &argc, char **&argv)
 
void printHelp (std::ostream &output)
 Prints a usage message to the given output. More...
 
void printHelp (std::ostream &output)
 
int serveForkedSocket (int(*callback)(Socket::Connection &S))
 
int serveForkedSocket (int(*callback)(Socket::Connection &S))
 
int servePlainSocket (int(*callback)(Socket::Connection &S))
 
int servePlainSocket (int(*callback)(Socket::Connection &S))
 
int serveThreadedSocket (int(*callback)(Socket::Connection &S))
 
int serveThreadedSocket (int(*callback)(Socket::Connection &S))
 
int threadServer (Socket::Server &server_socket, int(*callback)(Socket::Connection &S))
 
int threadServer (Socket::Server &server_socket, int(*callback)(Socket::Connection &S))
 

Static Public Attributes

static bool is_active = false
 Set to true by activate(), set to false by the signal handler. More...
 
static unsigned int printDebugLevel = DEBUG
 

Static Private Member Functions

static void signal_handler (int signum, siginfo_t *sigInfo, void *ignore)
 Basic signal handler. More...
 
static void signal_handler (int signum, siginfo_t *sigInfo, void *ignore)
 

Private Attributes

int long_count
 
JSON::Value vals
 Holds all current config values. More...
 

Detailed Description

Deals with parsing configuration from commandline options.

Constructor & Destructor Documentation

Util::Config::Config ( )
Util::Config::Config ( std::string  cmd)

Creates a new configuration manager.

Util::Config::Config ( )
Util::Config::Config ( std::string  cmd)

Member Function Documentation

void Util::Config::activate ( )

Activated the stored config.

This will:

  • Drop permissions to the stored "username", if any.
  • Daemonize the process if "daemonize" exists and is true.
  • Set is_active to true.
  • Set up a signal handler to set is_active to false for the SIGINT, SIGHUP and SIGTERM signals.
void Util::Config::activate ( )
void Util::Config::addBasicConnectorOptions ( JSON::Value capabilities)

Adds the default connector options. Also updates the capabilities structure with the default options.

void Util::Config::addBasicConnectorOptions ( JSON::Value capabilities)
void Util::Config::addConnectorOptions ( int  port,
JSON::Value capabilities 
)

Adds the default connector options.

Also updates the capabilities structure with the default options. Besides the options addBasicConnectorOptions adds, this function also adds port and interface options.

void Util::Config::addConnectorOptions ( int  port,
JSON::Value capabilities 
)
void Util::Config::addOption ( std::string  optname,
JSON::Value  option 
)

Adds an option to the configuration parser.

The option needs an unique name (doubles will overwrite the previous) and can contain the following in the option itself:

{
"short":"o", //The short option letter
"long":"onName", //The long option
"short_off":"n", //The short option-off letter
"long_off":"offName", //The long option-off
"arg":"integer", //The type of argument, if required.
"value":[], //The default value(s) for this option if it is not given on the commandline.
"arg_num":1, //The count this value has on the commandline, after all the options have been processed.
"help":"Blahblahblah" //The helptext for this option.
}
void Util::Config::addOption ( std::string  optname,
JSON::Value  option 
)
int Util::Config::forkServer ( Socket::Server server_socket,
int(*)(Socket::Connection &S)  callback 
)
int Util::Config::forkServer ( Socket::Server server_socket,
int(*)(Socket::Connection &S)  callback 
)
bool Util::Config::getBool ( std::string  optname)

Returns the current value of an option or default if none was set as a bool.

Calls getOption internally.

bool Util::Config::getBool ( std::string  optname)
long long int Util::Config::getInteger ( std::string  optname)
long long int Util::Config::getInteger ( std::string  optname)

Returns the current value of an option or default if none was set as a long long int.

Calls getOption internally.

JSON::Value & Util::Config::getOption ( std::string  optname,
bool  asArray = false 
)

Returns a reference to the current value of an option or default if none was set.

If the option does not exist, this exits the application with a return code of 37.

JSON::Value& Util::Config::getOption ( std::string  optname,
bool  asArray = false 
)
std::string Util::Config::getString ( std::string  optname)
std::string Util::Config::getString ( std::string  optname)

Returns the current value of an option or default if none was set as a string.

Calls getOption internally.

bool Util::Config::parseArgs ( int &  argc,
char **&  argv 
)
bool Util::Config::parseArgs ( int &  argc,
char **&  argv 
)

Parses commandline arguments.

Calls exit if an unknown option is encountered, printing a help message.

void Util::Config::printHelp ( std::ostream &  output)
void Util::Config::printHelp ( std::ostream &  output)

Prints a usage message to the given output.

int Util::Config::serveForkedSocket ( int(*)(Socket::Connection &S)  callback)
int Util::Config::serveForkedSocket ( int(*)(Socket::Connection &S)  callback)
int Util::Config::servePlainSocket ( int(*)(Socket::Connection &S)  callback)
int Util::Config::servePlainSocket ( int(*)(Socket::Connection &S)  callback)
int Util::Config::serveThreadedSocket ( int(*)(Socket::Connection &S)  callback)
int Util::Config::serveThreadedSocket ( int(*)(Socket::Connection &S)  callback)
void Util::Config::signal_handler ( int  signum,
siginfo_t *  sigInfo,
void *  ignore 
)
staticprivate

Basic signal handler.

Sets is_active to false if it receives a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD signal, and ignores all other signals.

static void Util::Config::signal_handler ( int  signum,
siginfo_t *  sigInfo,
void *  ignore 
)
staticprivate
int Util::Config::threadServer ( Socket::Server server_socket,
int(*)(Socket::Connection &S)  callback 
)
int Util::Config::threadServer ( Socket::Server server_socket,
int(*)(Socket::Connection &S)  callback 
)

Field Documentation

static bool Util::Config::is_active = false
static

Set to true by activate(), set to false by the signal handler.

int Util::Config::long_count
private
static unsigned int Util::Config::printDebugLevel = DEBUG
static
JSON::Value Util::Config::vals
private

Holds all current config values.


The documentation for this class was generated from the following files: