36 #include <sys/socket.h>
48 #define G_FIND_HUB "GVOClient::find_hub()"
49 #define G_REQUIRE_HUB "GVOClient::require_hub()"
50 #define G_REGISTER_TO_HUB "GVOClient::register_to_hub()"
128 if (
this != &client) {
273 std::string request =
"";
276 request.append(
"<?xml version=\"1.0\"?>\n");
277 request.append(
"<methodCall>\n");
278 request.append(
" <methodName>samp.hub.ping</methodName>\n");
279 request.append(
" <params>\n");
280 request.append(
" </params>\n");
281 request.append(
"</methodCall>\n");
302 std::string request =
"";
305 request.append(
"<?xml version=\"1.0\"?>\n");
306 request.append(
"<methodCall>\n");
307 request.append(
" <methodName>samp.hub.shutdown</methodName>\n");
308 request.append(
" <params>\n");
309 request.append(
" <param><value/></param>\n");
310 request.append(
" </params>\n");
311 request.append(
"</methodCall>\n");
345 size_t start = response.find(
"<?xml");
348 if (start != std::string::npos) {
349 xml =
GXml(response.substr(start, std::string::npos));
387 fits.
saveto(samp_share,
true);
390 std::string extname = hdu.
extname();
391 if (extname.empty()) {
392 extname =
"FITS Image";
396 std::string hub_command =
"";
397 hub_command.append(
"<?xml version=\"1.0\"?>\n");
398 hub_command.append(
"<methodCall>\n");
399 hub_command.append(
" <methodName>samp.hub.notifyAll</methodName>\n");
400 hub_command.append(
" <params>\n");
401 hub_command.append(
" <param><value>"+
m_client_key+
"</value></param>\n");
402 hub_command.append(
" <param><value><struct>\n");
403 hub_command.append(
" <member><name>samp.params</name><value><struct>\n");
404 hub_command.append(
" <member>\n");
405 hub_command.append(
" <name>name</name>\n");
406 hub_command.append(
" <value>"+extname+
"</value>\n");
407 hub_command.append(
" </member>\n");
408 hub_command.append(
" <member>\n");
409 hub_command.append(
" <name>url</name>\n");
410 hub_command.append(
" <value>file://localhost"+samp_share+
"</value>\n");
411 hub_command.append(
" </member>\n");
412 hub_command.append(
" <member>\n");
413 hub_command.append(
" <name>image-id</name>\n");
414 hub_command.append(
" <value>Gammalib Data</value>\n");
415 hub_command.append(
" </member>\n");
416 hub_command.append(
" </struct></value></member>\n");
417 hub_command.append(
" <member>\n");
418 hub_command.append(
" <name>samp.mtype</name>\n");
419 hub_command.append(
" <value>image.load.fits</value>\n");
420 hub_command.append(
" </member>\n");
421 hub_command.append(
" </struct></value></param>\n");
422 hub_command.append(
" </params>\n");
423 hub_command.append(
"</methodCall>\n");
458 votable.
xml().
save(samp_share);
461 std::string hub_command =
"";
462 hub_command.append(
"<?xml version=\"1.0\"?>\n");
463 hub_command.append(
"<methodCall>");
464 hub_command.append(
" <methodName>samp.hub.notifyAll</methodName>\n");
465 hub_command.append(
" <params>\n");
466 hub_command.append(
" <param><value>"+
m_client_key+
"</value></param>\n");
467 hub_command.append(
" <param><value><struct>\n");
468 hub_command.append(
" <member><name>samp.params</name><value><struct>\n");
469 hub_command.append(
" <member>\n");
470 hub_command.append(
" <name>name</name>\n");
471 hub_command.append(
" <value>"+votable.
name()+
"</value>\n");
472 hub_command.append(
" </member>\n");
473 hub_command.append(
" <member>\n");
474 hub_command.append(
" <name>url</name>\n");
475 hub_command.append(
" <value>\n");
476 hub_command.append(
" file://localhost"+samp_share+
"\n");
477 hub_command.append(
" </value>\n");
478 hub_command.append(
" </member>\n");
479 hub_command.append(
" <member>\n");
480 hub_command.append(
" <name>table-id</name>\n");
481 hub_command.append(
" <value>\n");
482 hub_command.append(
" file://localhost"+samp_share+
"\n");
483 hub_command.append(
" </value>\n");
484 hub_command.append(
" </member>\n");
485 hub_command.append(
" </struct></value></member>\n");
486 hub_command.append(
" <member>\n");
487 hub_command.append(
" <name>samp.mtype</name>\n");
488 hub_command.append(
" <value>table.load.votable</value>\n");
489 hub_command.append(
" </member>\n");
490 hub_command.append(
" </struct></value></param>\n");
491 hub_command.append(
" </params>\n");
492 hub_command.append(
"</methodCall>\n");
522 result.append(
"=== GVOClient ===");
540 result.append(
"\" on Hub \""+
m_hub_id);
541 result.append(
"\".");
544 result.append(
"established.");
553 result.append(
"No Hub has been found");
659 if (!lockurl.empty()) {
664 if (lockurl.compare(0, 7,
"file://") == 0) {
665 lockurl = lockurl.substr(7, std::string::npos);
669 FILE* fptr = fopen(lockurl.c_str(),
"r");
677 while (fgets(line, n, fptr) != NULL) {
680 std::string cline = std::string(line);
683 if (cline.compare(0, 12,
"samp.secret=") == 0) {
688 else if (cline.compare(0, 20,
"samp.hub.xmlrpc.url=") == 0) {
693 else if (cline.compare(0, 21,
"samp.profile.version=") == 0) {
703 if (
m_hub_url.compare(0, 7,
"http://") == 0) {
706 size_t stop =
m_hub_url.find(
":", start);
707 size_t end = std::string::npos;
708 if (stop != std::string::npos) {
709 length = stop - start;
712 length = std::string::npos;
715 if (stop != std::string::npos) {
718 if (end != std::string::npos) {
722 length = std::string::npos;
726 if (end != std::string::npos) {
769 std::string msg =
"Unable to create child process for VO Hub.";
786 for (
int i = 0; i < 5; ++i) {
822 request.append(
"<?xml version=\"1.0\"?>\n");
823 request.append(
"<methodCall>\n");
824 request.append(
" <methodName>samp.hub.register</methodName>\n");
825 request.append(
" <params>\n");
826 request.append(
" <param><value>"+
m_secret+
"</value></param>\n");
827 request.append(
" </params>\n");
828 request.append(
"</methodCall>\n");
842 std::string msg =
"Unable to connect to Hub (" +
865 request.append(
"<?xml version=\"1.0\"?>\n");
866 request.append(
"<methodCall>\n");
867 request.append(
" <methodName>samp.hub.unregister</methodName>\n");
868 request.append(
" <params>\n");
869 request.append(
" <param><value>"+
m_client_key+
"</value></param>\n");
870 request.append(
" </params>\n");
871 request.append(
"</methodCall>\n");
897 request.append(
"<?xml version=\"1.0\"?>\n");
898 request.append(
"<methodCall>\n");
899 request.append(
"<methodName>samp.hub.declareMetadata</methodName>\n");
900 request.append(
"<params>\n");
901 request.append(
" <param><value>"+
m_client_key+
"</value></param>\n");
902 request.append(
" <param><value><struct>\n");
905 request.append(
" <member>\n");
906 request.append(
" <name>samp.name</name>\n");
907 request.append(
" <value>"+
m_name+
"</value>\n");
908 request.append(
" </member>\n");
911 request.append(
" <member>\n");
912 request.append(
" <name>samp.description.text</name>\n");
913 request.append(
" <value>GammaLib client</value>\n");
914 request.append(
" </member>\n");
917 request.append(
" <member>\n");
918 request.append(
" <name>samp.icon.url</name>\n");
919 request.append(
" <value>http://a.fsdn.com/allura/p/gammalib/icon</value>\n");
920 request.append(
" </member>\n");
923 request.append(
" <member>\n");
924 request.append(
" <name>author.affiliation</name>\n");
925 request.append(
" <value>IRAP, Toulouse, France</value>\n");
926 request.append(
" </member>\n");
929 request.append(
" <member>\n");
930 request.append(
" <name>author.email</name>\n");
931 request.append(
" <value>jurgen.knodlseder@irap.omp.eu</value>\n");
932 request.append(
" </member>\n");
935 request.append(
" <member>\n");
936 request.append(
" <name>author.name</name>\n");
937 request.append(
" <value>Juergen Knoedlseder</value>\n");
938 request.append(
" </member>\n");
941 request.append(
" </struct></value></param>\n");
942 request.append(
"</params>\n");
943 request.append(
"</methodCall>\n");
984 struct addrinfo hints;
985 std::memset(&hints, 0,
sizeof(hints));
986 hints.ai_family = AF_INET;
987 hints.ai_socktype = SOCK_STREAM;
990 struct addrinfo* servinfo;
992 &hints, &servinfo) == 0) {
996 for (
struct addrinfo* ptr = servinfo; ptr != NULL; ptr = ptr->ai_next) {
1007 ptr->ai_addrlen) == -1) {
1043 int length = content.length();
1046 std::string prefix =
"POST /"+
m_hub_path+
" HTTP/1.0\n"
1047 "User-Agent: GammaLib\n"
1048 "Content-Type: text/xml\n"
1052 std::string post = prefix + content;
1055 #if defined(G_SHOW_MESSAGE)
1056 std::cout << post << std::endl;
1062 int length = post.length();
1063 int sent_length = send(
m_socket, post.c_str(), length, 0);
1064 if (sent_length < length) {
1065 post = post.substr(sent_length, std::string::npos);
1091 std::string result =
"";
1106 result.append(std::string(buffer));
1112 #if defined(G_SHOW_MESSAGE)
1113 std::cout << result << std::endl;
1135 const std::string& name)
const
1138 std::string value =
"";
1141 const GXmlNode* node = xml.
element(
"methodResponse > params > param > value > struct");
1143 int num = node->
elements(
"member");
1144 for (
int i = 0; i < num; ++i) {
1146 std::string one_name;
1147 std::string one_value;
1149 if (one_name == name) {
1171 std::string url =
"";
1175 if (hub_ptr != NULL) {
1179 std::string lockurl = std::string(hub_ptr);
1180 if (lockurl.compare(0, 12,
"std-lockurl:") == 0) {
1183 url = lockurl.substr(12, std::string::npos);
1196 std::string prefix =
"";
1198 if (home_ptr != NULL) {
1199 prefix = std::string(home_ptr) +
"/";
1203 url = prefix +
".samp";
1223 const GXmlNode* node = xml.
element(
"methodResponse > params > param > value");
1244 const GXmlNode* node = xml.
element(
"methodResponse > fault > value > struct");
1248 error_code =
gammalib::toint(static_cast<const GXmlText*>((*code)[0])->text());
1265 std::string error_message;
1268 const GXmlNode* node = xml.
element(
"methodResponse > fault > value > struct");
1272 error_message =
static_cast<const GXmlText*
>((*msg)[0])->text();
1277 return error_message;
Abstract XML node base class.
bool ping_hub(void) const
Ping VO Hub.
void xml_get_name_value_pair(const GXmlNode *node, std::string &name, std::string &value)
Extract name / value pair from XML node.
void connect_to_hub(void) const
Connect to SAMP Hub.
std::string m_name
Client name.
GXml execute(const std::string &request) const
Execute function on server.
std::string getenv(const std::string &arg)
Return value of environment variable.
void clear(void)
Clear object.
void save(const GFilename &filename) const
Save XML document into file.
GVOClient * clone(void) const
Clone object.
void publish(const GFitsHDU &hdu)
Publish FITS HDU.
XML class interface definition.
Abstract FITS extension base class.
std::string receive_string(void) const
Receive string content from Hub.
int recv(int fd, char *buffer, int len, int flags, int timeout)
Checks whether a parameter has occured once.
std::string get_response_value(const GXml &xml, const std::string &name) const
Returns value for a SAMP Hub response parameter.
std::string strip_chars(const std::string &arg, const std::string &chars)
Strip leading and trailing character from string.
void shutdown_hub(void) const
Shutdown VO Hub.
std::string m_version
The version of the SAMP Standard Profile implemented by the hub.
void disconnect(void)
Unregister client from VO Hub.
virtual int elements(void) const
Return number of GXMLElement children of node.
std::string m_hub_url
The XML-RPC endpoint for communication with the hub.
std::string m_hub_path
Hub path (extracted from XML-RPC endpoint)
FITS file class interface definition.
std::string print(const GChatter &chatter=NORMAL) const
Print VO client information.
bool find_hub(void)
Find VO Hub.
std::string m_secret
Secret Hub key.
void unregister_from_hub(void)
Unregister client from SAMP Hub.
virtual ~GVOClient(void)
Destructor.
VO client class interface definition.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
bool require_hub(void)
Require VO Hub.
std::string m_hub_host
Hub host (extracted from XML-RPC endpoint)
std::string m_client_id
Client identifier.
GXmlElement * element(const int &index)
Return pointer to child element.
SAMP hub class interface definition.
void start(void)
Start Hub.
std::string m_client_key
Private client key.
bool is_connected(void) const
Signals if client is connected to VO Hub.
const std::string & extname(void) const
Return extension name.
#define G_REGISTER_TO_HUB
int response_error_code(const GXml &xml) const
Return response error code.
bool response_is_valid(const GXml &xml) const
Checks if response is valid.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
const std::string & name(void) const
Return VO table name.
std::string tmpnam(void)
Return temporary file name.
bool has_hub(void) const
Signals if client has VO Hub information.
Exception handler interface definition.
GFitsHDU * append(const GFitsHDU &hdu)
Append HDU to FITS file.
VO table class definition.
const GXml & xml(void) const
Return VO table XML file.
std::string m_hub_port
Hub port (extracted from XML-RPC endpoint)
int toint(const std::string &arg)
Convert string into integer value.
void copy_members(const GVOClient &client)
Copy class members.
std::string get_hub_lockfile(void) const
Returns SAMP Hub lockfile URL.
void send_metadata(void) const
Send client metadata to SAMP Hub.
GVOClient(void)
Void constructor.
void connect(void)
Register client at VO Hub.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
GVOClient & operator=(const GVOClient &client)
Assignment operator.
std::string response_error_message(const GXml &xml) const
Return response error message.
Abstract XML node base class interface definition.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
void register_to_hub(void)
Register client at SAMP Hub.
void post_string(const std::string &string) const
Post string content to Hub.
std::string m_hub_id
Hub identifier.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.