Changeset 6:8dd4ca9966d0 in xplra
- Timestamp:
- 01/03/13 19:09:46 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/client.py
-
Property exe
set to
*
r3 r6 1 1 #!/usr/bin/env python 2 2 3 import sys 3 4 import cmd 4 5 import struct … … 42 43 self.use_rawinput = True 43 44 self.intro = "\nX-Plane Remote Access plugin command prompt\n" 44 self.prompt = "XPLRA> "45 self.prompt = "XPLRA> " 45 46 46 47 self.daemon = True … … 50 51 if line=="EOF": 51 52 print 52 return self.do_quit("")53 return True 53 54 else: 54 55 return super(CLI, self).default(line) … … 58 59 words = args.split() 59 60 if len(words)<2: 60 print >> sys.stderr, " missing parameters"61 print >> sys.stderr, "Missing parameters" 61 62 return False 62 63 … … 65 66 type = words[1] 66 67 if type not in self._types: 67 print >> sys.stderr, " invalid type"68 print >> sys.stderr, "Invalid type" 68 69 return False 69 70 70 71 length = None 71 if len(words)>2: 72 offset = None 73 if len(words)>3: 72 74 length = int(words[2]) 75 offset = int(words[3]) 73 76 74 77 self._writeU8(0x01) … … 77 80 if length is not None: 78 81 self._writeS32(length) 82 self._writeS32(offset) 79 83 self._flush() 80 84 81 85 result = self._readU8() 82 print "result:", result83 86 if result==0: 87 value = None 84 88 if type=="i": 85 89 value = self._readS32() … … 92 96 if length>0: 93 97 value = [self._readFloat() for i in range(0, length)] 94 else:95 value = None96 98 elif type=="ia": 97 99 length = self._readS32() 98 100 if length>0: 99 101 value = [self._readS32() for i in range(0, length)] 100 else:101 value = None102 102 elif type=="ba": 103 103 length = self._readS32() … … 108 108 if b==0: break 109 109 value += chr(b) 110 else: 111 value = None 110 #value = bytes 112 111 113 print "value:", value, len(value) 112 print value 113 else: 114 print "Result code:", result 114 115 115 116 def _writeU8(self, x): -
Property exe
set to
-
src/xplra/DataRefTask.h
r3 r6 72 72 DataRefTask(XPLMDataRef dataRef); 73 73 74 public: 74 75 /** 75 76 * Determine if the task is valid, which is so, if the dataref is … … 88 89 XPLMDataRef getDataRef() const; 89 90 91 protected: 90 92 /** 91 93 * Perform the task. If the dataref is not valid yet, it will be -
src/xplra/GetDataRefTask.cc
r4 r6 30 30 31 31 #include "GetDataRefTask.h" 32 #include "Protocol.h" 32 33 33 34 #include "xplcommon/Util.h" … … 35 36 //------------------------------------------------------------------------------ 36 37 38 using xplra::GetDataRefTask; 39 using xplra::GetIntDataRefTask; 40 using xplra::GetFloatDataRefTask; 41 using xplra::GetDoubleDataRefTask; 42 43 using xplcommon::DataStream; 44 45 using std::string; 46 47 //------------------------------------------------------------------------------ 48 49 GetDataRefTask* GetDataRefTask::create(uint8_t& result, DataStream& stream) 50 { 51 result = Protocol::RESULT_OK; 52 53 string name = stream.readString(); 54 uint8_t type = stream.readU8(); 55 if (!stream) return 0; 56 57 if (type==Protocol::TYPE_INT) { 58 return new GetIntDataRefTask(name); 59 } else if (type==Protocol::TYPE_FLOAT) { 60 return new GetFloatDataRefTask(name); 61 } else if (type==Protocol::TYPE_DOUBLE) { 62 return new GetDoubleDataRefTask(name); 63 } else if (type==Protocol::TYPE_FLOAT_ARRAY || 64 type==Protocol::TYPE_INT_ARRAY || 65 type==Protocol::TYPE_BYTE_ARRAY) 66 { 67 int length = stream.readS32(); 68 int offset = stream.readS32(); 69 if (!stream) return 0; 70 71 if (type==Protocol::TYPE_FLOAT_ARRAY) { 72 return new GetFloatArrayDataRefTask(name, length, offset); 73 } else if (type==Protocol::TYPE_INT_ARRAY) { 74 return new GetIntArrayDataRefTask(name, length, offset); 75 } else { 76 return new GetByteArrayDataRefTask(name, length, offset); 77 } 78 } else { 79 result = Protocol::RESULT_INVALID_TYPE; 80 return 0; 81 } 82 } 83 84 //------------------------------------------------------------------------------ 85 //------------------------------------------------------------------------------ 86 87 void GetIntDataRefTask::writeValue(DataStream& stream) 88 { 89 stream.writeS32(getValue()); 90 } 91 92 //------------------------------------------------------------------------------ 93 94 void GetFloatDataRefTask::writeValue(DataStream& stream) 95 { 96 stream.writeFloat(getValue()); 97 } 98 99 //------------------------------------------------------------------------------ 100 101 void GetDoubleDataRefTask::writeValue(DataStream& stream) 102 { 103 stream.writeDouble(getValue()); 104 } 37 105 38 106 //------------------------------------------------------------------------------ -
src/xplra/GetDataRefTask.h
r4 r6 33 33 #include "DataRefTask.h" 34 34 35 #include <xplcommon/DataStream.h> 36 35 37 //------------------------------------------------------------------------------ 36 38 … … 46 48 public: 47 49 /** 50 * Read a dataref query specification and create the appropriate 51 * GetDataRefTask instance. 52 * 53 * @return the new instance, or 0 on error. In that case the given 54 * result reference variable will be filled with the error code, 55 * unless the stream failed, in which case it remains RESULT_OK. 56 */ 57 static GetDataRefTask* create(uint8_t& result, xplcommon::DataStream& stream); 58 59 /** 48 60 * Construct the task for the dataref with the given name. 49 61 */ … … 54 66 */ 55 67 GetDataRefTask(XPLMDataRef dataRef); 68 69 /** 70 * Write the value into the given stream. 71 */ 72 virtual void writeValue(xplcommon::DataStream& stream) = 0; 56 73 }; 57 74 … … 120 137 */ 121 138 GetIntDataRefTask(XPLMDataRef dataRef); 139 140 /** 141 * Write the value into the given stream. 142 */ 143 virtual void writeValue(xplcommon::DataStream& stream); 122 144 }; 123 145 … … 147 169 */ 148 170 GetFloatDataRefTask(XPLMDataRef dataRef); 171 172 /** 173 * Write the value into the given stream. 174 */ 175 virtual void writeValue(xplcommon::DataStream& stream); 149 176 }; 150 177 … … 174 201 */ 175 202 GetDoubleDataRefTask(XPLMDataRef dataRef); 203 204 /** 205 * Write the value into the given stream. 206 */ 207 virtual void writeValue(xplcommon::DataStream& stream); 176 208 }; 177 209 … … 253 285 */ 254 286 virtual void process(); 287 288 /** 289 * Write the value into the given stream. 290 */ 291 virtual void writeValue(xplcommon::DataStream& stream); 255 292 }; 256 293 … … 493 530 494 531 //------------------------------------------------------------------------------ 532 533 template <typename T, class ConcreteClass> 534 void GetArrayDataRefTask<T, ConcreteClass>:: 535 writeValue(xplcommon::DataStream& stream) 536 { 537 stream.writeS32(length); 538 if (length>0) { 539 stream.write(data, length * sizeof(T)); 540 } 541 } 542 543 //------------------------------------------------------------------------------ 495 544 // Inline definitions 496 545 //------------------------------------------------------------------------------ -
src/xplra/Makefile.am
r5 r6 29 29 ServerThread.cc \ 30 30 TaskRequest.cc \ 31 DataRefTask.cc 31 DataRefTask.cc \ 32 GetDataRefTask.cc 32 33 33 34 libxplra_la_LIBADD=$(LIBXPLCOMMON_LIBS) -
src/xplra/Protocol.h
r5 r6 44 44 * Command: get the value of a single dataref. 45 45 */ 46 static const uint8_t C MD_GET_SINGLE = 0x01;46 static const uint8_t COMMAND_GET_SINGLE = 0x01; 47 47 48 48 /** -
src/xplra/ServerThread.cc
r5 r6 110 110 // this, command); 111 111 112 if (command==Protocol::CMD_GET_SINGLE) { 113 string name = stream.readString(); 114 uint8_t type = stream.readU8(); 115 if (!stream) continue; 116 // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: name='%s', type=0x%02x\n", 117 // this, name.c_str(), type); 118 if (type==Protocol::TYPE_BYTE_ARRAY) { 119 int length = stream.readS32(); 120 if (!stream) continue; 121 122 // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: length=%lu\n", 123 // this, static_cast<unsigned long>(length)); 124 125 GetByteArrayDataRefTask* task = 126 new GetByteArrayDataRefTask(name, length); 127 TaskRequest request(task); 128 129 if (requestQueue.execute(&request)) { 130 // Util::debug("hu.varadiistvan.xplra.ServerThread[%p]::run: request executed\n"); 131 stream.writeU8(Protocol::RESULT_OK); 132 int length = task->getLength(); 133 stream.writeS32(length); 134 if (length>0) { 135 stream.write(task->getData(), length); 136 } 137 } else { 138 break; 139 } 140 } else { 141 stream.writeU8(Protocol::RESULT_OTHER_ERROR); 142 } 112 if (command==Protocol::COMMAND_GET_SINGLE) { 113 if (!handleGetSingle(stream)) break; 143 114 } else { 144 115 stream.writeU8(Protocol::RESULT_INVALID_COMMAND); … … 152 123 //------------------------------------------------------------------------------ 153 124 125 bool ServerThread::handleGetSingle(xplcommon::DataStream& stream) 126 { 127 uint8_t result = Protocol::RESULT_OK; 128 129 GetDataRefTask* task = GetDataRefTask::create(result, stream); 130 131 if (!stream) return false; 132 else if (task==0) { 133 stream.writeU8(Protocol::RESULT_INVALID_TYPE); 134 return true; 135 } 136 137 TaskRequest request(task); 138 if (!requestQueue.execute(&request)) return false; 139 140 if (task->isValid()) { 141 stream.writeU8(Protocol::RESULT_OK); 142 task->writeValue(stream); 143 } else { 144 stream.writeU8(Protocol::RESULT_UNKNOWN_DATAREF); 145 } 146 147 return true; 148 } 149 150 //------------------------------------------------------------------------------ 151 154 152 // Local Variables: 155 153 // mode: C++ -
src/xplra/ServerThread.h
r5 r6 122 122 */ 123 123 virtual void run(); 124 125 private: 126 /** 127 * Handle the COMMAND_GET_SINGLE command 128 * 129 * @return true, if we can continue, false if the thread should quit 130 */ 131 bool handleGetSingle(xplcommon::DataStream& stream); 124 132 }; 125 133
Note:
See TracChangeset
for help on using the changeset viewer.