2001-10-06 14:13:28 +00:00
|
|
|
#ifndef CSERVER_H
|
|
|
|
#define CSERVER_H
|
|
|
|
|
2002-04-27 14:19:53 +00:00
|
|
|
#include "ClipboardTypes.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
#include "KeyTypes.h"
|
|
|
|
#include "MouseTypes.h"
|
|
|
|
#include "CScreenMap.h"
|
2001-11-25 18:32:41 +00:00
|
|
|
#include "CClipboard.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
#include "CMutex.h"
|
|
|
|
#include "CString.h"
|
|
|
|
#include "XBase.h"
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
class CThread;
|
|
|
|
class IServerProtocol;
|
|
|
|
class ISocketFactory;
|
|
|
|
class ISecurityFactory;
|
|
|
|
class IPrimaryScreen;
|
|
|
|
|
|
|
|
class CServer {
|
|
|
|
public:
|
|
|
|
CServer();
|
|
|
|
~CServer();
|
|
|
|
|
|
|
|
// manipulators
|
|
|
|
|
2001-11-19 00:33:36 +00:00
|
|
|
// start the server. does not return until quit() is called.
|
2001-10-06 14:13:28 +00:00
|
|
|
void run();
|
|
|
|
|
2001-11-19 00:33:36 +00:00
|
|
|
// tell server to exit gracefully
|
|
|
|
void quit();
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// update screen map
|
|
|
|
void setScreenMap(const CScreenMap&);
|
|
|
|
|
2001-11-19 00:33:36 +00:00
|
|
|
// handle events on server's screen. onMouseMovePrimary() returns
|
|
|
|
// true iff the mouse enters a jump zone and jumps.
|
2001-10-06 14:13:28 +00:00
|
|
|
void onKeyDown(KeyID, KeyModifierMask);
|
|
|
|
void onKeyUp(KeyID, KeyModifierMask);
|
2001-11-25 18:32:41 +00:00
|
|
|
void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count);
|
2001-10-06 14:13:28 +00:00
|
|
|
void onMouseDown(ButtonID);
|
|
|
|
void onMouseUp(ButtonID);
|
2001-11-19 00:33:36 +00:00
|
|
|
bool onMouseMovePrimary(SInt32 x, SInt32 y);
|
2001-10-06 14:13:28 +00:00
|
|
|
void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
|
|
|
|
void onMouseWheel(SInt32 delta);
|
2002-04-27 14:19:53 +00:00
|
|
|
void grabClipboard(ClipboardID);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// handle messages from clients
|
|
|
|
void setInfo(const CString& clientName,
|
2001-10-14 16:58:01 +00:00
|
|
|
SInt32 w, SInt32 h, SInt32 zoneSize);
|
2002-04-27 14:19:53 +00:00
|
|
|
void grabClipboard(ClipboardID, const CString& clientName);
|
|
|
|
void setClipboard(ClipboardID,
|
|
|
|
UInt32 seqNum, const CString& data);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// accessors
|
|
|
|
|
|
|
|
bool isLockedToScreen() const;
|
|
|
|
|
|
|
|
// get the current screen map
|
|
|
|
void getScreenMap(CScreenMap*) const;
|
|
|
|
|
2001-11-19 00:33:36 +00:00
|
|
|
// get the sides of the primary screen that have neighbors
|
|
|
|
UInt32 getActivePrimarySides() const;
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
protected:
|
|
|
|
bool onCommandKey(KeyID, KeyModifierMask, bool down);
|
|
|
|
|
|
|
|
private:
|
|
|
|
class CCleanupNote {
|
|
|
|
public:
|
|
|
|
CCleanupNote(CServer*);
|
|
|
|
~CCleanupNote();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CServer* m_server;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CConnectionNote {
|
|
|
|
public:
|
|
|
|
CConnectionNote(CServer*, const CString&, IServerProtocol*);
|
|
|
|
~CConnectionNote();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_pending;
|
|
|
|
CServer* m_server;
|
|
|
|
CString m_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CScreenInfo {
|
|
|
|
public:
|
|
|
|
CScreenInfo(const CString& name, IServerProtocol*);
|
|
|
|
~CScreenInfo();
|
|
|
|
|
|
|
|
public:
|
|
|
|
CString m_name;
|
|
|
|
IServerProtocol* m_protocol;
|
|
|
|
SInt32 m_width, m_height;
|
|
|
|
SInt32 m_zoneSize;
|
2002-04-27 14:19:53 +00:00
|
|
|
bool m_gotClipboard[kClipboardEnd];
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// change the active screen
|
|
|
|
void switchScreen(CScreenInfo*, SInt32 x, SInt32 y);
|
|
|
|
|
|
|
|
// lookup neighboring screen
|
|
|
|
CScreenInfo* getNeighbor(CScreenInfo*, CScreenMap::EDirection) const;
|
|
|
|
|
|
|
|
// lookup neighboring screen. given a position relative to the
|
|
|
|
// source screen, find the screen we should move onto and where.
|
|
|
|
// if the position is sufficiently far from the source then we
|
|
|
|
// cross multiple screens.
|
|
|
|
CScreenInfo* getNeighbor(CScreenInfo*,
|
|
|
|
CScreenMap::EDirection,
|
|
|
|
SInt32& x, SInt32& y) const;
|
|
|
|
|
|
|
|
// adjust coordinates to account for resolution differences. the
|
|
|
|
// position is converted to a resolution independent form then
|
|
|
|
// converted back to screen coordinates on the destination screen.
|
|
|
|
void mapPosition(CScreenInfo* src,
|
|
|
|
CScreenMap::EDirection srcSide,
|
|
|
|
CScreenInfo* dst,
|
|
|
|
SInt32& x, SInt32& y) const;
|
|
|
|
|
|
|
|
// open/close the primary screen
|
|
|
|
void openPrimaryScreen();
|
2001-10-14 16:58:01 +00:00
|
|
|
void closePrimaryScreen();
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// cancel running threads
|
2001-10-14 16:58:01 +00:00
|
|
|
void cleanupThreads();
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// thread method to accept incoming client connections
|
|
|
|
void acceptClients(void*);
|
|
|
|
|
|
|
|
// thread method to do startup handshake with client
|
|
|
|
void handshakeClient(void*);
|
|
|
|
|
|
|
|
// thread cleanup list maintenance
|
|
|
|
friend class CCleanupNote;
|
|
|
|
void addCleanupThread(const CThread& thread);
|
|
|
|
void removeCleanupThread(const CThread& thread);
|
|
|
|
|
|
|
|
// connection list maintenance
|
|
|
|
friend class CConnectionNote;
|
|
|
|
CScreenInfo* addConnection(const CString& name, IServerProtocol*);
|
|
|
|
void removeConnection(const CString& name);
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::list<CThread*> CThreadList;
|
|
|
|
typedef std::map<CString, CScreenInfo*> CScreenList;
|
2002-04-27 14:19:53 +00:00
|
|
|
class ClipboardInfo {
|
|
|
|
public:
|
|
|
|
ClipboardInfo();
|
|
|
|
|
|
|
|
public:
|
|
|
|
CClipboard m_clipboard;
|
|
|
|
CString m_clipboardData;
|
|
|
|
CString m_clipboardOwner;
|
|
|
|
UInt32 m_clipboardSeqNum;
|
|
|
|
bool m_clipboardReady;
|
|
|
|
};
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
CMutex m_mutex;
|
|
|
|
|
|
|
|
double m_bindTimeout;
|
|
|
|
|
|
|
|
ISocketFactory* m_socketFactory;
|
|
|
|
ISecurityFactory* m_securityFactory;
|
|
|
|
|
|
|
|
CThreadList m_cleanupList;
|
|
|
|
|
|
|
|
IPrimaryScreen* m_primary;
|
|
|
|
CScreenList m_screens;
|
|
|
|
CScreenInfo* m_active;
|
2001-10-24 23:29:29 +00:00
|
|
|
CScreenInfo* m_primaryInfo;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
SInt32 m_x, m_y;
|
|
|
|
|
|
|
|
CScreenMap m_screenMap;
|
2001-11-25 18:32:41 +00:00
|
|
|
|
2002-04-27 14:19:53 +00:00
|
|
|
ClipboardInfo m_clipboards[kClipboardEnd];
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|