[411] | 1 | /* |
---|
| 2 | Copyright 2009 Virginia Polytechnic Institute and State University |
---|
[163] | 3 | |
---|
[411] | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 5 | you may not use this file except in compliance with the License. |
---|
| 6 | You may obtain a copy of the License at |
---|
| 7 | |
---|
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 9 | |
---|
| 10 | Unless required by applicable law or agreed to in writing, software |
---|
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 13 | See the License for the specific language governing permissions and |
---|
| 14 | limitations under the License. |
---|
| 15 | */ |
---|
| 16 | |
---|
[278] | 17 | /* Inter-component communication handled by sockets and FD's. |
---|
| 18 | * Server support has been completely implemented and tested. |
---|
| 19 | * |
---|
| 20 | * Services are stored in a SQLite DB by the ID of the CE that registered them. Service |
---|
| 21 | * support has been completely implemented and tested. |
---|
| 22 | * |
---|
| 23 | * Missions are loaded from an XML file, connected with services provided by components, |
---|
| 24 | * and run. See the documentation for the "PerformActiveMission" below for important |
---|
[419] | 25 | * info. |
---|
[163] | 26 | */ |
---|
| 27 | |
---|
| 28 | |
---|
[439] | 29 | #include <cmath> |
---|
[442] | 30 | #include <cstdio> |
---|
| 31 | #include <cstdlib> |
---|
[439] | 32 | #include <cstring> |
---|
[163] | 33 | #include <stdint.h> |
---|
| 34 | |
---|
[278] | 35 | #include <arpa/inet.h> |
---|
| 36 | #include <iostream> |
---|
| 37 | #include <netinet/in.h> |
---|
| 38 | #include <netdb.h> |
---|
| 39 | #include <fcntl.h> |
---|
[441] | 40 | #include <sqlite3.h> |
---|
[442] | 41 | #include <string> |
---|
[278] | 42 | #include <sys/ioctl.h> |
---|
| 43 | #include <sys/mman.h> |
---|
| 44 | #include <sys/socket.h> |
---|
| 45 | #include <sys/types.h> |
---|
| 46 | #include <sys/wait.h> |
---|
[163] | 47 | |
---|
[278] | 48 | #include "tinyxml/tinyxml.h" |
---|
| 49 | #include "tinyxml/tinystr.h" |
---|
| 50 | |
---|
[439] | 51 | #include "vtcross/debug.h" |
---|
| 52 | #include "vtcross/error.h" |
---|
| 53 | #include "vtcross/common.h" |
---|
| 54 | #include "vtcross/components.h" |
---|
| 55 | #include "vtcross/containers.h" |
---|
| 56 | #include "vtcross/socketcomm.h" |
---|
| 57 | |
---|
| 58 | |
---|
[278] | 59 | typedef struct services_s *services_DB; |
---|
| 60 | typedef struct data_s *data_DB; |
---|
| 61 | |
---|
| 62 | using namespace std; |
---|
| 63 | |
---|
| 64 | struct services_s { |
---|
[419] | 65 | string filename; |
---|
| 66 | string tablename; |
---|
| 67 | string command; |
---|
[278] | 68 | sqlite3 *db; |
---|
| 69 | unsigned int num_columns; |
---|
| 70 | }; |
---|
| 71 | |
---|
| 72 | struct data_s { |
---|
[419] | 73 | string filename; |
---|
| 74 | string tablename; |
---|
| 75 | string command; |
---|
[278] | 76 | sqlite3 *db; |
---|
| 77 | unsigned int num_columns; |
---|
| 78 | }; |
---|
| 79 | |
---|
| 80 | services_DB _services_DB; |
---|
| 81 | data_DB _data_DB; |
---|
[442] | 82 | string _SML_Config; |
---|
[316] | 83 | bool shellFound; |
---|
[278] | 84 | |
---|
[441] | 85 | /* Callback function used internally by some of the SQLite3 commands */ |
---|
| 86 | int32_t |
---|
| 87 | callback(void *notUsed, int32_t argc, char **argv, char **azColName) |
---|
| 88 | { |
---|
| 89 | for(size_t i = 0; i < argc; i++) { |
---|
[445] | 90 | LOG("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); |
---|
[278] | 91 | } |
---|
[441] | 92 | |
---|
[445] | 93 | LOG("\n"); |
---|
[278] | 94 | return 0; |
---|
| 95 | } |
---|
| 96 | |
---|
[445] | 97 | /* Useful for spotchecking what's in the database */ |
---|
| 98 | void |
---|
| 99 | printDatabase() |
---|
| 100 | { |
---|
| 101 | LOG("\n\n\n"); |
---|
[447] | 102 | _data_DB->command = "select "; |
---|
| 103 | _data_DB->command.append(_data_DB->tablename); |
---|
| 104 | _data_DB->command.append(".* from "); |
---|
| 105 | _data_DB->command.append(_data_DB->tablename); |
---|
| 106 | _data_DB->command.append(";"); |
---|
[445] | 107 | |
---|
[447] | 108 | char *errorMsg; |
---|
| 109 | int32_t rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg); |
---|
[445] | 110 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 111 | WARNING("SQL error: %s\n", errorMsg); |
---|
| 112 | |
---|
| 113 | LOG("database %s, table %s:\n", _data_DB->filename, _data_DB->tablename); |
---|
| 114 | LOG("\n\n\n"); |
---|
| 115 | } |
---|
| 116 | |
---|
[163] | 117 | ServiceManagementLayer::ServiceManagementLayer() |
---|
| 118 | { |
---|
[164] | 119 | LOG("Creating Service Management Layer.\n"); |
---|
[441] | 120 | |
---|
[204] | 121 | shellSocketFD = -1; |
---|
[278] | 122 | numberOfCognitiveEngines = 0; |
---|
| 123 | CE_Present = false; |
---|
| 124 | cogEngSrv = 1; |
---|
[163] | 125 | } |
---|
| 126 | |
---|
[441] | 127 | /* Free and clear the DB's associated with this SML in the destructor. |
---|
| 128 | * |
---|
| 129 | * Note that exiting with an error condition will cause SML to not be destructed, |
---|
| 130 | * resulting in the DB's staying in memory until the destructor is encountered in |
---|
| 131 | * future executions. */ |
---|
[163] | 132 | ServiceManagementLayer::~ServiceManagementLayer() |
---|
| 133 | { |
---|
[278] | 134 | char *errorMsg; |
---|
[441] | 135 | int32_t rc; /* sqlite command return code */ |
---|
| 136 | |
---|
[444] | 137 | _services_DB->command = "drop table "; |
---|
[419] | 138 | _services_DB->command.append(_services_DB->tablename); |
---|
[441] | 139 | rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); |
---|
| 140 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 141 | WARNING("ServiceManagementLayer::Destructor services 'drop table' error: %s\n", errorMsg); |
---|
| 142 | |
---|
[444] | 143 | _services_DB->command = "vacuum"; |
---|
[419] | 144 | rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); |
---|
[441] | 145 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 146 | WARNING("ServiceManagementLayer::Destructor services 'vacuum' error: %s\n", errorMsg); |
---|
| 147 | |
---|
[278] | 148 | free(_services_DB); |
---|
| 149 | |
---|
[444] | 150 | _data_DB->command = "drop table "; |
---|
[419] | 151 | _data_DB->command.append(_data_DB->tablename); |
---|
| 152 | rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg); |
---|
[441] | 153 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 154 | WARNING("ServiceManagementLayer::Destructor data 'drop table' error: %s\n", errorMsg); |
---|
| 155 | |
---|
[444] | 156 | _data_DB->command = "vacuum"; |
---|
[419] | 157 | rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg); |
---|
[441] | 158 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 159 | WARNING("ServiceManagementLayer::Destructor data 'vacuum' error: %s\n", errorMsg); |
---|
| 160 | |
---|
[278] | 161 | free(_data_DB); |
---|
[163] | 162 | } |
---|
| 163 | |
---|
[442] | 164 | /* Note that sizes of CE_List, miss, and service are hardcoded for now. |
---|
| 165 | * Also, their sizes are hardcoded into the code in various places; a fix |
---|
| 166 | * for a future version. */ |
---|
[278] | 167 | ServiceManagementLayer::ServiceManagementLayer(const char* SML_Config, \ |
---|
[438] | 168 | const char* serverName, const char* serverPort, int16_t clientPort) |
---|
[204] | 169 | { |
---|
| 170 | LOG("Creating Service Management Layer.\n"); |
---|
[442] | 171 | |
---|
| 172 | _SML_Config = string(SML_Config); |
---|
[285] | 173 | SMLport = clientPort; |
---|
[204] | 174 | |
---|
| 175 | ConnectToShell(serverName, serverPort); |
---|
[278] | 176 | CE_List = new CE_Reg[10]; |
---|
[204] | 177 | |
---|
[278] | 178 | miss = new Mission[10]; |
---|
[443] | 179 | for(size_t i = 0; i < 10; i++) { |
---|
[438] | 180 | miss[i].services = new Service[30]; |
---|
[443] | 181 | } |
---|
[278] | 182 | |
---|
| 183 | Current_ID = 0; |
---|
| 184 | |
---|
| 185 | LoadConfiguration(SML_Config, miss); |
---|
[442] | 186 | |
---|
[278] | 187 | CreateServicesDB(); |
---|
| 188 | CreateDataDB(); |
---|
[204] | 189 | } |
---|
| 190 | |
---|
[278] | 191 | /* CALLED BY: constructor |
---|
| 192 | * INPUTS: <none> |
---|
| 193 | * OUTPUTS: <none> |
---|
| 194 | * |
---|
| 195 | * DESCRIPTION: Create and initialize a DB to hold the services registered by components |
---|
| 196 | */ |
---|
| 197 | void |
---|
| 198 | ServiceManagementLayer::CreateServicesDB() |
---|
| 199 | { |
---|
[443] | 200 | sqlite3_stmt *ppStmt; /* OUT: Statement handle */ |
---|
[419] | 201 | const char *pzTail; /* OUT: Pointer to unused portion of zSql */ |
---|
[443] | 202 | int32_t rc; /* sqlite command return code */ |
---|
[282] | 203 | |
---|
[419] | 204 | _services_DB = new services_s; |
---|
| 205 | _services_DB->filename="Services_Table"; |
---|
| 206 | sqlite3_open(_services_DB->filename.c_str(), &(_services_DB->db)); |
---|
[443] | 207 | |
---|
[444] | 208 | char *cols[] = {(char *)"ID_Num", (char *)"Service_Name"}; |
---|
[278] | 209 | |
---|
[419] | 210 | _services_DB->tablename="Services"; |
---|
[308] | 211 | |
---|
[446] | 212 | /* ifprogram execution ends in anything other than a ordered shutdown, DB's will still |
---|
[443] | 213 | * be there for next run. Need to get rid of it so that old data isn't inadvertantly |
---|
| 214 | * used in the next execution cycle. */ |
---|
[446] | 215 | _services_DB->command = "DROP TABLE ifEXISTS Services;"; |
---|
[278] | 216 | |
---|
[443] | 217 | rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail); |
---|
| 218 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 219 | WARNING("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); |
---|
| 220 | |
---|
[282] | 221 | rc = sqlite3_step(ppStmt); |
---|
[443] | 222 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 223 | WARNING("ServiceManagementLayer::CreateServicesDB 'step' error\n"); |
---|
[282] | 224 | |
---|
[278] | 225 | _services_DB->num_columns = 2; |
---|
| 226 | |
---|
[443] | 227 | /* Generate command */ |
---|
[419] | 228 | _services_DB->command="CREATE TABLE "; |
---|
| 229 | _services_DB->command.append(_services_DB->tablename); |
---|
| 230 | _services_DB->command.append("("); |
---|
| 231 | _services_DB->command.append(cols[0]); |
---|
| 232 | _services_DB->command.append(" INT, "); |
---|
| 233 | _services_DB->command.append(cols[1]); |
---|
| 234 | _services_DB->command.append(" TEXT);"); |
---|
[278] | 235 | |
---|
[443] | 236 | /* Execute create table command */ |
---|
[419] | 237 | rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail); |
---|
[443] | 238 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 239 | WARNING("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); |
---|
| 240 | |
---|
[278] | 241 | rc = sqlite3_step(ppStmt); |
---|
[443] | 242 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 243 | WARNING("ServiceManagementLayer::CreateServicesDB 'step' error\n"); |
---|
[278] | 244 | } |
---|
| 245 | |
---|
| 246 | /* CALLED BY: constructor |
---|
| 247 | * INPUTS: <none> |
---|
| 248 | * OUTPUTS: <none> |
---|
| 249 | * |
---|
| 250 | * DESCRIPTION: Create and initialize a DB to hold the data sent by components |
---|
| 251 | */ |
---|
| 252 | void |
---|
| 253 | ServiceManagementLayer::CreateDataDB() |
---|
| 254 | { |
---|
[443] | 255 | sqlite3_stmt *ppStmt; /* OUT: Statement handle */ |
---|
[419] | 256 | const char *pzTail; /* OUT: Pointer to unused portion of zSql */ |
---|
[443] | 257 | int32_t rc; /* sqlite command return code */ |
---|
[278] | 258 | |
---|
[443] | 259 | _data_DB = new data_s; |
---|
[419] | 260 | |
---|
| 261 | _data_DB->filename="Data_Table"; |
---|
| 262 | sqlite3_open(_data_DB->filename.c_str(), &(_data_DB->db)); |
---|
[443] | 263 | |
---|
[444] | 264 | char *cols[] = {(char *)"Tag", (char *)"Data"}; |
---|
[278] | 265 | |
---|
[444] | 266 | _data_DB->tablename = "Data"; |
---|
[446] | 267 | _data_DB->command = "DROP TABLE ifEXISTS Data;"; |
---|
[278] | 268 | |
---|
[443] | 269 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail); |
---|
| 270 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 271 | WARNING("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc); |
---|
| 272 | |
---|
[287] | 273 | rc = sqlite3_step(ppStmt); |
---|
[443] | 274 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 275 | WARNING("ServiceManagementLayer::CreateDataDB 'step' error\n"); |
---|
[287] | 276 | |
---|
[278] | 277 | _data_DB->num_columns = 2; |
---|
| 278 | |
---|
[443] | 279 | /* Generate command */ |
---|
[444] | 280 | _data_DB->command = "CREATE TABLE "; |
---|
[419] | 281 | _data_DB->command.append(_data_DB->tablename); |
---|
| 282 | _data_DB->command.append("("); |
---|
| 283 | _data_DB->command.append(cols[0]); |
---|
[443] | 284 | |
---|
| 285 | /* First column is the name of the data (corresponding to the name of the output/input pair) |
---|
| 286 | * It is the primary key so any subsequent data with the same name will replace the row. */ |
---|
[419] | 287 | _data_DB->command.append(" TEXT PRIMARY KEY ON CONFLICT REPLACE, "); |
---|
| 288 | _data_DB->command.append(cols[1]); |
---|
| 289 | _data_DB->command.append(" TEXT);"); |
---|
[278] | 290 | |
---|
[419] | 291 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail); |
---|
[443] | 292 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 293 | WARNING("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc); |
---|
| 294 | |
---|
[278] | 295 | rc = sqlite3_step(ppStmt); |
---|
[443] | 296 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 297 | WARNING("ServiceManagementLayer::CreateDataDB 'step' error\n"); |
---|
[278] | 298 | } |
---|
| 299 | |
---|
| 300 | /* CALLED BY: MessageHandler |
---|
| 301 | * INPUTS: <none> |
---|
| 302 | * OUTPUTS: <none> |
---|
| 303 | * |
---|
| 304 | * DESCRIPTION: Sends a message identifying this component as an SML to the Shell |
---|
| 305 | */ |
---|
[163] | 306 | void |
---|
[200] | 307 | ServiceManagementLayer::SendComponentType() |
---|
[163] | 308 | { |
---|
[204] | 309 | SendMessage(shellSocketFD, "response_sml"); |
---|
| 310 | LOG("SML responded to GetRemoteComponentType query.\n"); |
---|
[163] | 311 | } |
---|
| 312 | |
---|
[278] | 313 | /* CALLED BY: constructor |
---|
| 314 | * INPUTS: |serverName| the IPv4 name of the server (127.0.0.1 for localhost) |
---|
[444] | 315 | * |serverPort| the port on the server to connect to |
---|
[278] | 316 | * OUTPUTS: <none> |
---|
| 317 | * |
---|
| 318 | * DESCRIPTION: Connecting to the shell takes 2 steps |
---|
| 319 | * 1) Establish a client socket for communication |
---|
| 320 | * 2) Run the initial Registration/handshake routine |
---|
| 321 | */ |
---|
[163] | 322 | void |
---|
[204] | 323 | ServiceManagementLayer::ConnectToShell(const char* serverName, \ |
---|
| 324 | const char* serverPort) |
---|
[200] | 325 | { |
---|
[204] | 326 | shellSocketFD = ClientSocket(serverName, serverPort); |
---|
| 327 | RegisterComponent(); |
---|
[200] | 328 | } |
---|
[164] | 329 | |
---|
[278] | 330 | /* CALLED BY: StartSMLServer |
---|
| 331 | * INPUTS: |ID| The ID number of the CE that has a message wating |
---|
| 332 | * OUTPUTS: <none> |
---|
| 333 | * |
---|
| 334 | * DESCRIPTION: Called whenever a socket is identified as being ready for communication |
---|
| 335 | * This funciton reads the message and calls the appropriate helper |
---|
| 336 | */ |
---|
| 337 | void |
---|
| 338 | ServiceManagementLayer::MessageHandler(int32_t ID) |
---|
[200] | 339 | { |
---|
[438] | 340 | char buffer[256]; |
---|
[278] | 341 | memset(buffer, 0, 256); |
---|
| 342 | int32_t _FD; |
---|
| 343 | |
---|
| 344 | if(ID != -1) |
---|
[444] | 345 | _FD = CE_List[ID].FD; |
---|
[278] | 346 | else |
---|
[444] | 347 | _FD = shellSocketFD; |
---|
| 348 | |
---|
[278] | 349 | ReadMessage(_FD, buffer); |
---|
| 350 | |
---|
| 351 | //--------Policy Engine Stuff - no policy engine support in this version-------// |
---|
[206] | 352 | |
---|
[278] | 353 | //printf("********* %s **********\n", buffer); |
---|
| 354 | // TODO |
---|
[446] | 355 | // ifwe send integer op codes rather than strings, this process will be |
---|
[278] | 356 | // MUCH faster since instead of donig string compares we can simply |
---|
| 357 | // switch on the integer value... |
---|
| 358 | /*if(strcmp(buffer, "register_service") == 0) { |
---|
| 359 | if(strcmp(buffer, "policy_geo") == 0) { |
---|
[206] | 360 | } |
---|
[278] | 361 | else if(strcmp(buffer, "policy_time") == 0) { |
---|
[206] | 362 | } |
---|
[278] | 363 | else if(strcmp(buffer, "policy_spectrum") == 0) { |
---|
[206] | 364 | } |
---|
[278] | 365 | else if(strcmp(buffer, "policy_spacial") == 0) { |
---|
[206] | 366 | } |
---|
[278] | 367 | } |
---|
| 368 | else if(strcmp(buffer, "deregister_service") == 0) { |
---|
| 369 | if(strcmp(buffer, "policy_geo") == 0) { |
---|
[206] | 370 | } |
---|
[278] | 371 | else if(strcmp(buffer, "policy_time") == 0) { |
---|
| 372 | } |
---|
| 373 | else if(strcmp(buffer, "policy_spectrum") == 0) { |
---|
| 374 | } |
---|
| 375 | else if(strcmp(buffer, "policy_spacial") == 0) { |
---|
| 376 | } |
---|
| 377 | }*/ |
---|
| 378 | |
---|
| 379 | //Go down the list to call the appropriate function |
---|
| 380 | if(strcmp(buffer, "query_component_type") == 0) { |
---|
| 381 | SendComponentType(); |
---|
[206] | 382 | } |
---|
[278] | 383 | else if(strcmp(buffer, "reset_sml") == 0) { |
---|
| 384 | Reset(); |
---|
| 385 | } |
---|
| 386 | else if(strcmp(buffer, "shutdown_sml") == 0) { |
---|
| 387 | Shutdown(); |
---|
| 388 | } |
---|
| 389 | else if(strcmp(buffer, "register_engine_cognitive") == 0) { |
---|
[444] | 390 | RegisterCognitiveEngine(ID); |
---|
[278] | 391 | } |
---|
| 392 | else if(strcmp(buffer, "register_service") == 0) { |
---|
[444] | 393 | ReceiveServices(ID); |
---|
[278] | 394 | } |
---|
| 395 | else if(strcmp(buffer, "send_component_type") == 0) { |
---|
[444] | 396 | SendComponentType(); |
---|
[278] | 397 | } |
---|
| 398 | else if(strcmp(buffer, "list_services") == 0) { |
---|
[444] | 399 | ListServices(); |
---|
[278] | 400 | } |
---|
| 401 | else if(strcmp(buffer, "set_active_mission") == 0) { |
---|
[444] | 402 | SetActiveMission(); |
---|
[278] | 403 | } |
---|
| 404 | else if(strcmp(buffer, "request_optimization") == 0) { |
---|
[444] | 405 | PerformActiveMission(); |
---|
[278] | 406 | } |
---|
| 407 | else if(strcmp(buffer, "deregister_engine_cognitive") == 0) { |
---|
[444] | 408 | DeregisterCognitiveEngine(ID); |
---|
[278] | 409 | } |
---|
| 410 | else if(strcmp(buffer, "deregister_service") == 0) { |
---|
[444] | 411 | DeregisterServices(ID); |
---|
[278] | 412 | } |
---|
[163] | 413 | } |
---|
| 414 | |
---|
[278] | 415 | //TODO Finish |
---|
| 416 | /* CALLED BY: MessageHandler |
---|
| 417 | * INPUTS: <none> |
---|
| 418 | * OUTPUTS: <none> |
---|
| 419 | * |
---|
| 420 | * DESCRIPTION: Deregisters the component from the Shell. |
---|
| 421 | */ |
---|
[163] | 422 | void |
---|
| 423 | ServiceManagementLayer::Shutdown() |
---|
| 424 | { |
---|
[204] | 425 | DeregisterComponent(); |
---|
[163] | 426 | } |
---|
| 427 | |
---|
[278] | 428 | //TODO Finish |
---|
| 429 | /* CALLED BY: MessageHandler |
---|
| 430 | * INPUTS: <none> |
---|
| 431 | * OUTPUTS: <none> |
---|
| 432 | * |
---|
| 433 | * DESCRIPTION: Deregisters the component from the Shell |
---|
| 434 | */ |
---|
[163] | 435 | void |
---|
| 436 | ServiceManagementLayer::Reset() |
---|
| 437 | { |
---|
[204] | 438 | DeregisterComponent(); |
---|
[278] | 439 | ReloadConfiguration(); |
---|
[163] | 440 | } |
---|
| 441 | |
---|
[278] | 442 | /* CALLED BY: ConnectToShell |
---|
| 443 | * INPUTS: <none> |
---|
| 444 | * OUTPUTS: <none> |
---|
| 445 | * |
---|
| 446 | * DESCRIPTION: Sends the registration message to the Shell |
---|
| 447 | */ |
---|
[163] | 448 | void |
---|
[200] | 449 | ServiceManagementLayer::RegisterComponent() |
---|
[163] | 450 | { |
---|
[200] | 451 | SendMessage(shellSocketFD, "register_sml"); |
---|
[164] | 452 | LOG("ServiceManagementLayer:: Registration message sent.\n"); |
---|
[163] | 453 | } |
---|
| 454 | |
---|
[278] | 455 | /* CALLED BY: Shutdown |
---|
| 456 | * INPUTS: <none> |
---|
| 457 | * OUTPUTS: <none> |
---|
| 458 | * |
---|
| 459 | * DESCRIPTION: Closes the client socket with the shell, sends a deregstration message |
---|
| 460 | */ |
---|
[163] | 461 | void |
---|
[200] | 462 | ServiceManagementLayer::DeregisterComponent() |
---|
[163] | 463 | { |
---|
[204] | 464 | SendMessage(shellSocketFD, "deregister_sml"); |
---|
| 465 | LOG("ServiceManagementLayer:: Deregistration message sent.\n"); |
---|
| 466 | |
---|
| 467 | shutdown(shellSocketFD, 2); |
---|
| 468 | close(shellSocketFD); |
---|
| 469 | shellSocketFD = -1; |
---|
| 470 | LOG("ServiceManagementLayer:: Shell socket closed.\n"); |
---|
[163] | 471 | } |
---|
| 472 | |
---|
| 473 | |
---|
[278] | 474 | /* CALLED BY: RegisterCognitiveEngine |
---|
| 475 | * INPUTS: |ID| The ID number of the component where the data is to be transfered to |
---|
| 476 | * OUTPUTS: <none> |
---|
| 477 | * |
---|
| 478 | * DESCRIPTION: Streams config data directly from the shell to the CE, and checks |
---|
| 479 | * for an "ack" message from the CE after every sent message |
---|
| 480 | * to know when to stop communication. |
---|
[444] | 481 | * |
---|
| 482 | * NOTE: Modified to check the incoming message buffer rather than the outgoing |
---|
| 483 | * message buffer to avoid a portion of the delay. May change this again to handle |
---|
| 484 | * data more inteligently, taking advantage of it's properties. |
---|
[278] | 485 | */ |
---|
[163] | 486 | void |
---|
[278] | 487 | ServiceManagementLayer::TransferRadioConfiguration(int32_t ID) |
---|
[163] | 488 | { |
---|
[278] | 489 | struct timeval selTimeout; |
---|
| 490 | fd_set sockSet; |
---|
[282] | 491 | int32_t rc = 1; |
---|
[278] | 492 | char buffer[256]; |
---|
[444] | 493 | |
---|
| 494 | /* Send data until the CE sends an ACK message back */ |
---|
| 495 | while(rc != 0) { |
---|
[278] | 496 | memset(buffer, 0, 256); |
---|
[444] | 497 | |
---|
| 498 | /* Receive data from Shell */ |
---|
| 499 | ReadMessage(shellSocketFD, buffer); |
---|
| 500 | |
---|
| 501 | /* Send data to CE */ |
---|
| 502 | SendMessage(CE_List[ID].FD, buffer); |
---|
[278] | 503 | FD_ZERO(&sockSet); |
---|
| 504 | FD_SET(shellSocketFD, &sockSet); |
---|
| 505 | selTimeout.tv_sec = 0; |
---|
[308] | 506 | selTimeout.tv_usec = 5000; |
---|
[444] | 507 | |
---|
[446] | 508 | /* Check ifthere is a message on the shell ready to be processed */ |
---|
[444] | 509 | rc = select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout); |
---|
[278] | 510 | } |
---|
[444] | 511 | |
---|
[278] | 512 | memset(buffer, 0, 256); |
---|
| 513 | ReadMessage(CE_List[ID].FD, buffer); |
---|
| 514 | SendMessage(shellSocketFD, buffer); |
---|
[163] | 515 | } |
---|
| 516 | |
---|
| 517 | |
---|
[278] | 518 | /* CALLED BY: RegisterCognitiveEngine |
---|
| 519 | * INPUTS: |ID| The ID number of the component where the data is to be transfered to |
---|
| 520 | * OUTPUTS: <none> |
---|
| 521 | * |
---|
| 522 | * DESCRIPTION: Simmilar to TransferRadioConfig, just with Experience data |
---|
[444] | 523 | * |
---|
| 524 | * NOTE: Modified to check the incoming message buffer rather than the outgoing |
---|
| 525 | * message buffer to avoid a portion of the delay. May change this again to handle |
---|
| 526 | * data more inteligently, taking advantage of it's properties. |
---|
[278] | 527 | */ |
---|
[163] | 528 | void |
---|
[278] | 529 | ServiceManagementLayer::TransferExperience(int32_t ID) |
---|
[163] | 530 | { |
---|
[278] | 531 | struct timeval selTimeout; |
---|
| 532 | fd_set sockSet; |
---|
[282] | 533 | int32_t rc = 1; |
---|
[278] | 534 | char buffer[256]; |
---|
[444] | 535 | /* Send data until the CE sends an ACK message back */ |
---|
| 536 | while(rc != 0) { |
---|
[278] | 537 | memset(buffer, 0, 256); |
---|
[444] | 538 | |
---|
| 539 | /* Receive data from Shell */ |
---|
| 540 | ReadMessage(shellSocketFD, buffer); |
---|
| 541 | |
---|
| 542 | /* Send data to CE */ |
---|
| 543 | SendMessage(CE_List[ID].FD, buffer); |
---|
[278] | 544 | FD_ZERO(&sockSet); |
---|
| 545 | FD_SET(shellSocketFD, &sockSet); |
---|
| 546 | selTimeout.tv_sec = 0; |
---|
[308] | 547 | selTimeout.tv_usec = 5000; |
---|
[444] | 548 | |
---|
[446] | 549 | /* Check ifthere is a message on the shell ready to be processed */ |
---|
[444] | 550 | rc = select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout); |
---|
[278] | 551 | } |
---|
[444] | 552 | |
---|
[278] | 553 | memset(buffer, 0, 256); |
---|
| 554 | ReadMessage(CE_List[ID].FD, buffer); |
---|
| 555 | SendMessage(shellSocketFD, buffer); |
---|
[163] | 556 | } |
---|
| 557 | |
---|
[278] | 558 | /* CALLED BY: MessageHandler |
---|
| 559 | * INPUTS: |ID| The ID number of the component where service is located |
---|
| 560 | * OUTPUTS: <none> |
---|
| 561 | * |
---|
| 562 | * DESCRIPTION: Inserts a service into the DB with the ID of the component where it exists |
---|
| 563 | */ |
---|
[163] | 564 | void |
---|
[278] | 565 | ServiceManagementLayer::ReceiveServices(int32_t ID) |
---|
[163] | 566 | { |
---|
[278] | 567 | char buffer[256]; |
---|
| 568 | memset(buffer, 0, 256); |
---|
| 569 | ReadMessage(CE_List[ID].FD, buffer); |
---|
[444] | 570 | |
---|
| 571 | char *cols[] = {(char *) "ID_Num", (char *) "Service_Name"}; |
---|
| 572 | |
---|
| 573 | /* Generate command */ |
---|
| 574 | _services_DB->command = "insert into "; |
---|
[419] | 575 | _services_DB->command.append(_services_DB->tablename); |
---|
| 576 | _services_DB->command.append(" ("); |
---|
| 577 | _services_DB->command.append(cols[0]); |
---|
| 578 | _services_DB->command.append(", "); |
---|
| 579 | _services_DB->command.append(cols[1]); |
---|
| 580 | _services_DB->command.append(") "); |
---|
| 581 | _services_DB->command.append(" values("); |
---|
[444] | 582 | |
---|
[419] | 583 | char temp[3]; |
---|
[444] | 584 | memset(temp, 0, 3); |
---|
[419] | 585 | sprintf(temp, "%d", ID); |
---|
[444] | 586 | |
---|
[419] | 587 | _services_DB->command.append(temp); |
---|
| 588 | _services_DB->command.append(", '"); |
---|
| 589 | _services_DB->command.append(buffer); |
---|
| 590 | _services_DB->command.append("');"); |
---|
[278] | 591 | |
---|
[444] | 592 | /* Execute add command */ |
---|
[278] | 593 | char *errorMsg; |
---|
[419] | 594 | int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); |
---|
[444] | 595 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 596 | WARNING("ServiceManagementLayer::RecieveServices DB Error %s\n", errorMsg); |
---|
[163] | 597 | } |
---|
| 598 | |
---|
[278] | 599 | /* CALLED BY: MessageHandler |
---|
| 600 | * INPUTS: <none> |
---|
| 601 | * OUTPUTS: <none> |
---|
| 602 | * |
---|
[444] | 603 | * DESCRIPTION: This method associates the services that components provide with the |
---|
| 604 | * services that are requested in the mission. Each service in the mission is given |
---|
| 605 | * the ID and FD of a component that has registered to provide that service. Deregistration |
---|
[446] | 606 | * is okay until this method is called without a reload, but ifderegistration occurs after this |
---|
| 607 | * method is called it needs to be called again even ifother engines also provide the services |
---|
[278] | 608 | */ |
---|
[163] | 609 | void |
---|
| 610 | ServiceManagementLayer::SetActiveMission() |
---|
| 611 | { |
---|
[278] | 612 | char buffer[256]; |
---|
| 613 | memset(buffer, 0, 256); |
---|
| 614 | ReadMessage(shellSocketFD, buffer); |
---|
[444] | 615 | |
---|
[287] | 616 | uint32_t missID = atoi(buffer); |
---|
[444] | 617 | for(activeMission = 0; activeMission < 10; activeMission++) { |
---|
| 618 | /* Find the active mission by comparing mission ID's */ |
---|
| 619 | if(miss[activeMission].missionID == missID) |
---|
| 620 | break; |
---|
[278] | 621 | } |
---|
[285] | 622 | |
---|
[444] | 623 | LOG("ServiceManagementLayer:: Received Set Active Mission command: %i.\n", missID); |
---|
| 624 | |
---|
| 625 | /* For each service in the mission */ |
---|
| 626 | for(size_t i = 0; i < miss[activeMission].numServices; i++) { |
---|
| 627 | /* Check whether the current service is an actual service or a conditional */ |
---|
| 628 | if(miss[activeMission].services[i].name.compare("if") && \ |
---|
| 629 | miss[activeMission].services[i].name.compare("dowhile") && \ |
---|
| 630 | miss[activeMission].services[i].name.compare("shell")) { |
---|
[446] | 631 | /* ifit is a service, search the database of registered services to find |
---|
[444] | 632 | * the ID of the component that registered it */ |
---|
| 633 | _services_DB->command="select "; |
---|
| 634 | _services_DB->command.append(_services_DB->tablename); |
---|
| 635 | _services_DB->command.append(".* from "); |
---|
| 636 | _services_DB->command.append( _services_DB->tablename); |
---|
| 637 | _services_DB->command.append(" where Service_Name=='"); |
---|
| 638 | _services_DB->command.append(miss[activeMission].services[i].name); |
---|
| 639 | _services_DB->command.append("';"); |
---|
[438] | 640 | |
---|
[444] | 641 | sqlite3_stmt * pStatement; |
---|
| 642 | int32_t rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), \ |
---|
| 643 | -1, &pStatement, NULL); |
---|
| 644 | if(rc == SQLITE_OK) { |
---|
[446] | 645 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
[444] | 646 | miss[activeMission].services[i].componentID = sqlite3_column_int(pStatement, 0); |
---|
| 647 | else { |
---|
| 648 | WARNING("services_DB:: Mission requires service %s ", \ |
---|
| 649 | miss[activeMission].services[i].name.c_str()); |
---|
[445] | 650 | WARNING("not provided by any connected component.\n"); |
---|
[444] | 651 | rc = 31337; |
---|
| 652 | } |
---|
| 653 | } else { |
---|
| 654 | WARNING("services_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
| 655 | rc, _services_DB->command.c_str()); |
---|
| 656 | } |
---|
| 657 | |
---|
| 658 | sqlite3_finalize(pStatement); |
---|
| 659 | miss[activeMission].services[i].socketFD = \ |
---|
| 660 | CE_List[miss[activeMission].services[i].componentID].FD; |
---|
| 661 | } |
---|
| 662 | /* TODO Nothing to be done for conditionals at this stage */ |
---|
[278] | 663 | } |
---|
[285] | 664 | |
---|
| 665 | SendMessage(shellSocketFD, "ack"); |
---|
[287] | 666 | LOG("ServiceManagementLayer:: Done setting active mission.\n"); |
---|
[163] | 667 | } |
---|
| 668 | |
---|
[278] | 669 | /* CALLED BY: PerformActiveMission |
---|
| 670 | * INPUTS: |sourceID| ID of the service that is being processed |
---|
| 671 | * OUTPUTS: <none> |
---|
| 672 | * |
---|
| 673 | * DESCRIPTION: This is a helper method for the "PerformActiveMission" function |
---|
[444] | 674 | * NOTE: This function has changed drastically from the previous implementation |
---|
| 675 | * |
---|
| 676 | * Takes an ID of a service. For that service, finds inputs in DB and forwords |
---|
| 677 | * those on to the engine after sending comm-starting messages. Afterwords, listenes |
---|
| 678 | * for the outputs so that it can store those in the database for future services or |
---|
| 679 | * the overall output |
---|
[278] | 680 | */ |
---|
| 681 | void |
---|
| 682 | ServiceManagementLayer::TransactData(int32_t sourceID) |
---|
| 683 | { |
---|
| 684 | char buffer[256]; |
---|
| 685 | std::string data; |
---|
[444] | 686 | char *cols[] = {(char *) "Tag", (char *) "Data"}; |
---|
[287] | 687 | char *token; |
---|
| 688 | |
---|
[444] | 689 | /* Send a message directly to the shell */ |
---|
| 690 | if(miss[activeMission].services[sourceID].name.find("shell") != string::npos) { |
---|
| 691 | shellFound=true; |
---|
| 692 | |
---|
| 693 | int32_t k = 0; |
---|
| 694 | while((k < 10) && (!miss[activeMission].input[k].empty())) { |
---|
| 695 | k++; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | sprintf(buffer, "%d", k); |
---|
| 699 | SendMessage(shellSocketFD, buffer); |
---|
| 700 | for(int32_t t = 0; t < k; t++) { |
---|
| 701 | memset(buffer, 0 , 256); |
---|
| 702 | _data_DB->command="select "; |
---|
[438] | 703 | _data_DB->command.append(_data_DB->tablename); |
---|
[444] | 704 | _data_DB->command.append(".* from "); |
---|
| 705 | _data_DB->command.append(_data_DB->tablename); |
---|
| 706 | _data_DB->command.append(" where Tag=='"); |
---|
| 707 | _data_DB->command.append(miss[activeMission].input[t]); |
---|
| 708 | _data_DB->command.append("';"); |
---|
| 709 | sqlite3_stmt * pStatement; |
---|
| 710 | |
---|
| 711 | int32_t rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \ |
---|
| 712 | -1, &pStatement, NULL); |
---|
| 713 | if(rc == SQLITE_OK) { |
---|
| 714 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 715 | data=((const char*) sqlite3_column_text(pStatement, 1)); |
---|
| 716 | else { |
---|
| 717 | LOG("3data_DB:: Data not yet in DB., %s\n", _data_DB->command.c_str()); |
---|
| 718 | rc = 31337; |
---|
| 719 | } |
---|
| 720 | } |
---|
| 721 | else { |
---|
| 722 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
| 723 | rc,_data_DB->command.c_str()); |
---|
| 724 | } |
---|
| 725 | |
---|
| 726 | sqlite3_finalize(pStatement); |
---|
| 727 | token = strtok((char *) data.c_str(), "@"); |
---|
| 728 | token = strtok(NULL, "@"); |
---|
| 729 | SendMessage(shellSocketFD, token); |
---|
| 730 | token = strtok(NULL, "@"); |
---|
| 731 | SendMessage(shellSocketFD, token); |
---|
| 732 | } |
---|
| 733 | |
---|
| 734 | return; |
---|
[287] | 735 | } |
---|
| 736 | |
---|
[446] | 737 | /* ifthis is a service command and not a shell command... */ |
---|
[444] | 738 | /* Transmission starting messages */ |
---|
[278] | 739 | SendMessage(miss[activeMission].services[sourceID].socketFD, "request_optimization_service"); |
---|
[444] | 740 | SendMessage(miss[activeMission].services[sourceID].socketFD, \ |
---|
| 741 | miss[activeMission].services[sourceID].name.c_str()); |
---|
[278] | 742 | } |
---|
| 743 | |
---|
| 744 | /* CALLED BY: MessageHandler |
---|
| 745 | * INPUTS: <none> |
---|
| 746 | * OUTPUTS: <none> |
---|
| 747 | * |
---|
[445] | 748 | * DESCRIPTION: This function works by first sending the inputs from the shell to |
---|
| 749 | * the appropriate components. The first service should begin immeadiately, as |
---|
| 750 | * should any others who have all of their input parameters. When they complete, |
---|
| 751 | * the output path is found and the data is transfered as it becomes available |
---|
| 752 | * Presumably at this point the second function has all of it's parameters, so it |
---|
| 753 | * begins to compute, and the cycle repeats. |
---|
[278] | 754 | * |
---|
| 755 | * Rules for active missions (currently) |
---|
[291] | 756 | * -Five inputs/outputs per service and per mission |
---|
[445] | 757 | * -All ordering constraints have been relaxed in this version; all data is stored |
---|
| 758 | * locally and only sent when requested |
---|
[446] | 759 | * -ifand while support fully implemented - up to three levels (if's can be nested, but dowhiles cannot) |
---|
[316] | 760 | * -For dowhiles, assumes loop condition determined on last line |
---|
[445] | 761 | * |
---|
| 762 | * -IMPORTANT: DB uses '@' to seperate individual statements; using '@' in the data |
---|
| 763 | * stream will result in incorrect behavior |
---|
[278] | 764 | */ |
---|
| 765 | void |
---|
| 766 | ServiceManagementLayer::PerformActiveMission() |
---|
| 767 | { |
---|
[316] | 768 | shellFound = false; |
---|
[445] | 769 | std::string data_param; |
---|
| 770 | std::string data_obsv; |
---|
| 771 | std::string data; |
---|
[278] | 772 | std::string input; |
---|
| 773 | std::string check; |
---|
[445] | 774 | |
---|
[278] | 775 | char buffer[256]; |
---|
[288] | 776 | char buffer1[256]; |
---|
[419] | 777 | std::string token, token2; |
---|
[313] | 778 | std::string data2; |
---|
[445] | 779 | |
---|
| 780 | int32_t rc; |
---|
[288] | 781 | char *errorMsg; |
---|
[445] | 782 | char *cols[] = {(char *) "Tag", (char *) "Data"}; |
---|
[316] | 783 | |
---|
| 784 | LOG("ServiceManagementLayer:: Received PerformActiveMission command.\n"); |
---|
| 785 | |
---|
[445] | 786 | /* Get the inputs */ |
---|
[287] | 787 | memset(buffer, 0, 256); |
---|
| 788 | ReadMessage(shellSocketFD, buffer); |
---|
| 789 | |
---|
| 790 | /* Receive Set of Parameters */ |
---|
| 791 | memset(buffer, 0, 256); |
---|
| 792 | ReadMessage(shellSocketFD, buffer); |
---|
[445] | 793 | int32_t t = atoi(buffer); |
---|
| 794 | for(size_t m = 0; m < t; m++) { |
---|
[288] | 795 | memset(buffer1, 0, 256); |
---|
| 796 | ReadMessage(shellSocketFD, buffer1); |
---|
[445] | 797 | _data_DB->command="insert into "; |
---|
[438] | 798 | _data_DB->command.append(_data_DB->tablename); |
---|
[445] | 799 | _data_DB->command.append(" ("); |
---|
[438] | 800 | _data_DB->command.append(cols[0]); |
---|
| 801 | _data_DB->command.append(", "); |
---|
[445] | 802 | _data_DB->command.append(cols[1]); |
---|
| 803 | _data_DB->command.append(") "); |
---|
| 804 | |
---|
[288] | 805 | memset(buffer, 0, 256); |
---|
| 806 | ReadMessage(shellSocketFD, buffer); |
---|
[445] | 807 | _data_DB->command.append(" values('"); |
---|
| 808 | _data_DB->command.append(buffer1); |
---|
| 809 | _data_DB->command.append("', '1@"); |
---|
| 810 | _data_DB->command.append(buffer1); |
---|
| 811 | _data_DB->command.append("@"); |
---|
| 812 | _data_DB->command.append(buffer); |
---|
| 813 | _data_DB->command.append("');"); |
---|
| 814 | |
---|
| 815 | rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg); |
---|
| 816 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 817 | WARNING("SQL error: %s\n", errorMsg); |
---|
[288] | 818 | } |
---|
[278] | 819 | |
---|
[445] | 820 | int32_t numstatements[3] = {0 ,0 ,0}; |
---|
| 821 | for(size_t i; i < miss[activeMission].numServices; i++) { |
---|
| 822 | if(miss[activeMission].services[i].name.compare("if") == 0) { |
---|
| 823 | input.clear(); |
---|
| 824 | check.clear(); |
---|
[287] | 825 | |
---|
[445] | 826 | for(size_t t = 0; t < 10; t++) { |
---|
| 827 | if(!miss[activeMission].services[i].output[t].empty()) { |
---|
| 828 | input = miss[activeMission].services[i - numstatements[0] - 1].output[t]; |
---|
[287] | 829 | |
---|
[445] | 830 | _data_DB->command="SELECT "; |
---|
[438] | 831 | _data_DB->command.append(_data_DB->tablename); |
---|
| 832 | _data_DB->command.append(".* from "); |
---|
| 833 | _data_DB->command.append(_data_DB->tablename); |
---|
| 834 | _data_DB->command.append(" where Tag=='"); |
---|
[445] | 835 | _data_DB->command.append(input); |
---|
[438] | 836 | _data_DB->command.append("';"); |
---|
[445] | 837 | |
---|
| 838 | sqlite3_stmt *pStatement; |
---|
| 839 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \ |
---|
| 840 | -1, &pStatement, NULL); |
---|
| 841 | if(rc == SQLITE_OK) { |
---|
| 842 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 843 | data = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 844 | else { |
---|
[446] | 845 | WARNING("1 data_DB:: Data not yet in DB.\n"); |
---|
[445] | 846 | rc=31337; |
---|
| 847 | } |
---|
| 848 | } else { |
---|
[446] | 849 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
[445] | 850 | rc,_data_DB->command.c_str()); |
---|
| 851 | } |
---|
| 852 | |
---|
| 853 | sqlite3_finalize(pStatement); |
---|
| 854 | int32_t pos = data.find_last_of("@", data.length() - 2); |
---|
| 855 | token = data.substr(pos + 1); |
---|
| 856 | token.erase(token.length() - 1); |
---|
| 857 | data.clear(); |
---|
| 858 | break; |
---|
| 859 | } |
---|
| 860 | } |
---|
| 861 | |
---|
| 862 | bool doit = false; |
---|
| 863 | if(miss[activeMission].services[i].output[t].find(">") != string::npos) { |
---|
| 864 | std::string data2; |
---|
| 865 | _data_DB->command="SELECT "; |
---|
| 866 | _data_DB->command.append(_data_DB->tablename); |
---|
| 867 | _data_DB->command.append(".* from "); |
---|
| 868 | _data_DB->command.append(_data_DB->tablename); |
---|
| 869 | _data_DB->command.append(" where Tag=='"); |
---|
| 870 | _data_DB->command.append(miss[activeMission].services[i].output[t].erase(0, 1)); |
---|
| 871 | _data_DB->command.append("';"); |
---|
| 872 | sqlite3_stmt *pStatement; |
---|
| 873 | |
---|
| 874 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \ |
---|
| 875 | -1, &pStatement, NULL); |
---|
| 876 | if(rc == SQLITE_OK) { |
---|
| 877 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
[438] | 878 | data2 = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 879 | else { |
---|
[446] | 880 | WARNING("2 data_DB:: Data not yet in DB.\n"); |
---|
[445] | 881 | rc = 31337; |
---|
[438] | 882 | } |
---|
[445] | 883 | } else { |
---|
[446] | 884 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
[445] | 885 | rc, _data_DB->command.c_str()); |
---|
[438] | 886 | } |
---|
[445] | 887 | |
---|
| 888 | sqlite3_finalize(pStatement); |
---|
| 889 | |
---|
| 890 | int32_t pos = data2.find_last_of("@", data2.length() - 2); |
---|
| 891 | token2 = data2.substr(pos + 1); |
---|
| 892 | token2.erase(token2.length() - 1); |
---|
| 893 | if(atof(token.c_str()) > atof(token2.c_str())) |
---|
| 894 | doit = true; |
---|
| 895 | } |
---|
| 896 | else if(miss[activeMission].services[i].output[t].find(token) != string::npos) |
---|
| 897 | doit = true; |
---|
| 898 | |
---|
| 899 | if(doit) { |
---|
| 900 | for(size_t k = i + 1; k <= i+miss[activeMission].services[i].num_conds; k++) { |
---|
| 901 | if(miss[activeMission].services[k].name.compare("if") == 0) { |
---|
[438] | 902 | input.clear(); |
---|
| 903 | check.clear(); |
---|
[445] | 904 | for(size_t t = 0; t < 10; t++) { |
---|
| 905 | if(!miss[activeMission].services[k].output[t].empty()) { |
---|
| 906 | input = miss[activeMission].services[k - numstatements[1] - 1].output[t]; |
---|
| 907 | _data_DB->command="SELECT "; |
---|
[438] | 908 | _data_DB->command.append(_data_DB->tablename); |
---|
[445] | 909 | _data_DB->command.append(".* from "); |
---|
| 910 | _data_DB->command.append(_data_DB->tablename); |
---|
| 911 | _data_DB->command.append(" where Tag=='"); |
---|
| 912 | _data_DB->command.append(input); |
---|
| 913 | _data_DB->command.append("';"); |
---|
| 914 | |
---|
| 915 | sqlite3_stmt *pStatement; |
---|
| 916 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \ |
---|
| 917 | -1, &pStatement, NULL); |
---|
| 918 | if(rc == SQLITE_OK) { |
---|
| 919 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 920 | data = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 921 | else { |
---|
[446] | 922 | WARNING("3 data_DB:: Data not yet in DB.\n"); |
---|
[445] | 923 | rc = 31337; |
---|
| 924 | } |
---|
| 925 | } else { |
---|
[446] | 926 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
[445] | 927 | rc,_data_DB->command.c_str()); |
---|
| 928 | } |
---|
| 929 | |
---|
[438] | 930 | sqlite3_finalize(pStatement); |
---|
[445] | 931 | int32_t pos = data.find_last_of("@", data.length() - 2); |
---|
| 932 | token = data.substr(pos + 1); |
---|
| 933 | token.erase(token.length() - 1); |
---|
| 934 | break; |
---|
| 935 | } |
---|
[438] | 936 | } |
---|
[445] | 937 | |
---|
[438] | 938 | bool doit = false; |
---|
[445] | 939 | if(miss[activeMission].services[k].output[t].find(">") != string::npos) { |
---|
| 940 | std::string data2; |
---|
[438] | 941 | _data_DB->command="SELECT "; |
---|
| 942 | _data_DB->command.append(_data_DB->tablename); |
---|
| 943 | _data_DB->command.append(".* from "); |
---|
[445] | 944 | _data_DB->command.append(_data_DB->tablename); |
---|
[438] | 945 | _data_DB->command.append(" where Tag=='"); |
---|
[445] | 946 | _data_DB->command.append(miss[activeMission].services[k].output[t].erase(0, 1)); |
---|
[438] | 947 | _data_DB->command.append("';"); |
---|
[446] | 948 | |
---|
| 949 | sqlite3_stmt *pStatement; |
---|
| 950 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \ |
---|
| 951 | -1, &pStatement, NULL); |
---|
| 952 | if(rc == SQLITE_OK) { |
---|
| 953 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 954 | data2 = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 955 | else { |
---|
| 956 | WARNING("4 data_DB:: Data not yet in DB.\n"); |
---|
| 957 | rc = 31337; |
---|
| 958 | } |
---|
[438] | 959 | } else { |
---|
[446] | 960 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
| 961 | rc, _data_DB->command.c_str()); |
---|
[438] | 962 | } |
---|
[446] | 963 | |
---|
| 964 | sqlite3_finalize(pStatement); |
---|
| 965 | int32_t pos = data2.find_last_of("@", data2.length() - 2); |
---|
| 966 | token2 = data2.substr(pos + 1); |
---|
| 967 | token2.erase(token2.length() - 1); |
---|
| 968 | if(atof(token.c_str()) > atof(token2.c_str())) |
---|
| 969 | doit = true; |
---|
[438] | 970 | } |
---|
[446] | 971 | else if(miss[activeMission].services[k].output[t].find(token) != string::npos) |
---|
| 972 | doit=true; |
---|
[445] | 973 | |
---|
[446] | 974 | if(doit) { |
---|
| 975 | for(size_t j = k + 1; j <= k+miss[activeMission].services[k].num_conds; j++) { |
---|
| 976 | if(miss[activeMission].services[j].name.compare("if") == 0) { |
---|
[445] | 977 | input.clear(); |
---|
| 978 | check.clear(); |
---|
[446] | 979 | for(t = 0; t < 10; t++) { |
---|
| 980 | if(!miss[activeMission].services[j].output[t].empty()) { |
---|
| 981 | input = miss[activeMission].services[j - numstatements[2] - 1].output[t]; |
---|
| 982 | |
---|
| 983 | _data_DB->command="SELECT "; |
---|
| 984 | _data_DB->command.append(_data_DB->tablename); |
---|
| 985 | _data_DB->command.append(".* from "); |
---|
| 986 | _data_DB->command.append(_data_DB->tablename); |
---|
| 987 | _data_DB->command.append(" where Tag=='"); |
---|
| 988 | _data_DB->command.append(input); |
---|
| 989 | _data_DB->command.append("';"); |
---|
| 990 | |
---|
| 991 | sqlite3_stmt *pStatement; |
---|
| 992 | |
---|
| 993 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); |
---|
| 994 | if(rc == SQLITE_OK) { |
---|
| 995 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 996 | data = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 997 | else { |
---|
| 998 | WARNING("5 data_DB:: Data not yet in DB.\n"); |
---|
| 999 | rc = 31337; |
---|
| 1000 | } |
---|
| 1001 | } else { |
---|
| 1002 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
| 1003 | rc, _data_DB->command.c_str()); |
---|
| 1004 | } |
---|
| 1005 | |
---|
| 1006 | sqlite3_finalize(pStatement); |
---|
| 1007 | int32_t pos = data.find_last_of("@", data.length()-2); |
---|
| 1008 | token = data.substr(pos+1); |
---|
| 1009 | token.erase(token.length()-1); |
---|
| 1010 | data.clear(); |
---|
| 1011 | break; |
---|
| 1012 | } |
---|
| 1013 | } |
---|
| 1014 | |
---|
| 1015 | bool doit = false; |
---|
| 1016 | if(miss[activeMission].services[j].output[t].find(">") != string::npos) { |
---|
[445] | 1017 | _data_DB->command="SELECT "; |
---|
| 1018 | _data_DB->command.append(_data_DB->tablename); |
---|
| 1019 | _data_DB->command.append(".* from "); |
---|
| 1020 | _data_DB->command.append(_data_DB->tablename); |
---|
| 1021 | _data_DB->command.append(" where Tag=='"); |
---|
[446] | 1022 | _data_DB->command.append(miss[activeMission].services[j].output[t].erase(0, 1)); |
---|
[445] | 1023 | _data_DB->command.append("';"); |
---|
| 1024 | |
---|
[446] | 1025 | sqlite3_stmt *pStatement; |
---|
[445] | 1026 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); |
---|
[446] | 1027 | if(rc == SQLITE_OK) { |
---|
| 1028 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 1029 | data2 = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 1030 | else { |
---|
| 1031 | WARNING("6 data_DB:: Data not yet in DB.\n"); |
---|
| 1032 | rc=31337; |
---|
| 1033 | } |
---|
[445] | 1034 | } else { |
---|
[446] | 1035 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
| 1036 | rc, _data_DB->command.c_str()); |
---|
[445] | 1037 | } |
---|
[446] | 1038 | |
---|
| 1039 | sqlite3_finalize(pStatement); |
---|
| 1040 | |
---|
| 1041 | int32_t pos = data2.find_last_of("@", data2.length()-2); |
---|
| 1042 | token2 = data2.substr(pos + 1); |
---|
| 1043 | token2.erase(token2.length()-1); |
---|
| 1044 | |
---|
| 1045 | if(atof(token.c_str()) > atof(token2.c_str())) |
---|
| 1046 | doit=true; |
---|
| 1047 | |
---|
| 1048 | data.clear(); |
---|
[445] | 1049 | } |
---|
[446] | 1050 | |
---|
| 1051 | else if(miss[activeMission].services[j].output[t].find(token) != string::npos) |
---|
| 1052 | doit = true; |
---|
| 1053 | |
---|
| 1054 | if(doit) { |
---|
| 1055 | for(size_t l = j + 1; l <= j + miss[activeMission].services[j].num_conds; l++) { |
---|
| 1056 | TransactData(l); |
---|
| 1057 | } |
---|
[445] | 1058 | } |
---|
[446] | 1059 | |
---|
| 1060 | numstatements[2] += miss[activeMission].services[j].num_conds + 1; |
---|
| 1061 | j += miss[activeMission].services[j].num_conds; |
---|
| 1062 | } else if(miss[activeMission].services[j].name.compare("dowhile") == 0) { |
---|
| 1063 | numstatements[0]=0; |
---|
| 1064 | |
---|
| 1065 | while(true) { |
---|
| 1066 | uint32_t l; |
---|
| 1067 | for(l = j + 1; l <= j+miss[activeMission].services[j].num_conds; l++) { |
---|
| 1068 | TransactData(l); |
---|
| 1069 | } |
---|
| 1070 | |
---|
| 1071 | data.clear(); |
---|
| 1072 | input.clear(); |
---|
| 1073 | check.clear(); |
---|
| 1074 | |
---|
| 1075 | int32_t t; |
---|
| 1076 | for(t = 0; t < 10; t++) { |
---|
| 1077 | if(!miss[activeMission].services[j].output[t].empty()){ |
---|
| 1078 | input=miss[activeMission].services[l-2].output[t]; |
---|
| 1079 | _data_DB->command="SELECT "; |
---|
| 1080 | _data_DB->command.append(_data_DB->tablename); |
---|
| 1081 | _data_DB->command.append(".* from "); |
---|
| 1082 | _data_DB->command.append(_data_DB->tablename); |
---|
| 1083 | _data_DB->command.append(" where Tag=='"); |
---|
| 1084 | _data_DB->command.append(input); |
---|
| 1085 | _data_DB->command.append("';"); |
---|
| 1086 | sqlite3_stmt *pStatement; |
---|
| 1087 | |
---|
| 1088 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); |
---|
| 1089 | if(rc == SQLITE_OK){ |
---|
| 1090 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 1091 | data = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 1092 | else { |
---|
| 1093 | WARNING("7 data_DB:: Data not yet in DB.: %s\n", _data_DB->command.c_str()); |
---|
| 1094 | rc = 31337; |
---|
| 1095 | } |
---|
| 1096 | } else { |
---|
| 1097 | WARNING("data_DB:: SQL statement error. rc = %i\n%s\n", \ |
---|
| 1098 | rc, _data_DB->command.c_str()); |
---|
| 1099 | } |
---|
| 1100 | |
---|
| 1101 | sqlite3_finalize(pStatement); |
---|
| 1102 | int32_t pos = data.find_last_of("@", data.length() - 2); |
---|
| 1103 | token = data.substr(pos + 1); |
---|
| 1104 | token.erase(token.length() - 1); |
---|
| 1105 | break; |
---|
| 1106 | } |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | if(miss[activeMission].services[j].output[t].find(token) == string::npos) { |
---|
| 1110 | break; |
---|
| 1111 | } |
---|
[445] | 1112 | } |
---|
[446] | 1113 | |
---|
| 1114 | j += miss[activeMission].services[j].num_conds; |
---|
| 1115 | } else { |
---|
| 1116 | numstatements[2] = 0; |
---|
| 1117 | TransactData(j); |
---|
[445] | 1118 | } |
---|
| 1119 | } |
---|
[438] | 1120 | } |
---|
[446] | 1121 | |
---|
| 1122 | numstatements[1] += miss[activeMission].services[k].num_conds + 1; |
---|
| 1123 | k += miss[activeMission].services[k].num_conds; |
---|
| 1124 | } else if(miss[activeMission].services[k].name.compare("dowhile") == 0) { |
---|
| 1125 | numstatements[0] = 0; |
---|
| 1126 | while(true) { |
---|
| 1127 | int32_t j; |
---|
| 1128 | for(j = k + 1; j <= k + miss[activeMission].services[k].num_conds; j++) { |
---|
| 1129 | TransactData(j); |
---|
[438] | 1130 | } |
---|
[446] | 1131 | |
---|
[438] | 1132 | data.clear(); |
---|
| 1133 | input.clear(); |
---|
| 1134 | check.clear(); |
---|
[446] | 1135 | int32_t t; |
---|
| 1136 | for(t = 0; t < 10; t++) { |
---|
| 1137 | if(!miss[activeMission].services[k].output[t].empty()) { |
---|
| 1138 | input = miss[activeMission].services[j - 1].output[t]; |
---|
| 1139 | _data_DB->command="SELECT "; |
---|
| 1140 | _data_DB->command.append(_data_DB->tablename); |
---|
| 1141 | _data_DB->command.append(".* from "); |
---|
| 1142 | _data_DB->command.append(_data_DB->tablename); |
---|
| 1143 | _data_DB->command.append(" where Tag=='"); |
---|
| 1144 | _data_DB->command.append(input); |
---|
| 1145 | _data_DB->command.append("';"); |
---|
| 1146 | |
---|
| 1147 | sqlite3_stmt *pStatement; |
---|
| 1148 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); |
---|
| 1149 | if(rc == SQLITE_OK) { |
---|
| 1150 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 1151 | data = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 1152 | else { |
---|
| 1153 | WARNING("8 data_DB:: Data not yet in DB.\n"); |
---|
| 1154 | rc = 31337; |
---|
| 1155 | } |
---|
| 1156 | } else { |
---|
| 1157 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
| 1158 | rc, _data_DB->command.c_str()); |
---|
| 1159 | } |
---|
| 1160 | |
---|
[438] | 1161 | sqlite3_finalize(pStatement); |
---|
[446] | 1162 | int32_t pos = data.find_last_of("@", data.length() - 2); |
---|
| 1163 | token = data.substr(pos + 1); |
---|
| 1164 | token.erase(token.length() - 1); |
---|
| 1165 | break; |
---|
| 1166 | } |
---|
| 1167 | } |
---|
| 1168 | |
---|
| 1169 | if(miss[activeMission].services[k].output[t].find(token) == string::npos) { |
---|
[438] | 1170 | break; |
---|
| 1171 | } |
---|
| 1172 | } |
---|
[446] | 1173 | |
---|
| 1174 | k += miss[activeMission].services[k].num_conds; |
---|
| 1175 | } else{ |
---|
| 1176 | numstatements[1] = 0; |
---|
| 1177 | TransactData(k); |
---|
[438] | 1178 | } |
---|
| 1179 | } |
---|
[445] | 1180 | } |
---|
[446] | 1181 | |
---|
| 1182 | numstatements[0] += miss[activeMission].services[i].num_conds + 1; |
---|
| 1183 | i += miss[activeMission].services[i].num_conds; |
---|
| 1184 | } else if(miss[activeMission].services[i].name.compare("dowhile") == 0) { |
---|
| 1185 | numstatements[0] = 0; |
---|
| 1186 | while(true) { |
---|
| 1187 | uint32_t k; |
---|
| 1188 | for(k = i + 1; k <= i + miss[activeMission].services[i].num_conds; k++){ |
---|
| 1189 | TransactData(k); |
---|
[438] | 1190 | } |
---|
[446] | 1191 | |
---|
[445] | 1192 | data.clear(); |
---|
| 1193 | input.clear(); |
---|
| 1194 | check.clear(); |
---|
[446] | 1195 | int32_t t; |
---|
[445] | 1196 | for(t = 0; t < 10; t++){ |
---|
[446] | 1197 | if(!miss[activeMission].services[i].output[t].empty()) { |
---|
| 1198 | input = miss[activeMission].services[k - 1].output[t]; |
---|
| 1199 | _data_DB->command="SELECT "; |
---|
| 1200 | _data_DB->command.append(_data_DB->tablename); |
---|
| 1201 | _data_DB->command.append(".* from "); |
---|
| 1202 | _data_DB->command.append(_data_DB->tablename); |
---|
| 1203 | _data_DB->command.append(" where Tag=='"); |
---|
| 1204 | _data_DB->command.append(input); |
---|
| 1205 | _data_DB->command.append("';"); |
---|
| 1206 | |
---|
| 1207 | sqlite3_stmt *pStatement; |
---|
| 1208 | rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); |
---|
| 1209 | if(rc == SQLITE_OK) { |
---|
| 1210 | if(sqlite3_step(pStatement) == SQLITE_ROW) |
---|
| 1211 | data = (const char *) sqlite3_column_text(pStatement, 1); |
---|
| 1212 | else { |
---|
| 1213 | WARNING("10data_DB:: Data not yet in DB.\n"); |
---|
| 1214 | rc = 31337; |
---|
| 1215 | } |
---|
| 1216 | } else { |
---|
| 1217 | WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ |
---|
| 1218 | rc, _data_DB->command.c_str()); |
---|
| 1219 | } |
---|
| 1220 | |
---|
[445] | 1221 | sqlite3_finalize(pStatement); |
---|
[446] | 1222 | int32_t pos = data.find_last_of("@", data.length()-2); |
---|
| 1223 | token = data.substr(pos + 1); |
---|
| 1224 | token.erase(token.length() - 1); |
---|
| 1225 | break; |
---|
| 1226 | } |
---|
| 1227 | } |
---|
| 1228 | |
---|
| 1229 | if(miss[activeMission].services[i].output[t].find(token) == string::npos) { |
---|
[445] | 1230 | break; |
---|
[438] | 1231 | } |
---|
| 1232 | } |
---|
[446] | 1233 | |
---|
| 1234 | i += miss[activeMission].services[i].num_conds; |
---|
| 1235 | } else{ |
---|
| 1236 | numstatements[0] = 0; |
---|
[445] | 1237 | TransactData(i); |
---|
| 1238 | } |
---|
[438] | 1239 | } |
---|
[445] | 1240 | |
---|
| 1241 | int32_t i = 0; |
---|
[278] | 1242 | data.clear(); |
---|
[316] | 1243 | |
---|
[446] | 1244 | if(!shellFound) { |
---|
| 1245 | int k = 0; |
---|
| 1246 | while(k < 10 && !miss[activeMission].input[k].empty()) { |
---|
| 1247 | k++; |
---|
| 1248 | } |
---|
[308] | 1249 | |
---|
[446] | 1250 | sprintf(buffer, "%d", k); |
---|
| 1251 | SendMessage(shellSocketFD, buffer); |
---|
[308] | 1252 | |
---|
[446] | 1253 | for(size_t t = 0; t < k; t++) { |
---|
| 1254 | SendMessage(shellSocketFD, miss[activeMission].input[t].c_str()); |
---|
| 1255 | SendMessage(shellSocketFD, "0"); |
---|
| 1256 | } |
---|
| 1257 | } |
---|
[292] | 1258 | |
---|
[446] | 1259 | LOG("ServiceManagementLayer:: Done performing active mission.\n"); |
---|
[278] | 1260 | } |
---|
| 1261 | |
---|
| 1262 | |
---|
| 1263 | /* CALLED BY: MessageHandler |
---|
| 1264 | * INPUTS: <none> |
---|
| 1265 | * OUTPUTS: <none> |
---|
| 1266 | * |
---|
| 1267 | * DESCRIPTION: Print a list of the services currently registered and the ID's of the components that registered them |
---|
| 1268 | */ |
---|
[163] | 1269 | void |
---|
| 1270 | ServiceManagementLayer::ListServices() |
---|
| 1271 | { |
---|
[419] | 1272 | _services_DB->command="select "; |
---|
| 1273 | _services_DB->command.append(_services_DB->tablename); |
---|
| 1274 | _services_DB->command.append(".* from "); |
---|
| 1275 | _services_DB->command.append(_services_DB->tablename); |
---|
| 1276 | _services_DB->command.append(";"); |
---|
[278] | 1277 | |
---|
[446] | 1278 | // Execute print (select all) command |
---|
[278] | 1279 | char *errorMsg; |
---|
[446] | 1280 | int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); |
---|
| 1281 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 1282 | WARNING("SQL error: %s\n", errorMsg); |
---|
| 1283 | |
---|
| 1284 | LOG("database %s, table %s:\n", _services_DB->filename.c_str(), _services_DB->tablename.c_str()); |
---|
[163] | 1285 | } |
---|
| 1286 | |
---|
[278] | 1287 | /* CALLED BY: Reset |
---|
| 1288 | * INPUTS: <none> |
---|
| 1289 | * OUTPUTS: <none> |
---|
| 1290 | * |
---|
| 1291 | * DESCRIPTION: Clear and reinitialize the mission array, then reload the configuration file |
---|
| 1292 | */ |
---|
[163] | 1293 | void |
---|
| 1294 | ServiceManagementLayer::ReloadConfiguration() |
---|
| 1295 | { |
---|
[204] | 1296 | LOG("ServiceManagementLayer:: Reloading Configuration.\n"); |
---|
[446] | 1297 | |
---|
[278] | 1298 | free(miss); |
---|
[446] | 1299 | |
---|
[278] | 1300 | miss = new Mission[10]; |
---|
[446] | 1301 | for(size_t i = 0; i < 10; i++) |
---|
[438] | 1302 | miss[i].services = new Service[30]; |
---|
[446] | 1303 | |
---|
[442] | 1304 | LoadConfiguration(_SML_Config.c_str(), miss); |
---|
[163] | 1305 | } |
---|
| 1306 | |
---|
[278] | 1307 | /* CALLED BY: constructor |
---|
| 1308 | * INPUTS: |SML_Config| Address (either relitive or full) of the XML file containing mission data |
---|
[438] | 1309 | * |mList| Mission array to be modified |
---|
[278] | 1310 | * OUTPUTS: <none> |
---|
| 1311 | * |
---|
| 1312 | * DESCRIPTION: IMPORTANT - See formatting instructions for correct parsing of data |
---|
[295] | 1313 | * Can currently handle 10 inputs and 10 outputs per service, but easily expandable |
---|
[291] | 1314 | * Also, can handle two layer of nested conditional statements, but could |
---|
| 1315 | * be expanded to meet additional needs. |
---|
[278] | 1316 | * |
---|
| 1317 | * Components assigned to mission during "set active mission" stage so that |
---|
| 1318 | * components can still continue to register after the configuration is loaded |
---|
| 1319 | */ |
---|
| 1320 | void |
---|
| 1321 | ServiceManagementLayer::LoadConfiguration(const char *SML_Config, Mission* &mList) |
---|
| 1322 | { |
---|
| 1323 | TiXmlElement *pMission; |
---|
| 1324 | TiXmlElement *pService; |
---|
[287] | 1325 | TiXmlElement *pChild0, *pChild1, *pChild2, *pChild3, *pChild4; |
---|
[278] | 1326 | TiXmlHandle hRoot(0); |
---|
[446] | 1327 | |
---|
| 1328 | LOG("ServiceManagementLayer:: Loading Configuration.\n"); |
---|
| 1329 | |
---|
[278] | 1330 | TiXmlDocument doc("."); |
---|
| 1331 | doc.LoadFile(SML_Config); |
---|
| 1332 | bool loadOkay = doc.LoadFile(); |
---|
| 1333 | if(!loadOkay) |
---|
[446] | 1334 | WARNING("Loading SML configuration failed: %s\n", SML_Config); |
---|
[163] | 1335 | |
---|
[278] | 1336 | TiXmlHandle hDoc(&doc); |
---|
| 1337 | |
---|
| 1338 | pMission = hDoc.FirstChildElement().Element(); |
---|
| 1339 | |
---|
| 1340 | if(!pMission) |
---|
[446] | 1341 | WARNING("No valid root!"); |
---|
[278] | 1342 | |
---|
| 1343 | hRoot = TiXmlHandle(pMission); |
---|
| 1344 | pService = pMission->FirstChildElement(); |
---|
[446] | 1345 | |
---|
[278] | 1346 | int32_t mission_num = 0; |
---|
[446] | 1347 | |
---|
| 1348 | /* Iterate through the missions */ |
---|
| 1349 | for(pChild0 = pMission->FirstChildElement(); pChild0 ; pChild0 = pChild0->NextSiblingElement()) { |
---|
| 1350 | int32_t service_num = 0; |
---|
| 1351 | uint16_t cond_array[] = {0, 0, 0}; |
---|
[438] | 1352 | |
---|
| 1353 | for(pChild1 = (pChild0->FirstChildElement())->FirstChildElement(); pChild1; \ |
---|
[446] | 1354 | pChild1 = pChild1->NextSiblingElement()) { |
---|
| 1355 | |
---|
| 1356 | int32_t conditional_0 = service_num; |
---|
| 1357 | for(pChild2 = pChild1->FirstChildElement(); pChild2; pChild2 = pChild2->NextSiblingElement()) { |
---|
| 1358 | service_num++; |
---|
| 1359 | |
---|
| 1360 | int32_t conditional_1 = service_num; |
---|
| 1361 | for(pChild3 = pChild2->FirstChildElement(); pChild3; pChild3 = pChild3->NextSiblingElement()) { |
---|
| 1362 | service_num++; |
---|
| 1363 | int32_t conditional_2 = service_num; |
---|
| 1364 | for(pChild4 = pChild3->FirstChildElement(); pChild4; pChild4 = pChild4->NextSiblingElement()) { |
---|
| 1365 | service_num++; |
---|
| 1366 | if(pChild4->Attribute("name")) |
---|
| 1367 | mList[mission_num].services[service_num].name = pChild4->Attribute("name"); |
---|
| 1368 | else |
---|
| 1369 | mList[mission_num].services[service_num].name = pChild4->Value(); |
---|
| 1370 | |
---|
| 1371 | for(size_t i = 1; i <= 10; i++) { |
---|
| 1372 | char buffer[9]="input"; |
---|
| 1373 | sprintf(buffer, "%s%d", buffer, i); |
---|
| 1374 | if(pChild4->Attribute(buffer)) |
---|
| 1375 | mList[mission_num].services[service_num].input[i - 1] = pChild4->Attribute(buffer); |
---|
| 1376 | |
---|
| 1377 | char buffer2[9]="output"; |
---|
| 1378 | sprintf(buffer2, "%s%d", buffer2, i); |
---|
| 1379 | if(pChild4->Attribute(buffer2)) |
---|
| 1380 | mList[mission_num].services[service_num].output[i - 1] = pChild4->Attribute(buffer2); |
---|
| 1381 | } |
---|
| 1382 | |
---|
| 1383 | if(pChild4->Attribute("parameter")) |
---|
| 1384 | mList[mission_num].services[service_num].parameter = pChild4->Attribute("parameter"); |
---|
| 1385 | |
---|
| 1386 | cond_array[2]++; |
---|
| 1387 | } |
---|
| 1388 | |
---|
| 1389 | if(!strcmp(pChild3->Value(), "shell") || conditional_2 != service_num) { |
---|
| 1390 | mList[mission_num].services[conditional_2].name = pChild3->Value(); |
---|
| 1391 | } else { |
---|
| 1392 | mList[mission_num].services[service_num].name = pChild3->Attribute("name"); |
---|
| 1393 | } |
---|
| 1394 | |
---|
| 1395 | for(size_t i = 1; i <= 10; i++) { |
---|
| 1396 | char buffer[9]="input"; |
---|
| 1397 | sprintf(buffer, "%s%d", buffer, i); |
---|
| 1398 | if(pChild3->Attribute(buffer)) |
---|
| 1399 | mList[mission_num].services[conditional_2].input[i - 1] = pChild3->Attribute(buffer); |
---|
| 1400 | |
---|
| 1401 | char buffer2[9]="output"; |
---|
| 1402 | sprintf(buffer2, "%s%d", buffer2, i); |
---|
| 1403 | if(pChild3->Attribute(buffer2)) |
---|
| 1404 | mList[mission_num].services[conditional_2].output[i - 1] = pChild3->Attribute(buffer2); |
---|
| 1405 | } |
---|
| 1406 | |
---|
| 1407 | if(pChild3->Attribute("parameter")) |
---|
| 1408 | mList[mission_num].services[conditional_2].parameter = pChild3->Attribute("parameter"); |
---|
| 1409 | |
---|
| 1410 | mList[mission_num].services[conditional_2].num_conds = cond_array[2]; |
---|
| 1411 | cond_array[1] += cond_array[2] + 1; |
---|
| 1412 | cond_array[2] = 0; |
---|
| 1413 | } |
---|
| 1414 | |
---|
| 1415 | if(!strcmp(pChild2->Value(), "shell") || (conditional_1 != service_num)) { |
---|
| 1416 | mList[mission_num].services[conditional_1].name = pChild2->Value(); |
---|
| 1417 | } else{ |
---|
| 1418 | mList[mission_num].services[service_num].name = pChild2->Attribute("name"); |
---|
| 1419 | } |
---|
| 1420 | |
---|
[438] | 1421 | for(int i = 1; i <= 10; i++) { |
---|
| 1422 | char buffer[9]="input"; |
---|
| 1423 | sprintf(buffer, "%s%d", buffer, i); |
---|
[446] | 1424 | if(pChild2->Attribute(buffer)) |
---|
| 1425 | mList[mission_num].services[conditional_1].input[i - 1] = pChild2->Attribute(buffer); |
---|
| 1426 | |
---|
[438] | 1427 | char buffer2[9]="output"; |
---|
| 1428 | sprintf(buffer2, "%s%d", buffer2, i); |
---|
[446] | 1429 | if(pChild2->Attribute(buffer2)) |
---|
| 1430 | mList[mission_num].services[conditional_1].output[i - 1] = pChild2->Attribute(buffer2); |
---|
[438] | 1431 | } |
---|
[446] | 1432 | |
---|
| 1433 | if(pChild2->Attribute("parameter")) |
---|
| 1434 | mList[mission_num].services[conditional_1].parameter = pChild2->Attribute("parameter"); |
---|
| 1435 | |
---|
| 1436 | mList[mission_num].services[conditional_1].num_conds = cond_array[1]; |
---|
| 1437 | cond_array[0] += cond_array[1] + 1; |
---|
| 1438 | cond_array[1] = 0; |
---|
[438] | 1439 | } |
---|
[446] | 1440 | |
---|
| 1441 | if(!strcmp(pChild1->Value(), "shell") || conditional_0 != service_num) { |
---|
| 1442 | mList[mission_num].services[conditional_0].name = pChild1->Value(); |
---|
| 1443 | } else{ |
---|
| 1444 | mList[mission_num].services[conditional_0].name = pChild1->Attribute("name"); |
---|
[438] | 1445 | } |
---|
[446] | 1446 | |
---|
| 1447 | for(size_t i = 1; i <= 10; i++) { |
---|
[438] | 1448 | char buffer[9]="input"; |
---|
| 1449 | sprintf(buffer, "%s%d", buffer, i); |
---|
[446] | 1450 | if(pChild1->Attribute(buffer)) |
---|
| 1451 | mList[mission_num].services[conditional_0].input[i-1] = pChild1->Attribute(buffer); |
---|
| 1452 | |
---|
[438] | 1453 | char buffer2[9]="output"; |
---|
| 1454 | sprintf(buffer2, "%s%d", buffer2, i); |
---|
[446] | 1455 | if(pChild1->Attribute(buffer2)) |
---|
| 1456 | mList[mission_num].services[conditional_0].output[i-1] = pChild1->Attribute(buffer2); |
---|
[438] | 1457 | } |
---|
[287] | 1458 | |
---|
[446] | 1459 | if(pChild1->Attribute("parameter")) |
---|
| 1460 | mList[mission_num].services[conditional_0].parameter = pChild1->Attribute("parameter"); |
---|
| 1461 | mList[mission_num].services[conditional_0].num_conds = cond_array[0]; |
---|
| 1462 | cond_array[0] = 0; |
---|
[287] | 1463 | |
---|
[446] | 1464 | service_num++; |
---|
[438] | 1465 | } |
---|
[446] | 1466 | |
---|
| 1467 | mList[mission_num].numServices = service_num; |
---|
| 1468 | mList[mission_num].name = pChild0->Attribute("name"); |
---|
| 1469 | mList[mission_num].missionID = atoi(pChild0->Attribute("id")); |
---|
[278] | 1470 | |
---|
[446] | 1471 | for(size_t i = 1; i <= 10; i++) { |
---|
| 1472 | char buffer[9]="param"; |
---|
[438] | 1473 | sprintf(buffer, "%s%d", buffer, i); |
---|
[446] | 1474 | if(pChild0->Attribute(buffer)){ |
---|
| 1475 | mList[mission_num].input[i-1] = pChild0->Attribute(buffer); |
---|
| 1476 | } |
---|
[438] | 1477 | } |
---|
[446] | 1478 | |
---|
| 1479 | mission_num++; |
---|
[438] | 1480 | } |
---|
[446] | 1481 | |
---|
[316] | 1482 | LOG("ServiceManagementLayer:: Done Loading Configuration\n"); |
---|
[278] | 1483 | } |
---|
| 1484 | |
---|
| 1485 | /* CALLED BY: MessageHandler |
---|
| 1486 | * INPUTS: |ID| The ID number of the engine to be registered |
---|
| 1487 | * OUTPUTS: <none> |
---|
| 1488 | * |
---|
| 1489 | * DESCRIPTION: Sends a registration message onto the shell and sends the ACK back to the component |
---|
| 1490 | */ |
---|
| 1491 | void |
---|
| 1492 | ServiceManagementLayer::RegisterCognitiveEngine(int32_t ID) |
---|
| 1493 | { |
---|
| 1494 | SendMessage(shellSocketFD, "register_engine_cognitive"); |
---|
[282] | 1495 | |
---|
[278] | 1496 | LOG("ServiceManagementLayer:: CE registration message forwarded to shell.\n"); |
---|
| 1497 | char buffer[256]; |
---|
| 1498 | memset(buffer, 0, 256); |
---|
| 1499 | ReadMessage(shellSocketFD, buffer); |
---|
| 1500 | SendMessage(CE_List[ID].FD, buffer); |
---|
| 1501 | |
---|
[279] | 1502 | TransferRadioConfiguration(ID); |
---|
[278] | 1503 | memset(buffer, 0, 256); |
---|
| 1504 | TransferExperience(ID); |
---|
[279] | 1505 | memset(buffer, 0, 256); |
---|
[278] | 1506 | numberOfCognitiveEngines++; |
---|
| 1507 | CE_Present = true; |
---|
| 1508 | } |
---|
| 1509 | |
---|
| 1510 | /* CALLED BY: MessageHandler |
---|
| 1511 | * INPUTS: |ID| The ID number of the engine to have it's services deregistered |
---|
| 1512 | * OUTPUTS: <none> |
---|
| 1513 | * |
---|
| 1514 | * DESCRIPTION: Deletes individual services from the DB |
---|
[446] | 1515 | * NOTE THAT this function only needs to be called ifservice deregistration is going |
---|
[278] | 1516 | * to be done at a different time than component deregistration; it is handled |
---|
| 1517 | * more efficiently and directly during that deregistration process. |
---|
| 1518 | */ |
---|
[163] | 1519 | void |
---|
[278] | 1520 | ServiceManagementLayer::DeregisterServices(int32_t ID) |
---|
[163] | 1521 | { |
---|
[278] | 1522 | char buffer[256]; |
---|
| 1523 | memset(buffer, 0, 256); |
---|
| 1524 | ReadMessage(CE_List[ID].FD, buffer); |
---|
[419] | 1525 | _services_DB->command="DELETE FROM "; |
---|
| 1526 | _services_DB->command.append(_services_DB->tablename); |
---|
| 1527 | _services_DB->command.append(" WHERE ID_Num IN (SELECT "); |
---|
[446] | 1528 | |
---|
[419] | 1529 | char tmp[3]; |
---|
| 1530 | memset(tmp,0,3); |
---|
| 1531 | sprintf(tmp, "%d", ID); |
---|
| 1532 | _services_DB->command.append(tmp); |
---|
| 1533 | _services_DB->command.append(" FROM "); |
---|
| 1534 | _services_DB->command.append(_services_DB->tablename); |
---|
| 1535 | _services_DB->command.append(" WHERE Service_Name"); |
---|
| 1536 | _services_DB->command.append("=='"); |
---|
| 1537 | _services_DB->command.append(buffer); |
---|
| 1538 | _services_DB->command.append("');"); |
---|
[446] | 1539 | |
---|
[278] | 1540 | char *errorMsg; |
---|
[446] | 1541 | int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); |
---|
| 1542 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 1543 | WARNING("SQL error: %s\n", errorMsg); |
---|
[163] | 1544 | } |
---|
| 1545 | |
---|
[278] | 1546 | /* CALLED BY: MessageHandler |
---|
| 1547 | * INPUTS: |ID| The ID number of the engine to have it's services deregistered |
---|
| 1548 | * OUTPUTS: <none> |
---|
| 1549 | * |
---|
| 1550 | * DESCRIPTION: Deletes the contact info for the cognitive engine, forwards a deregistration message to the shell |
---|
| 1551 | * Also, deletes the services from the DB |
---|
| 1552 | */ |
---|
| 1553 | void |
---|
| 1554 | ServiceManagementLayer::DeregisterCognitiveEngine(int32_t ID) |
---|
| 1555 | { |
---|
| 1556 | LOG("ServiceManagementLayer:: CE deregistration message forwarded to shell.\n"); |
---|
| 1557 | |
---|
| 1558 | numberOfCognitiveEngines--; |
---|
| 1559 | if(numberOfCognitiveEngines == 0) |
---|
| 1560 | CE_Present = false; |
---|
| 1561 | |
---|
| 1562 | SendMessage(shellSocketFD, "deregister_engine_cognitive"); |
---|
| 1563 | char buffer[256]; |
---|
| 1564 | memset(buffer, 0, 256); |
---|
| 1565 | ReadMessage(shellSocketFD, buffer); |
---|
| 1566 | SendMessage(CE_List[ID].FD, buffer); |
---|
| 1567 | if(strcmp("deregister_ack", buffer) != 0) { |
---|
[446] | 1568 | ERROR(1, "SML:: Failed to close CE socket\n"); |
---|
[278] | 1569 | } |
---|
| 1570 | |
---|
| 1571 | //Deregister the services |
---|
[419] | 1572 | _services_DB->command="DELETE FROM "; |
---|
| 1573 | _services_DB->command.append(_services_DB->tablename); |
---|
| 1574 | _services_DB->command.append(" WHERE "); |
---|
| 1575 | _services_DB->command.append("ID_Num"); |
---|
| 1576 | _services_DB->command.append("=="); |
---|
[446] | 1577 | |
---|
[419] | 1578 | char tmp[3]; |
---|
| 1579 | memset(tmp,0,3); |
---|
| 1580 | sprintf(tmp, "%d", ID); |
---|
| 1581 | _services_DB->command.append(tmp); |
---|
| 1582 | _services_DB->command.append(";"); |
---|
[446] | 1583 | |
---|
[278] | 1584 | char *errorMsg; |
---|
[446] | 1585 | int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); |
---|
| 1586 | if((rc != SQLITE_OK) && (rc != 101)) |
---|
| 1587 | WARNING("SQL error: %s\n", errorMsg); |
---|
[278] | 1588 | |
---|
| 1589 | CE_List[ID].FD = -1; |
---|
| 1590 | CE_List[ID].ID_num = -1; |
---|
| 1591 | |
---|
| 1592 | LOG("Cognitive Radio Shell:: CE Socket closed for engine #%d.\n", ID); |
---|
| 1593 | } |
---|
| 1594 | |
---|
| 1595 | |
---|
| 1596 | /* CALLED BY: test class |
---|
| 1597 | * INPUTS: <none> |
---|
| 1598 | * OUTPUTS: <none> |
---|
| 1599 | * |
---|
| 1600 | * DESCRIPTION: Sets up a server socket and listens for communication on either that or the shell socket |
---|
| 1601 | */ |
---|
| 1602 | void |
---|
| 1603 | ServiceManagementLayer::StartSMLServer() |
---|
| 1604 | { |
---|
| 1605 | struct timeval selTimeout; |
---|
| 1606 | int32_t running = 1; |
---|
| 1607 | int32_t port, rc, new_sd = 1; |
---|
| 1608 | int32_t desc_ready = 1; |
---|
| 1609 | fd_set sockSet, shellSet; |
---|
| 1610 | |
---|
[285] | 1611 | cogEngSrv = CreateTCPServerSocket(SMLport); |
---|
[278] | 1612 | int32_t maxDescriptor = cogEngSrv; |
---|
| 1613 | |
---|
| 1614 | if(InitializeTCPServerPort(cogEngSrv) == -1) |
---|
| 1615 | ERROR(1,"Error initializing primary port\n"); |
---|
| 1616 | |
---|
[282] | 1617 | while (running) { |
---|
[278] | 1618 | /* Zero socket descriptor vector and set for server sockets */ |
---|
| 1619 | /* This must be reset every time select() is called */ |
---|
| 1620 | FD_ZERO(&sockSet); |
---|
| 1621 | FD_SET(cogEngSrv, &sockSet); |
---|
[421] | 1622 | |
---|
[287] | 1623 | for(uint16_t k = 0; k < Current_ID; k++){ |
---|
[446] | 1624 | if(CE_List[k].ID_num != -1) |
---|
| 1625 | FD_SET(CE_List[k].FD, &sockSet); |
---|
| 1626 | } |
---|
[278] | 1627 | |
---|
| 1628 | /* Timeout specification */ |
---|
| 1629 | /* This must be reset every time select() is called */ |
---|
[446] | 1630 | selTimeout.tv_sec = 0; /* timeout (secs.) */ |
---|
| 1631 | selTimeout.tv_usec = 0; /* 0 microseconds */ |
---|
[278] | 1632 | |
---|
[446] | 1633 | /* Changed both to zero so that select will check messages from the shell |
---|
| 1634 | * instead of blocking when there is no command from the CE's to be processed */ |
---|
| 1635 | |
---|
| 1636 | /* Check ifthere is a message on the socket waiting to be read */ |
---|
| 1637 | rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout); |
---|
| 1638 | if(rc == 0) { |
---|
[278] | 1639 | FD_ZERO(&shellSet); |
---|
| 1640 | FD_SET(shellSocketFD, &shellSet); |
---|
| 1641 | selTimeout.tv_sec = 0; |
---|
| 1642 | selTimeout.tv_usec = 0; |
---|
[447] | 1643 | |
---|
| 1644 | /* Check if there is a message on the shell socket ready to be processed */ |
---|
[287] | 1645 | select(shellSocketFD + 1, &shellSet, NULL, NULL, &selTimeout); |
---|
[446] | 1646 | if(FD_ISSET(shellSocketFD, &shellSet)){ |
---|
| 1647 | MessageHandler(-1);} |
---|
| 1648 | } else { |
---|
[278] | 1649 | desc_ready = rc; |
---|
| 1650 | for(port = 0; port <= maxDescriptor && desc_ready > 0; port++) { |
---|
| 1651 | if(FD_ISSET(port, &sockSet)) { |
---|
| 1652 | desc_ready -= 1; |
---|
| 1653 | |
---|
[446] | 1654 | /* Check ifrequest is new or on an existing open descriptor */ |
---|
[278] | 1655 | if(port == cogEngSrv) { |
---|
[446] | 1656 | /* If new, assign it a descriptor and give it an ID */ |
---|
[278] | 1657 | new_sd = AcceptTCPConnection(port); |
---|
[438] | 1658 | |
---|
[278] | 1659 | if(new_sd < 0) |
---|
| 1660 | break; |
---|
| 1661 | |
---|
| 1662 | CE_List[Current_ID].FD = new_sd; |
---|
[446] | 1663 | CE_List[Current_ID].ID_num = Current_ID; |
---|
[278] | 1664 | MessageHandler(Current_ID); |
---|
[446] | 1665 | Current_ID++; |
---|
[438] | 1666 | |
---|
[446] | 1667 | FD_SET(new_sd,&sockSet); |
---|
[278] | 1668 | if(new_sd > maxDescriptor) |
---|
| 1669 | maxDescriptor = new_sd; |
---|
[446] | 1670 | } else { |
---|
| 1671 | /* If old, figure out which ID it coresponds to and handle it accordingly */ |
---|
| 1672 | for(size_t z = 0; z < Current_ID; z++) { |
---|
| 1673 | if(CE_List[z].FD == port) { |
---|
| 1674 | MessageHandler(z); |
---|
| 1675 | } |
---|
| 1676 | } |
---|
[278] | 1677 | } |
---|
| 1678 | } |
---|
| 1679 | } |
---|
[446] | 1680 | } |
---|
[278] | 1681 | } |
---|
| 1682 | |
---|
| 1683 | /* Close sockets */ |
---|
| 1684 | close(cogEngSrv); |
---|
| 1685 | |
---|
| 1686 | return; |
---|
| 1687 | } |
---|
[446] | 1688 | |
---|