2002-08-02 23:57:46 +04:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* 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 COPYING 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.
|
|
|
|
*/
|
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
#ifndef CCLIENT_H
|
|
|
|
#define CCLIENT_H
|
|
|
|
|
2002-07-11 01:22:28 +04:00
|
|
|
#include "IScreenReceiver.h"
|
2002-07-11 00:18:32 +04:00
|
|
|
#include "IClient.h"
|
2002-04-29 17:31:44 +04:00
|
|
|
#include "IClipboard.h"
|
2002-07-11 00:18:32 +04:00
|
|
|
#include "CNetworkAddress.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "CMutex.h"
|
2003-03-13 01:34:07 +03:00
|
|
|
#include "CJobList.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
class CSecondaryScreen;
|
2002-07-11 00:18:32 +04:00
|
|
|
class CServerProxy;
|
|
|
|
class CThread;
|
|
|
|
class IDataSocket;
|
2002-07-11 01:22:28 +04:00
|
|
|
class IScreenReceiver;
|
2002-07-30 22:31:00 +04:00
|
|
|
class ISecondaryScreenFactory;
|
|
|
|
class ISocketFactory;
|
|
|
|
class IStreamFilterFactory;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Synergy client
|
|
|
|
/*!
|
|
|
|
This class implements the top-level client algorithms for synergy.
|
|
|
|
*/
|
2002-07-11 01:22:28 +04:00
|
|
|
class CClient : public IScreenReceiver, public IClient {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2003-03-13 01:34:07 +03:00
|
|
|
enum EStatus {
|
|
|
|
kNotRunning,
|
|
|
|
kRunning,
|
|
|
|
kError,
|
|
|
|
kMaxStatus
|
|
|
|
};
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
/*!
|
|
|
|
This client will attempt to connect the server using \c clientName
|
|
|
|
as its name.
|
|
|
|
*/
|
2001-10-06 18:13:28 +04:00
|
|
|
CClient(const CString& clientName);
|
|
|
|
~CClient();
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Set camping state
|
|
|
|
/*!
|
|
|
|
Turns camping on or off. When camping the client will keep
|
|
|
|
trying to connect to the server until it succeeds. This
|
|
|
|
is useful if the client may start before the server. Do
|
2002-07-30 19:17:44 +04:00
|
|
|
not call this while in mainLoop().
|
2002-07-30 18:59:36 +04:00
|
|
|
*/
|
2002-06-10 02:20:28 +04:00
|
|
|
void camp(bool on);
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Set server address
|
|
|
|
/*!
|
|
|
|
Sets the server's address that the client should connect to.
|
|
|
|
*/
|
2002-07-11 00:18:32 +04:00
|
|
|
void setAddress(const CNetworkAddress& serverAddress);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-30 22:31:00 +04:00
|
|
|
//! Set secondary screen factory
|
|
|
|
/*!
|
|
|
|
Sets the factory for creating secondary screens. This must be
|
|
|
|
set before calling open(). This object takes ownership of the
|
|
|
|
factory.
|
|
|
|
*/
|
|
|
|
void setScreenFactory(ISecondaryScreenFactory*);
|
|
|
|
|
|
|
|
//! Set socket factory
|
|
|
|
/*!
|
|
|
|
Sets the factory used to create a socket to connect to the server.
|
|
|
|
This must be set before calling mainLoop(). This object takes
|
|
|
|
ownership of the factory.
|
|
|
|
*/
|
|
|
|
void setSocketFactory(ISocketFactory*);
|
|
|
|
|
|
|
|
//! Set stream filter factory
|
|
|
|
/*!
|
|
|
|
Sets the factory used to filter the socket streams used to
|
|
|
|
communicate with the server. This object takes ownership
|
|
|
|
of the factory.
|
|
|
|
*/
|
|
|
|
void setStreamFilterFactory(IStreamFilterFactory*);
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Exit event loop
|
|
|
|
/*!
|
2002-07-30 19:17:44 +04:00
|
|
|
Force mainLoop() to return. This call can return before
|
|
|
|
mainLoop() does (i.e. asynchronously). This may only be
|
2002-07-30 18:59:36 +04:00
|
|
|
called between a successful open() and close().
|
|
|
|
*/
|
2002-07-30 19:17:44 +04:00
|
|
|
void exitMainLoop();
|
2002-06-09 01:48:00 +04:00
|
|
|
|
2003-03-13 01:34:07 +03:00
|
|
|
//! Add a job to notify of status changes
|
|
|
|
/*!
|
|
|
|
The added job is run whenever the server's status changes in
|
|
|
|
certain externally visible ways. The client keeps ownership
|
|
|
|
of the job.
|
|
|
|
*/
|
|
|
|
void addStatusJob(IJob*);
|
|
|
|
|
|
|
|
//! Remove a job to notify of status changes
|
|
|
|
/*!
|
|
|
|
Removes a previously added status notification job. A job can
|
|
|
|
remove itself when called but must not remove any other jobs.
|
|
|
|
The client keeps ownership of the job.
|
|
|
|
*/
|
|
|
|
void removeStatusJob(IJob*);
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//!
|
|
|
|
/*!
|
|
|
|
Returns true if the server rejected our connection.
|
|
|
|
*/
|
2002-07-11 00:18:32 +04:00
|
|
|
bool wasRejected() const;
|
|
|
|
|
2003-03-13 01:34:07 +03:00
|
|
|
//! Get the status
|
|
|
|
/*!
|
|
|
|
Returns the current status and status message.
|
|
|
|
*/
|
|
|
|
EStatus getStatus(CString* = NULL) const;
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//@}
|
|
|
|
|
2002-07-11 01:22:28 +04:00
|
|
|
// IScreenReceiver overrides
|
2002-07-16 20:52:26 +04:00
|
|
|
virtual void onError();
|
2002-07-11 01:22:28 +04:00
|
|
|
virtual void onInfoChanged(const CClientInfo&);
|
|
|
|
virtual bool onGrabClipboard(ClipboardID);
|
|
|
|
virtual void onClipboardChanged(ClipboardID, const CString&);
|
|
|
|
|
2002-07-11 00:18:32 +04:00
|
|
|
// IClient overrides
|
2002-07-31 16:39:34 +04:00
|
|
|
virtual void open();
|
2002-07-30 19:17:44 +04:00
|
|
|
virtual void mainLoop();
|
2002-07-11 00:18:32 +04:00
|
|
|
virtual void close();
|
|
|
|
virtual void enter(SInt32 xAbs, SInt32 yAbs,
|
|
|
|
UInt32 seqNum, KeyModifierMask mask,
|
2002-07-14 02:00:38 +04:00
|
|
|
bool forScreensaver);
|
2002-07-11 00:18:32 +04:00
|
|
|
virtual bool leave();
|
|
|
|
virtual void setClipboard(ClipboardID, const CString&);
|
|
|
|
virtual void grabClipboard(ClipboardID);
|
|
|
|
virtual void setClipboardDirty(ClipboardID, bool dirty);
|
|
|
|
virtual void keyDown(KeyID, KeyModifierMask);
|
|
|
|
virtual void keyRepeat(KeyID, KeyModifierMask, SInt32 count);
|
|
|
|
virtual void keyUp(KeyID, KeyModifierMask);
|
|
|
|
virtual void mouseDown(ButtonID);
|
|
|
|
virtual void mouseUp(ButtonID);
|
|
|
|
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
|
|
|
|
virtual void mouseWheel(SInt32 delta);
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual void screensaver(bool activate);
|
2002-12-23 16:55:21 +03:00
|
|
|
virtual void resetOptions();
|
|
|
|
virtual void setOptions(const COptionsList& options);
|
2002-07-11 00:18:32 +04:00
|
|
|
virtual CString getName() const;
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual SInt32 getJumpZoneSize() const;
|
2002-07-11 00:18:32 +04:00
|
|
|
virtual void getShape(SInt32& x, SInt32& y,
|
|
|
|
SInt32& width, SInt32& height) const;
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual void getCursorPos(SInt32& x, SInt32& y) const;
|
|
|
|
virtual void getCursorCenter(SInt32& x, SInt32& y) const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2003-03-13 01:34:07 +03:00
|
|
|
// notify status jobs of a change
|
|
|
|
void runStatusJobs() const;
|
|
|
|
|
|
|
|
// set new status
|
|
|
|
void setStatus(EStatus, const char* msg = NULL);
|
|
|
|
|
2002-06-26 17:48:08 +04:00
|
|
|
// open/close the secondary screen
|
2001-11-19 03:33:36 +03:00
|
|
|
void openSecondaryScreen();
|
|
|
|
void closeSecondaryScreen();
|
|
|
|
|
2002-07-11 00:18:32 +04:00
|
|
|
// send the clipboard to the server
|
|
|
|
void sendClipboard(ClipboardID);
|
|
|
|
|
|
|
|
// handle server messaging
|
|
|
|
void runSession(void*);
|
2002-07-16 20:52:26 +04:00
|
|
|
void deleteSession(double timeout = -1.0);
|
2002-07-11 00:18:32 +04:00
|
|
|
void runServer();
|
|
|
|
CServerProxy* handshakeServer(IDataSocket*);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2001-11-25 21:32:41 +03:00
|
|
|
CMutex m_mutex;
|
2001-10-06 18:13:28 +04:00
|
|
|
CString m_name;
|
2002-07-14 02:00:38 +04:00
|
|
|
CSecondaryScreen* m_screen;
|
2002-07-11 01:22:28 +04:00
|
|
|
IScreenReceiver* m_server;
|
2002-07-11 00:18:32 +04:00
|
|
|
CNetworkAddress m_serverAddress;
|
2002-06-10 02:20:28 +04:00
|
|
|
bool m_camp;
|
2002-07-30 22:31:00 +04:00
|
|
|
ISecondaryScreenFactory* m_screenFactory;
|
|
|
|
ISocketFactory* m_socketFactory;
|
|
|
|
IStreamFilterFactory* m_streamFilterFactory;
|
2002-07-16 20:52:26 +04:00
|
|
|
CThread* m_session;
|
2002-04-29 17:31:44 +04:00
|
|
|
bool m_active;
|
2002-07-11 00:18:32 +04:00
|
|
|
bool m_rejected;
|
2002-04-29 17:31:44 +04:00
|
|
|
bool m_ownClipboard[kClipboardEnd];
|
|
|
|
IClipboard::Time m_timeClipboard[kClipboardEnd];
|
2002-05-24 21:54:28 +04:00
|
|
|
CString m_dataClipboard[kClipboardEnd];
|
2003-03-13 01:34:07 +03:00
|
|
|
|
|
|
|
// the status change jobs and status
|
|
|
|
CJobList m_statusJobs;
|
|
|
|
EStatus m_status;
|
|
|
|
CString m_statusMessage;
|
2001-10-06 18:13:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|