2001-10-06 14:13:28 +00:00
|
|
|
#ifndef CSERVER_H
|
|
|
|
#define CSERVER_H
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
#include "CConfig.h"
|
|
|
|
#include "CClipboard.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"
|
2002-06-09 16:53:25 +00:00
|
|
|
#include "CNetworkAddress.h"
|
2002-06-02 11:49:46 +00:00
|
|
|
#include "CCondVar.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
#include "CMutex.h"
|
2002-05-31 18:09:43 +00:00
|
|
|
#include "CThread.h"
|
2002-06-01 19:26:11 +00:00
|
|
|
#include "stdlist.h"
|
|
|
|
#include "stdmap.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
class CThread;
|
|
|
|
class IServerProtocol;
|
|
|
|
class ISocketFactory;
|
|
|
|
class ISecurityFactory;
|
|
|
|
class IPrimaryScreen;
|
2002-05-30 16:13:16 +00:00
|
|
|
class CHTTPServer;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
class CServer {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2002-06-09 17:59:32 +00:00
|
|
|
CServer(const CString& serverName);
|
2001-10-06 14:13:28 +00:00
|
|
|
~CServer();
|
|
|
|
|
|
|
|
// manipulators
|
|
|
|
|
2002-06-21 17:55:47 +00:00
|
|
|
// open the server's screen
|
|
|
|
bool open();
|
|
|
|
|
2001-11-19 00:33:36 +00:00
|
|
|
// start the server. does not return until quit() is called.
|
2002-06-21 17:55:47 +00:00
|
|
|
// this must be preceeded by a successful call to open().
|
2001-10-06 14:13:28 +00:00
|
|
|
void run();
|
|
|
|
|
2002-06-21 17:55:47 +00:00
|
|
|
// tell server to exit gracefully. this may only be called
|
|
|
|
// after a successful open().
|
2001-11-19 00:33:36 +00:00
|
|
|
void quit();
|
|
|
|
|
2002-06-03 13:45:30 +00:00
|
|
|
// tell the server to shutdown. this is called in an emergency
|
|
|
|
// when we need to tell the server that we cannot continue. the
|
|
|
|
// server will attempt to clean up.
|
|
|
|
void shutdown();
|
|
|
|
|
2002-05-31 18:09:43 +00:00
|
|
|
// update screen map. returns true iff the new configuration was
|
|
|
|
// accepted.
|
|
|
|
bool setConfig(const CConfig&);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
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);
|
2002-06-22 19:20:21 +00:00
|
|
|
void onScreenSaver(bool activated);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-05-24 17:54:28 +00:00
|
|
|
// handle updates from primary
|
2002-06-19 17:03:29 +00:00
|
|
|
void setInfo(SInt32 xScreen, SInt32 yScreen,
|
|
|
|
SInt32 wScreen, SInt32 hScreen,
|
2002-06-10 22:06:45 +00:00
|
|
|
SInt32 zoneSize,
|
|
|
|
SInt32 xMouse, SInt32 yMouse);
|
2002-05-24 17:54:28 +00:00
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// handle messages from clients
|
|
|
|
void setInfo(const CString& clientName,
|
2002-06-19 17:03:29 +00:00
|
|
|
SInt32 xScreen, SInt32 yScreen,
|
2002-06-10 22:06:45 +00:00
|
|
|
SInt32 wScreen, SInt32 hScreen,
|
|
|
|
SInt32 zoneSize,
|
|
|
|
SInt32 xMouse, SInt32 yMouse);
|
2002-04-29 13:31:44 +00:00
|
|
|
void grabClipboard(ClipboardID,
|
2002-06-10 22:06:45 +00:00
|
|
|
UInt32 seqNum, const CString& clientName);
|
2002-04-27 14:19:53 +00:00
|
|
|
void setClipboard(ClipboardID,
|
2002-06-10 22:06:45 +00:00
|
|
|
UInt32 seqNum, const CString& data);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// accessors
|
|
|
|
|
2002-06-01 10:52:02 +00:00
|
|
|
// returns true if the mouse should be locked to the current screen
|
2001-10-06 14:13:28 +00:00
|
|
|
bool isLockedToScreen() const;
|
|
|
|
|
|
|
|
// get the current screen map
|
2002-05-31 14:43:23 +00:00
|
|
|
void getConfig(CConfig*) const;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-05-30 16:13:16 +00:00
|
|
|
// get the primary screen's name
|
|
|
|
CString getPrimaryScreenName() const;
|
|
|
|
|
2001-11-19 00:33:36 +00:00
|
|
|
// get the sides of the primary screen that have neighbors
|
|
|
|
UInt32 getActivePrimarySides() const;
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
protected:
|
2001-10-06 14:13:28 +00:00
|
|
|
bool onCommandKey(KeyID, KeyModifierMask, bool down);
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2002-06-21 15:18:01 +00:00
|
|
|
typedef std::list<CThread*> CThreadList;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
class CScreenInfo {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2001-10-06 14:13:28 +00:00
|
|
|
CScreenInfo(const CString& name, IServerProtocol*);
|
|
|
|
~CScreenInfo();
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2002-06-01 10:52:02 +00:00
|
|
|
// the thread handling this screen's connection. used when
|
|
|
|
// forcing a screen to disconnect.
|
2002-05-31 18:09:43 +00:00
|
|
|
CThread m_thread;
|
2001-10-06 14:13:28 +00:00
|
|
|
CString m_name;
|
|
|
|
IServerProtocol* m_protocol;
|
2002-06-01 10:52:02 +00:00
|
|
|
bool m_ready;
|
2002-06-19 17:03:29 +00:00
|
|
|
|
|
|
|
// screen shape and jump zone size
|
|
|
|
SInt32 m_x, m_y;
|
|
|
|
SInt32 m_w, m_h;
|
2001-10-06 14:13:28 +00:00
|
|
|
SInt32 m_zoneSize;
|
2002-06-19 17:03:29 +00:00
|
|
|
|
2002-04-27 14:19:53 +00:00
|
|
|
bool m_gotClipboard[kClipboardEnd];
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
2002-06-01 10:52:02 +00:00
|
|
|
// handle mouse motion
|
|
|
|
bool onMouseMovePrimaryNoLock(SInt32 x, SInt32 y);
|
|
|
|
void onMouseMoveSecondaryNoLock(SInt32 dx, SInt32 dy);
|
|
|
|
|
|
|
|
// update screen info
|
|
|
|
void setInfoNoLock(const CString& screenName,
|
2002-06-19 17:03:29 +00:00
|
|
|
SInt32 xScreen, SInt32 yScreen,
|
2002-06-10 22:06:45 +00:00
|
|
|
SInt32 wScreen, SInt32 hScreen,
|
|
|
|
SInt32 zoneSize,
|
|
|
|
SInt32 xMouse, SInt32 yMouse);
|
2002-06-01 10:52:02 +00:00
|
|
|
|
|
|
|
// grab the clipboard
|
|
|
|
void grabClipboardNoLock(ClipboardID,
|
2002-06-10 22:06:45 +00:00
|
|
|
UInt32 seqNum, const CString& clientName);
|
2002-06-01 10:52:02 +00:00
|
|
|
|
|
|
|
// returns true iff mouse should be locked to the current screen
|
|
|
|
bool isLockedToScreenNoLock() const;
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// change the active screen
|
2002-06-23 23:24:22 +00:00
|
|
|
void switchScreen(CScreenInfo*,
|
|
|
|
SInt32 x, SInt32 y, bool forScreenSaver);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// lookup neighboring screen
|
2002-05-31 14:43:23 +00:00
|
|
|
CScreenInfo* getNeighbor(CScreenInfo*, CConfig::EDirection) const;
|
2001-10-06 14:13:28 +00: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
|
2002-06-19 17:03:29 +00:00
|
|
|
// cross multiple screens. if there is no suitable screen then
|
|
|
|
// return NULL and x,y are not modified.
|
2001-10-06 14:13:28 +00:00
|
|
|
CScreenInfo* getNeighbor(CScreenInfo*,
|
2002-06-10 22:06:45 +00:00
|
|
|
CConfig::EDirection,
|
|
|
|
SInt32& x, SInt32& y) const;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2002-04-29 13:31:44 +00: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);
|
|
|
|
|
2002-06-21 15:18:01 +00:00
|
|
|
// start a thread, adding it to the list of threads
|
|
|
|
void startThread(IJob* adopted);
|
|
|
|
|
|
|
|
// cancel running threads, waiting at most timeout seconds for
|
|
|
|
// them to finish.
|
|
|
|
void stopThreads(double timeout = -1.0);
|
|
|
|
|
|
|
|
// reap threads, clearing finished threads from the thread list.
|
|
|
|
// doReapThreads does the work on the given thread list.
|
|
|
|
void reapThreads();
|
|
|
|
void doReapThreads(CThreadList&);
|
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*);
|
|
|
|
|
2002-05-30 16:13:16 +00:00
|
|
|
// thread method to accept incoming HTTP connections
|
|
|
|
void acceptHTTPClients(void*);
|
|
|
|
|
|
|
|
// thread method to process HTTP requests
|
|
|
|
void processHTTPRequest(void*);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// connection list maintenance
|
|
|
|
CScreenInfo* addConnection(const CString& name, IServerProtocol*);
|
|
|
|
void removeConnection(const CString& name);
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2001-10-06 14:13:28 +00:00
|
|
|
typedef std::map<CString, CScreenInfo*> CScreenList;
|
2002-04-29 13:31:44 +00:00
|
|
|
class CClipboardInfo {
|
2002-04-27 14:19:53 +00:00
|
|
|
public:
|
2002-04-29 13:31:44 +00:00
|
|
|
CClipboardInfo();
|
2002-04-27 14:19:53 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// the name of the primary screen
|
2002-06-09 17:59:32 +00:00
|
|
|
CString m_name;
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
double m_bindTimeout;
|
|
|
|
|
|
|
|
ISocketFactory* m_socketFactory;
|
|
|
|
ISecurityFactory* m_securityFactory;
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// running threads
|
2002-06-21 15:18:01 +00:00
|
|
|
CThreadList m_threads;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// the screens
|
2001-10-06 14:13:28 +00:00
|
|
|
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
|
|
|
|
2002-04-29 13:31:44 +00:00
|
|
|
// the sequence number of enter messages
|
|
|
|
UInt32 m_seqNum;
|
|
|
|
|
2002-05-24 17:54:28 +00:00
|
|
|
// current mouse position (in absolute secondary screen coordinates)
|
2001-10-06 14:13:28 +00:00
|
|
|
SInt32 m_x, m_y;
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// current configuration
|
2002-05-31 14:43:23 +00:00
|
|
|
CConfig m_config;
|
2001-11-25 18:32:41 +00:00
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// clipboard cache
|
2002-04-29 13:31:44 +00:00
|
|
|
CClipboardInfo m_clipboards[kClipboardEnd];
|
2002-05-30 16:13:16 +00:00
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// state saved when screen saver activates
|
|
|
|
CScreenInfo* m_activeSaver;
|
|
|
|
SInt32 m_xSaver, m_ySaver;
|
|
|
|
|
2002-06-02 11:49:46 +00:00
|
|
|
// HTTP request processing stuff
|
2002-05-30 16:13:16 +00:00
|
|
|
CHTTPServer* m_httpServer;
|
2002-06-02 11:49:46 +00:00
|
|
|
CCondVar<SInt32> m_httpAvailable;
|
|
|
|
static const SInt32 s_httpMaxSimultaneousRequests;
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|