Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Files | Functions
Initialization

Detailed Description

Functions called during program startup.

Programs using the OLA libraries should call either ServerInit() or AppInit(). There are also extra functions to help with installing signal handlers and daemonizing a process.

Example
// For client applications
AppInit(argc, argv);
// For server applications
ServerInit(argc, argv, &export_map);

Files

file  Init.cpp
file  Init.h
 Functions called during program startup.

Functions

bool ola::ServerInit (int argc, char *argv[], ExportMap *export_map)
 Used to initialize a server.
bool ola::ServerInit (int *argc, char *argv[], ExportMap *export_map, const std::string &first_line, const std::string &description)
 Used to initialize a server. Installs the SEGV handler, initializes the random number generator and populates the export map. Also sets the help string for the program, parses flags and initialises logging from flags.
bool ola::AppInit (int *argc, char *argv[], const std::string &first_line, const std::string &description)
 Used to initialize a application. Installs the SEGV handler and initializes the random number generator, sets the help string for the program, parses flags and initialises logging from flags.
bool ola::NetworkInit ()
 Perform platform-specific initialization of the networking subsystem.
bool ola::InstallSignal (int signal, void(*fp)(int signo))
 Install a signal handler.
bool ola::InstallSEGVHandler ()
 Install signal handlers to deal with SIGBUS & SIGSEGV.
void ola::InitExportMap (int argc, char *argv[], ExportMap *export_map)
 Populate the ExportMap with a couple of basic variables.
void ola::Daemonise ()
 Run as a daemon.

Function Documentation

bool ola::AppInit ( int *  argc,
char *  argv[],
const std::string &  first_line,
const std::string &  description 
)

Used to initialize a application. Installs the SEGV handler and initializes the random number generator, sets the help string for the program, parses flags and initialises logging from flags.

Parameters
argcargument count
argvpointer to the argument strings
first_linethe inital line that is displayed in the help section. This is displayed after argv[0].
descriptiona multiline description of the program
Returns
true on success and false otherwise
Note
If you are a server then call ServerInit() instead.
See Also
ola::SetHelpString ola::ParseFlags ola::InitLoggingFromFlags
void ola::Daemonise ( )

Run as a daemon.

Daemonize logs messages if it fails, so it's best to initialize the logging system (ola::InitLogging) before calling. However Daemonize() closes all open file descriptors so stdout/stderr will point to /dev/null in the daemon process. Therefore daemons should always use syslog logging.

If we can't daemonize the process is terminated.

See logging.

See Also
Logging
void ola::InitExportMap ( int  argc,
char *  argv[],
ExportMap *  export_map 
)

Populate the ExportMap with a couple of basic variables.

Parameters
argcargument count
argvpointer to the arugment strings
export_mapExportMap to populate

This is called by ServerInit(). It sets the following variables:

  • binary: name of the binary.
  • cmd-line: command line used to start the binary
  • fd-limit: the max number of file descriptors
bool ola::InstallSEGVHandler ( )

Install signal handlers to deal with SIGBUS & SIGSEGV.

Returns
true on success and false otherwise

On receiving a SIGBUS or SIGSEGV a stack trace will be printed.

bool ola::InstallSignal ( int  signal,
void(*)(int signo)  fp 
)

Install a signal handler.

Parameters
signalthe signal number to catch
fpis a function pointer to the handler
Returns
true on success and false otherwise
bool ola::NetworkInit ( )

Perform platform-specific initialization of the networking subsystem.

This method is called by ServerInit() and AppInit(), so you only need to call this yourself if you're not using those.

Returns
true on success and false otherwise
bool ola::ServerInit ( int  argc,
char *  argv[],
ExportMap *  export_map 
)

Used to initialize a server.

Parameters
argcargument count
argvpointer to argument strings
export_mapan optional pointer to an ExportMap
Returns
true on success and false otherwise
Note
If you are a client/application then call AppInit() instead.

This does the following:

  • installs the SEGV handler
  • initializes the random number generator
  • sets the thread scheduling options
  • populates the export map
  • initializes the network stack (Windows only).
bool ola::ServerInit ( int *  argc,
char *  argv[],
ExportMap *  export_map,
const std::string &  first_line,
const std::string &  description 
)

Used to initialize a server. Installs the SEGV handler, initializes the random number generator and populates the export map. Also sets the help string for the program, parses flags and initialises logging from flags.

Parameters
argcargument count
argvpointer to argument strings
export_mapan optional pointer to an ExportMap
first_linethe inital line that is displayed in the help section. This is displayed after argv[0].
descriptiona multiline description of the program
Returns
true on success and false otherwise
Note
If you are a client/application then call AppInit() instead.
See Also
ola::SetHelpString ola::ParseFlags ola::InitLoggingFromFlags