GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GVOHub Class Reference

VO SAMP Hub class. More...

#include <GVOHub.hpp>

Inheritance diagram for GVOHub:
GBase

Classes

struct  client
 

Public Member Functions

 GVOHub (void)
 Void constructor. More...
 
 GVOHub (const GVOHub &hub)
 Copy constructor. More...
 
virtual ~GVOHub (void)
 Destructor. More...
 
GVOHuboperator= (const GVOHub &hub)
 Assignment operator. More...
 
void clear (void)
 Clear object. More...
 
GVOHubclone (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 &notification) 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< clientm_clients
 Clients. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
[in]hubVO Hub.

Definition at line 88 of file GVOHub.cpp.

References copy_members(), and init_members().

GVOHub::~GVOHub ( void  )
virtual

Destructor.

Definition at line 104 of file GVOHub.cpp.

References free_members().

Member Function Documentation

std::string GVOHub::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GVOHub").

Implements GBase.

Definition at line 167 of file GVOHub.hpp.

void GVOHub::clear ( void  )
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().

GVOHub * GVOHub::clone ( void  ) const
virtual

Clone object.

Implements GBase.

Definition at line 174 of file GVOHub.cpp.

References GVOHub().

void GVOHub::copy_members ( const GVOHub hub)
protected

Copy class members.

Parameters
[in]hubVO 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=().

void GVOHub::create_samp_file ( void  ) const
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().

void GVOHub::delete_samp_file ( void  ) const
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().

void GVOHub::free_members ( void  )
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().

std::string GVOHub::get_callback_url ( const GXml xml) const
protected

Returns callback URL of client.

Parameters
[in]xmlclient query XML document.
Returns
Callback URL of client.

Definition at line 1388 of file GVOHub.cpp.

References GXmlNode::append(), GXml::element(), and GXmlText::text().

Referenced by request_set_xml_rpc_callback().

int GVOHub::get_client_index ( const GXml xml) const
protected

Extract client index in shared memory from XML request.

Parameters
[in]xmlXML message sent by client.
Returns
Client index (-1 if not found).

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().

int GVOHub::get_client_index ( const std::string &  reference) const
protected

Extract client index in shared memory from XML request.

Parameters
[in]referenceClient reference.
Returns
Client index (-1 if not found).

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.

std::string GVOHub::get_client_key ( const GXml xml) const
protected

Extract client key from XML request.

Parameters
[in]xmlXML 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().

std::string GVOHub::get_client_name ( const GXml xml) const
protected

Return client name from XML message.

Parameters
[in]xmlXML 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().

std::string GVOHub::get_hub_lockfile ( void  ) const
protected

Returns SAMP Hub lockfile URL.

Returns
SAMP Hub lockfile URL (empty if no lockfile was found).

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().

std::string GVOHub::get_mtype ( const GXml xml) const
protected

Extract mtype from XML request.

Parameters
[in]xmlXML 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().

std::string GVOHub::get_response_value ( const GXmlNode node,
const std::string &  name 
) const
protected

Returns value for a named parameter.

Parameters
[in]nodeXML node containing the response values.
[in]nameParameter name.
Returns
Parameter value.

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().

int GVOHub::get_socket ( void  )
protected

Get Hub socket.

Returns
Hub socket (-1 if no socket was found).

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().

std::vector< std::string > GVOHub::get_subscriptions ( const GXml xml) const
protected

Returns subscriptions from XML document.

Parameters
[in]xmlclient query XML document.
Returns
List of subscriptions.

Definition at line 1353 of file GVOHub.cpp.

References GXmlNode::element(), GXml::element(), GXmlNode::elements(), and GXmlText::text().

Referenced by request_declare_subscriptions().

void GVOHub::handle_request ( const socklen_t &  sock)
protected
std::string GVOHub::hub_url ( void  ) const
protected

Return Hub URL.

Returns
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().

void GVOHub::init_members ( void  )
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=().

void GVOHub::notify ( const std::string &  url,
const std::string &  notification 
) const
protected

Send notification to client.

Parameters
[in]urlURL.
[in]notificationNotification.

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().

void GVOHub::notify_image_load ( const client client,
const GXml xml 
)
protected

Notify client about image loading.

Parameters
[in]clientClient.
[in]xmlMessage 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().

void GVOHub::notify_metadata ( const client client,
const std::string &  reference 
)
protected

Notify client about the metadata of another client.

Parameters
[in]clientClient to notify.
[in]referenceReference 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().

void GVOHub::notify_register ( const client client,
const std::string &  reference 
)
protected

Notify client about another client registering at Hub.

Parameters
[in]clientClient to notify.
[in]referenceReference 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().

void GVOHub::notify_table_load ( const GVOHub::client client,
const GXml xml 
)
protected

Notify client about VO table loading.

Parameters
[in]clientClient.
[in]xmlMessage 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().

void GVOHub::notify_unregister ( const client client,
const std::string &  reference 
)
protected

Notify client about another client unregistering at Hub.

Parameters
[in]clientClient to notify.
[in]referenceReference 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().

GVOHub & GVOHub::operator= ( const GVOHub hub)

Assignment operator.

Parameters
[in]hubVO hub.
Returns
VO hub.

Definition at line 126 of file GVOHub.cpp.

References copy_members(), free_members(), and init_members().

void GVOHub::post_samp_ok ( const socklen_t &  sock) const
protected

Post SAMP ok massage to client.

Parameters
[in]sockSocket.

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().

void GVOHub::post_samp_void ( const socklen_t &  sock) const
protected

Post SAMP void massage to client.

Parameters
[in]sockSocket.

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().

void GVOHub::post_string ( const std::string &  content,
const socklen_t &  sock 
) const
protected

Post string content to client.

Parameters
[in]contentString content to post.
[in]sockSocket.

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().

std::string GVOHub::print ( const GChatter chatter = NORMAL) const
virtual

Print VO hub information.

Parameters
[in]chatterChattiness (defaults to NORMAL).
Returns
String containing VO hub information

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.

std::string GVOHub::random_string ( const size_t &  length) const
protected

Generates random string of characters.

Parameters
[in]lengthLength of random string

Definition at line 2156 of file GVOHub.cpp.

References gammalib::str().

Referenced by init_members(), and request_register().

void GVOHub::request_declare_metadata ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles metadata declaration requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::request_declare_subscriptions ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles subscriptions declaration requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::request_get_metadata ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles a metadata requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::request_get_registered_clients ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles registered client information requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::request_get_subscribed_clients ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles subscribed client information requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

Handles all incoming subscribed client information requests.

Definition at line 937 of file GVOHub.cpp.

References post_string().

Referenced by handle_request().

void GVOHub::request_get_subscriptions ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles subscriptions getting requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::request_notify_all ( const GXml xml,
const socklen_t &  sock 
)
protected

Handle request to notify all clients.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::request_ping ( const socklen_t &  sock)
protected

Handles ping requests.

Parameters
[in]sockSocket.

Handles all incoming ping requests.

Definition at line 487 of file GVOHub.cpp.

References post_samp_void().

Referenced by handle_request().

void GVOHub::request_register ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles registration requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::request_set_xml_rpc_callback ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles XML-RPC callback setting requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::request_shutdown ( const socklen_t &  sock)
protected

Handles Hub shutdown requests.

Parameters
[in]sockSocket.

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().

void GVOHub::request_unregister ( const GXml xml,
const socklen_t &  sock 
)
protected

Handles unregistration requests.

Parameters
[in]xmlXML message sent by client.
[in]sockSocket.

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().

void GVOHub::start_hub ( void  )
protected

Starts the SAMP hub socket and listens on it.

Exceptions
GException::runtime_errorProblem 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().

Member Data Documentation

std::string GVOHub::m_hub_host
protected

Hub host.

Definition at line 150 of file GVOHub.hpp.

Referenced by copy_members(), get_socket(), hub_url(), init_members(), and print().

std::string GVOHub::m_hub_id
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().

std::string GVOHub::m_hub_path
protected

Hub path.

Definition at line 152 of file GVOHub.hpp.

Referenced by copy_members(), hub_url(), init_members(), and print().

std::string GVOHub::m_hub_port
protected

Hub port.

Definition at line 151 of file GVOHub.hpp.

Referenced by copy_members(), get_socket(), hub_url(), init_members(), and print().

std::string GVOHub::m_secret
protected

Secret Hub key.

Definition at line 149 of file GVOHub.hpp.

Referenced by copy_members(), create_samp_file(), init_members(), and print().

bool GVOHub::m_shutdown
protected

Shutdown request.

Definition at line 156 of file GVOHub.hpp.

Referenced by copy_members(), init_members(), request_shutdown(), and start_hub().

int GVOHub::m_socket
protected

Hub socket.

Definition at line 155 of file GVOHub.hpp.

Referenced by copy_members(), free_members(), init_members(), and start_hub().

std::string GVOHub::m_version
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().


The documentation for this class was generated from the following files: