Changeset 9:953cd606427c in xplra
- Timestamp:
- 01/04/13 16:12:21 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/client.py
r8 r9 100 100 self._stream = stream 101 101 self._multiGets = {} 102 self._multiSets = {} 102 103 103 104 self.use_rawinput = True … … 230 231 231 232 def do_exec_multiget(self, args): 232 """Handle the ' unreg_multiget' command"""233 """Handle the 'exec_multiget' command""" 233 234 words = self._splitArgs(args) 234 235 if len(words)<1: … … 254 255 print >> sys.stderr, "Invalid dataref at #%d" % (index,) 255 256 else: 257 print >> sys.stderr, "Error code:", result 258 259 def do_reg_multiset(self, args): 260 """Handle the 'reg_multiset' command""" 261 words = self._splitArgs(args) 262 specs = [] 263 while words: 264 result = self._parseGetSpec(words) 265 if result is None: 266 return False 267 else: 268 specs.append(result[0]) 269 words = result[1] 270 271 if not specs: 272 return False 273 274 self._writeU8(0x21) 275 self._writeU32(len(specs)) 276 for (name, type, length, offset) in specs: 277 print name, type 278 self._writeString(name) 279 self._writeU8(self._types[type]) 280 if length is not None: 281 self._writeS32(length) 282 self._writeS32(offset) 283 self._flush() 284 285 result = self._readU8() 286 if result==0: 287 id = self._readU32() 288 self._multiSets[id] = \ 289 [(type, length) for (name, type, length, offset) in specs] 290 print "ID:", id 291 else: 292 print >> sys.stderr, "Error code:", result 293 294 def do_unreg_multiset(self, args): 295 """Handle the 'unreg_multiset' command""" 296 words = self._splitArgs(args) 297 if len(words)<1: 298 print >> sys.stderr, "Missing parameter" 299 return False 300 301 id = int(words[0]) 302 303 self._writeU8(0x22) 304 self._writeU32(id) 305 self._flush() 306 307 result = self._readU8() 308 if result!=0: 309 print >> sys.stderr, "Error code:", result 310 311 if id in self._multiSets: 312 del self._multiSets[id] 313 314 def do_exec_multiset(self, args): 315 """Handle the 'exec_multiget' command""" 316 words = self._splitArgs(args) 317 if len(words)<1: 318 print >> sys.stderr, "Missing parameter" 319 return False 320 321 id = int(words[0]) 322 if id not in self._multiSets: 323 print >> sys.stderr, "Invalid ID" 324 return False 325 326 words = words[1:] 327 types = self._multiSets[id] 328 if len(words)<len(types): 329 print >> sys.stderr, "Missing parameter" 330 return False 331 332 333 self._writeU8(0x23) 334 self._writeU32(id) 335 for ((type, length), word) in zip(types, words): 336 self._writeValue(type, word, length) 337 self._flush() 338 339 result = self._readU8() 340 if result==0x02: 341 index = self._readU32() 342 print >> sys.stderr, "Invalid dataref at #%d" % (index,) 343 elif result!=0: 256 344 print >> sys.stderr, "Error code:", result 257 345 -
src/xplra/Makefile.am
r8 r9 33 33 SetDataRefTask.cc \ 34 34 MultiTaskRequest.cc \ 35 GetMultiDataRefRequest.cc 35 GetMultiDataRefRequest.cc \ 36 SetMultiDataRefRequest.cc 36 37 37 38 libxplra_la_LIBADD=$(LIBXPLCOMMON_LIBS) … … 49 50 SetDataRefTask.h \ 50 51 MultiTaskRequest.h \ 51 GetMultiDataRefRequest.h 52 GetMultiDataRefRequest.h \ 53 SetMultiDataRefRequest.h -
src/xplra/Protocol.h
r8 r9 65 65 */ 66 66 static const uint8_t COMMAND_EXECUTE_GET_MULTI = 0x13; 67 68 /** 69 * Command: register a multiple-data update request 70 */ 71 static const uint8_t COMMAND_REGISTER_SET_MULTI = 0x21; 72 73 /** 74 * Command: unregister a multiple-data update request 75 */ 76 static const uint8_t COMMAND_UNREGISTER_SET_MULTI = 0x22; 77 78 /** 79 * Command: execute a registered multiple-data update request 80 */ 81 static const uint8_t COMMAND_EXECUTE_SET_MULTI = 0x23; 67 82 68 83 /** -
src/xplra/ServerThread.cc
r8 r9 37 37 #include "TaskRequest.h" 38 38 #include "GetMultiDataRefRequest.h" 39 #include "SetMultiDataRefRequest.h" 39 40 40 41 #include <xplcommon/Util.h> … … 76 77 bufferedStream(acceptor.getSocket(&waiter)), 77 78 stream(*bufferedStream), 78 nextGetMultiRequestID(1) 79 nextGetMultiRequestID(1), 80 nextSetMultiRequestID(1) 79 81 { 80 82 instancesMutex.lock(); … … 91 93 for(getMultiRequests_t::iterator i = getMultiRequests.begin(); 92 94 i!=getMultiRequests.end(); ++i) 95 { 96 delete i->second; 97 } 98 99 for(setMultiRequests_t::iterator i = setMultiRequests.begin(); 100 i!=setMultiRequests.end(); ++i) 93 101 { 94 102 delete i->second; … … 129 137 } else if (command==Protocol::COMMAND_EXECUTE_GET_MULTI) { 130 138 if (!handleExecuteGetMulti()) break; 139 } else if (command==Protocol::COMMAND_REGISTER_SET_MULTI) { 140 if (!handleRegisterSetMulti()) break; 141 } else if (command==Protocol::COMMAND_UNREGISTER_SET_MULTI) { 142 if (!handleUnregisterSetMulti()) break; 143 } else if (command==Protocol::COMMAND_EXECUTE_SET_MULTI) { 144 if (!handleExecuteSetMulti()) break; 131 145 } else { 132 146 stream.writeU8(Protocol::RESULT_INVALID_COMMAND); … … 177 191 stream.writeU8(result); 178 192 return true; 193 } 194 195 task->readValue(stream); 196 if (!stream) { 197 delete task; 198 return false; 179 199 } 180 200 … … 258 278 //------------------------------------------------------------------------------ 259 279 280 bool ServerThread::handleRegisterSetMulti() 281 { 282 uint8_t result = Protocol::RESULT_OK; 283 SetMultiDataRefRequest* request = 284 new SetMultiDataRefRequest(result, stream); 285 if (result!=Protocol::RESULT_OK || !stream) { 286 delete request; 287 stream.writeU8(result); 288 return stream; 289 } 290 291 size_t id = nextSetMultiRequestID++; 292 setMultiRequests[id] = request; 293 294 stream.writeU8(Protocol::RESULT_OK); 295 stream.writeU32(id); 296 297 return true; 298 } 299 300 //------------------------------------------------------------------------------ 301 302 bool ServerThread::handleUnregisterSetMulti() 303 { 304 uint32_t id = stream.readU32(); 305 if (!stream) return false; 306 307 setMultiRequests_t::iterator i = setMultiRequests.find(id); 308 if (i==setMultiRequests.end()) { 309 stream.writeU8(Protocol::RESULT_INVALID_ID); 310 } else { 311 SetMultiDataRefRequest* request = i->second; 312 setMultiRequests.erase(i); 313 delete request; 314 stream.writeU8(Protocol::RESULT_OK); 315 } 316 317 return true; 318 } 319 320 //------------------------------------------------------------------------------ 321 322 bool ServerThread::handleExecuteSetMulti() 323 { 324 uint32_t id = stream.readU32(); 325 if (!stream) return false; 326 327 setMultiRequests_t::iterator i = setMultiRequests.find(id); 328 if (i==setMultiRequests.end()) { 329 stream.writeU8(Protocol::RESULT_INVALID_ID); 330 } else { 331 SetMultiDataRefRequest* request = i->second; 332 request->readValues(stream); 333 if (!stream || !requestQueue.execute(request)) return false; 334 request->writeResult(stream); 335 } 336 337 return true; 338 } 339 340 //------------------------------------------------------------------------------ 341 260 342 // Local Variables: 261 343 // mode: C++ -
src/xplra/ServerThread.h
r8 r9 52 52 53 53 class GetMultiDataRefRequest; 54 class SetMultiDataRefRequest; 54 55 55 56 //------------------------------------------------------------------------------ … … 67 68 68 69 /** 69 * Type for the registered multiple-data requests.70 * Type for the registered multiple-data query requests. 70 71 */ 71 72 typedef std::map<size_t, GetMultiDataRefRequest*> getMultiRequests_t; 72 73 73 74 /** 75 * Type for the registered multiple-data update requests. 76 */ 77 typedef std::map<size_t, SetMultiDataRefRequest*> setMultiRequests_t; 78 79 /** 74 80 * A mutex to protect the collection of server threads. 75 81 */ … … 117 123 */ 118 124 getMultiRequests_t getMultiRequests; 125 126 /** 127 * The ID of the next multiple-data update request. 128 */ 129 size_t nextSetMultiRequestID; 130 131 /** 132 * The registered multiple-data query requests. 133 */ 134 setMultiRequests_t setMultiRequests; 119 135 120 136 public: … … 176 192 */ 177 193 bool handleExecuteGetMulti(); 194 195 /** 196 * Handle the COMMAND_REGISTER_SET_MULTI command 197 * 198 * @return true, if we can continue, false if the thread should quit 199 */ 200 bool handleRegisterSetMulti(); 201 202 /** 203 * Handle the COMMAND_UNREGISTER_SET_MULTI command 204 * 205 * @return true, if we can continue, false if the thread should quit 206 */ 207 bool handleUnregisterSetMulti(); 208 209 /** 210 * Handle the COMMAND_EXECUTE_SET_MULTI command 211 * 212 * @return true, if we can continue, false if the thread should quit 213 */ 214 bool handleExecuteSetMulti(); 178 215 }; 179 216 -
src/xplra/SetDataRefTask.cc
r7 r9 55 55 56 56 if (type==Protocol::TYPE_INT) { 57 int value = stream.readS32(); 58 if (stream) return new SetIntDataRefTask(name, value); 57 return new SetIntDataRefTask(name); 59 58 } else if (type==Protocol::TYPE_FLOAT) { 60 float value = stream.readFloat(); 61 if (stream) return new SetFloatDataRefTask(name, value); 59 return new SetFloatDataRefTask(name); 62 60 } else if (type==Protocol::TYPE_DOUBLE) { 63 double value = stream.readDouble(); 64 if (stream) return new SetDoubleDataRefTask(name, value); 61 return new SetDoubleDataRefTask(name); 65 62 } else if (type==Protocol::TYPE_FLOAT_ARRAY || 66 63 type==Protocol::TYPE_INT_ARRAY || … … 79 76 } 80 77 81 SetDataRefTask* task = 0;82 78 if (type==Protocol::TYPE_INT_ARRAY) { 83 task =new SetIntArrayDataRefTask(name, length, offset);79 return new SetIntArrayDataRefTask(name, length, offset); 84 80 } else if (type==Protocol::TYPE_FLOAT_ARRAY) { 85 task =new SetFloatArrayDataRefTask(name, length, offset);81 return new SetFloatArrayDataRefTask(name, length, offset); 86 82 } else { 87 task = new SetByteArrayDataRefTask(name, length, offset); 88 } 89 90 task->readValue(stream); 91 92 if (stream) { 93 return task; 94 } else { 95 delete task; 83 return new SetByteArrayDataRefTask(name, length, offset); 96 84 } 97 85 } else { -
src/xplra/SetDataRefTask.h
r7 r9 107 107 * dataref with the given name. 108 108 */ 109 SetScalarDataRefTask(const std::string& name , T value);109 SetScalarDataRefTask(const std::string& name); 110 110 111 111 /** … … 113 113 * dataref. 114 114 */ 115 SetScalarDataRefTask(XPLMDataRef dataRef , T value);115 SetScalarDataRefTask(XPLMDataRef dataRef); 116 116 117 117 protected: … … 140 140 * Construct the task for the dataref with the given name. 141 141 */ 142 SetIntDataRefTask(const std::string& name , int value);142 SetIntDataRefTask(const std::string& name); 143 143 144 144 /** 145 145 * Construct the task for the given dataref. 146 146 */ 147 SetIntDataRefTask(XPLMDataRef dataRef , int value);147 SetIntDataRefTask(XPLMDataRef dataRef); 148 148 149 149 /** … … 171 171 * Construct the task for the dataref with the given name. 172 172 */ 173 SetFloatDataRefTask(const std::string& name , float value);173 SetFloatDataRefTask(const std::string& name); 174 174 175 175 /** 176 176 * Construct the task for the given dataref. 177 177 */ 178 SetFloatDataRefTask(XPLMDataRef dataRef , float value);178 SetFloatDataRefTask(XPLMDataRef dataRef); 179 179 180 180 /** … … 202 202 * Construct the task for the dataref with the given name. 203 203 */ 204 SetDoubleDataRefTask(const std::string& name , double value);204 SetDoubleDataRefTask(const std::string& name); 205 205 206 206 /** 207 207 * Construct the task for the given dataref. 208 208 */ 209 SetDoubleDataRefTask(XPLMDataRef dataRef , double value);209 SetDoubleDataRefTask(XPLMDataRef dataRef); 210 210 211 211 /** … … 365 365 template <typename T, class ConcreteClass> 366 366 inline SetScalarDataRefTask<T, ConcreteClass>:: 367 SetScalarDataRefTask(const std::string& name, T value) : 368 SetDataRefTask(name), 369 value(value) 367 SetScalarDataRefTask(const std::string& name) : 368 SetDataRefTask(name) 370 369 { 371 370 } … … 375 374 template <typename T, class ConcreteClass> 376 375 inline SetScalarDataRefTask<T, ConcreteClass>:: 377 SetScalarDataRefTask(XPLMDataRef dataRef, T value) : 378 SetDataRefTask(dataRef), 379 value(value) 376 SetScalarDataRefTask(XPLMDataRef dataRef) : 377 SetDataRefTask(dataRef) 380 378 { 381 379 } … … 465 463 //------------------------------------------------------------------------------ 466 464 467 inline SetIntDataRefTask::SetIntDataRefTask(const std::string& name , int value) :468 SetScalarDataRefTask<int, SetIntDataRefTask>(name , value)469 { 470 } 471 472 //------------------------------------------------------------------------------ 473 474 inline SetIntDataRefTask::SetIntDataRefTask(XPLMDataRef dataRef , int value) :475 SetScalarDataRefTask<int, SetIntDataRefTask>(dataRef , value)465 inline SetIntDataRefTask::SetIntDataRefTask(const std::string& name) : 466 SetScalarDataRefTask<int, SetIntDataRefTask>(name) 467 { 468 } 469 470 //------------------------------------------------------------------------------ 471 472 inline SetIntDataRefTask::SetIntDataRefTask(XPLMDataRef dataRef) : 473 SetScalarDataRefTask<int, SetIntDataRefTask>(dataRef) 476 474 { 477 475 } … … 487 485 //------------------------------------------------------------------------------ 488 486 489 inline SetFloatDataRefTask::SetFloatDataRefTask(const std::string& name, 490 float value) : 491 SetScalarDataRefTask<float, SetFloatDataRefTask>(name, value) 492 { 493 } 494 495 //------------------------------------------------------------------------------ 496 497 inline SetFloatDataRefTask::SetFloatDataRefTask(XPLMDataRef dataRef, 498 float value) : 499 SetScalarDataRefTask<float, SetFloatDataRefTask>(dataRef, value) 487 inline SetFloatDataRefTask::SetFloatDataRefTask(const std::string& name) : 488 SetScalarDataRefTask<float, SetFloatDataRefTask>(name) 489 { 490 } 491 492 //------------------------------------------------------------------------------ 493 494 inline SetFloatDataRefTask::SetFloatDataRefTask(XPLMDataRef dataRef) : 495 SetScalarDataRefTask<float, SetFloatDataRefTask>(dataRef) 500 496 { 501 497 } … … 511 507 //------------------------------------------------------------------------------ 512 508 513 inline SetDoubleDataRefTask::SetDoubleDataRefTask(const std::string& name, 514 double value) : 515 SetScalarDataRefTask<double, SetDoubleDataRefTask>(name, value) 516 { 517 } 518 519 //------------------------------------------------------------------------------ 520 521 inline SetDoubleDataRefTask::SetDoubleDataRefTask(XPLMDataRef dataRef, 522 double value) : 523 SetScalarDataRefTask<double, SetDoubleDataRefTask>(dataRef, value) 509 inline SetDoubleDataRefTask::SetDoubleDataRefTask(const std::string& name) : 510 SetScalarDataRefTask<double, SetDoubleDataRefTask>(name) 511 { 512 } 513 514 //------------------------------------------------------------------------------ 515 516 inline SetDoubleDataRefTask::SetDoubleDataRefTask(XPLMDataRef dataRef) : 517 SetScalarDataRefTask<double, SetDoubleDataRefTask>(dataRef) 524 518 { 525 519 } -
src/xplra/plugin.cc
r1 r9 32 32 33 33 #include <xplcommon/Util.h> 34 #include <xplcommon/config.h> 34 35 35 36 #include <XPLMDefs.h> … … 40 41 #include <cstring> 41 42 #include <cstdarg> 43 44 #if TARGET_API_POSIX 45 #include <signal.h> 46 #endif 42 47 43 48 //------------------------------------------------------------------------------ … … 64 69 strcpy(outSignature, "hu.varadiistvan.xplra"); 65 70 strcpy(outDescription, "Provides remote access to datarefs"); 71 72 #if TARGET_API_POSIX 73 signal(SIGPIPE, SIG_IGN); 74 #endif 66 75 67 76 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.