barrier/server/CServer.h

212 lines
5.5 KiB
C
Raw Normal View History

2001-10-06 14:13:28 +00:00
#ifndef CSERVER_H
#define CSERVER_H
#include "IServer.h"
#include "CConfig.h"
#include "CClipboard.h"
#include "CCondVar.h"
2001-10-06 14:13:28 +00:00
#include "CMutex.h"
#include "CThread.h"
#include "stdlist.h"
#include "stdmap.h"
2001-10-06 14:13:28 +00:00
class CClientProxy;
class CHTTPServer;
class CPrimaryClient;
2001-10-06 14:13:28 +00:00
class CThread;
class IClient;
class IDataSocket;
2001-10-06 14:13:28 +00:00
class IServerProtocol;
class ISocketFactory;
class ISecurityFactory;
class CServer : public IServer {
2002-04-29 14:40:01 +00:00
public:
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();
// 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().
void quit();
// update screen map. returns true iff the new configuration was
// accepted.
bool setConfig(const CConfig&);
2001-10-06 14:13:28 +00:00
// accessors
// get the current screen map
void getConfig(CConfig*) const;
2001-10-06 14:13:28 +00:00
// get the primary screen's name
CString getPrimaryScreenName() const;
// get the sides of the primary screen that have neighbors
UInt32 getActivePrimarySides() const;
2002-07-10 21:22:28 +00:00
// IPrimaryScreenReceiver overrides
virtual void onError();
virtual void onKeyDown(KeyID, KeyModifierMask);
virtual void onKeyUp(KeyID, KeyModifierMask);
virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count);
virtual void onMouseDown(ButtonID);
virtual void onMouseUp(ButtonID);
virtual bool onMouseMovePrimary(SInt32 x, SInt32 y);
virtual void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
virtual void onMouseWheel(SInt32 delta);
virtual void onScreenSaver(bool activated);
2002-07-10 21:22:28 +00:00
// IServer overrides
virtual void onInfoChanged(const CString&, const CClientInfo&);
virtual bool onGrabClipboard(const CString&, ClipboardID, UInt32);
virtual void onClipboardChanged(ClipboardID, UInt32, const CString&);
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:
typedef std::list<CThread> CThreadList;
2001-10-06 14:13:28 +00:00
// handle mouse motion
bool onMouseMovePrimaryNoLock(SInt32 x, SInt32 y);
void onMouseMoveSecondaryNoLock(SInt32 dx, SInt32 dy);
// set the clipboard
void onClipboardChangedNoLock(ClipboardID,
UInt32 seqNum, const CString& data);
// 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
void switchScreen(IClient*,
SInt32 x, SInt32 y, bool forScreenSaver);
2001-10-06 14:13:28 +00:00
// lookup neighboring screen
IClient* getNeighbor(IClient*, 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
// cross multiple screens. if there is no suitable screen then
// return NULL and x,y are not modified.
IClient* getNeighbor(IClient*,
CConfig::EDirection,
SInt32& x, SInt32& y) const;
2001-10-06 14:13:28 +00:00
// open/close the primary screen
void openPrimaryScreen();
void closePrimaryScreen();
2001-10-06 14:13:28 +00:00
// update the clipboard if owned by the primary screen
void updatePrimaryClipboard(ClipboardID);
// close all clients that are *not* in config, not including the
// primary client.
void closeClients(const CConfig& config);
// 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 client interaction
void runClient(void*);
CClientProxy* handshakeClient(IDataSocket*);
2001-10-06 14:13:28 +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
void addConnection(IClient*);
2001-10-06 14:13:28 +00:00
void removeConnection(const CString& name);
2002-04-29 14:40:01 +00:00
private:
class CClipboardInfo {
public:
CClipboardInfo();
public:
CClipboard m_clipboard;
CString m_clipboardData;
CString m_clipboardOwner;
UInt32 m_clipboardSeqNum;
};
2001-10-06 14:13:28 +00:00
CMutex m_mutex;
// the name of the primary screen
CString m_name;
// how long to wait to bind our socket until we give up
2001-10-06 14:13:28 +00:00
double m_bindTimeout;
ISocketFactory* m_socketFactory;
ISecurityFactory* m_securityFactory;
// running threads
CThreadList m_threads;
2001-10-06 14:13:28 +00:00
// the screens
typedef std::map<CString, IClient*> CClientList;
typedef std::map<CString, CThread> CClientThreadList;
// all clients indexed by name
CClientList m_clients;
// run thread of all secondary screen clients. does not include the
// primary screen's run thread.
CClientThreadList m_clientThreads;
// the primary screen client
CPrimaryClient* m_primaryClient;
// the client with focus
IClient* m_active;
2001-10-06 14:13:28 +00:00
// the sequence number of enter messages
UInt32 m_seqNum;
// current mouse position (in absolute secondary screen coordinates)
2001-10-06 14:13:28 +00:00
SInt32 m_x, m_y;
// current configuration
CConfig m_config;
// clipboard cache
CClipboardInfo m_clipboards[kClipboardEnd];
// state saved when screen saver activates
IClient* m_activeSaver;
SInt32 m_xSaver, m_ySaver;
// HTTP request processing stuff
CHTTPServer* m_httpServer;
CCondVar<SInt32> m_httpAvailable;
static const SInt32 s_httpMaxSimultaneousRequests;
2001-10-06 14:13:28 +00:00
};
#endif