Commit 997f99d7dbdaa8ca98922fa338dd0529c19955c2
1 parent
9f358883
Correct registration of applications connected to hub in a configuration file is ok
Showing
5 changed files
with
296 additions
and
81 deletions
include/GVOApp.hpp
| @@ -77,8 +77,8 @@ protected: | @@ -77,8 +77,8 @@ protected: | ||
| 77 | // Protected data area | 77 | // Protected data area |
| 78 | std::string m_name; //!< Client name | 78 | std::string m_name; //!< Client name |
| 79 | char m_id[32]; //!< Id assigned to client by the hub | 79 | char m_id[32]; //!< Id assigned to client by the hub |
| 80 | - std::list <std::string> registered_calls; //!< Calls for which is registered the application. | ||
| 81 | - std::list<std::string>::iterator iterator_calls; | 80 | + std::list <std::string> registeredMethods; //!< Calls for which is registered the application. |
| 81 | + //std::list<std::string>::iterator iterator_calls; | ||
| 82 | 82 | ||
| 83 | }; | 83 | }; |
| 84 | 84 |
include/GVOHub.hpp
| @@ -75,6 +75,8 @@ protected: | @@ -75,6 +75,8 @@ protected: | ||
| 75 | void unregister(const socklen_t& sock); | 75 | void unregister(const socklen_t& sock); |
| 76 | void handle_request(const socklen_t& sock); | 76 | void handle_request(const socklen_t& sock); |
| 77 | void register_metadata(const GXml& xml,const socklen_t& sock); | 77 | void register_metadata(const GXml& xml,const socklen_t& sock); |
| 78 | + void set_xml_rpc_callback(const GXml& xml,const socklen_t& sock); | ||
| 79 | + void get_registered_clients(const GXml& xml,const socklen_t& sock); | ||
| 78 | void declare_subscriptions(const GXml& xml,const socklen_t& sock); | 80 | void declare_subscriptions(const GXml& xml,const socklen_t& sock); |
| 79 | 81 | ||
| 80 | // Low-level methods | 82 | // Low-level methods |
| @@ -84,6 +86,8 @@ protected: | @@ -84,6 +86,8 @@ protected: | ||
| 84 | const std::string& name) const; | 86 | const std::string& name) const; |
| 85 | std::list<std::string> get_registrations(const GXml& xml, | 87 | std::list<std::string> get_registrations(const GXml& xml, |
| 86 | const std::string& name) const; | 88 | const std::string& name) const; |
| 89 | + std::string get_callback_port(const GXml& xml, | ||
| 90 | + const std::string& name) const; | ||
| 87 | void get_name_value_pair(const GXmlNode* node, | 91 | void get_name_value_pair(const GXmlNode* node, |
| 88 | std::string& name, | 92 | std::string& name, |
| 89 | std::string& value) const; | 93 | std::string& value) const; |
| @@ -99,13 +103,11 @@ protected: | @@ -99,13 +103,11 @@ protected: | ||
| 99 | std::string m_client_key; //!< Private client key | 103 | std::string m_client_key; //!< Private client key |
| 100 | std::string m_hub_id; //!< Hub identifier used by the hub when it sends message itself rather than forwarding from others | 104 | std::string m_hub_id; //!< Hub identifier used by the hub when it sends message itself rather than forwarding from others |
| 101 | int m_socket; //!< Hub socket | 105 | int m_socket; //!< Hub socket |
| 102 | -<<<<<<< HEAD | ||
| 103 | - int m_nb_clients; //!< Number of already registered clients | ||
| 104 | - static std::list<GVOApp*> m_connected_apps; //!< list of apps connected to the hub | ||
| 105 | -======= | ||
| 106 | int m_nb_clients; //!< Number of already registered clients | 106 | int m_nb_clients; //!< Number of already registered clients |
| 107 | - std::list<GVOApp> m_connected_apps; //!< list of apps connected to the hub | ||
| 108 | ->>>>>>> dab81eb3c037358cd6c4dc35ed8cc4e35a5646c0 | 107 | + static std::vector<GVOApp>& connected() { |
| 108 | + static std::vector<GVOApp> m_connected_apps; //!< list of apps connected to the hub | ||
| 109 | + return m_connected_apps; | ||
| 110 | + } | ||
| 109 | }; | 111 | }; |
| 110 | 112 | ||
| 111 | #endif /* GVOHUB_HPP */ | 113 | #endif /* GVOHUB_HPP */ |
registrations.txt
| @@ -541,4 +541,52 @@ GXmlElement::name | @@ -541,4 +541,52 @@ GXmlElement::name | ||
| 541 | GXmlText::samp.hub.event.unregisterGXmlElement::name | 541 | GXmlText::samp.hub.event.unregisterGXmlElement::name |
| 542 | ======= | 542 | ======= |
| 543 | >>>>>>> parent of a9b1ce3... Hub is functionning, pb with visibility of list of apps | 543 | >>>>>>> parent of a9b1ce3... Hub is functionning, pb with visibility of list of apps |
| 544 | + GXmlText::script.aladin.sendGXmlElement::name | ||
| 545 | + GXmlText::samp.hub.event.registerGXmlElement::name | ||
| 546 | + GXmlText::table.select.rowListGXmlElement::name | ||
| 547 | + GXmlText::table.highlight.rowGXmlElement::name | ||
| 548 | + GXmlText::table.load.fitsGXmlElement::name | ||
| 549 | + GXmlText::samp.app.pingGXmlElement::name | ||
| 550 | + GXmlText::coord.pointAt.skyGXmlElement::name | ||
| 551 | + GXmlText::samp.hub.event.shutdownGXmlElement::name | ||
| 552 | + GXmlText::image.load.fitsGXmlElement::name | ||
| 553 | + GXmlText::samp.hub.disconnectGXmlElement::name | ||
| 554 | + GXmlText::table.load.votableGXmlElement::name | ||
| 555 | + GXmlText::samp.hub.event.unregisterGXmlElement::name | ||
| 556 | + GXmlText::script.aladin.sendGXmlElement::name | ||
| 557 | + GXmlText::samp.hub.event.registerGXmlElement::name | ||
| 558 | + GXmlText::table.select.rowListGXmlElement::name | ||
| 559 | + GXmlText::table.highlight.rowGXmlElement::name | ||
| 560 | + GXmlText::table.load.fitsGXmlElement::name | ||
| 561 | + GXmlText::samp.app.pingGXmlElement::name | ||
| 562 | + GXmlText::coord.pointAt.skyGXmlElement::name | ||
| 563 | + GXmlText::samp.hub.event.shutdownGXmlElement::name | ||
| 564 | + GXmlText::image.load.fitsGXmlElement::name | ||
| 565 | + GXmlText::samp.hub.disconnectGXmlElement::name | ||
| 566 | + GXmlText::table.load.votableGXmlElement::name | ||
| 567 | + GXmlText::samp.hub.event.unregisterGXmlElement::name | ||
| 568 | + GXmlText::script.aladin.sendGXmlElement::name | ||
| 569 | + GXmlText::samp.hub.event.registerGXmlElement::name | ||
| 570 | + GXmlText::table.select.rowListGXmlElement::name | ||
| 571 | + GXmlText::table.highlight.rowGXmlElement::name | ||
| 572 | + GXmlText::table.load.fitsGXmlElement::name | ||
| 573 | + GXmlText::samp.app.pingGXmlElement::name | ||
| 574 | + GXmlText::coord.pointAt.skyGXmlElement::name | ||
| 575 | + GXmlText::samp.hub.event.shutdownGXmlElement::name | ||
| 576 | + GXmlText::image.load.fitsGXmlElement::name | ||
| 577 | + GXmlText::samp.hub.disconnectGXmlElement::name | ||
| 578 | + GXmlText::table.load.votableGXmlElement::name | ||
| 579 | + GXmlText::samp.hub.event.unregisterGXmlElement::name | ||
| 580 | + GXmlText::script.aladin.sendGXmlElement::name | ||
| 581 | + GXmlText::samp.hub.event.registerGXmlElement::name | ||
| 582 | + GXmlText::table.select.rowListGXmlElement::name | ||
| 583 | + GXmlText::table.highlight.rowGXmlElement::name | ||
| 584 | + GXmlText::table.load.fitsGXmlElement::name | ||
| 585 | + GXmlText::samp.app.pingGXmlElement::name | ||
| 586 | + GXmlText::coord.pointAt.skyGXmlElement::name | ||
| 587 | + GXmlText::samp.hub.event.shutdownGXmlElement::name | ||
| 588 | + GXmlText::image.load.fitsGXmlElement::name | ||
| 589 | + GXmlText::samp.hub.disconnectGXmlElement::name | ||
| 590 | + GXmlText::table.load.votableGXmlElement::name | ||
| 591 | + GXmlText::samp.hub.event.unregisterGXmlElement::name | ||
| 544 | GXmlText::script.aladin.send | 592 | GXmlText::script.aladin.send |
| 545 | \ No newline at end of file | 593 | \ No newline at end of file |
src/vo/GVOApp.cpp
| @@ -183,7 +183,7 @@ std::string GVOApp::print(const GChatter& chatter) const | @@ -183,7 +183,7 @@ std::string GVOApp::print(const GChatter& chatter) const | ||
| 183 | // Initialise result string | 183 | // Initialise result string |
| 184 | std::string result; | 184 | std::string result; |
| 185 | std::list<std::string> temp; | 185 | std::list<std::string> temp; |
| 186 | - temp = registered_calls; | 186 | + temp = registeredMethods; |
| 187 | 187 | ||
| 188 | // Continue only if chatter is not silent | 188 | // Continue only if chatter is not silent |
| 189 | if (chatter != SILENT) { | 189 | if (chatter != SILENT) { |
src/vo/GVOHub.cpp
| @@ -227,47 +227,24 @@ void GVOHub::register_service(const GXml& xml, const socklen_t& sock) | @@ -227,47 +227,24 @@ void GVOHub::register_service(const GXml& xml, const socklen_t& sock) | ||
| 227 | std::string msg = ""; | 227 | std::string msg = ""; |
| 228 | char buffer[124]; | 228 | char buffer[124]; |
| 229 | char privatekey[124]; | 229 | char privatekey[124]; |
| 230 | + char cl_id[256]; | ||
| 230 | int i; | 231 | int i; |
| 231 | - std::list<GVOApp>::iterator q; | ||
| 232 | std::string content; | 232 | std::string content; |
| 233 | std::string translator = "http://localhost:8001/"; | 233 | std::string translator = "http://localhost:8001/"; |
| 234 | printf("Message composition\n"); | 234 | printf("Message composition\n"); |
| 235 | + | ||
| 236 | + FILE* fptr = fopen("SAMP-registered.txt", "w"); | ||
| 237 | + if (fptr != NULL) { | ||
| 235 | 238 | ||
| 236 | - // Add application | ||
| 237 | - GVOApp new_app; | ||
| 238 | - sprintf(new_app.m_id,"client-key:%d", m_nb_clients); | ||
| 239 | -std::cout << "Nb. of current applications registered:" << std::endl; | ||
| 240 | -std::cout << m_connected_apps.size()<< std::endl; | ||
| 241 | - m_connected_apps.push_front(new_app); | ||
| 242 | -std::cout << "Nb. of current applications registered:" << std::endl; | ||
| 243 | -std::cout << m_connected_apps.size()<< std::endl; | ||
| 244 | - | ||
| 245 | - /* | ||
| 246 | - GVOApp* new_app = new GVOApp(); | ||
| 247 | - sprintf(new_app -> m_id,"client-key:%d",m_nb_clients); | ||
| 248 | - std::cout<< "Nb. of current applications registered:" << std::endl; | ||
| 249 | - std::cout<< m_connected_apps.size()<< std::endl; | ||
| 250 | - m_connected_apps.push_front(new_app); | ||
| 251 | - std::cout<< new_app->m_id << std::endl; | ||
| 252 | - std::cout<< "Nb. of current applications registered:" << std::endl; | ||
| 253 | - std::cout<< m_connected_apps.size()<< std::endl; | ||
| 254 | -<<<<<<< HEAD | ||
| 255 | - */ | ||
| 256 | - | ||
| 257 | - /* | ||
| 258 | - for (int i = 0; i < m_connected_apps.size(); ++i) { | ||
| 259 | - std::cout << "Displaying element of applications list:" << std::endl; | ||
| 260 | - std::cout << m_connected_apps[i].print() << std::endl; | ||
| 261 | - } | ||
| 262 | - */ | ||
| 263 | -======= | ||
| 264 | ->>>>>>> parent of a9b1ce3... Hub is functionning, pb with visibility of list of apps | ||
| 265 | - for( i=0,q=m_connected_apps.begin(); i<m_connected_apps.size(); i++,q++ ) { | ||
| 266 | - std::cout << "Displaying element of applications list:" << std::endl; | ||
| 267 | - content = (q)->print(); | ||
| 268 | - std::cout << content << std::endl; | 239 | + // If successfull writes application definition |
| 240 | + fputs ("# SAMP registered applications and Methods \n",fptr); | ||
| 241 | + sprintf(cl_id,"Registered client-key:%d\n", m_nb_clients); | ||
| 242 | + fputs (cl_id,fptr); | ||
| 269 | } | 243 | } |
| 270 | 244 | ||
| 245 | + // Closes file | ||
| 246 | + fclose(fptr); | ||
| 247 | + | ||
| 271 | printf("Message composition 2 \n"); | 248 | printf("Message composition 2 \n"); |
| 272 | sprintf(buffer,"<member><name>samp.self-id</name><value><string>client-id:%d</string></value></member>\n",m_nb_clients); | 249 | sprintf(buffer,"<member><name>samp.self-id</name><value><string>client-id:%d</string></value></member>\n",m_nb_clients); |
| 273 | sprintf(privatekey,"<member><name>samp.private-key</name><value><string>client-key:%d</string></value></member>\n",m_nb_clients); | 250 | sprintf(privatekey,"<member><name>samp.private-key</name><value><string>client-key:%d</string></value></member>\n",m_nb_clients); |
| @@ -311,7 +288,29 @@ std::cout << m_connected_apps.size()<< std::endl; | @@ -311,7 +288,29 @@ std::cout << m_connected_apps.size()<< std::endl; | ||
| 311 | ***************************************************************************/ | 288 | ***************************************************************************/ |
| 312 | void GVOHub::unregister(const socklen_t& sock) | 289 | void GVOHub::unregister(const socklen_t& sock) |
| 313 | { | 290 | { |
| 291 | + /* Code to create new file with replacement to erase registered app. File output should be renamed to the original file name | ||
| 292 | + string strReplace = "HELLO"; | ||
| 293 | + string strNew = "GOODBYE"; | ||
| 294 | + ifstream filein("filein.txt"); //File to read from | ||
| 295 | + ofstream fileout("fileout.txt"); //Temporary file | ||
| 296 | + if(!filein || !fileout) | ||
| 297 | + { | ||
| 298 | + cout << "Error opening files!" << endl; | ||
| 299 | + return 1; | ||
| 300 | + } | ||
| 314 | 301 | ||
| 302 | + string strTemp; | ||
| 303 | + //bool found = false; | ||
| 304 | + while(filein >> strTemp) | ||
| 305 | + { | ||
| 306 | + if(strTemp == strReplace){ | ||
| 307 | + strTemp = strNew; | ||
| 308 | + //found = true; | ||
| 309 | + } | ||
| 310 | + strTemp += "\n"; | ||
| 311 | + fileout << strTemp; | ||
| 312 | + //if(found) break; | ||
| 313 | + }*/ | ||
| 315 | close(sock); | 314 | close(sock); |
| 316 | return; | 315 | return; |
| 317 | } | 316 | } |
| @@ -326,11 +325,31 @@ void GVOHub::register_metadata(const GXml& xml,const socklen_t& sock) | @@ -326,11 +325,31 @@ void GVOHub::register_metadata(const GXml& xml,const socklen_t& sock) | ||
| 326 | char buffer[124]; | 325 | char buffer[124]; |
| 327 | printf("Client Metadata received\n"); | 326 | printf("Client Metadata received\n"); |
| 328 | // Search for metadata values to store | 327 | // Search for metadata values to store |
| 328 | + std::string client_calling = ""; | ||
| 329 | + // Search for value of methodName | ||
| 330 | + const GXmlNode* node = xml.element("methodCall", 0); | ||
| 331 | + node = node->element("params", 0); | ||
| 332 | + node = node->element("param", 0); | ||
| 333 | + node = node->element("value", 0); | ||
| 334 | + if (node != NULL) { | ||
| 335 | + const GXmlText* text = static_cast<const GXmlText*>((*node)[0]); | ||
| 336 | + if (text != NULL) { | ||
| 337 | + client_calling = text->text(); | ||
| 338 | + } | ||
| 339 | + } | ||
| 340 | + std::cout << client_calling << std::endl; | ||
| 329 | std::string client_name = get_response_value(xml, "samp.name"); | 341 | std::string client_name = get_response_value(xml, "samp.name"); |
| 330 | - printf("\nClient Metadata : Name %s\n", client_name.c_str()); | ||
| 331 | - sprintf(buffer,"Client number: %d\n",m_nb_clients); | 342 | + sprintf(buffer,"\n%s metadata : Name %s\n",client_calling.c_str(),client_name.c_str()); |
| 343 | + | ||
| 332 | printf(buffer); | 344 | printf(buffer); |
| 333 | fflush(stdout); | 345 | fflush(stdout); |
| 346 | + FILE* fptr = fopen("SAMP-registered.txt", "a"); | ||
| 347 | + if (fptr != NULL) { | ||
| 348 | + fputs (buffer,fptr); | ||
| 349 | + } | ||
| 350 | + | ||
| 351 | + // Closes file | ||
| 352 | + fclose(fptr); | ||
| 334 | // Declare message | 353 | // Declare message |
| 335 | std::string msg = ""; | 354 | std::string msg = ""; |
| 336 | 355 | ||
| @@ -353,6 +372,97 @@ void GVOHub::register_metadata(const GXml& xml,const socklen_t& sock) | @@ -353,6 +372,97 @@ void GVOHub::register_metadata(const GXml& xml,const socklen_t& sock) | ||
| 353 | //Return | 372 | //Return |
| 354 | return; | 373 | return; |
| 355 | } | 374 | } |
| 375 | + | ||
| 376 | +/***********************************************************************//** | ||
| 377 | + * @brief | ||
| 378 | + * | ||
| 379 | + * | ||
| 380 | + ***************************************************************************/ | ||
| 381 | +void GVOHub::set_xml_rpc_callback(const GXml& xml,const socklen_t& sock) | ||
| 382 | +{ | ||
| 383 | + char buffer[124]; | ||
| 384 | + printf("Client callback registration\n"); | ||
| 385 | + // Search for metadata values to store | ||
| 386 | + std::string client_subscriptions = get_callback_port(xml, "samp.hub.setXmlrpcCallback"); | ||
| 387 | + std::cout << client_subscriptions << std::endl; | ||
| 388 | + | ||
| 389 | + FILE* fptr = fopen("SAMP-registered.txt", "a"); | ||
| 390 | + if (fptr != NULL) { | ||
| 391 | + fputs (client_subscriptions.c_str(),fptr); | ||
| 392 | + } | ||
| 393 | + | ||
| 394 | + // Closes file | ||
| 395 | + fclose(fptr); | ||
| 396 | + // Declare message | ||
| 397 | + std::string msg = ""; | ||
| 398 | + | ||
| 399 | + //The hub response to rpc callback declaration has no usefull content and can be discarded by the client. | ||
| 400 | + // Set methodResponse elts | ||
| 401 | + msg.append("<?xml version=\"1.0\"?>\n"); | ||
| 402 | + msg.append("<methodResponse>\n"); | ||
| 403 | + msg.append("</methodResponse>\n"); | ||
| 404 | + | ||
| 405 | + int length = msg.length(); | ||
| 406 | + | ||
| 407 | + int n = write(sock,msg.c_str(),length); | ||
| 408 | + if (n < 0) { | ||
| 409 | + printf("Could not write socket buffer.\n"); | ||
| 410 | + std::string msg = "Could not write socket buffer."; | ||
| 411 | + throw GException::invalid_value(G_HANDLE_REQUEST, msg); | ||
| 412 | + } | ||
| 413 | + | ||
| 414 | + printf("Response message sent\n"); | ||
| 415 | + //Return | ||
| 416 | + return; | ||
| 417 | +} | ||
| 418 | +/***********************************************************************//** | ||
| 419 | + * @brief | ||
| 420 | + * | ||
| 421 | + * | ||
| 422 | + ***************************************************************************/ | ||
| 423 | +void GVOHub::get_registered_clients(const GXml& xml,const socklen_t& sock) | ||
| 424 | +{ | ||
| 425 | + std::string buffer; | ||
| 426 | + const int n = 1000; | ||
| 427 | + char line[n]; | ||
| 428 | + FILE* fptr = fopen("SAMP-registered.txt", "r"); | ||
| 429 | + if (fptr != NULL) { | ||
| 430 | + while (fgets(line, n, fptr) != NULL) { | ||
| 431 | + | ||
| 432 | + // Convert line to C++ string | ||
| 433 | + std::string cline = std::string(line); | ||
| 434 | + | ||
| 435 | + // Check for secret key | ||
| 436 | + if (cline.compare(0, 10, "Registered") == 0) { | ||
| 437 | + buffer = gammalib::strip_chars(cline.substr(10, std::string::npos), "\r\n"); | ||
| 438 | + } | ||
| 439 | + } | ||
| 440 | + | ||
| 441 | + // Closes file | ||
| 442 | + fclose(fptr); | ||
| 443 | + // Declare message | ||
| 444 | + std::string msg = ""; | ||
| 445 | + | ||
| 446 | + //The hub response to rpc callback declaration has no usefull content and can be discarded by the client. | ||
| 447 | + // Set methodResponse elts | ||
| 448 | + msg.append("<?xml version=\"1.0\"?>\n"); | ||
| 449 | + msg.append("<methodResponse>\n"); | ||
| 450 | + msg.append("</methodResponse>\n"); | ||
| 451 | + | ||
| 452 | + int length = msg.length(); | ||
| 453 | + | ||
| 454 | + int n = write(sock,msg.c_str(),length); | ||
| 455 | + if (n < 0) { | ||
| 456 | + printf("Could not write socket buffer.\n"); | ||
| 457 | + std::string msg = "Could not write socket buffer."; | ||
| 458 | + throw GException::invalid_value(G_HANDLE_REQUEST, msg); | ||
| 459 | + } | ||
| 460 | + | ||
| 461 | + printf("Response message sent\n"); | ||
| 462 | + //Return | ||
| 463 | + return; | ||
| 464 | + } | ||
| 465 | +} | ||
| 356 | /***********************************************************************//** | 466 | /***********************************************************************//** |
| 357 | * @brief | 467 | * @brief |
| 358 | * | 468 | * |
| @@ -361,43 +471,43 @@ void GVOHub::register_metadata(const GXml& xml,const socklen_t& sock) | @@ -361,43 +471,43 @@ void GVOHub::register_metadata(const GXml& xml,const socklen_t& sock) | ||
| 361 | void GVOHub::declare_subscriptions(const GXml& xml,const socklen_t& sock) | 471 | void GVOHub::declare_subscriptions(const GXml& xml,const socklen_t& sock) |
| 362 | { | 472 | { |
| 363 | std::list<std::string>::iterator p; | 473 | std::list<std::string>::iterator p; |
| 364 | - std::list<GVOApp>::iterator q; | ||
| 365 | int i; | 474 | int i; |
| 366 | std::ofstream myfile; | 475 | std::ofstream myfile; |
| 367 | std::string content; | 476 | std::string content; |
| 368 | printf("Declare Subscriptions\n"); | 477 | printf("Declare Subscriptions\n"); |
| 369 | - std::list<std::string> client_subscriptions = get_registrations(xml, "samp.hub.declareSubscriptions"); | ||
| 370 | 478 | ||
| 371 | - for( i=0,p=client_subscriptions.begin(); i<client_subscriptions.size()-1; i++,p++ ) { | ||
| 372 | - myfile.open ("registrations.txt", std::ios::out | std::ios::app); | ||
| 373 | - myfile << *p; | ||
| 374 | - myfile.close(); | ||
| 375 | - std::cout << "Client registered to following methods calls:" << std::endl; | ||
| 376 | - std::cout << *p << std::endl; | ||
| 377 | - | ||
| 378 | - } | ||
| 379 | - std::string method_called = ""; | ||
| 380 | - //const GXmlNode* node = xml.element("methodCall", 0); | ||
| 381 | - const GXmlNode* ptr = xml.element("methodCall", 0)->element("params", 0)->element("param", 0)->element("value", 0); | ||
| 382 | - if (ptr != NULL) { | ||
| 383 | - const GXmlText* text = static_cast<const GXmlText*>((*ptr)[0]); | 479 | + std::string client_calling = ""; |
| 480 | + // Search for value of methodName | ||
| 481 | + const GXmlNode* node = xml.element("methodCall", 0); | ||
| 482 | + node = node->element("params", 0); | ||
| 483 | + node = node->element("param", 0); | ||
| 484 | + node = node->element("value", 0); | ||
| 485 | + if (node != NULL) { | ||
| 486 | + const GXmlText* text = static_cast<const GXmlText*>((*node)[0]); | ||
| 384 | if (text != NULL) { | 487 | if (text != NULL) { |
| 385 | - method_called = text->text(); | ||
| 386 | - std::cout << "current app calling is:" << std::endl; | ||
| 387 | - std::cout << method_called << std::endl; | 488 | + client_calling = text->text(); |
| 388 | } | 489 | } |
| 389 | } | 490 | } |
| 491 | + std::cout << client_calling << std::endl; | ||
| 390 | 492 | ||
| 391 | - std::cout<< "Nb. of current applications registered:" << std::endl; | ||
| 392 | - std::cout<< m_connected_apps.size()<< std::endl; | ||
| 393 | - for( i=0,q=m_connected_apps.begin(); i<m_connected_apps.size(); i++,q++ ) { | ||
| 394 | - std::cout << "Displaying element of applications list:" << std::endl; | ||
| 395 | - content = (q)->print(); | ||
| 396 | - std::cout << content << std::endl; | 493 | + std::list<std::string> client_subscriptions = get_registrations(xml, "samp.hub.declareSubscriptions"); |
| 494 | + std::string temp; | ||
| 495 | + temp.append("\n"); | ||
| 496 | + FILE* fptr = fopen("SAMP-registered.txt", "a"); | ||
| 497 | + if (fptr != NULL) { | ||
| 498 | + for( i=0,p=client_subscriptions.begin(); i<client_subscriptions.size()-1; i++,p++ ) { | ||
| 499 | + std::cout << "Client registered to following methods calls:" << std::endl; | ||
| 500 | + std::cout << *p << std::endl; | ||
| 501 | + temp.append(*p); | ||
| 502 | + temp.append(" registered for "); | ||
| 503 | + temp.append(client_calling); | ||
| 504 | + temp.append("\n"); | ||
| 505 | + } | ||
| 506 | + fputs (temp.c_str(),fptr); | ||
| 397 | } | 507 | } |
| 398 | 508 | ||
| 509 | + // Declare message | ||
| 399 | std::string msg = ""; | 510 | std::string msg = ""; |
| 400 | - | ||
| 401 | // Set methodResponse elts | 511 | // Set methodResponse elts |
| 402 | msg.append("<?xml version=\"1.0\"?>\n"); | 512 | msg.append("<?xml version=\"1.0\"?>\n"); |
| 403 | msg.append("<methodResponse>\n"); | 513 | msg.append("<methodResponse>\n"); |
| @@ -491,7 +601,7 @@ void GVOHub::init_members(void) | @@ -491,7 +601,7 @@ void GVOHub::init_members(void) | ||
| 491 | //m_client_id.clear(); | 601 | //m_client_id.clear(); |
| 492 | m_socket = -1; // Signals no socket | 602 | m_socket = -1; // Signals no socket |
| 493 | m_nb_clients = 0; // No registered clients at initialization | 603 | m_nb_clients = 0; // No registered clients at initialization |
| 494 | - m_connected_apps.clear(); | 604 | + connected().clear(); |
| 495 | 605 | ||
| 496 | // Return | 606 | // Return |
| 497 | return; | 607 | return; |
| @@ -516,7 +626,7 @@ void GVOHub::copy_members(const GVOHub& hub) | @@ -516,7 +626,7 @@ void GVOHub::copy_members(const GVOHub& hub) | ||
| 516 | m_hub_id = hub.m_hub_id; | 626 | m_hub_id = hub.m_hub_id; |
| 517 | //m_client_id = hub.m_client_id; | 627 | //m_client_id = hub.m_client_id; |
| 518 | m_socket = hub.m_socket; | 628 | m_socket = hub.m_socket; |
| 519 | - m_connected_apps = hub.m_connected_apps; | 629 | + connected() = hub.connected(); |
| 520 | 630 | ||
| 521 | // Return | 631 | // Return |
| 522 | return; | 632 | return; |
| @@ -694,10 +804,10 @@ void GVOHub::handle_request(const socklen_t& sock) | @@ -694,10 +804,10 @@ void GVOHub::handle_request(const socklen_t& sock) | ||
| 694 | ping_service(sock); | 804 | ping_service(sock); |
| 695 | } | 805 | } |
| 696 | if (method_called.compare("samp.hub.setXmlrpcCallback") == 0) { | 806 | if (method_called.compare("samp.hub.setXmlrpcCallback") == 0) { |
| 697 | - ping_service(sock); | 807 | + set_xml_rpc_callback(xml,sock); |
| 698 | } | 808 | } |
| 699 | if (method_called.compare("samp.hub.getRegisteredClients") == 0) { | 809 | if (method_called.compare("samp.hub.getRegisteredClients") == 0) { |
| 700 | - ping_service(sock); | 810 | + get_registered_clients(xml, sock); |
| 701 | } | 811 | } |
| 702 | if (method_called.compare("samp.hub.getSubscribedClients") == 0) { | 812 | if (method_called.compare("samp.hub.getSubscribedClients") == 0) { |
| 703 | ping_service(sock); | 813 | ping_service(sock); |
| @@ -772,7 +882,7 @@ void GVOHub::start_hub(void) | @@ -772,7 +882,7 @@ void GVOHub::start_hub(void) | ||
| 772 | 882 | ||
| 773 | // Server socket is opened. Now, bind it to the port, with family etc. | 883 | // Server socket is opened. Now, bind it to the port, with family etc. |
| 774 | if (bind(hub_socket, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) { | 884 | if (bind(hub_socket, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) { |
| 775 | - std::string msg = "Hub hub socket could not bind to server socket."; | 885 | + std::string msg = "Hub socket could not bind to server socket."; |
| 776 | throw GException::invalid_value(G_START_HUB, msg); | 886 | throw GException::invalid_value(G_START_HUB, msg); |
| 777 | } | 887 | } |
| 778 | 888 | ||
| @@ -794,7 +904,8 @@ void GVOHub::start_hub(void) | @@ -794,7 +904,8 @@ void GVOHub::start_hub(void) | ||
| 794 | std::string msg = "Client connection to socket not accepted."; | 904 | std::string msg = "Client connection to socket not accepted."; |
| 795 | throw GException::invalid_value(G_START_HUB, msg); | 905 | throw GException::invalid_value(G_START_HUB, msg); |
| 796 | } | 906 | } |
| 797 | - | 907 | + //handle_request(newsocket); |
| 908 | + | ||
| 798 | // Create child process to handle the request | 909 | // Create child process to handle the request |
| 799 | pid = fork(); | 910 | pid = fork(); |
| 800 | if (pid < 0) { | 911 | if (pid < 0) { |
| @@ -810,6 +921,7 @@ void GVOHub::start_hub(void) | @@ -810,6 +921,7 @@ void GVOHub::start_hub(void) | ||
| 810 | close(newsocket); | 921 | close(newsocket); |
| 811 | 922 | ||
| 812 | } | 923 | } |
| 924 | + | ||
| 813 | 925 | ||
| 814 | } // endwhile | 926 | } // endwhile |
| 815 | 927 | ||
| @@ -901,15 +1013,17 @@ std::list<std::string> GVOHub::get_registrations(const GXml& xml, | @@ -901,15 +1013,17 @@ std::list<std::string> GVOHub::get_registrations(const GXml& xml, | ||
| 901 | if (node != NULL) { | 1013 | if (node != NULL) { |
| 902 | int num = node->elements("member"); | 1014 | int num = node->elements("member"); |
| 903 | for (int i = 0; i < num; ++i) { | 1015 | for (int i = 0; i < num; ++i) { |
| 904 | - std::cout << i << std::endl; | 1016 | + /*std::cout << i << std::endl; |
| 905 | std::cout << "Affichage du membre\n"; | 1017 | std::cout << "Affichage du membre\n"; |
| 906 | - std::cout << *(node->element("member", i)) << std::cout; | 1018 | + std::cout << *(node->element("member", i)) << std::cout;*/ |
| 907 | subnode = node->element("member", i); | 1019 | subnode = node->element("member", i); |
| 908 | subnode = subnode->element("name", 0); | 1020 | subnode = subnode->element("name", 0); |
| 909 | - std::cout << "\nsubnode" << std::endl; | ||
| 910 | std::cout << node->element("member",i)->element("name", 0)->print(NORMAL,0) << std::cout; | 1021 | std::cout << node->element("member",i)->element("name", 0)->print(NORMAL,0) << std::cout; |
| 911 | - value.push_front(node->element("member",i)->element("name", 0)->print(NORMAL,0)); | ||
| 912 | - std::cout << "\nFin Affichage du membre\n"; | 1022 | + //value.push_front(node->element("member",i)->element("name", 0)->print(NORMAL,0)); |
| 1023 | + const GXmlText* text = static_cast<const GXmlText*>((*subnode)[0]); | ||
| 1024 | + if (text != NULL) { | ||
| 1025 | + value.push_front(text->text()); | ||
| 1026 | + } | ||
| 913 | } | 1027 | } |
| 914 | } | 1028 | } |
| 915 | } | 1029 | } |
| @@ -923,6 +1037,57 @@ std::list<std::string> GVOHub::get_registrations(const GXml& xml, | @@ -923,6 +1037,57 @@ std::list<std::string> GVOHub::get_registrations(const GXml& xml, | ||
| 923 | return value; | 1037 | return value; |
| 924 | } | 1038 | } |
| 925 | /***********************************************************************//** | 1039 | /***********************************************************************//** |
| 1040 | + * @brief Returns value for a SAMP client query parameter | ||
| 1041 | + * | ||
| 1042 | + * @param[in] xml client query XML document. | ||
| 1043 | + * @param[in] name Parameter name. | ||
| 1044 | + * @return Parameter value. | ||
| 1045 | + * | ||
| 1046 | + * Returns value for a SAMP client query parameter. If the specified | ||
| 1047 | + * parameter was not found or if the response structure is not compliant, | ||
| 1048 | + * an empty string is returned. | ||
| 1049 | + ***************************************************************************/ | ||
| 1050 | +std::string GVOHub::get_callback_port(const GXml& xml, | ||
| 1051 | + const std::string& name) const | ||
| 1052 | +{ | ||
| 1053 | + // Declare value | ||
| 1054 | + std::string value; | ||
| 1055 | + | ||
| 1056 | + // Search for value of specified member | ||
| 1057 | + const GXmlNode* node = xml.element("methodCall", 0); | ||
| 1058 | + const GXmlNode* subnode; | ||
| 1059 | + const GXmlText* subtext; | ||
| 1060 | + if (node != NULL) { | ||
| 1061 | + node = node->element("params", 0); | ||
| 1062 | + if (node != NULL) { | ||
| 1063 | + subnode = node->element("param", 0); | ||
| 1064 | + if (subnode != NULL) { | ||
| 1065 | + subnode = subnode->element("value", 0); | ||
| 1066 | + if (subnode != NULL) { | ||
| 1067 | + const GXmlText* text = static_cast<const GXmlText*>((*subnode)[0]); | ||
| 1068 | + if (text != NULL) { | ||
| 1069 | + value = text->text(); | ||
| 1070 | + value.append(" port : "); | ||
| 1071 | + } | ||
| 1072 | + } | ||
| 1073 | + } | ||
| 1074 | + subnode = node->element("param", 1); | ||
| 1075 | + if (subnode != NULL) { | ||
| 1076 | + subnode = subnode->element("value", 0); | ||
| 1077 | + if (subnode != NULL) { | ||
| 1078 | + const GXmlText* text = static_cast<const GXmlText*>((*subnode)[0]); | ||
| 1079 | + if (text != NULL) { | ||
| 1080 | + value.append(text->text()); | ||
| 1081 | + } | ||
| 1082 | + } | ||
| 1083 | + } | ||
| 1084 | + } | ||
| 1085 | + } | ||
| 1086 | + | ||
| 1087 | + // Return value | ||
| 1088 | + return value; | ||
| 1089 | +} | ||
| 1090 | +/***********************************************************************//** | ||
| 926 | * @brief Extract name / value pair from XML node | 1091 | * @brief Extract name / value pair from XML node |
| 927 | * | 1092 | * |
| 928 | * @param[in] node Pointer to XML node. | 1093 | * @param[in] node Pointer to XML node. |