Changeset 8:acc105036a41 in xplra for src
- Timestamp:
- 01/04/13 14:24:04 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/xplra
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/xplra/GetDataRefTask.cc
r7 r8 42 42 43 43 using xplcommon::DataStream; 44 using xplcommon::Util; 44 45 45 46 using std::string; … … 54 55 uint8_t type = stream.readU8(); 55 56 if (!stream) return 0; 57 58 // Util::debug("hu.varadiistvan.xplra.GetDataRefTask::execute: name='%s', type=0x%02x\n", 59 // name.c_str(), type); 56 60 57 61 if (type==Protocol::TYPE_INT) { -
src/xplra/Makefile.am
r7 r8 24 24 25 25 libxplra_la_SOURCES= \ 26 plugin.cc \ 27 ListenThread.cc \ 28 RequestQueue.cc \ 29 ServerThread.cc \ 30 TaskRequest.cc \ 31 DataRefTask.cc \ 32 GetDataRefTask.cc \ 33 SetDataRefTask.cc 26 plugin.cc \ 27 ListenThread.cc \ 28 RequestQueue.cc \ 29 ServerThread.cc \ 30 TaskRequest.cc \ 31 DataRefTask.cc \ 32 GetDataRefTask.cc \ 33 SetDataRefTask.cc \ 34 MultiTaskRequest.cc \ 35 GetMultiDataRefRequest.cc 34 36 35 37 libxplra_la_LIBADD=$(LIBXPLCOMMON_LIBS) 36 38 37 39 noinst_HEADERS= \ 38 ListenThread.h \ 39 Request.h \ 40 RequestQueue.h \ 41 Protocol.h \ 42 ServerThread.h \ 43 Task.h \ 44 TaskRequest.h \ 45 DataRefTask.h \ 46 GetDataRefTask.h \ 47 SetDataRefTask.h 40 ListenThread.h \ 41 Request.h \ 42 RequestQueue.h \ 43 Protocol.h \ 44 ServerThread.h \ 45 Task.h \ 46 TaskRequest.h \ 47 DataRefTask.h \ 48 GetDataRefTask.h \ 49 SetDataRefTask.h \ 50 MultiTaskRequest.h \ 51 GetMultiDataRefRequest.h -
src/xplra/Protocol.h
r7 r8 50 50 */ 51 51 static const uint8_t COMMAND_SET_SINGLE = 0x02; 52 53 /** 54 * Command: register a multiple-data query request 55 */ 56 static const uint8_t COMMAND_REGISTER_GET_MULTI = 0x11; 57 58 /** 59 * Command: unregister a multiple-data query request 60 */ 61 static const uint8_t COMMAND_UNREGISTER_GET_MULTI = 0x12; 62 63 /** 64 * Command: execute a registered multiple-data query request 65 */ 66 static const uint8_t COMMAND_EXECUTE_GET_MULTI = 0x13; 52 67 53 68 /** … … 112 127 113 128 /** 129 * Result code: invalid count 130 */ 131 static const uint8_t RESULT_INVALID_COUNT = 0x06; 132 133 /** 134 * Result code: invalid ID 135 */ 136 static const uint8_t RESULT_INVALID_ID = 0x07; 137 138 /** 114 139 * Result code: other error 115 140 */ … … 120 145 */ 121 146 static const int MAX_LENGTH = 2048; 147 148 /** 149 * The maximal count of requests in a multiple-data query or 150 * update. 151 */ 152 static const size_t MAX_MULTI_COUNT = 1024; 122 153 }; 123 154 -
src/xplra/Request.h
r2 r8 58 58 virtual ~Request(); 59 59 60 protected: 60 61 /** 61 62 * Execute the request. Make this very fast! -
src/xplra/ServerThread.cc
r7 r8 36 36 #include "SetDataRefTask.h" 37 37 #include "TaskRequest.h" 38 #include "GetMultiDataRefRequest.h" 38 39 39 40 #include <xplcommon/Util.h> … … 74 75 requestQueue(requestQueue), 75 76 bufferedStream(acceptor.getSocket(&waiter)), 76 stream(*bufferedStream) 77 stream(*bufferedStream), 78 nextGetMultiRequestID(1) 77 79 { 78 80 instancesMutex.lock(); … … 86 88 { 87 89 delete bufferedStream; 90 91 for(getMultiRequests_t::iterator i = getMultiRequests.begin(); 92 i!=getMultiRequests.end(); ++i) 93 { 94 delete i->second; 95 } 88 96 89 97 instancesMutex.lock(); … … 115 123 } else if (command==Protocol::COMMAND_SET_SINGLE) { 116 124 if (!handleSetSingle()) break; 125 } else if (command==Protocol::COMMAND_REGISTER_GET_MULTI) { 126 if (!handleRegisterGetMulti()) break; 127 } else if (command==Protocol::COMMAND_UNREGISTER_GET_MULTI) { 128 if (!handleUnregisterGetMulti()) break; 129 } else if (command==Protocol::COMMAND_EXECUTE_GET_MULTI) { 130 if (!handleExecuteGetMulti()) break; 117 131 } else { 118 132 stream.writeU8(Protocol::RESULT_INVALID_COMMAND); … … 131 145 GetDataRefTask* task = GetDataRefTask::create(result, stream); 132 146 133 if (!stream) return false; 134 else if (task==0) { 147 if (!stream) { 148 return false; 149 } else if (task==0) { 135 150 stream.writeU8(result); 136 151 return true; … … 157 172 SetDataRefTask* task = SetDataRefTask::create(result, stream); 158 173 159 if (!stream) return false; 160 else if (task==0) { 174 if (!stream) { 175 return false; 176 } else if (task==0) { 161 177 stream.writeU8(result); 162 178 return true; … … 168 184 stream.writeU8(task->isValid() ? Protocol::RESULT_OK : 169 185 Protocol::RESULT_UNKNOWN_DATAREF); 186 return true; 187 } 188 189 //------------------------------------------------------------------------------ 190 191 bool ServerThread::handleRegisterGetMulti() 192 { 193 uint32_t numTasks = stream.readU32(); 194 if (!stream) { 195 return false; 196 } else if (numTasks==0 || numTasks>Protocol::MAX_MULTI_COUNT) { 197 stream.writeU8(Protocol::RESULT_INVALID_COUNT); 198 return true; 199 } 200 201 uint8_t result = Protocol::RESULT_OK; 202 GetMultiDataRefRequest* request = 203 new GetMultiDataRefRequest(result, numTasks, stream); 204 if (result!=Protocol::RESULT_OK || !stream) { 205 delete request; 206 stream.writeU8(result); 207 return stream; 208 } 209 210 size_t id = nextGetMultiRequestID++; 211 getMultiRequests[id] = request; 212 213 stream.writeU8(Protocol::RESULT_OK); 214 stream.writeU32(id); 215 216 return true; 217 } 218 219 //------------------------------------------------------------------------------ 220 221 bool ServerThread::handleUnregisterGetMulti() 222 { 223 uint32_t id = stream.readU32(); 224 if (!stream) return false; 225 226 getMultiRequests_t::iterator i = getMultiRequests.find(id); 227 if (i==getMultiRequests.end()) { 228 stream.writeU8(Protocol::RESULT_INVALID_ID); 229 } else { 230 GetMultiDataRefRequest* request = i->second; 231 getMultiRequests.erase(i); 232 delete request; 233 stream.writeU8(Protocol::RESULT_OK); 234 } 235 236 return true; 237 } 238 239 //------------------------------------------------------------------------------ 240 241 bool ServerThread::handleExecuteGetMulti() 242 { 243 uint32_t id = stream.readU32(); 244 if (!stream) return false; 245 246 getMultiRequests_t::iterator i = getMultiRequests.find(id); 247 if (i==getMultiRequests.end()) { 248 stream.writeU8(Protocol::RESULT_INVALID_ID); 249 } else { 250 GetMultiDataRefRequest* request = i->second; 251 if (!requestQueue.execute(request)) return false; 252 request->writeResult(stream); 253 } 254 170 255 return true; 171 256 } -
src/xplra/ServerThread.h
r7 r8 41 41 42 42 #include <set> 43 #include <map> 43 44 44 45 //------------------------------------------------------------------------------ … … 49 50 50 51 class RequestQueue; 52 53 class GetMultiDataRefRequest; 51 54 52 55 //------------------------------------------------------------------------------ … … 62 65 */ 63 66 typedef std::set<ServerThread*> instances_t; 67 68 /** 69 * Type for the registered multiple-data requests. 70 */ 71 typedef std::map<size_t, GetMultiDataRefRequest*> getMultiRequests_t; 64 72 65 73 /** … … 100 108 xplcommon::DataStream stream; 101 109 110 /** 111 * The ID of the next multiple-data query request. 112 */ 113 size_t nextGetMultiRequestID; 114 115 /** 116 * The registered multiple-data query requests. 117 */ 118 getMultiRequests_t getMultiRequests; 119 102 120 public: 103 121 /** … … 137 155 */ 138 156 bool handleSetSingle(); 157 158 /** 159 * Handle the COMMAND_REGISTER_GET_MULTI command 160 * 161 * @return true, if we can continue, false if the thread should quit 162 */ 163 bool handleRegisterGetMulti(); 164 165 /** 166 * Handle the COMMAND_UNREGISTER_GET_MULTI command 167 * 168 * @return true, if we can continue, false if the thread should quit 169 */ 170 bool handleUnregisterGetMulti(); 171 172 /** 173 * Handle the COMMAND_EXECUTE_GET_MULTI command 174 * 175 * @return true, if we can continue, false if the thread should quit 176 */ 177 bool handleExecuteGetMulti(); 139 178 }; 140 179
Note:
See TracChangeset
for help on using the changeset viewer.