// WsClientUniqueIdGenerator.cxx #include "dial_ws_uid/WsClientUniqueIdGenerator.h" #include #include "dataset_util/getcwd.h" #include "../gsoap/dial_ws_uidH.h" #include "dial_ws/dial_ws_flags.h" #ifdef WITH_GSI #define GLOBUS_DEBUG_H #include "gsi.h" #endif using std::string; using std::ostream; using std::cout; using std::cerr; using std::endl; using dial::WsClientUniqueIdGenerator; using dial_ws_uid::soap_call_dial__uid_next; using dial_ws_uid::soap_call_dial__uid_close; using dial_ws_uid::soap_call_dial__uid_is_valid; using dial_ws_uid::soap_call_dial__uid_is_global; using dial_ws_uid::soap_call_dial__uid_next; using dial_ws_uid::soap_call_dial__terminate; //********************************************************************** // Local definitions. //********************************************************************** namespace { // Register creator. //********************************************************************** // Creator. // The colon separator makes things difficult because it is also used in // URL's. We assume the service address has one or two colons. UniqueIdGenerator* create(string context, string conn) { // Decompose the connection string. Text::WordList words = Text::split(conn, ":", false); Text::WordList::size_type nword = words.size(); if ( nword < 4 ) return 0; if ( nword > 5 ) return 0; string type = words[0]; string url1 = words[1]; string url2 = words[2]; string url3 = words[3]; string susegsi = words[nword-1]; if ( type != "WsClientUniqueIdGenerator" ) return 0; if ( ! url1.size() ) return 0; if ( ! url2.size() ) return 0; string url = url1 + ":" + url2; if ( nword == 5 ) { if ( ! url3.size() ) return 0; url += ":"; url += url3; } bool usegsi = susegsi == "true"; return new WsClientUniqueIdGenerator(context, url, usegsi); } //********************************************************************** int stat_WsClientUniqueIdGenerator = UniqueIdGenerator:: register_creator("WsClientUniqueIdGenerator", create); //********************************************************************** // Function to ping the service. bool ping(void* pobj) { WsClientUniqueIdGenerator* pcli = (WsClientUniqueIdGenerator*) pobj; return pcli->is_valid(); } //********************************************************************** } // end unnamed namespace //********************************************************************** // Methods. //********************************************************************** // Constructor. WsClientUniqueIdGenerator:: WsClientUniqueIdGenerator(string context, string url, bool usegsi) : m_context(context), m_ws(url, usegsi) { m_ws.set_ping_callback(ping, this); } //********************************************************************** WsClientUniqueIdGenerator::~WsClientUniqueIdGenerator() { } //********************************************************************** // Next ID. UniqueId WsClientUniqueIdGenerator::next() { string pre = "WsClientUniqueIdGenerator::next: "; if ( ! m_ws.is_valid() ) return UniqueId(); string sid; int sstat = soap_call_dial__uid_next(m_ws.psoap(), m_ws.curl(), "", m_context, sid); if ( sstat != 0 ) { cerr << pre << "WS call failed" << endl; cerr << " Thread: " << pthread_self() << endl; cerr << " cwd: " << getcwd() << endl; soap_print_fault(m_ws.psoap(), stderr); } UniqueId id(sid); m_ws.clean_soap(); return id; } //********************************************************************** // Close. int WsClientUniqueIdGenerator::close() { if ( ! m_ws.is_valid() ) return 91; int stat; int sstat = soap_call_dial__uid_close(m_ws.psoap(), m_ws.curl(), "", m_context, stat); if ( sstat != SOAP_OK ) { soap_print_fault(m_ws.psoap(), stderr); stat = 92; } m_ws.clean_soap(); return stat; } //********************************************************************** // Validity. bool WsClientUniqueIdGenerator::is_valid() const { if ( ! m_ws.is_valid() ) return false; bool stat; int sstat = soap_call_dial__uid_is_valid(m_ws.psoap(), m_ws.curl(), "", m_context, stat); if ( sstat != SOAP_OK ) { soap_print_fault(m_ws.psoap(), stderr); stat = false; } m_ws.clean_soap(); return stat; } //********************************************************************** // Global. bool WsClientUniqueIdGenerator::is_global() const { if ( ! m_ws.is_valid() ) return false; bool stat; int sstat = soap_call_dial__uid_is_global(m_ws.psoap(), m_ws.curl(), "", m_context, stat); if ( sstat != SOAP_OK ) { soap_print_fault(m_ws.psoap(), stderr); stat = false; } return stat; m_ws.clean_soap(); } //********************************************************************** // Context. string WsClientUniqueIdGenerator::context() const { return m_context; } //********************************************************************** // Terminate service. void WsClientUniqueIdGenerator::terminate_service() const { int rstat; soap_call_dial__terminate(m_ws.psoap(), m_ws.curl(), "", rstat); m_ws.clean_soap(); } //********************************************************************** // Output stream. ostream& WsClientUniqueIdGenerator::ostr(ostream& str) const { if ( ! is_valid() ) str << "Invalid "; str << "WS " << context() << " ID generator connected to " << endl; str << " " << m_ws.curl(); return str; } //**********************************************************************