Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

CArchDaemonWindows.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2002 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #ifndef CARCHDAEMONWINDOWS_H
00016 #define CARCHDAEMONWINDOWS_H
00017 
00018 #define WIN32_LEAN_AND_MEAN
00019 
00020 #include "IArchDaemon.h"
00021 #include "IArchMultithread.h"
00022 #include "stdstring.h"
00023 #include <windows.h>
00024 #include <tchar.h>
00025 
00026 #define ARCH_DAEMON CArchDaemonWindows
00027 
00029 class CArchDaemonWindows : public IArchDaemon {
00030 public:
00031     typedef int         (*RunFunc)(void);
00032 
00033     CArchDaemonWindows();
00034     virtual ~CArchDaemonWindows();
00035 
00037 
00049     static int          runDaemon(RunFunc runFunc);
00050 
00052 
00057     static void         daemonRunning(bool running);
00058 
00060 
00064     static void         daemonFailed(int result);
00065 
00067 
00072     static UINT         getDaemonQuitMessage();
00073 
00074     // IArchDaemon overrides
00075     virtual void        installDaemon(const char* name,
00076                             const char* description,
00077                             const char* pathname,
00078                             const char* commandLine,
00079                             const char* dependencies,
00080                             bool allUsers);
00081     virtual void        uninstallDaemon(const char* name, bool allUsers);
00082     virtual int         daemonize(const char* name, DaemonFunc func);
00083     virtual bool        canInstallDaemon(const char* name, bool allUsers);
00084     virtual bool        isDaemonInstalled(const char* name, bool allUsers);
00085 
00086 private:
00087     static HKEY         openNTServicesKey();
00088     static HKEY         open95ServicesKey();
00089     static HKEY         openUserStartupKey();
00090 
00091     int                 doRunDaemon(RunFunc runFunc);
00092     void                doDaemonRunning(bool running);
00093     UINT                doGetDaemonQuitMessage();
00094 
00095     static void         setStatus(DWORD state);
00096     static void         setStatus(DWORD state, DWORD step, DWORD waitHint);
00097     static void         setStatusError(DWORD error);
00098 
00099     static bool         isRunState(DWORD state);
00100 
00101     void                serviceMain(DWORD, LPTSTR*);
00102     static void WINAPI  serviceMainEntry(DWORD, LPTSTR*);
00103 
00104     void                serviceHandler(DWORD ctrl);
00105     static void WINAPI  serviceHandlerEntry(DWORD ctrl);
00106 
00107 private:
00108     class XArchDaemonRunFailed {
00109     public:
00110         XArchDaemonRunFailed(int result) : m_result(result) { }
00111 
00112     public:
00113         int             m_result;
00114     };
00115 
00116 private:
00117     static CArchDaemonWindows*  s_daemon;
00118 
00119     CArchMutex          m_serviceMutex;
00120     CArchCond           m_serviceCondVar;
00121     DWORD               m_serviceState;
00122     bool                m_serviceHandlerWaiting;
00123     bool                m_serviceRunning;
00124 
00125     DWORD               m_daemonThreadID;
00126     DaemonFunc          m_daemonFunc;
00127     int                 m_daemonResult;
00128 
00129     SERVICE_STATUS_HANDLE m_statusHandle;
00130 
00131     UINT                m_quitMessage;
00132 };
00133 
00134 #endif

Generated on Fri Nov 6 00:21:13 2009 for synergy-plus by  doxygen 1.3.9.1