Commit 4f7282d6d3b7ca3b9bdea24351358c683ab5204b
1 parent
2e8c917e
GVOClient using publish_fits to broadcast data without using GVOTable
Showing
8 changed files
with
187 additions
and
74 deletions
include/GSkymap.hpp
| ... | ... | @@ -41,6 +41,7 @@ |
| 41 | 41 | #include "GMatrix.hpp" |
| 42 | 42 | #include "GVector.hpp" |
| 43 | 43 | #include "GBilinear.hpp" |
| 44 | +#include "GVOClient.hpp" | |
| 44 | 45 | |
| 45 | 46 | /***********************************************************************//** |
| 46 | 47 | * @class GSkymap |
| ... | ... | @@ -146,7 +147,6 @@ public: |
| 146 | 147 | void read(const GFitsHDU& hdu); |
| 147 | 148 | void write(GFits& file) const; |
| 148 | 149 | std::string print(const GChatter& chatter = NORMAL) const; |
| 149 | - | |
| 150 | 150 | |
| 151 | 151 | private: |
| 152 | 152 | // Private methods | ... | ... |
include/GVOClient.hpp
| ... | ... | @@ -75,6 +75,7 @@ public: |
| 75 | 75 | void shutdown_hub(void) const; |
| 76 | 76 | GXml execute(const std::string& request) const; |
| 77 | 77 | std::string print(const GChatter& chatter = NORMAL) const; |
| 78 | + void publish_fits(const std::string& filename); | |
| 78 | 79 | |
| 79 | 80 | protected: |
| 80 | 81 | // Protected methods | ... | ... |
include/GVOHub.hpp
| ... | ... | @@ -103,10 +103,9 @@ protected: |
| 103 | 103 | std::vector<std::string> get_subscriptions(const GXml& xml) const; |
| 104 | 104 | std::string get_callback_url(const GXml& xml) const; |
| 105 | 105 | std::string get_hub_lockfile(void) const; |
| 106 | - void send_notifications(const std::string& method, | |
| 107 | - const std::string& client); | |
| 108 | - void request_call(const GXml& xml, | |
| 109 | - const socklen_t& sock); | |
| 106 | + void send_notifications(const std::string& method,const std::string& client); | |
| 107 | + void send_notifications(const std::string& method,const std::string& client,const GXml& xml); | |
| 108 | + void broadcast(const GXml& xml,const socklen_t& sock); | |
| 110 | 109 | std::string get_mtype(const GXml& xml) const; |
| 111 | 110 | std::string get_destination(const GXml& xml) const; |
| 112 | 111 | ... | ... |
pyext/GVOClient.i
src/sky/GSkymap.cpp
src/vo/GVOClient.cpp
| ... | ... | @@ -412,7 +412,38 @@ std::string GVOClient::print(const GChatter& chatter) const |
| 412 | 412 | // Return result |
| 413 | 413 | return result; |
| 414 | 414 | } |
| 415 | - | |
| 415 | +/***********************************************************************//** | |
| 416 | + * @brief publishes the VOTable in a VO Hub | |
| 417 | + * | |
| 418 | + * @param[in] | |
| 419 | + * | |
| 420 | + * @exception GException:: | |
| 421 | + * | |
| 422 | + ***************************************************************************/ | |
| 423 | +void GVOClient::publish_fits(const std::string& filename) | |
| 424 | +{ | |
| 425 | + std::string hub_command = ""; | |
| 426 | + //ELABORATE THE COMMAND TO BE PASSED TO THE HUB | |
| 427 | + //SEND THE DATA | |
| 428 | + hub_command.append("<?xml version=\"1.0\"?>\n"); | |
| 429 | + hub_command.append("<methodCall>"); | |
| 430 | + hub_command.append(" <methodName>samp.hub.notifyAll</methodName>\n"); | |
| 431 | + hub_command.append(" <params>\n"); | |
| 432 | + hub_command.append(" <param><value>image.load.fits</value></param>\n"); | |
| 433 | + hub_command.append(" <param><value>"+m_secret+"</value></param>\n"); | |
| 434 | + hub_command.append(" <param><value><struct>\n"); | |
| 435 | + hub_command.append(" <member><name>samp.params</name><value><struct>\n"); | |
| 436 | + hub_command.append(" <member><name>name</name><value>Gammalib_FITS_FILE</value></member>\n"); | |
| 437 | + hub_command.append(" <member><name>url</name><value>file://localhost:2526/"+filename+"</value></member>\n"); | |
| 438 | + hub_command.append(" <member><name>image-id</name><value>file:"+filename+"</value></member>\n"); | |
| 439 | + hub_command.append(" </struct></value></member>\n"); | |
| 440 | + hub_command.append(" <member><name>samp.mtype</name><value>image.load.fits</value></member>\n"); | |
| 441 | + hub_command.append(" </struct></value></param>\n"); | |
| 442 | + hub_command.append(" </params>\n</methodCall>\n"); | |
| 443 | + execute(hub_command); | |
| 444 | + // Return | |
| 445 | + return; | |
| 446 | +} | |
| 416 | 447 | |
| 417 | 448 | /*========================================================================== |
| 418 | 449 | = = | ... | ... |
src/vo/GVOHub.cpp
| ... | ... | @@ -53,7 +53,7 @@ |
| 53 | 53 | /* __ Coding definitions _________________________________________________ */ |
| 54 | 54 | |
| 55 | 55 | /* __ Debug definitions __________________________________________________ */ |
| 56 | -//#define G_CONSOLE_DUMP | |
| 56 | +#define G_CONSOLE_DUMP | |
| 57 | 57 | #define G_SHOW_MESSAGE |
| 58 | 58 | |
| 59 | 59 | |
| ... | ... | @@ -85,7 +85,7 @@ GVOHub::GVOHub(const GVOHub& hub) |
| 85 | 85 | { |
| 86 | 86 | // Initialise members |
| 87 | 87 | init_members(); |
| 88 | - | |
| 88 | + | |
| 89 | 89 | // Copy members |
| 90 | 90 | copy_members(hub); |
| 91 | 91 | |
| ... | ... | @@ -481,14 +481,21 @@ void GVOHub::handle_request(const socklen_t& sock) |
| 481 | 481 | else if (method_called.compare("samp.hub.getMetadata") == 0) { |
| 482 | 482 | request_get_metadata(xml, sock); |
| 483 | 483 | } |
| 484 | + else if (method_called.compare("table.load.votable") == 0) { | |
| 485 | + request_ping(sock); | |
| 486 | + } | |
| 484 | 487 | else if (method_called.compare("samp.hub.notify") == 0) { |
| 485 | 488 | request_ping(sock); |
| 486 | 489 | } |
| 487 | 490 | else if (method_called.compare("samp.hub.notifyAll") == 0) { |
| 488 | - request_ping(sock); | |
| 491 | + #if defined(G_CONSOLE_DUMP) | |
| 492 | + std::cout << "==========================================" << std::endl; | |
| 493 | + std::cout << "samp.hub.notifyAll" << std::endl; | |
| 494 | + #endif | |
| 495 | + broadcast(xml, sock); | |
| 489 | 496 | } |
| 490 | 497 | else if (method_called.compare("samp.hub.call") == 0) { |
| 491 | - request_call(xml,sock); | |
| 498 | + request_ping(sock); | |
| 492 | 499 | } |
| 493 | 500 | else if (method_called.compare("samp.hub.callAll") == 0) { |
| 494 | 501 | request_ping(sock); |
| ... | ... | @@ -1123,72 +1130,49 @@ void GVOHub::request_get_metadata(const GXml& xml, const socklen_t& sock) |
| 1123 | 1130 | } |
| 1124 | 1131 | |
| 1125 | 1132 | /***********************************************************************//** |
| 1126 | - * @brief Handles calls to specific client | |
| 1133 | + * @brief broadcasts a message | |
| 1127 | 1134 | * |
| 1128 | 1135 | * @param[in] xml XML message sent by client. |
| 1129 | 1136 | * @param[in] sock Socket. |
| 1130 | 1137 | * |
| 1131 | - * Handles all incoming cals for a specific client | |
| 1138 | + * broadcasts an image to every registered client | |
| 1132 | 1139 | ***************************************************************************/ |
| 1133 | -void GVOHub::request_call(const GXml& xml, const socklen_t& sock) | |
| 1140 | +void GVOHub::broadcast(const GXml& xml, const socklen_t& sock) | |
| 1134 | 1141 | { |
| 1135 | 1142 | // Header |
| 1136 | - #if defined(G_CONSOLE_DUMP) | |
| 1137 | - std::cout << "GVOHub::request_get_registered_clients" << std::endl; | |
| 1138 | - #endif | |
| 1139 | - | |
| 1140 | - // Get client key | |
| 1141 | - std::string key = get_client_key(xml); | |
| 1143 | + | |
| 1144 | + // Get client index | |
| 1145 | + int i = get_client_index(xml); | |
| 1142 | 1146 | // Get message mtype |
| 1143 | 1147 | std::string mtype = get_mtype(xml); |
| 1144 | - // Get the key of client who is to be contacted with the message | |
| 1145 | - // Declare message | |
| 1146 | - std::string msg = ""; | |
| 1147 | - // Determine which call has been invoqued | |
| 1148 | - // Loop over all clients and send notification | |
| 1149 | - for (int i = 0; i < m_clients.size(); ++i) { | |
| 1150 | - msg = ""; | |
| 1151 | - | |
| 1152 | - // Set response for table.load.votable | |
| 1153 | - msg.append("<?xml version=\"1.0\"?>\n"); | |
| 1154 | - msg.append("<methodCall><methodName>samp.client.receiveCall</methodName>\n"); | |
| 1155 | - msg.append("<params>\n"); | |
| 1156 | - msg.append(" <param><value>"); | |
| 1157 | - msg.append(m_clients[i].private_key); | |
| 1158 | - msg.append("</value></param>\n"); | |
| 1159 | - msg.append(" <param><value>"+m_hub_id+"</value></param>\n"); | |
| 1160 | - msg.append(" <param><value><struct>\n"); | |
| 1161 | - msg.append(" <member>\n"); | |
| 1162 | - msg.append(" <name>samp.mtype</name>\n"); | |
| 1163 | - msg.append(" <value>table.load.votable</value>\n"); | |
| 1164 | - msg.append(" </member>\n"); | |
| 1165 | - msg.append(" <member>\n"); | |
| 1166 | - msg.append(" <name>samp.params</name>\n"); | |
| 1167 | - msg.append(" <value><struct>\n"); | |
| 1168 | - msg.append(" <member>\n"); | |
| 1169 | - msg.append(" <name>name</name>\n"); | |
| 1170 | - msg.append(" <value>imagename</value>\n"); | |
| 1171 | - msg.append(" </member>\n"); | |
| 1172 | - msg.append(" <member>\n"); | |
| 1173 | - msg.append(" <name>table-id</name>\n"); | |
| 1174 | - msg.append(" <value>id of table</value>\n"); | |
| 1175 | - msg.append(" </member>\n"); | |
| 1176 | - msg.append(" <member>\n"); | |
| 1177 | - msg.append(" <name>url</name>\n"); | |
| 1178 | - msg.append(" <value>url to the table</value>\n"); | |
| 1179 | - msg.append(" </member>\n"); | |
| 1180 | - msg.append(" </struct></value>\n"); | |
| 1181 | - msg.append(" </member>\n"); | |
| 1182 | - msg.append(" </struct></value>\n"); | |
| 1183 | - msg.append(" </param>\n"); | |
| 1184 | - msg.append("</params>\n"); | |
| 1185 | - msg.append("</methodCall>\n"); | |
| 1186 | - | |
| 1187 | - | |
| 1188 | - // Post notification | |
| 1189 | - notify(m_clients[i].url, msg); | |
| 1148 | + #if defined(G_CONSOLE_DUMP) | |
| 1149 | + std::cout<<"mtype is: " +mtype + "i value: " + gammalib::str(i)<<std::endl; | |
| 1150 | + #endif | |
| 1151 | + // Continue only if index is valid | |
| 1152 | + if (i != -1) { | |
| 1153 | + #if defined(G_CONSOLE_DUMP) | |
| 1154 | + std::cout<<"i not negative"<<std::endl; | |
| 1155 | + #endif | |
| 1156 | + // Post void message | |
| 1157 | + post_samp_void(sock); | |
| 1158 | + if (mtype == "image.load.fits") { | |
| 1159 | + #if defined(G_CONSOLE_DUMP) | |
| 1160 | + std::cout<<"notifying image.load.fits"<<std::endl; | |
| 1161 | + #endif | |
| 1162 | + // Send notifications | |
| 1163 | + send_notifications("image.load.fits", | |
| 1164 | + m_clients[i].reference,xml); | |
| 1190 | 1165 | } |
| 1191 | - | |
| 1166 | + if (mtype == "table.load.votable") { | |
| 1167 | + // Send notifications | |
| 1168 | + send_notifications("table.load.votable", | |
| 1169 | + m_clients[i].reference,xml); | |
| 1170 | + } | |
| 1171 | + | |
| 1172 | + } // endif: valid client found | |
| 1173 | + #if defined(G_CONSOLE_DUMP) | |
| 1174 | + std::cout<<"Returning from broadcast function"<<std::endl; | |
| 1175 | + #endif | |
| 1192 | 1176 | // Return |
| 1193 | 1177 | return; |
| 1194 | 1178 | |
| ... | ... | @@ -1527,6 +1511,9 @@ std::string GVOHub::get_hub_lockfile(void) const |
| 1527 | 1511 | void GVOHub::send_notifications(const std::string& method, |
| 1528 | 1512 | const std::string& client) |
| 1529 | 1513 | { |
| 1514 | + #if defined(G_CONSOLE_DUMP) | |
| 1515 | + std::cout << "GVOHub::send_notifications 1st form" << std::endl; | |
| 1516 | + #endif | |
| 1530 | 1517 | // Loop over all clients |
| 1531 | 1518 | for (int i = 0; i < m_clients.size(); ++i) { |
| 1532 | 1519 | |
| ... | ... | @@ -1573,7 +1560,7 @@ void GVOHub::send_notifications(const std::string& method, |
| 1573 | 1560 | notify(m_clients[i].url, msg); |
| 1574 | 1561 | |
| 1575 | 1562 | } |
| 1576 | - | |
| 1563 | + | |
| 1577 | 1564 | // Unregister |
| 1578 | 1565 | else if (method == "samp.hub.event.unregister") { |
| 1579 | 1566 | |
| ... | ... | @@ -1693,7 +1680,7 @@ void GVOHub::send_notifications(const std::string& method, |
| 1693 | 1680 | // Post notification |
| 1694 | 1681 | notify(m_clients[i].url, msg); |
| 1695 | 1682 | |
| 1696 | - } // endelse: metadata | |
| 1683 | + } // endelse: metadata | |
| 1697 | 1684 | |
| 1698 | 1685 | } // endif: method was requested one |
| 1699 | 1686 | |
| ... | ... | @@ -1704,7 +1691,102 @@ void GVOHub::send_notifications(const std::string& method, |
| 1704 | 1691 | // Return |
| 1705 | 1692 | return; |
| 1706 | 1693 | } |
| 1694 | +/***********************************************************************//** | |
| 1695 | + * @brief Send notifications | |
| 1696 | + * | |
| 1697 | + * @param[in] method Name of the method | |
| 1698 | + * @param[in] client Reference of the client | |
| 1699 | + * @param[in] xml message sent by the client | |
| 1700 | + * | |
| 1701 | + * The method send notifications to all registered clients that request so. | |
| 1702 | + ***************************************************************************/ | |
| 1703 | +void GVOHub::send_notifications(const std::string& method, | |
| 1704 | + const std::string& client, | |
| 1705 | + const GXml& xml) | |
| 1706 | +{ | |
| 1707 | + #if defined(G_CONSOLE_DUMP) | |
| 1708 | + std::cout << "GVOHub::send_notifications 2nd form" << std::endl; | |
| 1709 | + #endif | |
| 1710 | + // Loop over all clients | |
| 1711 | + for (int i = 0; i < m_clients.size(); ++i) { | |
| 1712 | + | |
| 1713 | + // Loop over all methods | |
| 1714 | + for (int j = 0; j < m_clients[i].subscriptions.size(); ++j) { | |
| 1715 | + | |
| 1716 | + // Continue only if method matches | |
| 1717 | + if (method == m_clients[i].subscriptions[j]) { | |
| 1718 | + | |
| 1719 | + // Declare notification | |
| 1720 | + std::string msg = ""; | |
| 1707 | 1721 | |
| 1722 | + if (method == "image.load.fits") { | |
| 1723 | + /* | |
| 1724 | + Example of message to send for VOTABLE message | |
| 1725 | + { "samp.mtype": "table.load.votable", | |
| 1726 | + "samp.params": { | |
| 1727 | + "name": "SDSS DR7", | |
| 1728 | + "table-id": "http://alasky.u-strasbg.fr/cats/SDSS-DR7", | |
| 1729 | + "url": "file://localhost/root/.aladin/.aladin.28999/sampSDSSDR71446626818775.xml" } } | |
| 1730 | + */ | |
| 1731 | + | |
| 1732 | + // Set response for image.load.fits | |
| 1733 | + msg.append("<?xml version=\"1.0\"?>\n"); | |
| 1734 | + msg.append("<methodCall>\n"); | |
| 1735 | + msg.append("<methodName>samp.client.receiveNotification</methodName>\n"); | |
| 1736 | + msg.append("<params>\n"); | |
| 1737 | + msg.append(" <param><value>"); | |
| 1738 | + msg.append(m_clients[i].private_key); | |
| 1739 | + msg.append("</value></param>\n"); | |
| 1740 | + msg.append(" <param><value>"); | |
| 1741 | + msg.append(m_hub_id); | |
| 1742 | + msg.append("</value></param>\n"); | |
| 1743 | + msg.append(" <param><value><struct>\n"); | |
| 1744 | + msg.append(" <member>\n"); | |
| 1745 | + msg.append(" <name>samp.mtype</name>\n"); | |
| 1746 | + msg.append(" <value>image.load.fits</value>\n"); | |
| 1747 | + msg.append(" </member>\n"); | |
| 1748 | + msg.append(" <member>\n"); | |
| 1749 | + msg.append(" <name>samp.params</name>\n"); | |
| 1750 | + msg.append(" <value><struct>\n"); | |
| 1751 | + msg.append(" <member>\n"); | |
| 1752 | + msg.append(" <name>name</name>\n"); | |
| 1753 | + msg.append(" <value>"); | |
| 1754 | + const GXmlNode* node = xml.element("methodCall > params > param[1] > value > struct > member[1] > value"); | |
| 1755 | + if (node != NULL) { | |
| 1756 | + const GXmlText* text = static_cast<const GXmlText*>((*node)[0]); | |
| 1757 | + if (text != NULL) { | |
| 1758 | + msg.append(text->text()); | |
| 1759 | + } | |
| 1760 | + } | |
| 1761 | + msg.append("</value>\n"); | |
| 1762 | + msg.append(" </member>\n"); | |
| 1763 | + msg.append(" <member>\n"); | |
| 1764 | + msg.append(" <name>image-id</name>\n"); | |
| 1765 | + msg.append(" <value>IMAGE_ID</value>\n"); | |
| 1766 | + msg.append(" </member>\n"); | |
| 1767 | + msg.append(" <member>\n"); | |
| 1768 | + msg.append(" <name>url</name>\n"); | |
| 1769 | + msg.append(" <value>http://127.0.0.1:2526/</value>\n"); | |
| 1770 | + msg.append(" </member>\n"); | |
| 1771 | + msg.append(" </struct></value>\n"); | |
| 1772 | + msg.append(" </member>\n"); | |
| 1773 | + msg.append(" </struct></value></param>\n"); | |
| 1774 | + msg.append("</params>\n"); | |
| 1775 | + msg.append("</methodCall>\n"); | |
| 1776 | + | |
| 1777 | + // Post notification | |
| 1778 | + notify(m_clients[i].url, msg); | |
| 1779 | + | |
| 1780 | + } | |
| 1781 | + } // endif: method was requested one | |
| 1782 | + | |
| 1783 | + } // endfor: looped over all methods | |
| 1784 | + | |
| 1785 | + } // endfor: looped over all clients | |
| 1786 | + | |
| 1787 | + // Return | |
| 1788 | + return; | |
| 1789 | +} | |
| 1708 | 1790 | |
| 1709 | 1791 | /***********************************************************************//** |
| 1710 | 1792 | * @brief Creates the lockfile, fill it | ... | ... |
src/vo/GVOTable.cpp
| ... | ... | @@ -221,13 +221,13 @@ std::string GVOTable::print(const GChatter& chatter) const |
| 221 | 221 | void GVOTable::open_votable(void) |
| 222 | 222 | { |
| 223 | 223 | m_header.append("<?xml version=\"1.0\"?>\n"); |
| 224 | - m_header.append("<VOTABLE version=\"1.3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); | |
| 225 | - m_header.append("xmlns=\"http://www.ivoa.net/xml/VOTable/v1.3\"\n"); | |
| 224 | + // m_header.append("<VOTABLE version=\"1.3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); | |
| 225 | + //m_header.append("xmlns=\"http://www.ivoa.net/xml/VOTable/v1.3\"\n"); | |
| 226 | 226 | //STC is recommended space time coordinates datamodel for galaxies |
| 227 | 227 | m_header.append("xmlns:stc=\"http://www.ivoa.net/xml/STC/v1.30\">\n"); |
| 228 | - m_header.append("\t<RESOURCE name=\"Gammalib\">\n"); | |
| 229 | - m_header.append("\t\t<TABLE name=\"GammalibTable\">\n"); | |
| 230 | - m_header.append("\t\t\t<DESCRIPTION>VOTable coming from gammalib</DESCRIPTION>\n"); | |
| 228 | + //m_header.append("\t<RESOURCE name=\"Gammalib\">\n"); | |
| 229 | + //m_header.append("\t\t<TABLE name=\"GammalibTable\">\n"); | |
| 230 | + //m_header.append("\t\t\t<DESCRIPTION>VOTable coming from gammalib</DESCRIPTION>\n"); | |
| 231 | 231 | // Return |
| 232 | 232 | return; |
| 233 | 233 | } | ... | ... |