00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CSERVER_H
00020 #define CSERVER_H
00021
00022 #include "CConfig.h"
00023 #include "CClipboard.h"
00024 #include "ClipboardTypes.h"
00025 #include "KeyTypes.h"
00026 #include "MouseTypes.h"
00027 #include "CEvent.h"
00028 #include "CStopwatch.h"
00029 #include "stdmap.h"
00030 #include "stdset.h"
00031 #include "stdvector.h"
00032 #include "INode.h"
00033
00034 class CBaseClientProxy;
00035 class CEventQueueTimer;
00036 class CPrimaryClient;
00037 class CInputFilter;
00038 class CScreen;
00039
00041
00044 class CServer : public INode {
00045 public:
00047 class CLockCursorToScreenInfo {
00048 public:
00049 enum State { kOff, kOn, kToggle };
00050
00051 static CLockCursorToScreenInfo* alloc(State state = kToggle);
00052
00053 public:
00054 State m_state;
00055 };
00056
00058 class CSwitchToScreenInfo {
00059 public:
00060 static CSwitchToScreenInfo* alloc(const CString& screen);
00061
00062 public:
00063
00064 char m_screen[1];
00065 };
00066
00068 class CSwitchInDirectionInfo {
00069 public:
00070 static CSwitchInDirectionInfo* alloc(EDirection direction);
00071
00072 public:
00073 EDirection m_direction;
00074 };
00075
00077 class CScreenConnectedInfo {
00078 public:
00079 CScreenConnectedInfo(CString screen) : m_screen(screen) { }
00080
00081 public:
00082 CString m_screen;
00083 };
00084
00086 class CKeyboardBroadcastInfo {
00087 public:
00088 enum State { kOff, kOn, kToggle };
00089
00090 static CKeyboardBroadcastInfo* alloc(State state = kToggle);
00091 static CKeyboardBroadcastInfo* alloc(State state,
00092 const CString& screens);
00093
00094 public:
00095 State m_state;
00096 char m_screens[1];
00097 };
00098
00104 CServer(const CConfig& config, CPrimaryClient* primaryClient, CScreen* screen);
00105 ~CServer();
00106
00107 #ifdef TEST_ENV
00108 CServer() { }
00109 #endif
00110
00112
00113
00115
00120 bool setConfig(const CConfig&);
00121
00123
00127 void adoptClient(CBaseClientProxy* client);
00128
00130
00136 void disconnect();
00137
00139 void gameDeviceTimingResp(UInt16 freq);
00140
00142 void gameDeviceFeedback(GameDeviceID id, UInt16 m1, UInt16 m2);
00143
00145
00146
00147
00149
00152 UInt32 getNumClients() const;
00153
00155
00158 void getClients(std::vector<CString>& list) const;
00159
00161
00165 static CEvent::Type getErrorEvent();
00166
00168
00173 static CEvent::Type getConnectedEvent();
00174
00176
00180 static CEvent::Type getDisconnectedEvent();
00181
00183
00188 static CEvent::Type getSwitchToScreenEvent();
00189
00191
00196 static CEvent::Type getSwitchInDirectionEvent();
00197
00199
00204 static CEvent::Type getKeyboardBroadcastEvent();
00205
00207
00212 static CEvent::Type getLockCursorToScreenEvent();
00213
00215
00219 static CEvent::Type getScreenSwitchedEvent();
00220
00222
00223 private:
00224
00225 CString getName(const CBaseClientProxy*) const;
00226
00227
00228 UInt32 getActivePrimarySides() const;
00229
00230
00231
00232
00233 bool isLockedToScreenServer() const;
00234
00235
00236
00237 bool isLockedToScreen() const;
00238
00239
00240 SInt32 getJumpZoneSize(CBaseClientProxy*) const;
00241
00242
00243 void switchScreen(CBaseClientProxy*,
00244 SInt32 x, SInt32 y, bool forScreenSaver);
00245
00246
00247 void jumpToScreen(CBaseClientProxy*);
00248
00249
00250
00251 float mapToFraction(CBaseClientProxy*, EDirection,
00252 SInt32 x, SInt32 y) const;
00253
00254
00255
00256 void mapToPixel(CBaseClientProxy*, EDirection, float f,
00257 SInt32& x, SInt32& y) const;
00258
00259
00260
00261 bool hasAnyNeighbor(CBaseClientProxy*, EDirection) const;
00262
00263
00264
00265 CBaseClientProxy* getNeighbor(CBaseClientProxy*, EDirection,
00266 SInt32& x, SInt32& y) const;
00267
00268
00269
00270
00271
00272
00273 CBaseClientProxy* mapToNeighbor(CBaseClientProxy*, EDirection,
00274 SInt32& x, SInt32& y) const;
00275
00276
00277
00278 void avoidJumpZone(CBaseClientProxy*, EDirection,
00279 SInt32& x, SInt32& y) const;
00280
00281
00282
00283
00284 bool isSwitchOkay(CBaseClientProxy* dst, EDirection,
00285 SInt32 x, SInt32 y, SInt32 xActive, SInt32 yActive);
00286
00287
00288
00289 void noSwitch(SInt32 x, SInt32 y);
00290
00291
00292 void stopSwitch();
00293
00294
00295 void startSwitchTwoTap();
00296
00297
00298 void armSwitchTwoTap(SInt32 x, SInt32 y);
00299
00300
00301 void stopSwitchTwoTap();
00302
00303
00304 bool isSwitchTwoTapStarted() const;
00305
00306
00307 bool shouldSwitchTwoTap() const;
00308
00309
00310 void startSwitchWait(SInt32 x, SInt32 y);
00311
00312
00313 void stopSwitchWait();
00314
00315
00316 bool isSwitchWaitStarted() const;
00317
00318
00319
00320 UInt32 getCorner(CBaseClientProxy*,
00321 SInt32 x, SInt32 y, SInt32 size) const;
00322
00323
00324 void stopRelativeMoves();
00325
00326
00327 void sendOptions(CBaseClientProxy* client) const;
00328
00329
00330 void processOptions();
00331
00332
00333 void handleShapeChanged(const CEvent&, void*);
00334 void handleClipboardGrabbed(const CEvent&, void*);
00335 void handleClipboardChanged(const CEvent&, void*);
00336 void handleKeyDownEvent(const CEvent&, void*);
00337 void handleKeyUpEvent(const CEvent&, void*);
00338 void handleKeyRepeatEvent(const CEvent&, void*);
00339 void handleButtonDownEvent(const CEvent&, void*);
00340 void handleButtonUpEvent(const CEvent&, void*);
00341 void handleMotionPrimaryEvent(const CEvent&, void*);
00342 void handleMotionSecondaryEvent(const CEvent&, void*);
00343 void handleWheelEvent(const CEvent&, void*);
00344 void handleGameDeviceButtons(const CEvent&, void*);
00345 void handleGameDeviceSticks(const CEvent&, void*);
00346 void handleGameDeviceTriggers(const CEvent&, void*);
00347 void handleGameDeviceTimingReq(const CEvent&, void*);
00348 void handleScreensaverActivatedEvent(const CEvent&, void*);
00349 void handleScreensaverDeactivatedEvent(const CEvent&, void*);
00350 void handleSwitchWaitTimeout(const CEvent&, void*);
00351 void handleClientDisconnected(const CEvent&, void*);
00352 void handleClientCloseTimeout(const CEvent&, void*);
00353 void handleSwitchToScreenEvent(const CEvent&, void*);
00354 void handleSwitchInDirectionEvent(const CEvent&, void*);
00355 void handleKeyboardBroadcastEvent(const CEvent&,void*);
00356 void handleLockCursorToScreenEvent(const CEvent&, void*);
00357 void handleFakeInputBeginEvent(const CEvent&, void*);
00358 void handleFakeInputEndEvent(const CEvent&, void*);
00359
00360
00361 void onClipboardChanged(CBaseClientProxy* sender,
00362 ClipboardID id, UInt32 seqNum);
00363 void onScreensaver(bool activated);
00364 void onKeyDown(KeyID, KeyModifierMask, KeyButton,
00365 const char* screens);
00366 void onKeyUp(KeyID, KeyModifierMask, KeyButton,
00367 const char* screens);
00368 void onKeyRepeat(KeyID, KeyModifierMask, SInt32, KeyButton);
00369 void onMouseDown(ButtonID);
00370 void onMouseUp(ButtonID);
00371 bool onMouseMovePrimary(SInt32 x, SInt32 y);
00372 void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
00373 void onMouseWheel(SInt32 xDelta, SInt32 yDelta);
00374 void onGameDeviceButtons(GameDeviceID id, GameDeviceButton buttons);
00375 void onGameDeviceSticks(GameDeviceID id, SInt16 x1, SInt16 y1, SInt16 x2, SInt16 y2);
00376 void onGameDeviceTriggers(GameDeviceID id, UInt8 t1, UInt8 t2);
00377 void onGameDeviceTimingReq();
00378
00379
00380 bool addClient(CBaseClientProxy*);
00381
00382
00383 bool removeClient(CBaseClientProxy*);
00384
00385
00386 void closeClient(CBaseClientProxy*, const char* msg);
00387
00388
00389 void closeClients(const CConfig& config);
00390
00391
00392
00393 void closeAllClients();
00394
00395
00396 void removeActiveClient(CBaseClientProxy*);
00397 void removeOldClient(CBaseClientProxy*);
00398
00399
00400 void forceLeaveClient(CBaseClientProxy* client);
00401
00402 public:
00403 bool m_mock;
00404
00405 private:
00406 class CClipboardInfo {
00407 public:
00408 CClipboardInfo();
00409
00410 public:
00411 CClipboard m_clipboard;
00412 CString m_clipboardData;
00413 CString m_clipboardOwner;
00414 UInt32 m_clipboardSeqNum;
00415 };
00416
00417
00418 CPrimaryClient* m_primaryClient;
00419
00420
00421 typedef std::map<CString, CBaseClientProxy*> CClientList;
00422 typedef std::set<CBaseClientProxy*> CClientSet;
00423 CClientList m_clients;
00424 CClientSet m_clientSet;
00425
00426
00427 typedef std::map<CBaseClientProxy*, CEventQueueTimer*> COldClients;
00428 COldClients m_oldClients;
00429
00430
00431 CBaseClientProxy* m_active;
00432
00433
00434 UInt32 m_seqNum;
00435
00436
00437
00438 SInt32 m_x, m_y;
00439
00440
00441
00442
00443
00444 SInt32 m_xDelta, m_yDelta;
00445 SInt32 m_xDelta2, m_yDelta2;
00446
00447
00448 CConfig m_config;
00449
00450
00451 CInputFilter* m_inputFilter;
00452
00453
00454 CClipboardInfo m_clipboards[kClipboardEnd];
00455
00456
00457 CBaseClientProxy* m_activeSaver;
00458 SInt32 m_xSaver, m_ySaver;
00459
00460
00461
00462 EDirection m_switchDir;
00463 CBaseClientProxy* m_switchScreen;
00464
00465
00466 double m_switchWaitDelay;
00467 CEventQueueTimer* m_switchWaitTimer;
00468 SInt32 m_switchWaitX, m_switchWaitY;
00469
00470
00471 double m_switchTwoTapDelay;
00472 CStopwatch m_switchTwoTapTimer;
00473 bool m_switchTwoTapEngaged;
00474 bool m_switchTwoTapArmed;
00475 SInt32 m_switchTwoTapZone;
00476
00477
00478 bool m_switchNeedsShift;
00479 bool m_switchNeedsControl;
00480 bool m_switchNeedsAlt;
00481
00482
00483 bool m_relativeMoves;
00484
00485
00486
00487 bool m_keyboardBroadcasting;
00488 CString m_keyboardBroadcastingScreens;
00489
00490
00491 bool m_lockedToScreen;
00492
00493
00494 CScreen* m_screen;
00495
00496 static CEvent::Type s_errorEvent;
00497 static CEvent::Type s_connectedEvent;
00498 static CEvent::Type s_disconnectedEvent;
00499 static CEvent::Type s_switchToScreen;
00500 static CEvent::Type s_switchInDirection;
00501 static CEvent::Type s_keyboardBroadcast;
00502 static CEvent::Type s_lockCursorToScreen;
00503 static CEvent::Type s_screenSwitched;
00504 };
00505
00506 #endif