ReplicaNet and RNLobby
1
|
#include <Service.h>
Public Member Functions | |
Service (const char *internalServiceName, const char *displayServiceName) | |
bool | Create (const char *userName=0, const char *password=0, const bool autoStart=true, const bool restartOnError=true, const char *longDescription=0, const char *dependencies=0) |
bool | Start (void) |
Starts the service. | |
bool | Stop (void) |
Stops the service. | |
bool | Delete (void) |
Deletes the service. | |
bool | Execute (const bool setCurrentDirectory=true, const bool storeLastDebugPrint=false) |
virtual int | Main (int argc=0, char **argv=0)=0 |
Static Public Member Functions | |
static void | SetDebugNames (const char *internalServiceName, const char *displayServiceName) |
Sets the debug printing names without instantiating this class. | |
static bool | SetDebugOutput (const char *verboseDebugFile, const char *profileDebugFile, const char *errorDebugFile, const int fileSize) |
static void | SetRegistry (const char *name, const char *value, const bool userModifiableKey=false) |
static void | SetRegistry (const char *name, const int value, const bool userModifiableKey=false) |
static bool | GetRegistry (const char *name, std::string &value, const bool userModifiableKey=false) |
static bool | GetRegistry (const char *name, int &value, const bool userModifiableKey=false) |
static bool | SetArgs (int argc=0, char **argv=0) |
Sets the arguments to use for this service. On Windows platforms these are stored in the registry. | |
static bool | GetArgs (int &argc, char **&argv) |
Gets the arguments to use for this service. On Windows platforms these are stored in the registry. | |
static void | DebugPrint (const char *,...) |
A utility function that allows the user to output debug information as the service is running. This debug information is stored for display by RLSrvMonitor so do not use this to display confidential information. | |
static void | DebugPrintNoParams (const char *) |
Same as DebugPrint except that the input text has no parameter parsing so it uses slightly less CPU time and memory. | |
static void | SetDebugLine (const char *buffer) |
A utility function that allows the user to output debug information as the service is running. This gets set into the RLSrvMonitor/RLServerMonitor accessible debug line and should not be used for confidential information. | |
static bool | GetDebugLine (std::string &buffer) |
Retrieves the last line from DebugPrint for the current service. | |
static bool | GetDebugLine (const char *serviceName, std::string &buffer) |
static bool | GetServiceList (std::list< std::string > &services) |
static void | DebugOut (const char *,...) |
A utility function that allows the user to output debug information as the service is running. This does not get set into the RLSrvMonitor/RLServerMonitor accessible debug line and can be used for more confidential information. | |
static void | DebugPrintFile (const char *text) |
A utility function that allows the user to output debug information to a file. | |
static void | GetSystemCPUMetrics (float &userPercent, float &kernelPercent) |
static const char * | GetInternalServiceName (void) |
static const char * | GetDisplayServiceName (void) |
static std::string | GetFileVersion (void) |
static std::string | GetUserInfo (void) |
Protected Member Functions | |
bool | NeedToExitMain (void) |
Returns true if the Main function needs to exit. This must be tested fairly regularly by the Main function. | |
Static Protected Member Functions | |
static void | CreateRegistry (void) |
static void | DebugPrintCommon (char *buffer) |
static void | DebugPrintCommonStore (char *buffer) |
Implements a service. Only one instance of this class may be allocated in a process. On Windows platforms the service is executed by the service scheduler. On Linux platforms the service runs as a separate process.
Service | ( | const char * | internalServiceName, |
const char * | displayServiceName | ||
) |
Initialises this service with the parameters.
internalServiceName | If there are different platform builds of the same service it is a good idea, but not mandatory, to postfix internalServiceName with ".x32" or ".x64". The _SrvCommon.cpp file does this automatically. |
bool Create | ( | const char * | userName = 0 , |
const char * | password = 0 , |
||
const bool | autoStart = true , |
||
const bool | restartOnError = true , |
||
const char * | longDescription = 0 , |
||
const char * | dependencies = 0 |
||
) |
Creates and installs a service using this process.
userName | Optional user name (account) to use for this service installation. Otherwise the default local system account will be used. |
password | The password for the userName |
autoStart | When true the service will automatically start when the operating system starts. |
restartOnError | If true and the Main function generates an exception this will restart the service. |
longDescription | Optional human readable text description for this service. |
bool Execute | ( | const bool | setCurrentDirectory = true , |
const bool | storeLastDebugPrint = false |
||
) |
Call this to start running the application as a service
setCurrentDirectory | When true the service will set the current process directory to be the directory of the executable. This is to allow compatibility with processes that expect the current directory to be the execution directory. When false and running under Windows the current directory will most likely be something similar to WINDIR% depending on the OS version. |
storeLastDebugPrint | When true this stores the last debug print line in the registry. Useful as an aid to debugging. |
|
static |
Retrieves the last line from DebugPrint for a service name. If the service name is postfixed with ".x32" or ".x64" the relevant service is queried, otherwise the service matching the calling process type is queried.
|
static |
Gets the registry values for this service. If it fails value is left unchanged.
userModifiableKey | See SetRegistry for an explanation of this parameter. |
|
static |
Gets the list of service names that are installed. Can return the service name prefixed with "x32." or "x64." if the service is registered to a different process type.
|
pure virtual |
|
static |
Sets the registry values for this service
userModifiableKey | By default this is false and will access keys in the "Replica Software\Managed Services" service configuration area. When true this will access keys in the "User Modifiable" sub-key that has full access for the installed service user account. |