2002-08-02 19:57:46 +00: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 14:13:28 +00:00
|
|
|
#ifndef CCLIENT_H
|
|
|
|
#define CCLIENT_H
|
|
|
|
|
2002-07-10 21:22:28 +00:00
|
|
|
#include "IScreenReceiver.h"
|
2002-07-10 20:18:32 +00:00
|
|
|
#include "IClient.h"
|
2002-04-29 13:31:44 +00:00
|
|
|
#include "IClipboard.h"
|
2002-07-10 20:18:32 +00:00
|
|
|
#include "CNetworkAddress.h"
|
2002-06-10 22:06:45 +00:00
|
|
|
#include "CMutex.h"
|
2003-03-12 22:34:07 +00:00
|
|
|
#include "CJobList.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
class CSecondaryScreen;
|
2002-07-10 20:18:32 +00:00
|
|
|
class CServerProxy;
|
|
|
|
class CThread;
|
|
|
|
class IDataSocket;
|
2002-07-10 21:22:28 +00:00
|
|
|
class IScreenReceiver;
|
2002-07-30 18:31:00 +00:00
|
|
|
class ISecondaryScreenFactory;
|
|
|
|
class ISocketFactory;
|
|
|
|
class IStreamFilterFactory;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-07-30 14:59:36 +00:00
|
|
|
//! Synergy client
|
|
|
|
/*!
|
|
|
|
This class implements the top-level client algorithms for synergy.
|
|
|
|
*/
|
2002-07-10 21:22:28 +00:00
|
|
|
class CClient : public IScreenReceiver, public IClient {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2003-03-12 22:34:07 +00:00
|
|
|
enum EStatus {
|
|
|
|
kNotRunning,
|
|
|
|
kRunning,
|
|
|
|
kError,
|
|
|
|
kMaxStatus
|
|
|
|
};
|
|
|
|
|
2002-07-30 14:59:36 +00:00
|
|
|
/*!
|
|
|
|
This client will attempt to connect the server using \c clientName
|
|
|
|
as its name.
|
|
|
|
*/
|
2001-10-06 14:13:28 +00:00
|
|
|
CClient(const CString& clientName);
|
|
|
|
~CClient();
|
|
|
|
|
2002-07-30 14:59:36 +00:00
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-07-30 14:59:36 +00:00
|
|
|
//! Set server address
|
|
|
|
/*!
|
|
|
|
Sets the server's address that the client should connect to.
|
|
|
|
*/
|
2002-07-10 20:18:32 +00:00
|
|
|
void setAddress(const CNetworkAddress& serverAddress);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-07-30 18:31:00 +00: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 14:59:36 +00:00
|
|
|
//! Exit event loop
|
|
|
|
/*!
|
2002-07-30 15:17:44 +00:00
|
|
|
Force mainLoop() to return. This call can return before
|
|
|
|
mainLoop() does (i.e. asynchronously). This may only be
|
2002-07-30 14:59:36 +00:00
|
|
|
called between a successful open() and close().
|
|
|
|
*/
|
2002-07-30 15:17:44 +00:00
|
|
|
void exitMainLoop();
|
2002-06-08 21:48:00 +00:00
|
|
|
|
2003-03-12 22:34:07 +00: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 14:59:36 +00:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-07-30 14:59:36 +00:00
|
|
|
//!
|
|
|
|
/*!
|
|
|
|
Returns true if the server rejected our connection.
|
|
|
|
*/
|
2002-07-10 20:18:32 +00:00
|
|
|
bool wasRejected() const;
|
|
|
|
|
2003-03-12 22:34:07 +00:00
|
|
|
//! Get the status
|
|
|
|
/*!
|
|
|
|
Returns the current status and status message.
|
|
|
|
*/
|
|
|
|
EStatus getStatus(CString* = NULL) const;
|
|
|
|
|
2002-07-30 14:59:36 +00:00
|
|
|
//@}
|
|
|
|
|
2002-07-10 21:22:28 +00:00
|
|
|
// IScreenReceiver overrides
|
2002-07-16 16:52:26 +00:00
|
|
|
virtual void onError();
|
2002-07-10 21:22:28 +00:00
|
|
|
virtual void onInfoChanged(const CClientInfo&);
|
|
|
|
virtual bool onGrabClipboard(ClipboardID);
|
|
|
|
virtual void onClipboardChanged(ClipboardID, const CString&);
|
|
|
|
|
2002-07-10 20:18:32 +00:00
|
|
|
// IClient overrides
|
2002-07-31 12:39:34 +00:00
|
|
|
virtual void open();
|
2002-07-30 15:17:44 +00:00
|
|
|
virtual void mainLoop();
|
2002-07-10 20:18:32 +00:00
|
|
|
virtual void close();
|
|
|
|
virtual void enter(SInt32 xAbs, SInt32 yAbs,
|
|
|
|
UInt32 seqNum, KeyModifierMask mask,
|
2002-07-13 22:00:38 +00:00
|
|
|
bool forScreensaver);
|
2002-07-10 20:18:32 +00:00
|
|
|
virtual bool leave();
|
|
|
|
virtual void setClipboard(ClipboardID, const CString&);
|
|
|
|
virtual void grabClipboard(ClipboardID);
|
|
|
|
virtual void setClipboardDirty(ClipboardID, bool dirty);
|
2003-04-27 17:01:14 +00:00
|
|
|
virtual void keyDown(KeyID, KeyModifierMask, KeyButton);
|
|
|
|
virtual void keyRepeat(KeyID, KeyModifierMask,
|
|
|
|
SInt32 count, KeyButton);
|
|
|
|
virtual void keyUp(KeyID, KeyModifierMask, KeyButton);
|
2002-07-10 20:18:32 +00:00
|
|
|
virtual void mouseDown(ButtonID);
|
|
|
|
virtual void mouseUp(ButtonID);
|
|
|
|
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
|
|
|
|
virtual void mouseWheel(SInt32 delta);
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual void screensaver(bool activate);
|
2002-12-23 13:55:21 +00:00
|
|
|
virtual void resetOptions();
|
|
|
|
virtual void setOptions(const COptionsList& options);
|
2002-07-10 20:18:32 +00:00
|
|
|
virtual CString getName() const;
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual SInt32 getJumpZoneSize() const;
|
2002-07-10 20:18:32 +00:00
|
|
|
virtual void getShape(SInt32& x, SInt32& y,
|
|
|
|
SInt32& width, SInt32& height) const;
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual void getCursorPos(SInt32& x, SInt32& y) const;
|
|
|
|
virtual void getCursorCenter(SInt32& x, SInt32& y) const;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2003-03-12 22:34:07 +00:00
|
|
|
// notify status jobs of a change
|
|
|
|
void runStatusJobs() const;
|
|
|
|
|
|
|
|
// set new status
|
|
|
|
void setStatus(EStatus, const char* msg = NULL);
|
|
|
|
|
2002-06-26 13:48:08 +00:00
|
|
|
// open/close the secondary screen
|
2001-11-19 00:33:36 +00:00
|
|
|
void openSecondaryScreen();
|
|
|
|
void closeSecondaryScreen();
|
|
|
|
|
2002-07-10 20:18:32 +00:00
|
|
|
// send the clipboard to the server
|
|
|
|
void sendClipboard(ClipboardID);
|
|
|
|
|
|
|
|
// handle server messaging
|
|
|
|
void runSession(void*);
|
2002-07-16 16:52:26 +00:00
|
|
|
void deleteSession(double timeout = -1.0);
|
2002-07-10 20:18:32 +00:00
|
|
|
void runServer();
|
|
|
|
CServerProxy* handshakeServer(IDataSocket*);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2001-11-25 18:32:41 +00:00
|
|
|
CMutex m_mutex;
|
2001-10-06 14:13:28 +00:00
|
|
|
CString m_name;
|
2002-07-13 22:00:38 +00:00
|
|
|
CSecondaryScreen* m_screen;
|
2002-07-10 21:22:28 +00:00
|
|
|
IScreenReceiver* m_server;
|
2002-07-10 20:18:32 +00:00
|
|
|
CNetworkAddress m_serverAddress;
|
2002-07-30 18:31:00 +00:00
|
|
|
ISecondaryScreenFactory* m_screenFactory;
|
|
|
|
ISocketFactory* m_socketFactory;
|
|
|
|
IStreamFilterFactory* m_streamFilterFactory;
|
2002-07-16 16:52:26 +00:00
|
|
|
CThread* m_session;
|
2002-04-29 13:31:44 +00:00
|
|
|
bool m_active;
|
2002-07-10 20:18:32 +00:00
|
|
|
bool m_rejected;
|
2002-04-29 13:31:44 +00:00
|
|
|
bool m_ownClipboard[kClipboardEnd];
|
|
|
|
IClipboard::Time m_timeClipboard[kClipboardEnd];
|
2002-05-24 17:54:28 +00:00
|
|
|
CString m_dataClipboard[kClipboardEnd];
|
2003-03-12 22:34:07 +00:00
|
|
|
|
|
|
|
// the status change jobs and status
|
|
|
|
CJobList m_statusJobs;
|
|
|
|
EStatus m_status;
|
|
|
|
CString m_statusMessage;
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|