Go to the source code of this file.
Macros | |
#define | SERVICENAME "RXAPI" |
#define | SERVICEDESCRIPTION "%s Service for Open Object Rexx version %d.%d.%d" |
#define | SYNTAX_HELP |
#define | APP_LOG_KEYNAME "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" |
#define | WINDOWS_95_98_ME VER_PLATFORM_WIN32_WINDOWS |
Enumerations | |
enum | ServiceStateType { installed_state , running_state , disabled_state , uninstalled_state } |
enum | WindowsVersionType { Windows_NT , Windows_2K } |
Functions | |
void | setServiceDACL (SC_HANDLE hService) |
void | showMessage (const char *msg, unsigned int icon) |
bool | isAtLeastVersion (WindowsVersionType type) |
void | Run (bool asService) |
bool | OnInit () |
void | OnStop () |
void | OnInterrogate () |
void | OnPause () |
void | OnContinue () |
void | OnShutdown () |
BOOL | OnUserControl (DWORD dwOpcode) |
void | SetStatus (DWORD dwState) |
static void __cdecl | Handler (DWORD dwOpcode) |
bool | Initialize () |
static void WINAPI | ServiceMain (DWORD dwArgc, LPTSTR *lpszArgv) |
bool | startTheService (void) |
bool | stopTheService (SC_HANDLE hService, DWORD timeOut) |
bool | Install () |
bool | Uninstall () |
bool | serviceIsRunning (SC_HANDLE hService) |
ServiceStateType | getServiceState (void) |
bool | startAsWindowsService (void) |
void | processCmdLine (const char *cmdLine) |
int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) |
Variables | |
static SERVICE_STATUS_HANDLE | m_hServiceStatus |
static SERVICE_STATUS | m_Status |
static SERVICE_DESCRIPTION | Info |
APIServer | apiServer |
#define APP_LOG_KEYNAME "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" |
Definition at line 53 of file windows/APIService.cpp.
#define SERVICEDESCRIPTION "%s Service for Open Object Rexx version %d.%d.%d" |
Definition at line 44 of file windows/APIService.cpp.
#define SERVICENAME "RXAPI" |
Definition at line 43 of file windows/APIService.cpp.
#define SYNTAX_HELP |
Definition at line 46 of file windows/APIService.cpp.
#define WINDOWS_95_98_ME VER_PLATFORM_WIN32_WINDOWS |
Definition at line 113 of file windows/APIService.cpp.
enum ServiceStateType |
Enumerator | |
---|---|
installed_state | |
running_state | |
disabled_state | |
uninstalled_state |
Definition at line 55 of file windows/APIService.cpp.
enum WindowsVersionType |
Enumerator | |
---|---|
Windows_NT | |
Windows_2K |
Definition at line 56 of file windows/APIService.cpp.
ServiceStateType getServiceState | ( | void | ) |
Determines if: rxapi is installed as a service and is already running, is installed as a service but not running, installed but the service is currently disabled, or not installed as a service.
Definition at line 758 of file windows/APIService.cpp.
References disabled_state, installed_state, running_state, serviceIsRunning(), SERVICENAME, and uninstalled_state.
Referenced by processCmdLine(), and startAsWindowsService().
|
static |
The handler function registered with the Service Control dispatcher. The dispatcher uses this function to send service control messages to the service process.
dwOpcode | The control message. |
Definition at line 223 of file windows/APIService.cpp.
References m_hServiceStatus, m_Status, OnContinue(), OnInterrogate(), OnPause(), OnShutdown(), OnStop(), and SetStatus().
Referenced by ServiceMain().
bool Initialize | ( | ) |
Definition at line 255 of file windows/APIService.cpp.
References m_Status, OnInit(), and SetStatus().
Referenced by ServiceMain().
bool Install | ( | ) |
Install rxapi as a Windows service and add the registry entries to allow logging through the Event Log service.
Definition at line 522 of file windows/APIService.cpp.
References APP_LOG_KEYNAME, Info, isAtLeastVersion(), SERVICEDESCRIPTION, SERVICENAME, setServiceDACL(), and Windows_2K.
Referenced by processCmdLine().
bool isAtLeastVersion | ( | WindowsVersionType | type | ) |
Definition at line 115 of file windows/APIService.cpp.
References type, Windows_2K, WINDOWS_95_98_ME, and Windows_NT.
void OnContinue | ( | ) |
Definition at line 190 of file windows/APIService.cpp.
Referenced by Handler().
bool OnInit | ( | ) |
The following functions handle the Service control requests.
Definition at line 168 of file windows/APIService.cpp.
Referenced by Initialize().
void OnInterrogate | ( | ) |
Definition at line 180 of file windows/APIService.cpp.
Referenced by Handler().
void OnPause | ( | ) |
Definition at line 185 of file windows/APIService.cpp.
Referenced by Handler().
void OnShutdown | ( | ) |
Definition at line 195 of file windows/APIService.cpp.
Referenced by Handler().
void OnStop | ( | ) |
Definition at line 174 of file windows/APIService.cpp.
References apiServer, and APIServer::terminateServer().
Referenced by Handler().
BOOL OnUserControl | ( | DWORD | dwOpcode | ) |
Definition at line 200 of file windows/APIService.cpp.
void processCmdLine | ( | const char * | cmdLine | ) |
We have command line args, process them. Most likely the args are to install or uninstall rxapi as a service.
cmdLine | The command line, must not be null. |
Definition at line 875 of file windows/APIService.cpp.
References getServiceState(), Install(), SERVICENAME, showMessage(), SYNTAX_HELP, Uninstall(), and uninstalled_state.
Referenced by WinMain().
void Run | ( | bool | asService | ) |
Starts up the API server and has it listen for messages.
Run() is either called from ServiceMain() in which case the API server will be running in a Service process. If rxapi is not installed as a service, or for some reason the service can not be started, then Run() is called from WinMain() and the API server runs in a standard process.
asService | If true, Run() was called from ServiceMain(), otherwise Run() was called from WinMain(). |
Definition at line 150 of file windows/APIService.cpp.
References apiServer, APIServer::initServer(), APIServer::listenForConnections(), and APIServer::terminateServer().
Referenced by ServiceMain(), and WinMain().
bool serviceIsRunning | ( | SC_HANDLE | hService | ) |
Determines if the service is currently running.
If the current state is START PENDING will wait until the service is running or times out.
hService | Handle to the opened service. Note that the handle has to have been opened with SERVICE_QUERY_STATUS so that we can use QueryServiceStatusEx(). |
Definition at line 674 of file windows/APIService.cpp.
Referenced by getServiceState().
|
static |
After the service control dislpatcher receives a start request, (see startTheService(),) it creates a new thread and invokes this function on that thread to do the actual work of the service.
dwArgc | Count of args (not used by rxapi) |
lpszArgv | Args (not used by rxapi) |
Definition at line 287 of file windows/APIService.cpp.
References Handler(), Initialize(), m_hServiceStatus, m_Status, Run(), SERVICENAME, and SetStatus().
Referenced by startTheService().
void setServiceDACL | ( | SC_HANDLE | hService | ) |
Definition at line 439 of file windows/APIService.cpp.
Referenced by Install().
void SetStatus | ( | DWORD | dwState | ) |
Updates the Service Control Manager with our current state.
dwState | The current state. |
Definition at line 210 of file windows/APIService.cpp.
References m_hServiceStatus, and m_Status.
Referenced by Handler(), Initialize(), and ServiceMain().
|
inline |
Definition at line 108 of file windows/APIService.cpp.
References SERVICENAME.
Referenced by processCmdLine().
bool startAsWindowsService | ( | void | ) |
Start rxapi as a Windows Service, if possible. This function determines if rxapi is installed as a Service and if it is already running as a service.
If it is installled as a service, but not running, an attempt is made to start it as a Service.
Definition at line 813 of file windows/APIService.cpp.
References getServiceState(), installed_state, running_state, and startTheService().
Referenced by WinMain().
bool startTheService | ( | void | ) |
Connects the main thread of this service process to the Service Control Manager. When this function succeeds, it will not return until the rxapi Service is stopped.
Definition at line 330 of file windows/APIService.cpp.
References m_Status, ServiceMain(), and SERVICENAME.
Referenced by startAsWindowsService().
bool stopTheService | ( | SC_HANDLE | hService, |
DWORD | timeOut | ||
) |
If rxapi is currently running as a Service process, then stop it.
hService | Opened handle to the service. The handle must have been opened with SERVICE_QUERY_STATUS and SERVICE_STOP access rights. |
timeOut | Time to wait, in miliseconds for a pending stop to clear. |
Definition at line 366 of file windows/APIService.cpp.
Referenced by Uninstall().
bool Uninstall | ( | ) |
Deletes rxapi as a service and cleans up the registry entries that were made when rxapi was installed as a service.
Definition at line 618 of file windows/APIService.cpp.
References APP_LOG_KEYNAME, SERVICENAME, and stopTheService().
Referenced by processCmdLine().
int APIENTRY WinMain | ( | HINSTANCE | hInstance, |
HINSTANCE | hPrevInstance, | ||
LPSTR | lpCmdLine, | ||
int | nCmdShow | ||
) |
The main entry point for rxapi.exe.
When rxapi is installed as a service, the invoker might be the service control manager, or the interpreter could be starting rxapi as a service because rxapi was not running.
When rxapi is not installed as a service, then the invoker is most likely the interpreter starting up rxapi. Although, the user could also be invoking rxapi from the command line.
The third possibility is that rxapi is being invoked from the command line with arguments to either install, uninstall, or query rxapi as a service.
hInstance | |
hPrevInstance | |
lpCmdLine | The only arg we are interested in, the command line arguments. |
nCmdShow |
Definition at line 1003 of file windows/APIService.cpp.
References isAtLeastVersion(), processCmdLine(), Run(), startAsWindowsService(), and Windows_NT.
APIServer apiServer |
Definition at line 105 of file windows/APIService.cpp.
|
static |
Definition at line 64 of file windows/APIService.cpp.
Referenced by Install().
|
static |
Definition at line 62 of file windows/APIService.cpp.
Referenced by Handler(), ServiceMain(), and SetStatus().
|
static |
Definition at line 63 of file windows/APIService.cpp.
Referenced by Handler(), Initialize(), ServiceMain(), SetStatus(), and startTheService().