GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GVOHub.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GVOHub.hpp - VO SAMP Hub class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2014-2019 by Thierry Louge *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GVOHub.hpp
23  * @brief SAMP hub class interface definition
24  * @author Thierry Louge
25  */
26 
27 #ifndef GVOHUB_HPP
28 #define GVOHUB_HPP
29 
30 /* __ Definitions ________________________________________________________ */
31 
32 /* __ Includes ___________________________________________________________ */
33 #include <string>
34 #include <vector>
35 #include <sys/socket.h>
36 #include "GBase.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 class GXml;
40 class GXmlNode;
41 
42 
43 /***********************************************************************//**
44  * @class GVOHub
45  *
46  * @brief VO SAMP Hub class
47  *
48  * This class implements a SAMP hub to support the interoperability of
49  * Virtual Observatory applications.
50  ***************************************************************************/
51 class GVOHub : public GBase {
52 
53 public:
54  // Constructors and destructors
55  GVOHub(void);
56  GVOHub(const GVOHub& hub);
57  virtual ~GVOHub(void);
58 
59  // Operators
60  GVOHub& operator=(const GVOHub& hub);
61 
62  // Methods
63  void clear(void);
64  GVOHub* clone(void) const;
65  std::string classname(void) const;
66  void start(void);
67  std::string print(const GChatter& chatter = NORMAL) const;
68 
69 protected:
70  // Protected methods
71  void init_members(void);
72  void copy_members(const GVOHub& client);
73  void free_members(void);
74  void start_hub(void);
75  void handle_request(const socklen_t& sock);
76  void request_ping(const socklen_t& sock);
77  void request_register(const GXml& xml,
78  const socklen_t& sock);
79  void request_unregister(const GXml& xml,
80  const socklen_t& sock);
81  void request_declare_metadata(const GXml& xml,
82  const socklen_t& sock);
83  void request_declare_subscriptions(const GXml& xml,
84  const socklen_t& sock);
85  void request_set_xml_rpc_callback(const GXml& xml,
86  const socklen_t& sock);
87  void request_get_subscriptions(const GXml& xml,
88  const socklen_t& sock);
89  void request_get_registered_clients(const GXml& xml,
90  const socklen_t& sock);
91  void request_get_subscribed_clients(const GXml& xml,
92  const socklen_t& sock);
93  void request_get_metadata(const GXml& xml,
94  const socklen_t& sock);
95  void request_notify_all(const GXml& xml,
96  const socklen_t& sock);
97  void request_shutdown(const socklen_t& sock);
98  std::string get_client_key(const GXml& xml) const;
99  int get_client_index(const GXml& xml) const;
100  int get_client_index(const std::string& reference) const;
101  std::string get_response_value(const GXmlNode* node,
102  const std::string& name) const;
103  std::vector<std::string> get_subscriptions(const GXml& xml) const;
104  std::string get_callback_url(const GXml& xml) const;
105  std::string get_hub_lockfile(void) const;
106  std::string get_mtype(const GXml& xml) const;
107 
108  // Client structure
109  struct client {
110  std::string name;
111  std::string private_key;
112  std::string reference;
113  std::string description;
114  std::string icon;
115  std::string documentation;
116  std::string affiliation;
117  std::string author_name;
118  std::string email;
119  std::string homepage;
120  std::string url;
121  std::vector<std::string> subscriptions;
122  };
123 
124  // Low-level methods
125  void create_samp_file(void) const;
126  void delete_samp_file(void) const;
127  int get_socket(void);
128  void post_samp_ok(const socklen_t& sock) const;
129  void post_samp_void(const socklen_t& sock) const;
130  void post_string(const std::string& content,
131  const socklen_t& sock) const;
132  void notify(const std::string& url,
133  const std::string& notification) const;
134  void notify_register(const client& client,
135  const std::string& reference);
136  void notify_unregister(const client& client,
137  const std::string& reference);
138  void notify_metadata(const client& client,
139  const std::string& reference);
140  void notify_image_load(const client& client,
141  const GXml& xml);
142  void notify_table_load(const GVOHub::client& client,
143  const GXml& xml);
144  std::string random_string(const size_t& length) const;
145  std::string hub_url(void) const;
146  std::string get_client_name(const GXml& xml) const;
147 
148  // Protected members
149  std::string m_secret; //!< Secret Hub key
150  std::string m_hub_host; //!< Hub host
151  std::string m_hub_port; //!< Hub port
152  std::string m_hub_path; //!< Hub path
153  std::string m_version; //!< The version of the SAMP Standard Profile implemented by the hub
154  std::string m_hub_id; //!< Hub identifier used by the hub when it sends message itself rather than forwarding from others
155  int m_socket; //!< Hub socket
156  bool m_shutdown; //!< Shutdown request
157  std::vector<client> m_clients; //!< Clients
158 };
159 
160 
161 /***********************************************************************//**
162  * @brief Return class name
163  *
164  * @return String containing the class name ("GVOHub").
165  ***************************************************************************/
166 inline
167 std::string GVOHub::classname(void) const
168 {
169  return ("GVOHub");
170 }
171 
172 #endif /* GVOHUB_HPP */
Abstract XML node base class.
Definition: GXmlNode.hpp:57
std::vector< std::string > get_subscriptions(const GXml &xml) const
Returns subscriptions from XML document.
Definition: GVOHub.cpp:1353
std::string author_name
Definition: GVOHub.hpp:117
std::string m_hub_id
Hub identifier used by the hub when it sends message itself rather than forwarding from others...
Definition: GVOHub.hpp:154
std::string url
Definition: GVOHub.hpp:120
void handle_request(const socklen_t &sock)
Reads the client message and runs appropriate function.
Definition: GVOHub.cpp:366
std::string hub_url(void) const
Return Hub URL.
Definition: GVOHub.cpp:2204
std::string private_key
Definition: GVOHub.hpp:111
void post_samp_void(const socklen_t &sock) const
Post SAMP void massage to client.
Definition: GVOHub.cpp:1671
std::string affiliation
Definition: GVOHub.hpp:116
void delete_samp_file(void) const
Delete the lockfile.
Definition: GVOHub.cpp:1500
std::string print(const GChatter &chatter=NORMAL) const
Print VO hub information.
Definition: GVOHub.cpp:200
GVOHub & operator=(const GVOHub &hub)
Assignment operator.
Definition: GVOHub.cpp:126
void free_members(void)
Delete class members.
Definition: GVOHub.cpp:281
void post_samp_ok(const socklen_t &sock) const
Post SAMP ok massage to client.
Definition: GVOHub.cpp:1637
void request_declare_subscriptions(const GXml &xml, const socklen_t &sock)
Handles subscriptions declaration requests.
Definition: GVOHub.cpp:718
void request_get_subscriptions(const GXml &xml, const socklen_t &sock)
Handles subscriptions getting requests.
Definition: GVOHub.cpp:810
void notify_metadata(const client &client, const std::string &reference)
Notify client about the metadata of another client.
Definition: GVOHub.cpp:1930
void request_register(const GXml &xml, const socklen_t &sock)
Handles registration requests.
Definition: GVOHub.cpp:510
Definition of interface for all GammaLib classes.
GVOHub(void)
Void constructor.
Definition: GVOHub.cpp:73
std::string documentation
Definition: GVOHub.hpp:115
std::string get_mtype(const GXml &xml) const
Extract mtype from XML request.
Definition: GVOHub.cpp:2178
void request_get_subscribed_clients(const GXml &xml, const socklen_t &sock)
Handles subscribed client information requests.
Definition: GVOHub.cpp:937
std::string m_hub_path
Hub path.
Definition: GVOHub.hpp:152
void request_get_registered_clients(const GXml &xml, const socklen_t &sock)
Handles registered client information requests.
Definition: GVOHub.cpp:887
std::string homepage
Definition: GVOHub.hpp:119
void init_members(void)
Initialise class members.
Definition: GVOHub.cpp:237
virtual ~GVOHub(void)
Destructor.
Definition: GVOHub.cpp:104
std::string random_string(const size_t &length) const
Generates random string of characters.
Definition: GVOHub.cpp:2156
std::string description
Definition: GVOHub.hpp:113
void start_hub(void)
Starts the SAMP hub socket and listens on it.
Definition: GVOHub.cpp:305
XML class.
Definition: GXml.hpp:172
std::string reference
Definition: GVOHub.hpp:112
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
std::string m_secret
Secret Hub key.
Definition: GVOHub.hpp:149
std::vector< client > m_clients
Clients.
Definition: GVOHub.hpp:157
void notify_register(const client &client, const std::string &reference)
Notify client about another client registering at Hub.
Definition: GVOHub.cpp:1834
void request_declare_metadata(const GXml &xml, const socklen_t &sock)
Handles metadata declaration requests.
Definition: GVOHub.cpp:654
std::string get_hub_lockfile(void) const
Returns SAMP Hub lockfile URL.
Definition: GVOHub.cpp:1415
void start(void)
Start Hub.
Definition: GVOHub.cpp:184
GChatter
Definition: GTypemaps.hpp:33
std::string get_client_key(const GXml &xml) const
Extract client key from XML request.
Definition: GVOHub.cpp:1197
void request_get_metadata(const GXml &xml, const socklen_t &sock)
Handles a metadata requests.
Definition: GVOHub.cpp:979
VO SAMP Hub class.
Definition: GVOHub.hpp:51
std::vector< std::string > subscriptions
Definition: GVOHub.hpp:121
void request_notify_all(const GXml &xml, const socklen_t &sock)
Handle request to notify all clients.
Definition: GVOHub.cpp:1117
GVOHub * clone(void) const
Clone object.
Definition: GVOHub.cpp:174
void post_string(const std::string &content, const socklen_t &sock) const
Post string content to client.
Definition: GVOHub.cpp:1584
void request_unregister(const GXml &xml, const socklen_t &sock)
Handles unregistration requests.
Definition: GVOHub.cpp:600
std::string m_version
The version of the SAMP Standard Profile implemented by the hub.
Definition: GVOHub.hpp:153
void request_shutdown(const socklen_t &sock)
Handles Hub shutdown requests.
Definition: GVOHub.cpp:1172
bool m_shutdown
Shutdown request.
Definition: GVOHub.hpp:156
std::string get_response_value(const GXmlNode *node, const std::string &name) const
Returns value for a named parameter.
Definition: GVOHub.cpp:1311
void clear(void)
Clear object.
Definition: GVOHub.cpp:158
void request_set_xml_rpc_callback(const GXml &xml, const socklen_t &sock)
Handles XML-RPC callback setting requests.
Definition: GVOHub.cpp:766
void notify_table_load(const GVOHub::client &client, const GXml &xml)
Notify client about VO table loading.
Definition: GVOHub.cpp:2094
void notify_unregister(const client &client, const std::string &reference)
Notify client about another client unregistering at Hub.
Definition: GVOHub.cpp:1882
void create_samp_file(void) const
Create the lockfile.
Definition: GVOHub.cpp:1465
std::string get_client_name(const GXml &xml) const
Return client name from XML message.
Definition: GVOHub.cpp:2221
std::string m_hub_port
Hub port.
Definition: GVOHub.hpp:151
void request_ping(const socklen_t &sock)
Handles ping requests.
Definition: GVOHub.cpp:487
std::string icon
Definition: GVOHub.hpp:114
void copy_members(const GVOHub &client)
Copy class members.
Definition: GVOHub.cpp:260
void notify(const std::string &url, const std::string &notification) const
Send notification to client.
Definition: GVOHub.cpp:1702
std::string get_callback_url(const GXml &xml) const
Returns callback URL of client.
Definition: GVOHub.cpp:1388
int get_socket(void)
Get Hub socket.
Definition: GVOHub.cpp:1521
std::string classname(void) const
Return class name.
Definition: GVOHub.hpp:167
int m_socket
Hub socket.
Definition: GVOHub.hpp:155
std::string name
Definition: GVOHub.hpp:110
std::string m_hub_host
Hub host.
Definition: GVOHub.hpp:150
int get_client_index(const GXml &xml) const
Extract client index in shared memory from XML request.
Definition: GVOHub.cpp:1230
std::string email
Definition: GVOHub.hpp:118
void notify_image_load(const client &client, const GXml &xml)
Notify client about image loading.
Definition: GVOHub.cpp:2028