aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/arch/IArchDaemon.h
blob: a4983d384bf0edc2618b5083124ffbc306c1e99e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * barrier -- mouse and keyboard sharing utility
 * Copyright (C) 2012-2016 Symless Ltd.
 * Copyright (C) 2002 Chris Schoeneman
 * 
 * This package is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * found in the file LICENSE that should have accompanied this file.
 * 
 * This package is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "common/IInterface.h"
#include "base/String.h"

//! Interface for architecture dependent daemonizing
/*!
This interface defines the operations required by barrier for installing
uninstalling daeamons and daemonizing a process.  Each architecture must
implement this interface.
*/
class IArchDaemon : public IInterface {
public:
    typedef int            (*DaemonFunc)(int argc, const char** argv);

    //! @name manipulators
    //@{

    //! Install daemon
    /*!
    Install a daemon.  \c name is the name of the daemon passed to the
    system and \c description is a short human readable description of
    the daemon.  \c pathname is the path to the daemon executable.
    \c commandLine should \b not include the name of program as the
    first argument.  If \c 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 \p 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 \c XArchDaemon exception on failure.
    */
    virtual void        installDaemon(const char* name,
                            const char* description,
                            const char* pathname,
                            const char* commandLine,
                            const char* dependencies) = 0;

    //! Uninstall daemon
    /*!
    Uninstall a daemon.  Throws an \c XArchDaemon on failure.
    */
    virtual void        uninstallDaemon(const char* name) = 0;

    //! Install daemon
    /*!
    Installs the default daemon.
    */
    virtual void        installDaemon() = 0;
    
    //! Uninstall daemon
    /*!
    Uninstalls the default daemon.
    */
    virtual void        uninstallDaemon() = 0;

    //! Daemonize the process
    /*!
    Daemonize.  Throw XArchDaemonFailed on error.  \c name is the name
    of the daemon.  Once daemonized, \c func is invoked and daemonize
    returns when and what it does.
    
    Exactly what happens when daemonizing depends on the platform.
    <ul>
    <li>unix:
      Detaches from terminal.  \c func gets passed one argument, the
      name passed to daemonize().
    <li>win32:
      Becomes a service.  Argument 0 is the name of the service
      and the rest are the arguments passed to StartService().
      \c func is only called when the service is actually started.
      \c func must call \c ArchMiscWindows::runDaemon() to finally
      becoming a service.  The \c runFunc function passed to \c runDaemon()
      must call \c ArchMiscWindows::daemonRunning(true) when it
      enters the main loop (i.e. after initialization) and
      \c ArchMiscWindows::daemonRunning(false) when it leaves
      the main loop.  The \c stopFunc function passed to \c runDaemon()
      is called when the daemon must exit the main loop and it must cause
      \c runFunc to return.  \c func should return what \c runDaemon()
      returns.  \c func or \c runFunc can call
      \c ArchMiscWindows::daemonFailed() to indicate startup failure.
    </ul>
    */
    virtual int            daemonize(const char* name, DaemonFunc func) = 0;

    //! 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.
    */
    virtual bool        canInstallDaemon(const char* name) = 0;

    //! Check if the daemon is installed
    /*!
    Returns true iff the daemon is installed.
    */
    virtual bool        isDaemonInstalled(const char* name) = 0;

    //@}

    //! Get the command line
    /*!
    Gets the command line with which the application was started.
    */
    virtual std::string    commandLine() const = 0;

    //@}
};