Changeset 10:b0048ba6f3ca in xplra
- Timestamp:
- 01/04/13 16:36:30 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/client.py
r9 r10 175 175 print >> sys.stderr, "Error code:", result 176 176 177 def do_ reg_multiget(self, args):178 """Handle the ' reg_multiget' command"""177 def do_multiget(self, args): 178 """Handle the 'multiget' command""" 179 179 words = self._splitArgs(args) 180 180 specs = [] … … 190 190 return False 191 191 192 self._writeU8(0x03) 193 self._writeU32(len(specs)) 194 for (name, type, length, offset) in specs: 195 self._writeString(name) 196 self._writeU8(self._types[type]) 197 if length is not None: 198 self._writeS32(length) 199 self._writeS32(offset) 200 self._flush() 201 202 result = self._readU8() 203 if result==0: 204 for (_, type, _, _) in specs: 205 value = self._readValue(type) 206 print value 207 elif result==0x02: 208 index = self._readU32() 209 print >> sys.stderr, "Invalid dataref at #%d" % (index,) 210 else: 211 print >> sys.stderr, "Error code:", result 212 213 def do_multiset(self, args): 214 """Handle the 'multiset' command""" 215 words = self._splitArgs(args) 216 specs = [] 217 values = [] 218 while words: 219 result = self._parseGetSpec(words) 220 if result is None: 221 return False 222 else: 223 words = result[1] 224 if not words: 225 print >> sys.stderr, "Missing argument" 226 return False 227 specs.append(result[0]) 228 values.append(words[0]) 229 words = words[1:] 230 231 if not specs: 232 return False 233 234 self._writeU8(0x04) 235 self._writeU32(len(specs)) 236 for ((name, type, length, offset), value) in zip(specs, values): 237 self._writeString(name) 238 self._writeU8(self._types[type]) 239 if length is not None: 240 self._writeS32(length) 241 self._writeS32(offset) 242 self._writeValue(type, value, length) 243 self._flush() 244 245 result = self._readU8() 246 if result==0x02: 247 index = self._readU32() 248 print >> sys.stderr, "Invalid dataref at #%d" % (index,) 249 elif result!=0: 250 print >> sys.stderr, "Error code:", result 251 252 def do_reg_multiget(self, args): 253 """Handle the 'reg_multiget' command""" 254 words = self._splitArgs(args) 255 specs = [] 256 while words: 257 result = self._parseGetSpec(words) 258 if result is None: 259 return False 260 else: 261 specs.append(result[0]) 262 words = result[1] 263 264 if not specs: 265 return False 266 192 267 self._writeU8(0x11) 193 268 self._writeU32(len(specs)) 194 269 for (name, type, length, offset) in specs: 195 print name, type196 270 self._writeString(name) 197 271 self._writeU8(self._types[type]) … … 275 349 self._writeU32(len(specs)) 276 350 for (name, type, length, offset) in specs: 277 print name, type278 351 self._writeString(name) 279 352 self._writeU8(self._types[type]) -
src/xplra/GetMultiDataRefRequest.cc
r8 r10 39 39 using xplra::GetMultiDataRefRequest; 40 40 41 using xplcommon::DataStream; 41 42 using xplcommon::Util; 42 43 43 44 //------------------------------------------------------------------------------ 44 45 45 GetMultiDataRefRequest::GetMultiDataRefRequest(uint8_t& result, size_t numTasks,46 xplcommon::DataStream& stream)46 GetMultiDataRefRequest::GetMultiDataRefRequest(uint8_t& result, 47 DataStream& stream) 47 48 { 48 49 result = Protocol::RESULT_OK; 50 51 uint32_t numTasks = stream.readU32(); 52 if (!stream) return; 53 if (numTasks==0 || numTasks>Protocol::MAX_MULTI_COUNT) { 54 result = Protocol::RESULT_INVALID_COUNT; 55 return; 56 } 57 49 58 for(size_t i = 0; 50 59 i<numTasks && result==Protocol::RESULT_OK && stream; ++i) -
src/xplra/GetMultiDataRefRequest.h
r8 r10 50 50 * specifications from the given stream. 51 51 */ 52 GetMultiDataRefRequest(uint8_t& result, size_t numTasks, 53 xplcommon::DataStream& stream); 52 GetMultiDataRefRequest(uint8_t& result, xplcommon::DataStream& stream); 54 53 55 54 /** -
src/xplra/Protocol.h
r9 r10 50 50 */ 51 51 static const uint8_t COMMAND_SET_SINGLE = 0x02; 52 53 /** 54 * Command: get the value of a multiple datarefs. 55 */ 56 static const uint8_t COMMAND_GET_MULTI = 0x03; 57 58 /** 59 * Command: set the value of a multiple datarefs. 60 */ 61 static const uint8_t COMMAND_SET_MULTI = 0x04; 52 62 53 63 /** -
src/xplra/ServerThread.cc
r9 r10 131 131 } else if (command==Protocol::COMMAND_SET_SINGLE) { 132 132 if (!handleSetSingle()) break; 133 } else if (command==Protocol::COMMAND_GET_MULTI) { 134 if (!handleGetMulti()) break; 135 } else if (command==Protocol::COMMAND_SET_MULTI) { 136 if (!handleSetMulti()) break; 133 137 } else if (command==Protocol::COMMAND_REGISTER_GET_MULTI) { 134 138 if (!handleRegisterGetMulti()) break; … … 209 213 //------------------------------------------------------------------------------ 210 214 215 bool ServerThread::handleGetMulti() 216 { 217 uint8_t result = Protocol::RESULT_OK; 218 GetMultiDataRefRequest* request = 219 new GetMultiDataRefRequest(result, stream); 220 if (result!=Protocol::RESULT_OK || !stream) { 221 delete request; 222 stream.writeU8(result); 223 return stream; 224 } 225 226 bool isOK = requestQueue.execute(request); 227 228 if (isOK) { 229 request->writeResult(stream); 230 } 231 232 delete request; 233 234 return isOK; 235 } 236 237 //------------------------------------------------------------------------------ 238 239 bool ServerThread::handleSetMulti() 240 { 241 uint8_t result = Protocol::RESULT_OK; 242 SetMultiDataRefRequest* request = 243 new SetMultiDataRefRequest(result, stream, true); 244 if (result!=Protocol::RESULT_OK || !stream) { 245 delete request; 246 stream.writeU8(result); 247 return stream; 248 } 249 250 bool isOK = requestQueue.execute(request); 251 252 if (isOK) { 253 request->writeResult(stream); 254 } 255 256 delete request; 257 258 return isOK; 259 } 260 261 //------------------------------------------------------------------------------ 262 211 263 bool ServerThread::handleRegisterGetMulti() 212 264 { 213 uint32_t numTasks = stream.readU32();214 if (!stream) {215 return false;216 } else if (numTasks==0 || numTasks>Protocol::MAX_MULTI_COUNT) {217 stream.writeU8(Protocol::RESULT_INVALID_COUNT);218 return true;219 }220 221 265 uint8_t result = Protocol::RESULT_OK; 222 266 GetMultiDataRefRequest* request = 223 new GetMultiDataRefRequest(result, numTasks,stream);267 new GetMultiDataRefRequest(result, stream); 224 268 if (result!=Protocol::RESULT_OK || !stream) { 225 269 delete request; … … 282 326 uint8_t result = Protocol::RESULT_OK; 283 327 SetMultiDataRefRequest* request = 284 new SetMultiDataRefRequest(result, stream );328 new SetMultiDataRefRequest(result, stream, false); 285 329 if (result!=Protocol::RESULT_OK || !stream) { 286 330 delete request; -
src/xplra/ServerThread.h
r9 r10 173 173 174 174 /** 175 * Handle the COMMAND_GET_MULTI command 176 * 177 * @return true, if we can continue, false if the thread should quit 178 */ 179 bool handleGetMulti(); 180 181 /** 182 * Handle the COMMAND_SET_MULTI command 183 * 184 * @return true, if we can continue, false if the thread should quit 185 */ 186 bool handleSetMulti(); 187 188 /** 175 189 * Handle the COMMAND_REGISTER_GET_MULTI command 176 190 * -
src/xplra/SetMultiDataRefRequest.cc
r9 r10 42 42 43 43 SetMultiDataRefRequest::SetMultiDataRefRequest(uint8_t& result, 44 DataStream& stream) 44 DataStream& stream, 45 bool readValues) 45 46 { 46 47 result = Protocol::RESULT_OK; … … 56 57 i<numTasks && result==Protocol::RESULT_OK && stream; ++i) { 57 58 SetDataRefTask* task = SetDataRefTask::create(result, stream); 58 if (task!=0) addTask(task); 59 if (task!=0) { 60 if (readValues) { 61 task->readValue(stream); 62 } 63 addTask(task); 64 } 59 65 } 60 66 } -
src/xplra/SetMultiDataRefRequest.h
r9 r10 50 50 * the given stream. 51 51 */ 52 SetMultiDataRefRequest(uint8_t& result, xplcommon::DataStream& stream); 52 SetMultiDataRefRequest(uint8_t& result, xplcommon::DataStream& stream, 53 bool readValues); 53 54 54 55 /**
Note:
See TracChangeset
for help on using the changeset viewer.