GammaLib
2.1.0.dev
|
VO SAMP Hub class. More...
#include <GVOHub.hpp>
Classes | |
struct | client |
Public Member Functions | |
GVOHub (void) | |
Void constructor. More... | |
GVOHub (const GVOHub &hub) | |
Copy constructor. More... | |
virtual | ~GVOHub (void) |
Destructor. More... | |
GVOHub & | operator= (const GVOHub &hub) |
Assignment operator. More... | |
void | clear (void) |
Clear object. More... | |
GVOHub * | clone (void) const |
Clone object. More... | |
std::string | classname (void) const |
Return class name. More... | |
void | start (void) |
Start Hub. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print VO hub information. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GVOHub &client) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | start_hub (void) |
Starts the SAMP hub socket and listens on it. More... | |
void | handle_request (const socklen_t &sock) |
Reads the client message and runs appropriate function. More... | |
void | request_ping (const socklen_t &sock) |
Handles ping requests. More... | |
void | request_register (const GXml &xml, const socklen_t &sock) |
Handles registration requests. More... | |
void | request_unregister (const GXml &xml, const socklen_t &sock) |
Handles unregistration requests. More... | |
void | request_declare_metadata (const GXml &xml, const socklen_t &sock) |
Handles metadata declaration requests. More... | |
void | request_declare_subscriptions (const GXml &xml, const socklen_t &sock) |
Handles subscriptions declaration requests. More... | |
void | request_set_xml_rpc_callback (const GXml &xml, const socklen_t &sock) |
Handles XML-RPC callback setting requests. More... | |
void | request_get_subscriptions (const GXml &xml, const socklen_t &sock) |
Handles subscriptions getting requests. More... | |
void | request_get_registered_clients (const GXml &xml, const socklen_t &sock) |
Handles registered client information requests. More... | |
void | request_get_subscribed_clients (const GXml &xml, const socklen_t &sock) |
Handles subscribed client information requests. More... | |
void | request_get_metadata (const GXml &xml, const socklen_t &sock) |
Handles a metadata requests. More... | |
void | request_notify_all (const GXml &xml, const socklen_t &sock) |
Handle request to notify all clients. More... | |
void | request_shutdown (const socklen_t &sock) |
Handles Hub shutdown requests. More... | |
std::string | get_client_key (const GXml &xml) const |
Extract client key from XML request. More... | |
int | get_client_index (const GXml &xml) const |
Extract client index in shared memory from XML request. More... | |
int | get_client_index (const std::string &reference) const |
Extract client index in shared memory from XML request. More... | |
std::string | get_response_value (const GXmlNode *node, const std::string &name) const |
Returns value for a named parameter. More... | |
std::vector< std::string > | get_subscriptions (const GXml &xml) const |
Returns subscriptions from XML document. More... | |
std::string | get_callback_url (const GXml &xml) const |
Returns callback URL of client. More... | |
std::string | get_hub_lockfile (void) const |
Returns SAMP Hub lockfile URL. More... | |
std::string | get_mtype (const GXml &xml) const |
Extract mtype from XML request. More... | |
void | create_samp_file (void) const |
Create the lockfile. More... | |
void | delete_samp_file (void) const |
Delete the lockfile. More... | |
int | get_socket (void) |
Get Hub socket. More... | |
void | post_samp_ok (const socklen_t &sock) const |
Post SAMP ok massage to client. More... | |
void | post_samp_void (const socklen_t &sock) const |
Post SAMP void massage to client. More... | |
void | post_string (const std::string &content, const socklen_t &sock) const |
Post string content to client. More... | |
void | notify (const std::string &url, const std::string ¬ification) const |
Send notification to client. More... | |
void | notify_register (const client &client, const std::string &reference) |
Notify client about another client registering at Hub. More... | |
void | notify_unregister (const client &client, const std::string &reference) |
Notify client about another client unregistering at Hub. More... | |
void | notify_metadata (const client &client, const std::string &reference) |
Notify client about the metadata of another client. More... | |
void | notify_image_load (const client &client, const GXml &xml) |
Notify client about image loading. More... | |
void | notify_table_load (const GVOHub::client &client, const GXml &xml) |
Notify client about VO table loading. More... | |
std::string | random_string (const size_t &length) const |
Generates random string of characters. More... | |
std::string | hub_url (void) const |
Return Hub URL. More... | |
std::string | get_client_name (const GXml &xml) const |
Return client name from XML message. More... | |
Protected Attributes | |
std::string | m_secret |
Secret Hub key. More... | |
std::string | m_hub_host |
Hub host. More... | |
std::string | m_hub_port |
Hub port. More... | |
std::string | m_hub_path |
Hub path. More... | |
std::string | m_version |
The version of the SAMP Standard Profile implemented by the hub. More... | |
std::string | m_hub_id |
Hub identifier used by the hub when it sends message itself rather than forwarding from others. More... | |
int | m_socket |
Hub socket. More... | |
bool | m_shutdown |
Shutdown request. More... | |
std::vector< client > | m_clients |
Clients. More... | |
VO SAMP Hub class.
This class implements a SAMP hub to support the interoperability of Virtual Observatory applications.
Definition at line 51 of file GVOHub.hpp.
GVOHub::GVOHub | ( | void | ) |
Void constructor.
Definition at line 73 of file GVOHub.cpp.
References init_members().
Referenced by clone().
GVOHub::GVOHub | ( | const GVOHub & | hub | ) |
Copy constructor.
[in] | hub | VO Hub. |
Definition at line 88 of file GVOHub.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 167 of file GVOHub.hpp.
|
virtual |
Clear object.
Reset object to a clean initial state.
Implements GBase.
Definition at line 158 of file GVOHub.cpp.
References free_members(), and init_members().
|
virtual |
|
protected |
Copy class members.
[in] | hub | VO hub. |
Definition at line 260 of file GVOHub.cpp.
References m_clients, m_hub_host, m_hub_id, m_hub_path, m_hub_port, m_secret, m_shutdown, m_socket, and m_version.
Referenced by GVOHub(), and operator=().
|
protected |
Create the lockfile.
Creates the SAMP lockfile and fill it with information. Implements IVOA standard REC-SAMP-1.3-20120411.
Definition at line 1465 of file GVOHub.cpp.
References get_hub_lockfile(), hub_url(), m_hub_id, m_secret, and m_version.
Referenced by start_hub().
|
protected |
Delete the lockfile.
Deletes the SAMP lockfile on disk.
Definition at line 1500 of file GVOHub.cpp.
References get_hub_lockfile().
Referenced by free_members(), and start_hub().
|
protected |
Delete class members.
Definition at line 281 of file GVOHub.cpp.
References delete_samp_file(), and m_socket.
Referenced by clear(), operator=(), and ~GVOHub().
|
protected |
Returns callback URL of client.
[in] | xml | client query XML document. |
Definition at line 1388 of file GVOHub.cpp.
References GXmlNode::append(), GXml::element(), and GXmlText::text().
Referenced by request_set_xml_rpc_callback().
|
protected |
Extract client index in shared memory from XML request.
[in] | xml | XML message sent by client. |
Extracts the client index from the XML request. The method returns -1 if no client was found.
Definition at line 1230 of file GVOHub.cpp.
References get_client_key(), and m_clients.
Referenced by request_declare_metadata(), request_declare_subscriptions(), request_get_metadata(), request_get_subscriptions(), request_set_xml_rpc_callback(), and request_unregister().
|
protected |
Extract client index in shared memory from XML request.
[in] | reference | Client reference. |
Extracts the client index from the client reference. The method returns -1 if no client was found.
Definition at line 1270 of file GVOHub.cpp.
References m_clients.
|
protected |
Extract client key from XML request.
[in] | xml | XML message sent by client. |
Extracts the clients key from the XML request.
Definition at line 1197 of file GVOHub.cpp.
References GXml::element(), and GXmlText::text().
Referenced by get_client_index(), request_declare_metadata(), request_declare_subscriptions(), request_get_metadata(), request_get_registered_clients(), request_get_subscriptions(), request_set_xml_rpc_callback(), and request_unregister().
|
protected |
Return client name from XML message.
[in] | xml | XML message sent by client. |
Returns client name from XML message.
Definition at line 2221 of file GVOHub.cpp.
References GXml::element(), and GXmlText::text().
Referenced by request_get_metadata(), and request_get_subscriptions().
|
protected |
Returns SAMP Hub lockfile URL.
Implements IVOA standard REC-SAMP-1.3-20120411.
Definition at line 1415 of file GVOHub.cpp.
References gammalib::getenv().
Referenced by create_samp_file(), and delete_samp_file().
|
protected |
Extract mtype from XML request.
[in] | xml | XML message sent by client. |
Extracts the mtype identifying calling message from the XML request.
Definition at line 2178 of file GVOHub.cpp.
References GXml::element(), and get_response_value().
Referenced by request_notify_all().
|
protected |
Returns value for a named parameter.
[in] | node | XML node containing the response values. |
[in] | name | Parameter name. |
Returns the value
for the parameter name
in a list of member
XML nodes with the structure
<member> <name>name</name> <value>value</value> </member>
If the specified parameter name
was not found, or the the XML node
is NULL, an empty string is returned.
Definition at line 1311 of file GVOHub.cpp.
References GXmlNode::element(), GXmlNode::elements(), and gammalib::xml_get_name_value_pair().
Referenced by get_mtype(), notify_image_load(), notify_table_load(), and request_declare_metadata().
|
protected |
Get Hub socket.
Returns Hub socket. Starting from an initial port of 2526 the method searches for the next free port and binds it to a socket.
Definition at line 1521 of file GVOHub.cpp.
References G_GET_SOCKET, m_hub_host, m_hub_port, and gammalib::str().
Referenced by start_hub().
|
protected |
Returns subscriptions from XML document.
[in] | xml | client query XML document. |
Definition at line 1353 of file GVOHub.cpp.
References GXmlNode::element(), GXml::element(), GXmlNode::elements(), and GXmlText::text().
Referenced by request_declare_subscriptions().
|
protected |
Reads the client message and runs appropriate function.
[in] | sock | Socket to client. |
Definition at line 366 of file GVOHub.cpp.
References GXml::element(), gammalib::recv(), request_declare_metadata(), request_declare_subscriptions(), request_get_metadata(), request_get_registered_clients(), request_get_subscribed_clients(), request_get_subscriptions(), request_notify_all(), request_ping(), request_register(), request_set_xml_rpc_callback(), request_shutdown(), request_unregister(), start(), and GXmlText::text().
Referenced by start_hub().
|
protected |
Return Hub URL.
Returns the XML-RPC endpoint for communication with the hub.
Definition at line 2204 of file GVOHub.cpp.
References m_hub_host, m_hub_path, and m_hub_port.
Referenced by create_samp_file(), print(), and request_register().
|
protected |
Initialise class members.
Definition at line 237 of file GVOHub.cpp.
References m_clients, m_hub_host, m_hub_id, m_hub_path, m_hub_port, m_secret, m_shutdown, m_socket, m_version, and random_string().
Referenced by clear(), GVOHub(), and operator=().
|
protected |
Send notification to client.
[in] | url | URL. |
[in] | notification | Notification. |
Send a notification
to a url
.
Definition at line 1702 of file GVOHub.cpp.
References start(), and gammalib::str().
Referenced by notify_image_load(), notify_metadata(), notify_register(), notify_table_load(), and notify_unregister().
Notify client about image loading.
[in] | client | Client. |
[in] | xml | Message from which image information is extracted. |
Notify a client that a FITS image is avialable for loading. The method sends a "image.load.fits" message to the client
. Information about the image is extracted from the xml
document.
Definition at line 2028 of file GVOHub.cpp.
References GXml::element(), get_response_value(), m_hub_id, notify(), GVOHub::client::private_key, and GVOHub::client::url.
Referenced by request_notify_all().
|
protected |
Notify client about the metadata of another client.
[in] | client | Client to notify. |
[in] | reference | Reference of client for which metadata should be sent. |
Notify a client about another the metadata of another client. The method sends a "samp.hub.event.metadata" message to the client
.
Definition at line 1930 of file GVOHub.cpp.
References m_clients, m_hub_id, notify(), GVOHub::client::private_key, and GVOHub::client::url.
Referenced by request_declare_metadata().
|
protected |
Notify client about another client registering at Hub.
[in] | client | Client to notify. |
[in] | reference | Reference to client which registered. |
Notify a client about another client that has registered at the Hub. The method sends a "samp.hub.event.register" message to the client
.
Definition at line 1834 of file GVOHub.cpp.
References m_hub_id, notify(), GVOHub::client::private_key, and GVOHub::client::url.
Referenced by request_register().
|
protected |
Notify client about VO table loading.
[in] | client | Client. |
[in] | xml | Message from which table information is extracted. |
Notify a client that a VO table is avialable for loading. The method sends sends a "table.load.votable" message to the client
. Information about the VO table is extracted from the xml
document.
Definition at line 2094 of file GVOHub.cpp.
References GXml::element(), get_response_value(), m_hub_id, notify(), GVOHub::client::private_key, and GVOHub::client::url.
Referenced by request_notify_all().
|
protected |
Notify client about another client unregistering at Hub.
[in] | client | Client to notify. |
[in] | reference | Reference to client who unregistered. |
Notify a client about another client that has unregistered at the Hub. The method sends a "samp.hub.event.unregister" message to the client
.
Definition at line 1882 of file GVOHub.cpp.
References m_hub_id, notify(), GVOHub::client::private_key, and GVOHub::client::url.
Referenced by request_unregister().
Assignment operator.
[in] | hub | VO hub. |
Definition at line 126 of file GVOHub.cpp.
References copy_members(), free_members(), and init_members().
|
protected |
Post SAMP ok massage to client.
[in] | sock | Socket. |
Posts a SAMP OK message to a client.
Definition at line 1637 of file GVOHub.cpp.
References post_string().
Referenced by request_declare_subscriptions(), request_set_xml_rpc_callback(), and request_shutdown().
|
protected |
Post SAMP void massage to client.
[in] | sock | Socket. |
Posts a void SAMP message to a client. Void messages can typically be discared by the client.
Definition at line 1671 of file GVOHub.cpp.
References post_string().
Referenced by request_declare_metadata(), request_notify_all(), request_ping(), and request_unregister().
|
protected |
Post string content to client.
[in] | content | String content to post. |
[in] | sock | Socket. |
Posts the content of a string to a client.
Definition at line 1584 of file GVOHub.cpp.
References gammalib::str().
Referenced by post_samp_ok(), post_samp_void(), request_get_metadata(), request_get_registered_clients(), request_get_subscribed_clients(), request_get_subscriptions(), and request_register().
Print VO hub information.
[in] | chatter | Chattiness (defaults to NORMAL). |
Implements GBase.
Definition at line 200 of file GVOHub.cpp.
References hub_url(), m_hub_host, m_hub_id, m_hub_path, m_hub_port, m_secret, m_version, gammalib::parformat(), and SILENT.
|
protected |
Generates random string of characters.
[in] | length | Length of random string |
Definition at line 2156 of file GVOHub.cpp.
References gammalib::str().
Referenced by init_members(), and request_register().
|
protected |
Handles metadata declaration requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all incoming metadata declaration requests.
Definition at line 654 of file GVOHub.cpp.
References GXml::element(), get_client_index(), get_client_key(), get_response_value(), m_clients, notify_metadata(), and post_samp_void().
Referenced by handle_request().
|
protected |
Handles subscriptions declaration requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all incoming subscription declaration requests.
Definition at line 718 of file GVOHub.cpp.
References get_client_index(), get_client_key(), get_subscriptions(), m_clients, and post_samp_ok().
Referenced by handle_request().
|
protected |
Handles a metadata requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all metadata requests.
Definition at line 979 of file GVOHub.cpp.
References get_client_index(), get_client_key(), get_client_name(), m_clients, and post_string().
Referenced by handle_request().
|
protected |
Handles registered client information requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all incoming registered client information requests.
Definition at line 887 of file GVOHub.cpp.
References get_client_key(), m_clients, and post_string().
Referenced by handle_request().
|
protected |
Handles subscribed client information requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all incoming subscribed client information requests.
Definition at line 937 of file GVOHub.cpp.
References post_string().
Referenced by handle_request().
|
protected |
Handles subscriptions getting requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all incoming subscriptions getting requests.
Definition at line 810 of file GVOHub.cpp.
References get_client_index(), get_client_key(), get_client_name(), m_clients, and post_string().
Referenced by handle_request().
|
protected |
Handle request to notify all clients.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles requests to notify all clients. The method will loop over all clients to check the subscriptions of each client, and send a notification to all clients that are subscribed to the requested message type.
Definition at line 1117 of file GVOHub.cpp.
References get_mtype(), m_clients, notify_image_load(), notify_table_load(), and post_samp_void().
Referenced by handle_request().
|
protected |
Handles ping requests.
[in] | sock | Socket. |
Handles all incoming ping requests.
Definition at line 487 of file GVOHub.cpp.
References post_samp_void().
Referenced by handle_request().
|
protected |
Handles registration requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all incoming registration requests.
Definition at line 510 of file GVOHub.cpp.
References hub_url(), m_clients, m_hub_id, notify_register(), post_string(), GVOHub::client::private_key, random_string(), GVOHub::client::reference, and gammalib::str().
Referenced by handle_request().
|
protected |
Handles XML-RPC callback setting requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all incoming XML-RPC callback setting requests.
Definition at line 766 of file GVOHub.cpp.
References get_callback_url(), get_client_index(), get_client_key(), m_clients, and post_samp_ok().
Referenced by handle_request().
|
protected |
Handles Hub shutdown requests.
[in] | sock | Socket. |
Handles all incoming Hub shutdown requests.
Definition at line 1172 of file GVOHub.cpp.
References m_shutdown, and post_samp_ok().
Referenced by handle_request().
|
protected |
Handles unregistration requests.
[in] | xml | XML message sent by client. |
[in] | sock | Socket. |
Handles all incoming unregistration requests.
Definition at line 600 of file GVOHub.cpp.
References get_client_index(), get_client_key(), m_clients, notify_unregister(), and post_samp_void().
Referenced by handle_request().
void GVOHub::start | ( | void | ) |
Start Hub.
Definition at line 184 of file GVOHub.cpp.
References start_hub().
Referenced by handle_request(), notify(), and GVOClient::require_hub().
|
protected |
Starts the SAMP hub socket and listens on it.
GException::runtime_error | Problem with creating of or listening on socket |
This is the main Hub event loop.
Definition at line 305 of file GVOHub.cpp.
References create_samp_file(), delete_samp_file(), G_START_HUB, get_socket(), handle_request(), m_shutdown, m_socket, and gammalib::str().
Referenced by start().
|
protected |
Clients.
Definition at line 157 of file GVOHub.hpp.
Referenced by copy_members(), get_client_index(), init_members(), notify_metadata(), request_declare_metadata(), request_declare_subscriptions(), request_get_metadata(), request_get_registered_clients(), request_get_subscriptions(), request_notify_all(), request_register(), request_set_xml_rpc_callback(), and request_unregister().
|
protected |
Hub host.
Definition at line 150 of file GVOHub.hpp.
Referenced by copy_members(), get_socket(), hub_url(), init_members(), and print().
|
protected |
Hub identifier used by the hub when it sends message itself rather than forwarding from others.
Definition at line 154 of file GVOHub.hpp.
Referenced by copy_members(), create_samp_file(), init_members(), notify_image_load(), notify_metadata(), notify_register(), notify_table_load(), notify_unregister(), print(), and request_register().
|
protected |
Hub path.
Definition at line 152 of file GVOHub.hpp.
Referenced by copy_members(), hub_url(), init_members(), and print().
|
protected |
Hub port.
Definition at line 151 of file GVOHub.hpp.
Referenced by copy_members(), get_socket(), hub_url(), init_members(), and print().
|
protected |
Secret Hub key.
Definition at line 149 of file GVOHub.hpp.
Referenced by copy_members(), create_samp_file(), init_members(), and print().
|
protected |
Shutdown request.
Definition at line 156 of file GVOHub.hpp.
Referenced by copy_members(), init_members(), request_shutdown(), and start_hub().
|
protected |
Hub socket.
Definition at line 155 of file GVOHub.hpp.
Referenced by copy_members(), free_members(), init_members(), and start_hub().
|
protected |
The version of the SAMP Standard Profile implemented by the hub.
Definition at line 153 of file GVOHub.hpp.
Referenced by copy_members(), create_samp_file(), init_members(), and print().