| 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 CARCH_H | 
|---|
| 16 | #define CARCH_H | 
|---|
| 17 |  | 
|---|
| 18 | #include "IArchConsole.h" | 
|---|
| 19 | #include "IArchDaemon.h" | 
|---|
| 20 | #include "IArchFile.h" | 
|---|
| 21 | #include "IArchLog.h" | 
|---|
| 22 | #include "IArchMultithread.h" | 
|---|
| 23 | #include "IArchNetwork.h" | 
|---|
| 24 | #include "IArchSleep.h" | 
|---|
| 25 | #include "IArchString.h" | 
|---|
| 26 | #include "IArchSystem.h" | 
|---|
| 27 | #include "IArchTaskBar.h" | 
|---|
| 28 | #include "IArchTime.h" | 
|---|
| 29 |  | 
|---|
| 30 | /*! | 
|---|
| 31 | \def ARCH | 
|---|
| 32 | This macro evaluates to the singleton CArch object. | 
|---|
| 33 | */ | 
|---|
| 34 | #define ARCH    (CArch::getInstance()) | 
|---|
| 35 |  | 
|---|
| 36 | #define ARCH_ARGS void | 
|---|
| 37 |  | 
|---|
| 38 | //! Delegating mplementation of architecture dependent interfaces | 
|---|
| 39 | /*! | 
|---|
| 40 | This class is a centralized interface to all architecture dependent | 
|---|
| 41 | interface implementations (except miscellaneous functions).  It | 
|---|
| 42 | instantiates an implementation of each interface and delegates calls | 
|---|
| 43 | to each method to those implementations.  Clients should use the | 
|---|
| 44 | \c ARCH macro to access this object.  Clients must also instantiate | 
|---|
| 45 | exactly one of these objects before attempting to call any method, | 
|---|
| 46 | typically at the beginning of \c main(). | 
|---|
| 47 | */ | 
|---|
| 48 | class CArch : public IArchConsole, | 
|---|
| 49 | public IArchDaemon, | 
|---|
| 50 | public IArchFile, | 
|---|
| 51 | public IArchLog, | 
|---|
| 52 | public IArchMultithread, | 
|---|
| 53 | public IArchNetwork, | 
|---|
| 54 | public IArchSleep, | 
|---|
| 55 | public IArchString, | 
|---|
| 56 | public IArchSystem, | 
|---|
| 57 | public IArchTaskBar, | 
|---|
| 58 | public IArchTime { | 
|---|
| 59 | public: | 
|---|
| 60 | CArch(ARCH_ARGS* args = NULL); | 
|---|
| 61 | ~CArch(); | 
|---|
| 62 |  | 
|---|
| 63 | // | 
|---|
| 64 | // accessors | 
|---|
| 65 | // | 
|---|
| 66 |  | 
|---|
| 67 | //! Return the singleton instance | 
|---|
| 68 | /*! | 
|---|
| 69 | The client must have instantiated exactly once CArch object before | 
|---|
| 70 | calling this function. | 
|---|
| 71 | */ | 
|---|
| 72 | static CArch*           getInstance(); | 
|---|
| 73 |  | 
|---|
| 74 | // IArchConsole overrides | 
|---|
| 75 | virtual void            openConsole(const char*); | 
|---|
| 76 | virtual void            closeConsole(); | 
|---|
| 77 | virtual void            showConsole(bool showIfEmpty); | 
|---|
| 78 | virtual void            writeConsole(const char*); | 
|---|
| 79 | virtual const char*     getNewlineForConsole(); | 
|---|
| 80 |  | 
|---|
| 81 | // IArchDaemon overrides | 
|---|
| 82 | virtual void            installDaemon(const char* name, | 
|---|
| 83 | const char* description, | 
|---|
| 84 | const char* pathname, | 
|---|
| 85 | const char* commandLine, | 
|---|
| 86 | const char* dependencies, | 
|---|
| 87 | bool allUsers); | 
|---|
| 88 | virtual void            uninstallDaemon(const char* name, bool allUsers); | 
|---|
| 89 | virtual int                     daemonize(const char* name, DaemonFunc func); | 
|---|
| 90 | virtual bool            canInstallDaemon(const char* name, bool allUsers); | 
|---|
| 91 | virtual bool            isDaemonInstalled(const char* name, bool allUsers); | 
|---|
| 92 |  | 
|---|
| 93 | // IArchFile overrides | 
|---|
| 94 | virtual const char*     getBasename(const char* pathname); | 
|---|
| 95 | virtual std::string     getUserDirectory(); | 
|---|
| 96 | virtual std::string     getSystemDirectory(); | 
|---|
| 97 | virtual std::string     concatPath(const std::string& prefix, | 
|---|
| 98 | const std::string& suffix); | 
|---|
| 99 |  | 
|---|
| 100 | // IArchLog overrides | 
|---|
| 101 | virtual void            openLog(const char*); | 
|---|
| 102 | virtual void            closeLog(); | 
|---|
| 103 | virtual void            showLog(bool showIfEmpty); | 
|---|
| 104 | virtual void            writeLog(ELevel, const char*); | 
|---|
| 105 |  | 
|---|
| 106 | // IArchMultithread overrides | 
|---|
| 107 | virtual CArchCond       newCondVar(); | 
|---|
| 108 | virtual void            closeCondVar(CArchCond); | 
|---|
| 109 | virtual void            signalCondVar(CArchCond); | 
|---|
| 110 | virtual void            broadcastCondVar(CArchCond); | 
|---|
| 111 | virtual bool            waitCondVar(CArchCond, CArchMutex, double timeout); | 
|---|
| 112 | virtual CArchMutex      newMutex(); | 
|---|
| 113 | virtual void            closeMutex(CArchMutex); | 
|---|
| 114 | virtual void            lockMutex(CArchMutex); | 
|---|
| 115 | virtual void            unlockMutex(CArchMutex); | 
|---|
| 116 | virtual CArchThread     newThread(ThreadFunc, void*); | 
|---|
| 117 | virtual CArchThread     newCurrentThread(); | 
|---|
| 118 | virtual CArchThread     copyThread(CArchThread); | 
|---|
| 119 | virtual void            closeThread(CArchThread); | 
|---|
| 120 | virtual void            cancelThread(CArchThread); | 
|---|
| 121 | virtual void            setPriorityOfThread(CArchThread, int n); | 
|---|
| 122 | virtual void            testCancelThread(); | 
|---|
| 123 | virtual bool            wait(CArchThread, double timeout); | 
|---|
| 124 | virtual bool            isSameThread(CArchThread, CArchThread); | 
|---|
| 125 | virtual bool            isExitedThread(CArchThread); | 
|---|
| 126 | virtual void*           getResultOfThread(CArchThread); | 
|---|
| 127 | virtual ThreadID        getIDOfThread(CArchThread); | 
|---|
| 128 | virtual void            setSignalHandler(ESignal, SignalFunc, void*); | 
|---|
| 129 | virtual void            raiseSignal(ESignal); | 
|---|
| 130 |  | 
|---|
| 131 | // IArchNetwork overrides | 
|---|
| 132 | virtual CArchSocket     newSocket(EAddressFamily, ESocketType); | 
|---|
| 133 | virtual CArchSocket     copySocket(CArchSocket s); | 
|---|
| 134 | virtual void            closeSocket(CArchSocket s); | 
|---|
| 135 | virtual void            closeSocketForRead(CArchSocket s); | 
|---|
| 136 | virtual void            closeSocketForWrite(CArchSocket s); | 
|---|
| 137 | virtual void            bindSocket(CArchSocket s, CArchNetAddress addr); | 
|---|
| 138 | virtual void            listenOnSocket(CArchSocket s); | 
|---|
| 139 | virtual CArchSocket     acceptSocket(CArchSocket s, CArchNetAddress* addr); | 
|---|
| 140 | virtual bool            connectSocket(CArchSocket s, CArchNetAddress name); | 
|---|
| 141 | virtual int                     pollSocket(CPollEntry[], int num, double timeout); | 
|---|
| 142 | virtual void            unblockPollSocket(CArchThread thread); | 
|---|
| 143 | virtual size_t          readSocket(CArchSocket s, void* buf, size_t len); | 
|---|
| 144 | virtual size_t          writeSocket(CArchSocket s, | 
|---|
| 145 | const void* buf, size_t len); | 
|---|
| 146 | virtual void            throwErrorOnSocket(CArchSocket); | 
|---|
| 147 | virtual bool            setNoDelayOnSocket(CArchSocket, bool noDelay); | 
|---|
| 148 | virtual bool            setReuseAddrOnSocket(CArchSocket, bool reuse); | 
|---|
| 149 | virtual std::string             getHostName(); | 
|---|
| 150 | virtual CArchNetAddress newAnyAddr(EAddressFamily); | 
|---|
| 151 | virtual CArchNetAddress copyAddr(CArchNetAddress); | 
|---|
| 152 | virtual CArchNetAddress nameToAddr(const std::string&); | 
|---|
| 153 | virtual void                    closeAddr(CArchNetAddress); | 
|---|
| 154 | virtual std::string             addrToName(CArchNetAddress); | 
|---|
| 155 | virtual std::string             addrToString(CArchNetAddress); | 
|---|
| 156 | virtual EAddressFamily  getAddrFamily(CArchNetAddress); | 
|---|
| 157 | virtual void                    setAddrPort(CArchNetAddress, int port); | 
|---|
| 158 | virtual int                             getAddrPort(CArchNetAddress); | 
|---|
| 159 | virtual bool                    isAnyAddr(CArchNetAddress); | 
|---|
| 160 | virtual bool                    isEqualAddr(CArchNetAddress, CArchNetAddress); | 
|---|
| 161 |  | 
|---|
| 162 | // IArchSleep overrides | 
|---|
| 163 | virtual void            sleep(double timeout); | 
|---|
| 164 |  | 
|---|
| 165 | // IArchString overrides | 
|---|
| 166 | virtual int                     vsnprintf(char* str, | 
|---|
| 167 | int size, const char* fmt, va_list ap); | 
|---|
| 168 | virtual int                     convStringMBToWC(wchar_t*, | 
|---|
| 169 | const char*, UInt32 n, bool* errors); | 
|---|
| 170 | virtual int                     convStringWCToMB(char*, | 
|---|
| 171 | const wchar_t*, UInt32 n, bool* errors); | 
|---|
| 172 | virtual EWideCharEncoding | 
|---|
| 173 | getWideCharEncoding(); | 
|---|
| 174 |  | 
|---|
| 175 | // IArchSystem overrides | 
|---|
| 176 | virtual std::string     getOSName() const; | 
|---|
| 177 |  | 
|---|
| 178 | // IArchTaskBar | 
|---|
| 179 | virtual void            addReceiver(IArchTaskBarReceiver*); | 
|---|
| 180 | virtual void            removeReceiver(IArchTaskBarReceiver*); | 
|---|
| 181 | virtual void            updateReceiver(IArchTaskBarReceiver*); | 
|---|
| 182 |  | 
|---|
| 183 | // IArchTime overrides | 
|---|
| 184 | virtual double          time(); | 
|---|
| 185 |  | 
|---|
| 186 | private: | 
|---|
| 187 | static CArch*           s_instance; | 
|---|
| 188 |  | 
|---|
| 189 | IArchConsole*           m_console; | 
|---|
| 190 | IArchDaemon*            m_daemon; | 
|---|
| 191 | IArchFile*                      m_file; | 
|---|
| 192 | IArchLog*                       m_log; | 
|---|
| 193 | IArchMultithread*       m_mt; | 
|---|
| 194 | IArchNetwork*           m_net; | 
|---|
| 195 | IArchSleep*                     m_sleep; | 
|---|
| 196 | IArchString*            m_string; | 
|---|
| 197 | IArchSystem*            m_system; | 
|---|
| 198 | IArchTaskBar*           m_taskbar; | 
|---|
| 199 | IArchTime*                      m_time; | 
|---|
| 200 | }; | 
|---|
| 201 |  | 
|---|
| 202 | //! Convenience object to lock/unlock an arch mutex | 
|---|
| 203 | class CArchMutexLock { | 
|---|
| 204 | public: | 
|---|
| 205 | CArchMutexLock(CArchMutex mutex) : m_mutex(mutex) | 
|---|
| 206 | { | 
|---|
| 207 | ARCH->lockMutex(m_mutex); | 
|---|
| 208 | } | 
|---|
| 209 | ~CArchMutexLock() | 
|---|
| 210 | { | 
|---|
| 211 | ARCH->unlockMutex(m_mutex); | 
|---|
| 212 | } | 
|---|
| 213 |  | 
|---|
| 214 | private: | 
|---|
| 215 | CArchMutex                      m_mutex; | 
|---|
| 216 | }; | 
|---|
| 217 |  | 
|---|
| 218 | #endif | 
|---|