2001-10-06 18:13:28 +04:00
|
|
|
#ifndef CSERVER_H
|
|
|
|
#define CSERVER_H
|
|
|
|
|
2002-04-27 18:19:53 +04:00
|
|
|
#include "ClipboardTypes.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
#include "KeyTypes.h"
|
|
|
|
#include "MouseTypes.h"
|
2002-05-31 18:34:16 +04:00
|
|
|
#include "CConfig.h"
|
2001-11-25 21:32:41 +03:00
|
|
|
#include "CClipboard.h"
|
2002-06-02 15:49:46 +04:00
|
|
|
#include "CCondVar.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
#include "CMutex.h"
|
|
|
|
#include "CString.h"
|
2002-05-31 22:09:43 +04:00
|
|
|
#include "CThread.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
#include "XBase.h"
|
2002-06-01 23:26:11 +04:00
|
|
|
#include "stdlist.h"
|
|
|
|
#include "stdmap.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
class CThread;
|
|
|
|
class IServerProtocol;
|
|
|
|
class ISocketFactory;
|
|
|
|
class ISecurityFactory;
|
|
|
|
class IPrimaryScreen;
|
2002-05-30 20:13:16 +04:00
|
|
|
class CHTTPServer;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
class CServer {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2001-10-06 18:13:28 +04:00
|
|
|
CServer();
|
|
|
|
~CServer();
|
|
|
|
|
|
|
|
// manipulators
|
|
|
|
|
2001-11-19 03:33:36 +03:00
|
|
|
// start the server. does not return until quit() is called.
|
2001-10-06 18:13:28 +04:00
|
|
|
void run();
|
|
|
|
|
2001-11-19 03:33:36 +03:00
|
|
|
// tell server to exit gracefully
|
|
|
|
void quit();
|
|
|
|
|
2002-05-31 22:09:43 +04:00
|
|
|
// update screen map. returns true iff the new configuration was
|
|
|
|
// accepted.
|
|
|
|
bool setConfig(const CConfig&);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2001-11-19 03:33:36 +03:00
|
|
|
// handle events on server's screen. onMouseMovePrimary() returns
|
|
|
|
// true iff the mouse enters a jump zone and jumps.
|
2001-10-06 18:13:28 +04:00
|
|
|
void onKeyDown(KeyID, KeyModifierMask);
|
|
|
|
void onKeyUp(KeyID, KeyModifierMask);
|
2001-11-25 21:32:41 +03:00
|
|
|
void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count);
|
2001-10-06 18:13:28 +04:00
|
|
|
void onMouseDown(ButtonID);
|
|
|
|
void onMouseUp(ButtonID);
|
2001-11-19 03:33:36 +03:00
|
|
|
bool onMouseMovePrimary(SInt32 x, SInt32 y);
|
2001-10-06 18:13:28 +04:00
|
|
|
void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
|
|
|
|
void onMouseWheel(SInt32 delta);
|
2002-04-27 18:19:53 +04:00
|
|
|
void grabClipboard(ClipboardID);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-05-24 21:54:28 +04:00
|
|
|
// handle updates from primary
|
|
|
|
void setInfo(SInt32 wScreen, SInt32 hScreen,
|
|
|
|
SInt32 zoneSize,
|
|
|
|
SInt32 xMouse, SInt32 yMouse);
|
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
// handle messages from clients
|
|
|
|
void setInfo(const CString& clientName,
|
2002-05-24 21:54:28 +04:00
|
|
|
SInt32 wScreen, SInt32 hScreen,
|
|
|
|
SInt32 zoneSize,
|
|
|
|
SInt32 xMouse, SInt32 yMouse);
|
2002-04-29 17:31:44 +04:00
|
|
|
void grabClipboard(ClipboardID,
|
|
|
|
UInt32 seqNum, const CString& clientName);
|
2002-04-27 18:19:53 +04:00
|
|
|
void setClipboard(ClipboardID,
|
|
|
|
UInt32 seqNum, const CString& data);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// accessors
|
|
|
|
|
2002-06-01 14:52:02 +04:00
|
|
|
// returns true if the mouse should be locked to the current screen
|
2001-10-06 18:13:28 +04:00
|
|
|
bool isLockedToScreen() const;
|
|
|
|
|
|
|
|
// get the current screen map
|
2002-05-31 18:43:23 +04:00
|
|
|
void getConfig(CConfig*) const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-05-30 20:13:16 +04:00
|
|
|
// get the primary screen's name
|
|
|
|
CString getPrimaryScreenName() const;
|
|
|
|
|
2001-11-19 03:33:36 +03:00
|
|
|
// get the sides of the primary screen that have neighbors
|
|
|
|
UInt32 getActivePrimarySides() const;
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
protected:
|
2001-10-06 18:13:28 +04:00
|
|
|
bool onCommandKey(KeyID, KeyModifierMask, bool down);
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2001-10-06 18:13:28 +04:00
|
|
|
class CCleanupNote {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2001-10-06 18:13:28 +04:00
|
|
|
CCleanupNote(CServer*);
|
|
|
|
~CCleanupNote();
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2001-10-06 18:13:28 +04:00
|
|
|
CServer* m_server;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CConnectionNote {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2001-10-06 18:13:28 +04:00
|
|
|
CConnectionNote(CServer*, const CString&, IServerProtocol*);
|
|
|
|
~CConnectionNote();
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2001-10-06 18:13:28 +04:00
|
|
|
bool m_pending;
|
|
|
|
CServer* m_server;
|
|
|
|
CString m_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CScreenInfo {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2001-10-06 18:13:28 +04:00
|
|
|
CScreenInfo(const CString& name, IServerProtocol*);
|
|
|
|
~CScreenInfo();
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2002-06-01 14:52:02 +04:00
|
|
|
// the thread handling this screen's connection. used when
|
|
|
|
// forcing a screen to disconnect.
|
2002-05-31 22:09:43 +04:00
|
|
|
CThread m_thread;
|
2001-10-06 18:13:28 +04:00
|
|
|
CString m_name;
|
|
|
|
IServerProtocol* m_protocol;
|
2002-06-01 14:52:02 +04:00
|
|
|
bool m_ready;
|
2001-10-06 18:13:28 +04:00
|
|
|
SInt32 m_width, m_height;
|
|
|
|
SInt32 m_zoneSize;
|
2002-04-27 18:19:53 +04:00
|
|
|
bool m_gotClipboard[kClipboardEnd];
|
2001-10-06 18:13:28 +04:00
|
|
|
};
|
|
|
|
|
2002-06-01 14:52:02 +04:00
|
|
|
// handle mouse motion
|
|
|
|
bool onMouseMovePrimaryNoLock(SInt32 x, SInt32 y);
|
|
|
|
void onMouseMoveSecondaryNoLock(SInt32 dx, SInt32 dy);
|
|
|
|
|
|
|
|
// update screen info
|
|
|
|
void setInfoNoLock(const CString& screenName,
|
|
|
|
SInt32 wScreen, SInt32 hScreen,
|
|
|
|
SInt32 zoneSize,
|
|
|
|
SInt32 xMouse, SInt32 yMouse);
|
|
|
|
|
|
|
|
// grab the clipboard
|
|
|
|
void grabClipboardNoLock(ClipboardID,
|
|
|
|
UInt32 seqNum, const CString& clientName);
|
|
|
|
|
|
|
|
// returns true iff mouse should be locked to the current screen
|
|
|
|
bool isLockedToScreenNoLock() const;
|
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
// change the active screen
|
|
|
|
void switchScreen(CScreenInfo*, SInt32 x, SInt32 y);
|
|
|
|
|
|
|
|
// lookup neighboring screen
|
2002-05-31 18:43:23 +04:00
|
|
|
CScreenInfo* getNeighbor(CScreenInfo*, CConfig::EDirection) const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// 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*,
|
2002-05-31 18:43:23 +04:00
|
|
|
CConfig::EDirection,
|
2001-10-06 18:13:28 +04:00
|
|
|
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,
|
2002-05-31 18:43:23 +04:00
|
|
|
CConfig::EDirection srcSide,
|
2001-10-06 18:13:28 +04:00
|
|
|
CScreenInfo* dst,
|
|
|
|
SInt32& x, SInt32& y) const;
|
|
|
|
|
|
|
|
// open/close the primary screen
|
|
|
|
void openPrimaryScreen();
|
2001-10-14 20:58:01 +04:00
|
|
|
void closePrimaryScreen();
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-04-29 17:31:44 +04:00
|
|
|
// clear gotClipboard flags in all screens
|
|
|
|
void clearGotClipboard(ClipboardID);
|
|
|
|
|
|
|
|
// send clipboard to the active screen if it doesn't already have it
|
|
|
|
void sendClipboard(ClipboardID);
|
|
|
|
|
|
|
|
// update the clipboard if owned by the primary screen
|
|
|
|
void updatePrimaryClipboard(ClipboardID);
|
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
// cancel running threads
|
2001-10-14 20:58:01 +04:00
|
|
|
void cleanupThreads();
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// thread method to accept incoming client connections
|
|
|
|
void acceptClients(void*);
|
|
|
|
|
|
|
|
// thread method to do startup handshake with client
|
|
|
|
void handshakeClient(void*);
|
|
|
|
|
2002-05-30 20:13:16 +04:00
|
|
|
// thread method to accept incoming HTTP connections
|
|
|
|
void acceptHTTPClients(void*);
|
|
|
|
|
|
|
|
// thread method to process HTTP requests
|
|
|
|
void processHTTPRequest(void*);
|
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
// 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);
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2001-10-06 18:13:28 +04:00
|
|
|
typedef std::list<CThread*> CThreadList;
|
|
|
|
typedef std::map<CString, CScreenInfo*> CScreenList;
|
2002-04-29 17:31:44 +04:00
|
|
|
class CClipboardInfo {
|
2002-04-27 18:19:53 +04:00
|
|
|
public:
|
2002-04-29 17:31:44 +04:00
|
|
|
CClipboardInfo();
|
2002-04-27 18:19:53 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
CClipboard m_clipboard;
|
|
|
|
CString m_clipboardData;
|
|
|
|
CString m_clipboardOwner;
|
|
|
|
UInt32 m_clipboardSeqNum;
|
|
|
|
bool m_clipboardReady;
|
|
|
|
};
|
2001-10-06 18:13:28 +04: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-25 03:29:29 +04:00
|
|
|
CScreenInfo* m_primaryInfo;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-04-29 17:31:44 +04:00
|
|
|
// the sequence number of enter messages
|
|
|
|
UInt32 m_seqNum;
|
|
|
|
|
2002-05-24 21:54:28 +04:00
|
|
|
// current mouse position (in absolute secondary screen coordinates)
|
2001-10-06 18:13:28 +04:00
|
|
|
SInt32 m_x, m_y;
|
|
|
|
|
2002-05-31 18:43:23 +04:00
|
|
|
CConfig m_config;
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2002-04-29 17:31:44 +04:00
|
|
|
CClipboardInfo m_clipboards[kClipboardEnd];
|
2002-05-30 20:13:16 +04:00
|
|
|
|
2002-06-02 15:49:46 +04:00
|
|
|
// HTTP request processing stuff
|
2002-05-30 20:13:16 +04:00
|
|
|
CHTTPServer* m_httpServer;
|
2002-06-02 15:49:46 +04:00
|
|
|
CCondVar<SInt32> m_httpAvailable;
|
|
|
|
static const SInt32 s_httpMaxSimultaneousRequests;
|
2001-10-06 18:13:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|