Commit 7b96c7ebd691427e13ba2df1485ae1e34b96ebb8

Authored by Jürgen Knödlseder
1 parent c11e6c15

Separate Hub finding from Hub launching.

The Hub is searched for when a client is initialised so that one can ping a Hub from a client.
include/GVOClient.hpp
... ... @@ -78,6 +78,7 @@ protected:
78 78 void copy_members(const GVOClient& client);
79 79 void free_members(void);
80 80 bool find_hub(void);
  81 + bool require_hub(void);
81 82 void register_to_hub(void);
82 83 void unregister_from_hub(void);
83 84 void send_metadata(void) const;
... ...
src/vo/GVOClient.cpp
... ... @@ -65,6 +65,9 @@ GVOClient::GVOClient(void)
65 65 // Initialise members
66 66 init_members();
67 67  
  68 + // Find Hub
  69 + find_hub();
  70 +
68 71 // Return
69 72 return;
70 73 }
... ... @@ -177,9 +180,9 @@ GVOClient* GVOClient::clone(void) const
177 180 ***************************************************************************/
178 181 void GVOClient::connect(void)
179 182 {
180   - // Find Hub
181   - find_hub();
182   -
  183 + // Require a Hub
  184 + require_hub();
  185 +
183 186 // Continue only if we have a Hub
184 187 if (has_hub()) {
185 188  
... ... @@ -465,9 +468,6 @@ void GVOClient::free_members(void)
465 468 * samp.hub.xmlrpc.url XML-RPC endpoint for communication
466 469 * samp.profile.version Version of SAMP profile
467 470 *
468   - * In case that no VO Hub is found (or alive) the method will start a
469   - * GammaLib internal Hub.
470   - *
471 471 * Implements IVOA standard REC-SAMP-1.3-20120411.
472 472 ***************************************************************************/
473 473 bool GVOClient::find_hub(void)
... ... @@ -560,7 +560,25 @@ bool GVOClient::find_hub(void)
560 560  
561 561 } // endif: URL has been found
562 562  
563   - // If we have found a Hub then check if the VO Hub is alive
  563 + // Return find flag
  564 + return found;
  565 +}
  566 +
  567 +
  568 +/***********************************************************************//**
  569 + * @brief Require VO Hub
  570 + *
  571 + * @return True if VO Hub has been found, false otherwise.
  572 + *
  573 + * Make sure that a VO Hub is available and alive. If no VO Hub is found
  574 + * or alive the method will start a GammaLib internal Hub.
  575 + ***************************************************************************/
  576 +bool GVOClient::require_hub(void)
  577 +{
  578 + // First get Hub information
  579 + bool found = find_hub();
  580 +
  581 + // If we have Hub information, check if the Hub is alive
564 582 if (found) {
565 583 found = ping_hub();
566 584 }
... ... @@ -586,12 +604,18 @@ bool GVOClient::find_hub(void)
586 604 // ... otherwise we are in the parent process. Check if the Hub
587 605 // is alive.
588 606 else {
  607 +
  608 + // Check that Hub is alive
589 609 for (int i = 0; i < 3; ++i) {
590 610 found = ping_hub();
591 611 if (found) {
592 612 break;
593 613 }
594 614 }
  615 +
  616 + // Get Hub information
  617 + found = find_hub();
  618 +
595 619 }
596 620  
597 621 } // endif: created own VO Hub
... ...
test/test_GVO.cpp
... ... @@ -146,19 +146,16 @@ void TestGVO::test_GVOClient(void)
146 146 // Create client
147 147 GVOClient client;
148 148  
149   - // Test ping
150   - test_assert(!client.ping_hub(), "Ping Hub (should fail).");
151   -
152 149 // Connect client
153 150 client.connect();
154   - std::cout << client << std::endl;
  151 + //std::cout << client << std::endl;
155 152  
156 153 // Test ping
157 154 test_assert(client.ping_hub(), "Ping Hub.");
158 155  
159 156 // Disconnect client
160 157 client.disconnect();
161   - std::cout << client << std::endl;
  158 + //std::cout << client << std::endl;
162 159  
163 160 // Test ping
164 161 test_assert(client.ping_hub(), "Ping Hub.");
... ...