Win32 implementation of IArchDaemon. More...
#include <CArchDaemonWindows.h>
Inherits IArchDaemon.
Classes | |
| class | XArchDaemonRunFailed |
Public Types | |
| typedef int(* | RunFunc )(void) |
Public Member Functions | |
| virtual void | installDaemon (const char *name, const char *description, const char *pathname, const char *commandLine, const char *dependencies, bool allUsers) |
| Install daemon. | |
| virtual void | uninstallDaemon (const char *name, bool allUsers) |
| Uninstall daemon. | |
| virtual void | installDaemon () |
| Install daemon. | |
| virtual void | uninstallDaemon () |
| Uninstall daemon. | |
| virtual int | daemonize (const char *name, DaemonFunc func) |
| Daemonize the process. | |
| virtual bool | canInstallDaemon (const char *name, bool allUsers) |
| Check if user has permission to install the daemon. | |
| virtual bool | isDaemonInstalled (const char *name, bool allUsers) |
| Check if the daemon is installed. | |
| std::string | commandLine () const |
| Get the command line. | |
Static Public Member Functions | |
| static int | runDaemon (RunFunc runFunc) |
| Run the daemon. | |
| static void | daemonRunning (bool running) |
| Indicate daemon is in main loop. | |
| static void | daemonFailed (int result) |
| Indicate failure of running daemon. | |
| static UINT | getDaemonQuitMessage () |
| Get daemon quit message. | |
Win32 implementation of IArchDaemon.
Definition at line 33 of file CArchDaemonWindows.h.
| bool CArchDaemonWindows::canInstallDaemon | ( | const char * | name, | |
| bool | allUsers | |||
| ) | [virtual] |
Check if user has permission to install the daemon.
Returns true iff the caller has permission to install or uninstall the daemon. Note that even if this method returns true it's possible that installing/uninstalling the service may still fail. This method ignores whether or not the service is already installed.
Implements IArchDaemon.
Definition at line 347 of file CArchDaemonWindows.cpp.
References CArchMiscWindows::closeKey(), and CArchMiscWindows::isWindows95Family().
| std::string CArchDaemonWindows::commandLine | ( | ) | const [inline, virtual] |
Get the command line.
Gets the command line with which the application was started.
Implements IArchDaemon.
Definition at line 91 of file CArchDaemonWindows.h.
| void CArchDaemonWindows::daemonFailed | ( | int | result | ) | [static] |
Indicate failure of running daemon.
The runFunc passed to runDaemon() should call this function to indicate failure. result is returned by daemonize().
Definition at line 74 of file CArchDaemonWindows.cpp.
| int CArchDaemonWindows::daemonize | ( | const char * | name, | |
| DaemonFunc | func | |||
| ) | [virtual] |
Daemonize the process.
Daemonize. Throw XArchDaemonFailed on error. name is the name of the daemon. Once daemonized, func is invoked and daemonize returns when and what it does.
Exactly what happens when daemonizing depends on the platform.
func gets passed one argument, the name passed to daemonize(). func is only called when the service is actually started. func must call CArchMiscWindows::runDaemon() to finally becoming a service. The runFunc function passed to runDaemon() must call CArchMiscWindows::daemonRunning(true) when it enters the main loop (i.e. after initialization) and CArchMiscWindows::daemonRunning(false) when it leaves the main loop. The stopFunc function passed to runDaemon() is called when the daemon must exit the main loop and it must cause runFunc to return. func should return what runDaemon() returns. func or runFunc can call CArchMiscWindows::daemonFailed() to indicate startup failure. Implements IArchDaemon.
Definition at line 283 of file CArchDaemonWindows.cpp.
References CArchMiscWindows::isWindows95Family().
| void CArchDaemonWindows::daemonRunning | ( | bool | running | ) | [static] |
Indicate daemon is in main loop.
The runFunc passed to runDaemon() should call this function to indicate when it has entered (running is true) or exited (running is false) the main loop.
Definition at line 51 of file CArchDaemonWindows.cpp.
| UINT CArchDaemonWindows::getDaemonQuitMessage | ( | ) | [static] |
Get daemon quit message.
The windows NT daemon tells daemon thread to exit by posting this message to it. The thread must, of course, have a message queue for this to work.
Definition at line 63 of file CArchDaemonWindows.cpp.
| void CArchDaemonWindows::installDaemon | ( | const char * | name, | |
| const char * | description, | |||
| const char * | pathname, | |||
| const char * | commandLine, | |||
| const char * | dependencies, | |||
| bool | allUsers | |||
| ) | [virtual] |
Install daemon.
Install a daemon. name is the name of the daemon passed to the system and description is a short human readable description of the daemon. pathname is the path to the daemon executable. commandLine should not include the name of program as the first argument. If allUsers is true then the daemon will be installed to start at boot time, otherwise it will be installed to start when the current user logs in. If dependencies is not NULL then it's a concatenation of NUL terminated other daemon names followed by a NUL; the daemon will be configured to startup after the listed daemons. Throws an XArchDaemon exception on failure.
Implements IArchDaemon.
Definition at line 86 of file CArchDaemonWindows.cpp.
References CArchMiscWindows::addKey(), CArchMiscWindows::closeKey(), CArchMiscWindows::isWindows95Family(), CArchMiscWindows::setValue(), and uninstallDaemon().
| void CArchDaemonWindows::installDaemon | ( | ) | [virtual] |
Install daemon.
Installs the default daemon.
Implements IArchDaemon.
Definition at line 815 of file CArchDaemonWindows.cpp.
References isDaemonInstalled().
| bool CArchDaemonWindows::isDaemonInstalled | ( | const char * | name, | |
| bool | allUsers | |||
| ) | [virtual] |
Check if the daemon is installed.
Returns true iff the daemon is installed.
Implements IArchDaemon.
Definition at line 379 of file CArchDaemonWindows.cpp.
Referenced by installDaemon(), and uninstallDaemon().
| int CArchDaemonWindows::runDaemon | ( | RunFunc | runFunc | ) | [static] |
Run the daemon.
When the client calls daemonize(), the DaemonFunc should call this function after initialization and argument parsing to perform the daemon processing. The runFunc should perform the daemon's main loop, calling daemonRunning(true) when it enters the main loop (i.e. after initialization) and daemonRunning(false) when it leaves the main loop. The runFunc is called in a new thread and when the daemon must exit the main loop due to some external control the getDaemonQuitMessage() is posted to the thread. This function returns what runFunc returns. runFunc should call daemonFailed() if the daemon fails.
Definition at line 43 of file CArchDaemonWindows.cpp.
| void CArchDaemonWindows::uninstallDaemon | ( | const char * | name, | |
| bool | allUsers | |||
| ) | [virtual] |
Uninstall daemon.
Uninstall a daemon. Throws an XArchDaemon on failure.
Implements IArchDaemon.
Definition at line 198 of file CArchDaemonWindows.cpp.
References CArchMiscWindows::closeKey(), CArchMiscWindows::deleteKey(), CArchMiscWindows::deleteValue(), isDaemonInstalled(), CArchMiscWindows::isWindows95Family(), and CArchMiscWindows::openKey().
| void CArchDaemonWindows::uninstallDaemon | ( | ) | [virtual] |
Uninstall daemon.
Uninstalls the default daemon.
Implements IArchDaemon.
Definition at line 828 of file CArchDaemonWindows.cpp.
References isDaemonInstalled().
Referenced by installDaemon().
1.7.1