Changeset 9:953cd606427c in xplra for src/xplra/ServerThread.cc
- Timestamp:
- 01/04/13 16:12:21 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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++
Note:
See TracChangeset
for help on using the changeset viewer.