~nobuto/ubuntu/natty/synergy/merge-from-experimental

« back to all changes in this revision

Viewing changes to lib/arch/CArchDaemonWindows.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Lutz
  • Date: 2003-10-31 19:36:30 UTC
  • Revision ID: james.westby@ubuntu.com-20031031193630-knbv79x5az7qh49y
Tags: upstream-1.0.14
ImportĀ upstreamĀ versionĀ 1.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 CARCHDAEMONWINDOWS_H
 
16
#define CARCHDAEMONWINDOWS_H
 
17
 
 
18
#define WIN32_LEAN_AND_MEAN
 
19
 
 
20
#include "IArchDaemon.h"
 
21
#include "IArchMultithread.h"
 
22
#include "stdstring.h"
 
23
#include <windows.h>
 
24
#include <tchar.h>
 
25
 
 
26
#define ARCH_DAEMON CArchDaemonWindows
 
27
 
 
28
//! Win32 implementation of IArchDaemon
 
29
class CArchDaemonWindows : public IArchDaemon {
 
30
public:
 
31
        typedef int                     (*RunFunc)(void);
 
32
 
 
33
        CArchDaemonWindows();
 
34
        virtual ~CArchDaemonWindows();
 
35
 
 
36
        //! Run the daemon
 
37
        /*!
 
38
        When the client calls \c daemonize(), the \c DaemonFunc should call this
 
39
        function after initialization and argument parsing to perform the
 
40
        daemon processing.  The \c runFunc should perform the daemon's
 
41
        main loop, calling \c daemonRunning(true) when it enters the main loop
 
42
        (i.e. after initialization) and \c daemonRunning(false) when it leaves
 
43
        the main loop.  The \c runFunc is called in a new thread and when the
 
44
        daemon must exit the main loop due to some external control the
 
45
        thread is cancelled on behalf of the client.  This function returns
 
46
        what \c runFunc returns.  \c runFunc should call \c daemonFailed() if
 
47
        the daemon fails.
 
48
        */
 
49
        static int                      runDaemon(RunFunc runFunc);
 
50
 
 
51
        //! Indicate daemon is in main loop
 
52
        /*!
 
53
        The \c runFunc passed to \c runDaemon() should call this function
 
54
        to indicate when it has entered (\c running is \c true) or exited
 
55
        (\c running is \c false) the main loop.
 
56
        */
 
57
        static void                     daemonRunning(bool running);
 
58
 
 
59
        //! Indicate failure of running daemon
 
60
        /*!
 
61
        The \c runFunc passed to \c runDaemon() should call this function
 
62
        to indicate failure.  \c result is returned by \c daemonize().
 
63
        */
 
64
        static void                     daemonFailed(int result);
 
65
 
 
66
        // IArchDaemon overrides
 
67
        virtual void            installDaemon(const char* name,
 
68
                                                        const char* description,
 
69
                                                        const char* pathname,
 
70
                                                        const char* commandLine,
 
71
                                                        bool allUsers);
 
72
        virtual void            uninstallDaemon(const char* name, bool allUsers);
 
73
        virtual int                     daemonize(const char* name, DaemonFunc func);
 
74
        virtual bool            canInstallDaemon(const char* name, bool allUsers);
 
75
        virtual bool            isDaemonInstalled(const char* name, bool allUsers);
 
76
 
 
77
private:
 
78
        static HKEY                     openNTServicesKey();
 
79
        static HKEY                     open95ServicesKey();
 
80
        static HKEY                     openUserStartupKey();
 
81
 
 
82
        int                                     doRunDaemon(RunFunc runFunc);
 
83
        void                            doDaemonRunning(bool running);
 
84
 
 
85
        static void                     setStatus(DWORD state);
 
86
        static void                     setStatus(DWORD state, DWORD step, DWORD waitHint);
 
87
        static void                     setStatusError(DWORD error);
 
88
 
 
89
        void*                           runDaemonThread(RunFunc);
 
90
        static void*            runDaemonThreadEntry(void*);
 
91
 
 
92
        void                            serviceMain(DWORD, LPTSTR*);
 
93
        static void WINAPI      serviceMainEntry(DWORD, LPTSTR*);
 
94
 
 
95
        void                            serviceHandler(DWORD ctrl);
 
96
        static void WINAPI      serviceHandlerEntry(DWORD ctrl);
 
97
 
 
98
private:
 
99
        class XArchDaemonRunFailed {
 
100
        public:
 
101
                XArchDaemonRunFailed(int result) : m_result(result) { }
 
102
 
 
103
        public:
 
104
                int                             m_result;
 
105
        };
 
106
 
 
107
private:
 
108
        static CArchDaemonWindows*      s_daemon;
 
109
 
 
110
        CArchMutex                      m_serviceMutex;
 
111
        CArchCond                       m_serviceCondVar;
 
112
        DWORD                           m_serviceState;
 
113
        bool                            m_serviceHandlerWaiting;
 
114
        bool                            m_serviceRunning;
 
115
 
 
116
        CArchThread                     m_daemonThread;
 
117
        DaemonFunc                      m_daemonFunc;
 
118
        int                                     m_daemonResult;
 
119
 
 
120
        SERVICE_STATUS_HANDLE m_statusHandle;
 
121
};
 
122
 
 
123
#endif