| 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 CCLIENT_H | 
|---|
| 16 | #define CCLIENT_H | 
|---|
| 17 |  | 
|---|
| 18 | #include "IClient.h" | 
|---|
| 19 | #include "IClipboard.h" | 
|---|
| 20 | #include "CNetworkAddress.h" | 
|---|
| 21 |  | 
|---|
| 22 | class CEventQueueTimer; | 
|---|
| 23 | class CScreen; | 
|---|
| 24 | class CServerProxy; | 
|---|
| 25 | class IDataSocket; | 
|---|
| 26 | class ISocketFactory; | 
|---|
| 27 | class IStream; | 
|---|
| 28 | class IStreamFilterFactory; | 
|---|
| 29 |  | 
|---|
| 30 | //! Synergy client | 
|---|
| 31 | /*! | 
|---|
| 32 | This class implements the top-level client algorithms for synergy. | 
|---|
| 33 | */ | 
|---|
| 34 | class CClient : public IClient { | 
|---|
| 35 | public: | 
|---|
| 36 | class CFailInfo { | 
|---|
| 37 | public: | 
|---|
| 38 | bool                    m_retry; | 
|---|
| 39 | char                    m_what[1]; | 
|---|
| 40 | }; | 
|---|
| 41 |  | 
|---|
| 42 | /*! | 
|---|
| 43 | This client will attempt to connect to the server using \p name | 
|---|
| 44 | as its name and \p address as the server's address and \p factory | 
|---|
| 45 | to create the socket.  \p screen is     the local screen. | 
|---|
| 46 | */ | 
|---|
| 47 | CClient(const CString& name, const CNetworkAddress& address, | 
|---|
| 48 | ISocketFactory* socketFactory, | 
|---|
| 49 | IStreamFilterFactory* streamFilterFactory, | 
|---|
| 50 | CScreen* screen); | 
|---|
| 51 | ~CClient(); | 
|---|
| 52 |  | 
|---|
| 53 | //! @name manipulators | 
|---|
| 54 | //@{ | 
|---|
| 55 |  | 
|---|
| 56 | //! Connect to server | 
|---|
| 57 | /*! | 
|---|
| 58 | Starts an attempt to connect to the server.  This is ignored if | 
|---|
| 59 | the client is trying to connect or is already connected. | 
|---|
| 60 | */ | 
|---|
| 61 | void                            connect(); | 
|---|
| 62 |  | 
|---|
| 63 | //! Disconnect | 
|---|
| 64 | /*! | 
|---|
| 65 | Disconnects from the server with an optional error message. | 
|---|
| 66 | */ | 
|---|
| 67 | void                            disconnect(const char* msg); | 
|---|
| 68 |  | 
|---|
| 69 | //! Notify of handshake complete | 
|---|
| 70 | /*! | 
|---|
| 71 | Notifies the client that the connection handshake has completed. | 
|---|
| 72 | */ | 
|---|
| 73 | void                            handshakeComplete(); | 
|---|
| 74 |  | 
|---|
| 75 | //@} | 
|---|
| 76 | //! @name accessors | 
|---|
| 77 | //@{ | 
|---|
| 78 |  | 
|---|
| 79 | //! Test if connected | 
|---|
| 80 | /*! | 
|---|
| 81 | Returns true iff the client is successfully connected to the server. | 
|---|
| 82 | */ | 
|---|
| 83 | bool                            isConnected() const; | 
|---|
| 84 |  | 
|---|
| 85 | //! Test if connecting | 
|---|
| 86 | /*! | 
|---|
| 87 | Returns true iff the client is currently attempting to connect to | 
|---|
| 88 | the server. | 
|---|
| 89 | */ | 
|---|
| 90 | bool                            isConnecting() const; | 
|---|
| 91 |  | 
|---|
| 92 | //! Get address of server | 
|---|
| 93 | /*! | 
|---|
| 94 | Returns the address of the server the client is connected (or wants | 
|---|
| 95 | to connect) to. | 
|---|
| 96 | */ | 
|---|
| 97 | CNetworkAddress         getServerAddress() const; | 
|---|
| 98 |  | 
|---|
| 99 | //! Get connected event type | 
|---|
| 100 | /*! | 
|---|
| 101 | Returns the connected event type.  This is sent when the client has | 
|---|
| 102 | successfully connected to the server. | 
|---|
| 103 | */ | 
|---|
| 104 | static CEvent::Type     getConnectedEvent(); | 
|---|
| 105 |  | 
|---|
| 106 | //! Get connection failed event type | 
|---|
| 107 | /*! | 
|---|
| 108 | Returns the connection failed event type.  This is sent when the | 
|---|
| 109 | server fails for some reason.  The event data is a CFailInfo*. | 
|---|
| 110 | */ | 
|---|
| 111 | static CEvent::Type     getConnectionFailedEvent(); | 
|---|
| 112 |  | 
|---|
| 113 | //! Get disconnected event type | 
|---|
| 114 | /*! | 
|---|
| 115 | Returns the disconnected event type.  This is sent when the client | 
|---|
| 116 | has disconnected from the server (and only after having successfully | 
|---|
| 117 | connected). | 
|---|
| 118 | */ | 
|---|
| 119 | static CEvent::Type     getDisconnectedEvent(); | 
|---|
| 120 |  | 
|---|
| 121 | //@} | 
|---|
| 122 |  | 
|---|
| 123 | // IScreen overrides | 
|---|
| 124 | virtual void*           getEventTarget() const; | 
|---|
| 125 | virtual bool            getClipboard(ClipboardID id, IClipboard*) const; | 
|---|
| 126 | virtual void            getShape(SInt32& x, SInt32& y, | 
|---|
| 127 | SInt32& width, SInt32& height) const; | 
|---|
| 128 | virtual void            getCursorPos(SInt32& x, SInt32& y) const; | 
|---|
| 129 |  | 
|---|
| 130 | // IClient overrides | 
|---|
| 131 | virtual void            enter(SInt32 xAbs, SInt32 yAbs, | 
|---|
| 132 | UInt32 seqNum, KeyModifierMask mask, | 
|---|
| 133 | bool forScreensaver); | 
|---|
| 134 | virtual bool            leave(); | 
|---|
| 135 | virtual void            setClipboard(ClipboardID, const IClipboard*); | 
|---|
| 136 | virtual void            grabClipboard(ClipboardID); | 
|---|
| 137 | virtual void            setClipboardDirty(ClipboardID, bool); | 
|---|
| 138 | virtual void            keyDown(KeyID, KeyModifierMask, KeyButton); | 
|---|
| 139 | virtual void            keyRepeat(KeyID, KeyModifierMask, | 
|---|
| 140 | SInt32 count, KeyButton); | 
|---|
| 141 | virtual void            keyUp(KeyID, KeyModifierMask, KeyButton); | 
|---|
| 142 | virtual void            mouseDown(ButtonID); | 
|---|
| 143 | virtual void            mouseUp(ButtonID); | 
|---|
| 144 | virtual void            mouseMove(SInt32 xAbs, SInt32 yAbs); | 
|---|
| 145 | virtual void            mouseRelativeMove(SInt32 xRel, SInt32 yRel); | 
|---|
| 146 | virtual void            mouseWheel(SInt32 xDelta, SInt32 yDelta); | 
|---|
| 147 | virtual void            screensaver(bool activate); | 
|---|
| 148 | virtual void            resetOptions(); | 
|---|
| 149 | virtual void            setOptions(const COptionsList& options); | 
|---|
| 150 | virtual CString         getName() const; | 
|---|
| 151 |  | 
|---|
| 152 | private: | 
|---|
| 153 | void                            sendClipboard(ClipboardID); | 
|---|
| 154 | void                            sendEvent(CEvent::Type, void*); | 
|---|
| 155 | void                            sendConnectionFailedEvent(const char* msg); | 
|---|
| 156 | void                            setupConnecting(); | 
|---|
| 157 | void                            setupConnection(); | 
|---|
| 158 | void                            setupScreen(); | 
|---|
| 159 | void                            setupTimer(); | 
|---|
| 160 | void                            cleanupConnecting(); | 
|---|
| 161 | void                            cleanupConnection(); | 
|---|
| 162 | void                            cleanupScreen(); | 
|---|
| 163 | void                            cleanupTimer(); | 
|---|
| 164 | void                            handleConnected(const CEvent&, void*); | 
|---|
| 165 | void                            handleConnectionFailed(const CEvent&, void*); | 
|---|
| 166 | void                            handleConnectTimeout(const CEvent&, void*); | 
|---|
| 167 | void                            handleOutputError(const CEvent&, void*); | 
|---|
| 168 | void                            handleDisconnected(const CEvent&, void*); | 
|---|
| 169 | void                            handleShapeChanged(const CEvent&, void*); | 
|---|
| 170 | void                            handleClipboardGrabbed(const CEvent&, void*); | 
|---|
| 171 | void                            handleHello(const CEvent&, void*); | 
|---|
| 172 | void                            handleSuspend(const CEvent& event, void*); | 
|---|
| 173 | void                            handleResume(const CEvent& event, void*); | 
|---|
| 174 |  | 
|---|
| 175 | private: | 
|---|
| 176 | CString                                 m_name; | 
|---|
| 177 | CNetworkAddress                 m_serverAddress; | 
|---|
| 178 | ISocketFactory*                 m_socketFactory; | 
|---|
| 179 | IStreamFilterFactory*   m_streamFilterFactory; | 
|---|
| 180 | CScreen*                                m_screen; | 
|---|
| 181 | IStream*                                m_stream; | 
|---|
| 182 | CEventQueueTimer*               m_timer; | 
|---|
| 183 | CServerProxy*                   m_server; | 
|---|
| 184 | bool                                    m_ready; | 
|---|
| 185 | bool                                    m_active; | 
|---|
| 186 | bool                                    m_suspended; | 
|---|
| 187 | bool                                    m_connectOnResume; | 
|---|
| 188 | bool                            m_ownClipboard[kClipboardEnd]; | 
|---|
| 189 | bool                            m_sentClipboard[kClipboardEnd]; | 
|---|
| 190 | IClipboard::Time        m_timeClipboard[kClipboardEnd]; | 
|---|
| 191 | CString                         m_dataClipboard[kClipboardEnd]; | 
|---|
| 192 |  | 
|---|
| 193 | static CEvent::Type     s_connectedEvent; | 
|---|
| 194 | static CEvent::Type     s_connectionFailedEvent; | 
|---|
| 195 | static CEvent::Type     s_disconnectedEvent; | 
|---|
| 196 | }; | 
|---|
| 197 |  | 
|---|
| 198 | #endif | 
|---|