Commit e0f7745f64d1fdcd452f27ab5d8ee8012820d571

Authored by Thierry Louge
1 parent 6f53a5ab

Correction of a few bugs, VOTable share is OK from xml file

include/GVOClient.hpp
... ... @@ -35,6 +35,7 @@
35 35 class GFitsHDU;
36 36 class GXml;
37 37 class GXmlNode;
  38 +class GVOTable;
38 39  
39 40  
40 41 /***********************************************************************//**
... ... @@ -78,6 +79,7 @@ public:
78 79 void shutdown_hub(void) const;
79 80 GXml execute(const std::string& request) const;
80 81 void publish(const GFitsHDU& hdu);
  82 + void publish(const GVOTable& votable);
81 83 std::string print(const GChatter& chatter = NORMAL) const;
82 84  
83 85 protected:
... ...
include/GVOHub.hpp
... ... @@ -142,6 +142,8 @@ protected:
142 142 const std::string& reference);
143 143 void notify_image_load(const client& client,
144 144 const GXml& xml);
  145 + void notify_table_load(const GVOHub::client& client,
  146 + const GXml& xml);
145 147 std::string random_string(const size_t& length) const;
146 148 std::string hub_url(void) const;
147 149  
... ...
include/GammaLib.hpp
... ... @@ -109,6 +109,7 @@
109 109 /* __ VO module __________________________________________________________ */
110 110 #include "GVOClient.hpp"
111 111 #include "GVOHub.hpp"
  112 +#include "GVOTable.hpp"
112 113  
113 114 /* __ XSPEC module _______________________________________________________ */
114 115 #include "GArf.hpp"
... ...
include/Makefile.am
... ... @@ -85,6 +85,7 @@ pkginclude_HEADERS = GammaLib.hpp \
85 85 GXmlPI.hpp \
86 86 GVOClient.hpp \
87 87 GVOHub.hpp \
  88 + GVOTable.hpp \
88 89 GPha.hpp \
89 90 GArf.hpp \
90 91 GRmf.hpp \
... ...
pyext/GVOClient.i
... ... @@ -54,6 +54,7 @@ public:
54 54 void shutdown_hub(void) const;
55 55 GXml execute(const std::string& request) const;
56 56 void publish(const GFitsHDU& hdu);
  57 + void publish(const GVOTable& votable);
57 58 };
58 59  
59 60  
... ...
pyext/gammalib/vo.i
... ... @@ -50,5 +50,6 @@
50 50 %import(module="gammalib.support") "GException.i";
51 51  
52 52 /* __ Virtual Observatory module _________________________________________ */
  53 +%include "GVOTable.i"
53 54 %include "GVOClient.i"
54 55 %include "GVOHub.i"
... ...
src/vo/GVOClient.cpp
... ... @@ -42,6 +42,7 @@
42 42 #include "GFits.hpp"
43 43 #include "GVOClient.hpp"
44 44 #include "GVOHub.hpp"
  45 +#include "GVOTable.hpp"
45 46  
46 47 /* __ Method name definitions ____________________________________________ */
47 48 #define G_FIND_HUB "GVOClient::find_hub()"
... ... @@ -53,7 +54,7 @@
53 54 /* __ Coding definitions _________________________________________________ */
54 55  
55 56 /* __ Debug definitions __________________________________________________ */
56   -//#define G_SHOW_MESSAGE //!< Show posted and received messages
  57 +#define G_SHOW_MESSAGE //!< Show posted and received messages
57 58  
58 59  
59 60 /*==========================================================================
... ... @@ -276,7 +277,7 @@ bool GVOClient::ping_hub(void) const
276 277 request.append("<methodCall>\n");
277 278 request.append(" <methodName>samp.hub.ping</methodName>\n");
278 279 request.append(" <params>\n");
279   - request.append(" <param><value/></param>\n");
  280 + //request.append(" <param><value/></param>\n");
280 281 request.append(" </params>\n");
281 282 request.append("</methodCall>\n");
282 283  
... ... @@ -423,7 +424,47 @@ void GVOClient::publish(const GFitsHDU&amp; hdu)
423 424 return;
424 425 }
425 426  
  427 +/***********************************************************************//**
  428 + * @brief publishes the VOTable in a VO Hub
  429 + *
  430 + * @param[in]
  431 + *
  432 + * @exception GException::
  433 + *
  434 + ***************************************************************************/
  435 +void GVOClient::publish(const GVOTable& votable)
  436 +{
  437 + //The Client should save the Table, not the table itself
  438 + //That implies to play with pointers and references somewhat
426 439  
  440 + //std::string samp_share = std::tmpnam(NULL);
  441 + //votable.m_tablexml->save(samp_share+".xml");
  442 + //votable.m_tablexml->print();
  443 +
  444 + std::string hub_command = "";
  445 + //ELABORATE THE COMMAND TO BE PASSED TO THE HUB
  446 + //SEND THE DATA
  447 + hub_command.append("<?xml version=\"1.0\"?>\n");
  448 + hub_command.append("<methodCall>");
  449 + hub_command.append(" <methodName>samp.hub.notifyAll</methodName>\n");
  450 + hub_command.append(" <params>\n");
  451 + hub_command.append(" <param><value>table.load.votable</value></param>\n");
  452 + hub_command.append(" <param><value>"+m_secret+"</value></param>\n");
  453 + hub_command.append(" <param><value><struct>\n");
  454 + hub_command.append(" <member><name>samp.params</name><value><struct>\n");
  455 + hub_command.append(" <member><name>name</name><value>Gammalib_VOTABLE</value></member>\n");
  456 + hub_command.append(" <member><name>url</name><value>file://localhost"+votable.m_sharedtablename+".xml"+"</value></member>\n");
  457 + hub_command.append(" <member><name>table-id</name><value>file://localhost"+votable.m_sharedtablename+".xml"+"</value></member>\n");
  458 + hub_command.append(" </struct></value></member>\n");
  459 + hub_command.append(" <member><name>samp.mtype</name><value>table.load.votable</value></member>\n");
  460 + hub_command.append(" </struct></value></param>\n");
  461 + hub_command.append(" </params>\n");
  462 + hub_command.append("</methodCall>\n");
  463 + execute(hub_command);
  464 +
  465 + // Return
  466 + return;
  467 +}
427 468 /***********************************************************************//**
428 469 * @brief Print VO client information
429 470 *
... ... @@ -675,11 +716,22 @@ bool GVOClient::require_hub(void)
675 716 // First get Hub information
676 717 bool found = find_hub();
677 718  
  719 + #if defined(G_SHOW_MESSAGE)
  720 + std::cout << "find_hub() result:" << std::endl;
  721 + std::cout << found << std::endl;
  722 + #endif
678 723 // If we have Hub information, check if the Hub is alive
679 724 if (found) {
680 725 found = ping_hub();
681 726 }
682 727  
  728 + // Debug option: show posted message
  729 + #if defined(G_SHOW_MESSAGE)
  730 + std::cout << "ping_hub() result:" << std::endl;
  731 + std::cout << found << std::endl;
  732 + #endif
  733 +
  734 +
683 735 // If the Hub is not alive then create a GammaLib own Hub
684 736 if (!found) {
685 737  
... ...
src/vo/GVOHub.cpp
... ... @@ -58,7 +58,7 @@
58 58 /* __ Debug definitions __________________________________________________ */
59 59 //#define G_CONSOLE_DUMP //!< Show method headers
60 60 //#define G_CONSOLE_ERRORS //!< Show error messages
61   -//#define G_SHOW_MESSAGE //!< Show posted and received messages
  61 +#define G_SHOW_MESSAGE //!< Show posted and received messages
62 62  
63 63  
64 64 /*==========================================================================
... ... @@ -1147,6 +1147,9 @@ void GVOHub::request_notify_all(const GXml&amp; xml, const socklen_t&amp; sock)
1147 1147 if (mtype == "image.load.fits") {
1148 1148 notify_image_load(m_clients[i], xml);
1149 1149 }
  1150 + if (mtype == "table.load.votable") {
  1151 + notify_table_load(m_clients[i], xml);
  1152 + }
1150 1153  
1151 1154 } // endif: message type matched client subscription
1152 1155  
... ... @@ -2061,8 +2064,8 @@ void GVOHub::notify_image_load(const GVOHub::client&amp; client,
2061 2064 const GXml& xml)
2062 2065 {
2063 2066 // Get client response
2064   - const GXmlNode* node = xml.element("methodCall > params > param[2] > value > struct > member > value > struct");
2065   -
  2067 + const GXmlNode* node = xml.element("methodCall > params > param[2] > value > struct > member > value > struct");
  2068 + //const GXmlNode* node = xml.element("methodCall > params > param[1] > value > struct > member > value > struct");
2066 2069 // Extract image information from client response
2067 2070 std::string name = get_response_value(node, "name");
2068 2071 std::string url = get_response_value(node, "url");
... ... @@ -2090,14 +2093,14 @@ void GVOHub::notify_image_load(const GVOHub::client&amp; client,
2090 2093 msg.append(" <name>name</name>\n");
2091 2094 msg.append(" <value>"+name+"</value>\n");
2092 2095 msg.append(" </member>\n");
2093   - msg.append(" <member>\n");
  2096 + msg.append(" <member>\n");
2094 2097 msg.append(" <name>image-id</name>\n");
2095 2098 msg.append(" <value>"+id+"</value>\n");
2096 2099 msg.append(" </member>\n");
2097   - msg.append(" <member>\n");
  2100 + msg.append(" <member>\n");
2098 2101 msg.append(" <name>url</name>\n");
2099 2102 msg.append(" <value>"+url+"</value>\n");
2100   - msg.append(" </member>\n");
  2103 + msg.append(" </member>\n");
2101 2104 msg.append(" </struct></value>\n");
2102 2105 msg.append(" </member>\n");
2103 2106 msg.append(" </struct></value></param>\n");
... ... @@ -2111,7 +2114,69 @@ void GVOHub::notify_image_load(const GVOHub::client&amp; client,
2111 2114 return;
2112 2115 }
2113 2116  
  2117 +/***********************************************************************//**
  2118 + * @brief Notify client about image loading
  2119 + *
  2120 + * @param[in] client Client.
  2121 + * @param[in] xml Message from which image information is extracted.
  2122 + *
  2123 + * Notify a client that a FITS image is avialable for loading. The method
  2124 + * sends a "image.load.fits" message to the @p client. Information about the
  2125 + * image is extracted from the @p xml document.
  2126 + ***************************************************************************/
  2127 +void GVOHub::notify_table_load(const GVOHub::client& client,
  2128 + const GXml& xml)
  2129 +{
  2130 + // Get client response
  2131 + const GXmlNode* node = xml.element("methodCall > params > param[2] > value > struct > member > value > struct");
  2132 +
  2133 + // Extract image information from client response
  2134 + std::string name = get_response_value(node, "name");
  2135 + std::string url = get_response_value(node, "url");
  2136 + std::string id = get_response_value(node, "table-id");
  2137 +
  2138 + // Declare notification
  2139 + std::string msg = "";
  2140 +
  2141 + // Set notification for image.load.fits
  2142 + msg.append("<?xml version=\"1.0\"?>\n");
  2143 + msg.append("<methodCall>\n");
  2144 + msg.append("<methodName>samp.client.receiveNotification</methodName>\n");
  2145 + msg.append("<params>\n");
  2146 + msg.append(" <param><value>"+client.private_key+"</value></param>\n");
  2147 + msg.append(" <param><value>"+m_hub_id+"</value></param>\n");
  2148 + msg.append(" <param><value><struct>\n");
  2149 + msg.append(" <member>\n");
  2150 + msg.append(" <name>samp.mtype</name>\n");
  2151 + msg.append(" <value>table.load.votable</value>\n");
  2152 + msg.append(" </member>\n");
  2153 + msg.append(" <member>\n");
  2154 + msg.append(" <name>samp.params</name>\n");
  2155 + msg.append(" <value><struct>\n");
  2156 + msg.append(" <member>\n");
  2157 + msg.append(" <name>name</name>\n");
  2158 + msg.append(" <value>"+name+"</value>\n");
  2159 + msg.append(" </member>\n");
  2160 + msg.append(" <member>\n");
  2161 + msg.append(" <name>table-id</name>\n");
  2162 + msg.append(" <value>"+id+"</value>\n");
  2163 + msg.append(" </member>\n");
  2164 + msg.append(" <member>\n");
  2165 + msg.append(" <name>url</name>\n");
  2166 + msg.append(" <value>"+url+"</value>\n");
  2167 + msg.append(" </member>\n");
  2168 + msg.append(" </struct></value>\n");
  2169 + msg.append(" </member>\n");
  2170 + msg.append(" </struct></value></param>\n");
  2171 + msg.append("</params>\n");
  2172 + msg.append("</methodCall>\n");
2114 2173  
  2174 + // Post notification
  2175 + notify(client.url, msg);
  2176 +
  2177 + // Return
  2178 + return;
  2179 +}
2115 2180 /***********************************************************************//**
2116 2181 * @brief Generates random string of characters
2117 2182 *
... ...
src/vo/Makefile.am
... ... @@ -26,7 +26,8 @@ INCLUDES = -I$(top_srcdir)/include \
26 26  
27 27 # Define sources for this directory
28 28 sources = GVOClient.cpp \
29   - GVOHub.cpp
  29 + GVOHub.cpp \
  30 + GVOTable.cpp
30 31  
31 32 # Build libtool library
32 33 noinst_LTLIBRARIES = libvo.la
... ...