ReplicaNet and RNLobby  1
Service.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef _SERVICE_H_
13 #define _SERVICE_H_
14 #include <string>
15 #include <list>
16 
17 namespace RNReplicaNet
18 {
19 
20 namespace RNLobby
21 {
22 
26 class Service
27 {
28 public:
31  Service(const char *internalServiceName,const char *displayServiceName);
32 
33  virtual ~Service();
34 
36  static void SetDebugNames(const char *internalServiceName,const char *displayServiceName);
37  static bool SetDebugOutput( const char *verboseDebugFile , const char *profileDebugFile , const char *errorDebugFile , const int fileSize );
40  static void SetRegistry(const char *name , const char *value , const bool userModifiableKey = false );
41  static void SetRegistry(const char *name , const int value , const bool userModifiableKey = false );
44  static bool GetRegistry(const char *name , std::string &value , const bool userModifiableKey = false);
45  static bool GetRegistry(const char *name , int &value , const bool userModifiableKey = false);
46 
53  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);
54 
56  static bool SetArgs(int argc = 0,char **argv = 0);
57 
59  static bool GetArgs(int &argc,char ** &argv);
60 
62  bool Start(void);
63 
65  bool Stop(void);
66 
68  bool Delete(void);
69 
73  bool Execute(const bool setCurrentDirectory = true,const bool storeLastDebugPrint = false);
74 
77  virtual int Main(int argc = 0,char **argv = 0) = 0;
78 
80  static void DebugPrint(const char *, ...);
82  static void DebugPrintNoParams(const char *);
83 
85  static void SetDebugLine(const char *buffer);
86 
88  static bool GetDebugLine(std::string &buffer);
89 
92  static bool GetDebugLine(const char *serviceName,std::string &buffer);
93 
96  static bool GetServiceList(std::list<std::string> &services);
97 
99  static void DebugOut(const char *, ...);
100 
102  static void DebugPrintFile(const char *text);
103 
104  // Gets CPU metrics for this process.
105  static void GetSystemCPUMetrics(float &userPercent, float &kernelPercent);
106 
107  // Gets the configured internal service name.
108  static const char *GetInternalServiceName(void);
109 
110  // Gets the configured display service name.
111  static const char *GetDisplayServiceName(void);
112 
113  static std::string GetFileVersion(void);
114  static std::string GetUserInfo(void);
115 
116 protected:
118  bool NeedToExitMain(void);
119 
120  static void CreateRegistry(void);
121 
122  static void DebugPrintCommon( char *buffer );
123  static void DebugPrintCommonStore( char *buffer );
124 private:
125 };
126 
127 } // namespace RNLobby
128 
129 } // namespace RNReplicaNet
130 
131 #endif
bool Stop(void)
Stops the service.
static void SetRegistry(const char *name, const char *value, const bool userModifiableKey=false)
virtual int Main(int argc=0, char **argv=0)=0
Definition: Service.h:26
static void DebugOut(const char *,...)
A utility function that allows the user to output debug information as the service is running...
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)
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 void SetDebugNames(const char *internalServiceName, const char *displayServiceName)
Sets the debug printing names without instantiating this class.
static bool GetRegistry(const char *name, std::string &value, const bool userModifiableKey=false)
bool Execute(const bool setCurrentDirectory=true, const bool storeLastDebugPrint=false)
static void DebugPrintFile(const char *text)
A utility function that allows the user to output debug information to a file.
bool Start(void)
Starts the service.
static void DebugPrintNoParams(const char *)
Same as DebugPrint except that the input text has no parameter parsing so it uses slightly less CPU t...
static bool GetDebugLine(std::string &buffer)
Retrieves the last line from DebugPrint for the current service.
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...
Service(const char *internalServiceName, const char *displayServiceName)
static void SetDebugLine(const char *buffer)
A utility function that allows the user to output debug information as the service is running...
static bool GetServiceList(std::list< std::string > &services)
bool NeedToExitMain(void)
Returns true if the Main function needs to exit. This must be tested fairly regularly by the Main fun...
bool Delete(void)
Deletes the service.