Changeset 38:128b9ced9779 in xplra
- Timestamp:
- 02/14/13 16:02:05 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/client.py
r10 r38 415 415 print >> sys.stderr, "Invalid dataref at #%d" % (index,) 416 416 elif result!=0: 417 print >> sys.stderr, "Error code:", result 418 419 def do_show_message(self, args): 420 words = self._splitArgs(args) 421 if len(words)<2: 422 print >> sys.stderr, "Missing parameters" 423 return False 424 425 message = words[0] 426 duration = float(words[1]) 427 428 self._writeU8(0x41) 429 self._writeString(message) 430 self._writeFloat(duration) 431 self._flush() 432 433 result = self._readU8() 434 if result!=0: 417 435 print >> sys.stderr, "Error code:", result 418 436 -
src/plugin/src/xplra/ListenThread.h
r36 r38 44 44 //------------------------------------------------------------------------------ 45 45 46 class MessageWindow; 47 48 //------------------------------------------------------------------------------ 49 46 50 /** 47 51 * The thread that listens to incoming connections and starts the … … 62 66 */ 63 67 int xplmVersion; 68 69 /** 70 * The message window for showing messages. 71 */ 72 MessageWindow& messageWindow; 64 73 65 74 /** … … 83 92 * Construct the thread. 84 93 */ 85 ListenThread(int xplaneVersion, int xplmVersion); 94 ListenThread(int xplaneVersion, int xplmVersion, 95 MessageWindow& messageWindow); 86 96 87 97 /** … … 89 99 */ 90 100 void getVersions(int& xplane, int& xplm) const; 101 102 /** 103 * Get the message window. 104 */ 105 MessageWindow& getMessageWindow(); 91 106 92 107 /** … … 105 120 //------------------------------------------------------------------------------ 106 121 107 inline ListenThread::ListenThread(int xplaneVersion, int xplmVersion) : 122 inline ListenThread::ListenThread(int xplaneVersion, int xplmVersion, 123 MessageWindow& messageWindow) : 108 124 Thread(true), 109 125 xplaneVersion(xplaneVersion), 110 126 xplmVersion(xplmVersion), 127 messageWindow(messageWindow), 111 128 quitEvent(&waiter) 112 129 { … … 119 136 xplane = xplaneVersion; 120 137 xplm = xplmVersion; 138 } 139 140 //------------------------------------------------------------------------------ 141 142 inline MessageWindow& ListenThread::getMessageWindow() 143 { 144 return messageWindow; 121 145 } 122 146 -
src/plugin/src/xplra/Makefile.am
r13 r38 3 3 AM_CXXFLAGS=$(VSCPL_CFLAGS) $(LIBXPLCOMMON_CFLAGS) 4 4 5 AM_CPPFLAGS=-DXPLM 2105 AM_CPPFLAGS=-DXPLM100 6 6 7 7 SRCS= \ … … 16 16 MultiTaskRequest.cc \ 17 17 GetMultiDataRefRequest.cc \ 18 SetMultiDataRefRequest.cc 18 SetMultiDataRefRequest.cc \ 19 MessageWindow.cc \ 20 MessageRequest.cc 19 21 20 22 noinst_HEADERS= \ … … 31 33 MultiTaskRequest.h \ 32 34 GetMultiDataRefRequest.h \ 33 SetMultiDataRefRequest.h 35 SetMultiDataRefRequest.h \ 36 MessageWindow.h \ 37 MessageRequest.h 34 38 35 39 if TARGET_API_POSIX -
src/plugin/src/xplra/Protocol.h
r36 r38 97 97 98 98 /** 99 * Command: show a message in the message window. 100 */ 101 static const uint8_t COMMAND_SHOW_MESSAGE = 0x41; 102 103 /** 99 104 * Data type: int 100 105 */ … … 165 170 */ 166 171 static const uint8_t RESULT_INVALID_ID = 0x07; 172 173 /** 174 * Result code: invalid duration 175 */ 176 static const uint8_t RESULT_INVALID_DURATION = 0x08; 167 177 168 178 /** … … 181 191 */ 182 192 static const size_t MAX_MULTI_COUNT = 1024; 193 194 /** 195 * The maximal message duration 196 */ 197 static const float MAX_MESSAGE_DURATION = 5*60; 183 198 184 199 /** -
src/plugin/src/xplra/ServerThread.cc
r36 r38 39 39 #include "GetMultiDataRefRequest.h" 40 40 #include "SetMultiDataRefRequest.h" 41 #include "MessageRequest.h" 41 42 42 43 #include <hu/varadiistvan/xplcommon/Util.h> … … 152 153 } else if (command==Protocol::COMMAND_GET_VERSIONS) { 153 154 if (!handleGetVersions()) break; 155 } else if (command==Protocol::COMMAND_SHOW_MESSAGE) { 156 if (!handleShowMessage()) break; 154 157 } else { 155 158 stream.writeU8(Protocol::RESULT_INVALID_COMMAND); … … 400 403 stream.writeS32(xplmVersion); 401 404 stream.writeS32(Protocol::version); 405 406 return true; 407 } 408 409 //------------------------------------------------------------------------------ 410 411 bool ServerThread::handleShowMessage() 412 { 413 string message = stream.readString(); 414 float duration = stream.readFloat(); 415 if (!stream) return false; 416 417 if (duration>Protocol::MAX_MESSAGE_DURATION) { 418 stream.writeU8(Protocol::RESULT_INVALID_DURATION); 419 } else { 420 MessageRequest request(listenThread.getMessageWindow(), message, duration); 421 if (!requestQueue.execute(&request)) return false; 422 423 stream.writeU8(Protocol::RESULT_OK); 424 } 402 425 403 426 return true; -
src/plugin/src/xplra/ServerThread.h
r36 r38 241 241 */ 242 242 bool handleGetVersions(); 243 244 /** 245 * Handle the COMMAND_SHOW_MESSAGE command 246 * 247 * @return true, if we can continue, false if the thread should quit 248 */ 249 bool handleShowMessage(); 243 250 }; 244 251 -
src/plugin/src/xplra/plugin.cc
r36 r38 31 31 #include "ListenThread.h" 32 32 33 #include "MessageWindow.h" 34 33 35 #include <hu/varadiistvan/xplcommon/Util.h> 34 36 #include <hu/varadiistvan/scpl/config.h> … … 49 51 50 52 using xplra::ListenThread; 53 using xplra::MessageWindow; 51 54 52 55 using hu::varadiistvan::xplcommon::Util; 53 56 54 57 //------------------------------------------------------------------------------ 58 59 /** 60 * The window to display messages from the clients. 61 */ 62 static MessageWindow* messageWindow = 0; 55 63 56 64 /** … … 89 97 XPLMGetVersions(&xplaneVersion, &xplmVersion, &hostID); 90 98 91 listenThread = new ListenThread(xplaneVersion, xplmVersion); 99 messageWindow = new MessageWindow(); 100 101 listenThread = new ListenThread(xplaneVersion, xplmVersion, 102 *messageWindow); 92 103 listenThread->start(); 93 104 } … … 108 119 Util::debug("hu.varadiistvan.xplra.XPluginDisable called\n"); 109 120 // XPLMUnregisterFlightLoopCallback(&callback, 0); 121 110 122 if (listenThread!=0) { 111 123 listenThread->quit(); 112 124 listenThread = 0; 113 125 } 126 127 delete messageWindow; messageWindow = 0; 114 128 } 115 129
Note:
See TracChangeset
for help on using the changeset viewer.