| 1 | /* | 
|---|
| 2 | * synergy -- mouse and keyboard sharing utility | 
|---|
| 3 | * Copyright (C) 2002 Chris Schoeneman | 
|---|
| 4 | * | 
|---|
| 5 | * This package is free software; you can redistribute it and/or | 
|---|
| 6 | * modify it under the terms of the GNU General Public License | 
|---|
| 7 | * found in the file COPYING that should have accompanied this file. | 
|---|
| 8 | * | 
|---|
| 9 | * This package is distributed in the hope that it will be useful, | 
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 12 | * GNU General Public License for more details. | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | #ifndef IARCHDAEMON_H | 
|---|
| 16 | #define IARCHDAEMON_H | 
|---|
| 17 |  | 
|---|
| 18 | #include "IInterface.h" | 
|---|
| 19 |  | 
|---|
| 20 | //! Interface for architecture dependent daemonizing | 
|---|
| 21 | /*! | 
|---|
| 22 | This interface defines the operations required by synergy for installing | 
|---|
| 23 | uninstalling daeamons and daemonizing a process.  Each architecture must | 
|---|
| 24 | implement this interface. | 
|---|
| 25 | */ | 
|---|
| 26 | class IArchDaemon : public IInterface { | 
|---|
| 27 | public: | 
|---|
| 28 | typedef int                     (*DaemonFunc)(int argc, const char** argv); | 
|---|
| 29 |  | 
|---|
| 30 | //! @name manipulators | 
|---|
| 31 | //@{ | 
|---|
| 32 |  | 
|---|
| 33 | //! Install daemon | 
|---|
| 34 | /*! | 
|---|
| 35 | Install a daemon.  \c name is the name of the daemon passed to the | 
|---|
| 36 | system and \c description is a short human readable description of | 
|---|
| 37 | the daemon.  \c pathname is the path to the daemon executable. | 
|---|
| 38 | \c commandLine should \b not include the name of program as the | 
|---|
| 39 | first argument.  If \c allUsers is true then the daemon will be | 
|---|
| 40 | installed to start at boot time, otherwise it will be installed to | 
|---|
| 41 | start when the current user logs in.  If \p dependencies is not NULL | 
|---|
| 42 | then it's a concatenation of NUL terminated other daemon names | 
|---|
| 43 | followed by a NUL;  the daemon will be configured to startup after | 
|---|
| 44 | the listed daemons.  Throws an \c XArchDaemon exception on failure. | 
|---|
| 45 | */ | 
|---|
| 46 | virtual void            installDaemon(const char* name, | 
|---|
| 47 | const char* description, | 
|---|
| 48 | const char* pathname, | 
|---|
| 49 | const char* commandLine, | 
|---|
| 50 | const char* dependencies, | 
|---|
| 51 | bool allUsers) = 0; | 
|---|
| 52 |  | 
|---|
| 53 | //! Uninstall daemon | 
|---|
| 54 | /*! | 
|---|
| 55 | Uninstall a daemon.  Throws an \c XArchDaemon on failure. | 
|---|
| 56 | */ | 
|---|
| 57 | virtual void            uninstallDaemon(const char* name, bool allUsers) = 0; | 
|---|
| 58 |  | 
|---|
| 59 | //! Daemonize the process | 
|---|
| 60 | /*! | 
|---|
| 61 | Daemonize.  Throw XArchDaemonFailed on error.  \c name is the name | 
|---|
| 62 | of the daemon.  Once daemonized, \c func is invoked and daemonize | 
|---|
| 63 | returns when and what it does. | 
|---|
| 64 |  | 
|---|
| 65 | Exactly what happens when daemonizing depends on the platform. | 
|---|
| 66 | <ul> | 
|---|
| 67 | <li>unix: | 
|---|
| 68 | Detaches from terminal.  \c func gets passed one argument, the | 
|---|
| 69 | name passed to daemonize(). | 
|---|
| 70 | <li>win32: | 
|---|
| 71 | Becomes a service.  Argument 0 is the name of the service | 
|---|
| 72 | and the rest are the arguments passed to StartService(). | 
|---|
| 73 | \c func is only called when the service is actually started. | 
|---|
| 74 | \c func must call \c CArchMiscWindows::runDaemon() to finally | 
|---|
| 75 | becoming a service.  The \c runFunc function passed to \c runDaemon() | 
|---|
| 76 | must call \c CArchMiscWindows::daemonRunning(true) when it | 
|---|
| 77 | enters the main loop (i.e. after initialization) and | 
|---|
| 78 | \c CArchMiscWindows::daemonRunning(false) when it leaves | 
|---|
| 79 | the main loop.  The \c stopFunc function passed to \c runDaemon() | 
|---|
| 80 | is called when the daemon must exit the main loop and it must cause | 
|---|
| 81 | \c runFunc to return.  \c func should return what \c runDaemon() | 
|---|
| 82 | returns.  \c func or \c runFunc can call | 
|---|
| 83 | \c CArchMiscWindows::daemonFailed() to indicate startup failure. | 
|---|
| 84 | </ul> | 
|---|
| 85 | */ | 
|---|
| 86 | virtual int                     daemonize(const char* name, DaemonFunc func) = 0; | 
|---|
| 87 |  | 
|---|
| 88 | //! Check if user has permission to install the daemon | 
|---|
| 89 | /*! | 
|---|
| 90 | Returns true iff the caller has permission to install or | 
|---|
| 91 | uninstall the daemon.  Note that even if this method returns | 
|---|
| 92 | true it's possible that installing/uninstalling the service | 
|---|
| 93 | may still fail.  This method ignores whether or not the | 
|---|
| 94 | service is already installed. | 
|---|
| 95 | */ | 
|---|
| 96 | virtual bool            canInstallDaemon(const char* name, bool allUsers) = 0; | 
|---|
| 97 |  | 
|---|
| 98 | //! Check if the daemon is installed | 
|---|
| 99 | /*! | 
|---|
| 100 | Returns true iff the daemon is installed. | 
|---|
| 101 | */ | 
|---|
| 102 | virtual bool            isDaemonInstalled(const char* name, bool allUsers) = 0; | 
|---|
| 103 |  | 
|---|
| 104 | //@} | 
|---|
| 105 | }; | 
|---|
| 106 |  | 
|---|
| 107 | #endif | 
|---|