barrier/lib/client/CClient.h

216 lines
5.7 KiB
C
Raw Normal View History

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"
#include "IClient.h"
#include "IClipboard.h"
#include "CNetworkAddress.h"
#include "CMutex.h"
#include "CJobList.h"
2001-10-06 14:13:28 +00:00
class CSecondaryScreen;
class CServerProxy;
class CThread;
class IDataSocket;
2002-07-10 21:22:28 +00:00
class IScreenReceiver;
class ISecondaryScreenFactory;
class ISocketFactory;
class IStreamFilterFactory;
2001-10-06 14:13:28 +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:
enum EStatus {
kNotRunning,
kRunning,
kError,
kMaxStatus
};
/*!
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();
//! @name manipulators
//@{
2001-10-06 14:13:28 +00: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
not call this while in mainLoop().
*/
void camp(bool on);
//! Set server address
/*!
Sets the server's address that the client should connect to.
*/
void setAddress(const CNetworkAddress& serverAddress);
2001-10-06 14:13:28 +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*);
//! Exit event loop
/*!
Force mainLoop() to return. This call can return before
mainLoop() does (i.e. asynchronously). This may only be
called between a successful open() and close().
*/
void exitMainLoop();
//! 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*);
//@}
//! @name accessors
//@{
2001-10-06 14:13:28 +00:00
//!
/*!
Returns true if the server rejected our connection.
*/
bool wasRejected() const;
//! Get the status
/*!
Returns the current status and status message.
*/
EStatus getStatus(CString* = NULL) const;
//@}
2002-07-10 21:22:28 +00:00
// IScreenReceiver overrides
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&);
// IClient overrides
virtual void open();
virtual void mainLoop();
virtual void close();
virtual void enter(SInt32 xAbs, SInt32 yAbs,
UInt32 seqNum, KeyModifierMask mask,
bool forScreensaver);
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);
virtual void screensaver(bool activate);
virtual void resetOptions();
virtual void setOptions(const COptionsList& options);
virtual CString getName() const;
virtual SInt32 getJumpZoneSize() const;
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const;
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:
// notify status jobs of a change
void runStatusJobs() const;
// set new status
void setStatus(EStatus, const char* msg = NULL);
// open/close the secondary screen
void openSecondaryScreen();
void closeSecondaryScreen();
// send the clipboard to the server
void sendClipboard(ClipboardID);
// handle server messaging
void runSession(void*);
void deleteSession(double timeout = -1.0);
void runServer();
CServerProxy* handshakeServer(IDataSocket*);
2001-10-06 14:13:28 +00:00
2002-04-29 14:40:01 +00:00
private:
CMutex m_mutex;
2001-10-06 14:13:28 +00:00
CString m_name;
CSecondaryScreen* m_screen;
2002-07-10 21:22:28 +00:00
IScreenReceiver* m_server;
CNetworkAddress m_serverAddress;
bool m_camp;
ISecondaryScreenFactory* m_screenFactory;
ISocketFactory* m_socketFactory;
IStreamFilterFactory* m_streamFilterFactory;
CThread* m_session;
bool m_active;
bool m_rejected;
bool m_ownClipboard[kClipboardEnd];
IClipboard::Time m_timeClipboard[kClipboardEnd];
CString m_dataClipboard[kClipboardEnd];
// the status change jobs and status
CJobList m_statusJobs;
EStatus m_status;
CString m_statusMessage;
2001-10-06 14:13:28 +00:00
};
#endif