Changeset 45:72d5105fcb72 in xplra for src
- Timestamp:
- 02/16/13 09:02:30 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/plugin/src/xplra
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/plugin/src/xplra/Globals.h
r44 r45 33 33 #include "MessageWindow.h" 34 34 #include "Menu.h" 35 #include "HotkeyHandler.h" 35 36 36 37 //------------------------------------------------------------------------------ … … 67 68 Menu menu; 68 69 70 /** 71 * The hotkey handler. 72 */ 73 HotkeyHandler hotkeyHandler; 74 69 75 public: 70 76 /** … … 82 88 */ 83 89 MessageWindow& getMessageWindow(); 90 91 /** 92 * Get the hotkey handler. 93 */ 94 HotkeyHandler& getHotkeyHandler(); 84 95 }; 85 96 86 97 //------------------------------------------------------------------------------ 87 98 // Inline definitions 99 //------------------------------------------------------------------------------ 100 101 inline void Globals::getVersions(int& xplaneV, int& xplmV) const 102 { 103 xplaneV = xplaneVersion; 104 xplmV = xplmVersion; 105 } 106 88 107 //------------------------------------------------------------------------------ 89 108 … … 95 114 //------------------------------------------------------------------------------ 96 115 97 inline void Globals::getVersions(int& xplaneV, int& xplmV) const116 inline HotkeyHandler& Globals::getHotkeyHandler() 98 117 { 99 xplaneV = xplaneVersion; 100 xplmV = xplmVersion; 118 return hotkeyHandler; 101 119 } 102 120 -
src/plugin/src/xplra/Makefile.am
r44 r45 21 21 MessageWindow.cc \ 22 22 MessageRequest.cc \ 23 Menu.cc 23 Menu.cc \ 24 HotkeyHandler.cc 24 25 25 26 noinst_HEADERS= \ … … 41 42 MessageWindow.h \ 42 43 MessageRequest.h \ 43 Menu.h 44 Menu.h \ 45 HotkeyHandler.h 44 46 45 47 if TARGET_API_POSIX -
src/plugin/src/xplra/Protocol.h
r39 r45 107 107 108 108 /** 109 * Command: register a set of hotkeys for the client. Old hotkeys, 110 * if any, are forgotten. 111 * 112 * The command is followed by the following data: 113 * - The number of the hotkeys defined (U32). 114 * - The code of the hotkeys (U16*number of the hotkeys). 115 * The lower byte is the same as the X-Plane virtual key code 116 * (the same as the ASCII code for numbers and upper-case letters), 117 * the upper one is a logical OR of the HOTKEY_MODIFIER_XXX 118 * codes. 119 * 120 * The reply consists of a result code only. It may fail with an 121 * invalid length code if the number of hotkeys is too large. 122 */ 123 static const uint8_t COMMAND_REGISTER_HOTKEYS = 0x51; 124 125 /** 126 * Command: query the hotkeys. 127 * 128 * The reply consists of a result code, followed by the following 129 * data, if the result code is RESULT_OK: 130 * - The number of hotkeys defined (U32). 131 * - An array of U8 values each being 0 or 1 depending on whether 132 * the corresponding hotkey has been pressed since the last 133 * query (or the registration, whichever is later). The value at 134 * index i corresponds to the hotkey code at index i in the 135 * array passed with COMMAND_REGISTER_HOTKEYS. 136 * 137 * If not hotkey has been registered, the number of hotkeys is 138 * returned as 0. 139 */ 140 static const uint8_t COMMAND_QUERY_HOTKEYS = 0x52; 141 142 /** 143 * Command: unregister the previously registered hotkeys. 144 * 145 * The reply is a result code. 146 */ 147 static const uint8_t COMMAND_UNREGISTER_HOTKEYS = 0x53; 148 149 /** 109 150 * Data type: int 110 151 */ … … 185 226 */ 186 227 static const uint8_t RESULT_OTHER_ERROR = 0xff; 228 229 /** 230 * Hotkey modifier: shift 231 */ 232 static const uint16_t HOTKEY_MODIFIER_SHIFT = 0x0100; 233 234 /** 235 * Hotkey modifier: control 236 */ 237 static const uint16_t HOTKEY_MODIFIER_CONTROL = 0x0200; 187 238 188 239 /** … … 201 252 */ 202 253 static const float MAX_MESSAGE_DURATION = 5*60; 254 255 /** 256 * The maximal number of hotkeys that can be registered for a 257 * client. 258 */ 259 static const size_t MAX_HOTKEY_COUNT = 128; 203 260 204 261 /** -
src/plugin/src/xplra/ServerThread.cc
r44 r45 76 76 //------------------------------------------------------------------------------ 77 77 78 inline bool ServerThread::destroyHotkeys() 79 { 80 if (hotkeys!=0) { 81 listenThread.getGlobals().getHotkeyHandler().unregisterHotkeys(hotkeys); 82 delete hotkeys; hotkeys = 0; 83 return true; 84 } else { 85 return false; 86 } 87 } 88 89 //------------------------------------------------------------------------------ 90 78 91 ServerThread::ServerThread(ListenThread& listenThread, 79 92 RequestQueue& requestQueue, LocalAcceptor& acceptor) : … … 84 97 stream(*bufferedStream), 85 98 nextGetMultiRequestID(1), 86 nextSetMultiRequestID(1) 99 nextSetMultiRequestID(1), 100 hotkeys(0) 87 101 { 88 102 instancesMutex.lock(); … … 159 173 } else if (command==Protocol::COMMAND_SHOW_MESSAGE) { 160 174 if (!handleShowMessage()) break; 175 } else if (command==Protocol::COMMAND_REGISTER_HOTKEYS) { 176 if (!handleRegisterHotkeys()) break; 177 } else if (command==Protocol::COMMAND_QUERY_HOTKEYS) { 178 if (!handleQueryHotkeys()) break; 179 } else if (command==Protocol::COMMAND_UNREGISTER_HOTKEYS) { 180 if (!handleUnregisterHotkeys()) break; 161 181 } else { 162 182 stream.writeU8(Protocol::RESULT_INVALID_COMMAND); … … 164 184 stream.flush(); 165 185 } 186 187 destroyHotkeys(); 166 188 167 189 Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: quitting\n", this); … … 446 468 //------------------------------------------------------------------------------ 447 469 470 bool ServerThread::handleRegisterHotkeys() 471 { 472 size_t numHotkeys = stream.readU32(); 473 if (!stream) return false; 474 475 if (numHotkeys>Protocol::MAX_HOTKEY_COUNT) { 476 stream.writeU8(Protocol::RESULT_INVALID_LENGTH); 477 } else { 478 HotkeyHandler::Hotkeys* newHotkeys = 479 new HotkeyHandler::Hotkeys(numHotkeys, stream); 480 if (newHotkeys->isValid()) { 481 destroyHotkeys(); 482 hotkeys = newHotkeys; 483 listenThread.getGlobals().getHotkeyHandler().registerHotkeys(hotkeys); 484 stream.writeU8(Protocol::RESULT_OK); 485 } else { 486 delete newHotkeys; 487 return false; 488 } 489 } 490 491 return true; 492 } 493 494 //------------------------------------------------------------------------------ 495 496 bool ServerThread::handleQueryHotkeys() 497 { 498 stream.writeU8(Protocol::RESULT_OK); 499 if (hotkeys==0) { 500 stream.writeU32(0); 501 } else { 502 hotkeys->writePressed(stream); 503 } 504 return true; 505 } 506 507 //------------------------------------------------------------------------------ 508 509 bool ServerThread::handleUnregisterHotkeys() 510 { 511 destroyHotkeys(); 512 stream.writeU8(Protocol::RESULT_OK); 513 return true; 514 } 515 516 //------------------------------------------------------------------------------ 517 448 518 // Local Variables: 449 519 // mode: C++ -
src/plugin/src/xplra/ServerThread.h
r39 r45 31 31 //------------------------------------------------------------------------------ 32 32 33 #include "HotkeyHandler.h" 34 33 35 #include <hu/varadiistvan/scpl/Thread.h> 34 36 … … 141 143 setMultiRequests_t setMultiRequests; 142 144 145 /** 146 * The set of hotkeys currently being handled. 147 */ 148 HotkeyHandler::Hotkeys* hotkeys; 149 143 150 public: 144 151 /** … … 255 262 */ 256 263 bool handleShowMessage(); 264 265 /** 266 * Handle the COMMAND_REGISTER_HOTKEYS command. 267 * 268 * @return true if we can continue, false if the thread should 269 * quit. 270 */ 271 bool handleRegisterHotkeys(); 272 273 /** 274 * Handle the COMMAND_QUERY_HOTKEYS command. 275 * 276 * @return true if we can continue, false if the thread should 277 * quit. 278 */ 279 bool handleQueryHotkeys(); 280 281 /** 282 * Handle the COMMAND_UNREGISTER_HOTKEYS command. 283 * 284 * @return true if we can continue, false if the thread should 285 * quit. 286 */ 287 bool handleUnregisterHotkeys(); 288 289 private: 290 /** 291 * Destroy the current set of hotkeys, if any. 292 * 293 * @return whether there were any hotkeys or not. 294 */ 295 bool destroyHotkeys(); 257 296 }; 258 297
Note:
See TracChangeset
for help on using the changeset viewer.