// WsClientGenericSelectionCatalog.cxx #include "dataset_util/Text.h" #include "dataset_xml/XmlParser.h" #include "dial_ws_selection/WsClientGenericSelectionCatalog.h" #include "../gsoap/dial_ws_selectionH.h" using std::string; using std::cerr; using std::endl; using std::vector; using dset::SqlQuery; using dset::GenericSelectionCatalog; using dial::WsClientGenericSelectionCatalog; using namespace dial_ws_selection; typedef GenericSelectionCatalog::size_type size_type; typedef GenericSelectionCatalog::Name Name; typedef GenericSelectionCatalog::NameList NameList; typedef GenericSelectionCatalog::Id Id; typedef GenericSelectionCatalog::Attributes Attributes; typedef vector AttributeList; //********************************************************************** // Local definitions. //********************************************************************** namespace { //********************************************************************** // Creator. // We expect connection of the form // @WS: // Also allowed are extra accessors, e.g. // @@WS: GenericSelectionCatalog* create(string type, string conn) { // Strip off the last accessor. string::size_type ipos = conn.rfind("@"); string accessor = conn.substr(ipos+1); if ( accessor.size() < 5 ) return 0; // Extract address (server:port) from accessor. if ( accessor.substr(0,3) != "WS:" ) return 0; string url = accessor.substr(3); // Keep the remaining prefix as the new connection. string newconn; if ( ipos > 1 ) { newconn = conn.substr(0, ipos); } // Create the client catalog. GenericSelectionCatalog* pcat = new WsClientGenericSelectionCatalog(url, type, newconn, true); return pcat; } //********************************************************************** // Register the creator. int wsgr_creator_stat = GenericSelectionCatalog::register_creator("WS", create); //********************************************************************** } // end unnamed namespace //********************************************************************** // Constructors and destructor. //********************************************************************** // Constructor. WsClientGenericSelectionCatalog::WsClientGenericSelectionCatalog( string url, string type, string conn, bool usegsi) : m_client(url, usegsi), m_type(type), m_conn(conn) { } //********************************************************************** // Catalog methods. //********************************************************************** // Validity. bool WsClientGenericSelectionCatalog::is_valid() const { bool res; int sstat = soap_call_dial__selection_is_valid( psoap(), curl(), "", type(), conn(), res ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return false; } clean_soap(); return res; } //********************************************************************** // Catalog type. Name WsClientGenericSelectionCatalog::catalog_type() const { return m_type; } //********************************************************************** // ID encoding. Name WsClientGenericSelectionCatalog::id_encoding() const { Name res; int sstat = soap_call_dial__selection_id_encoding( psoap(), curl(), "", type(), conn(), res ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return ""; } clean_soap(); return res; } //********************************************************************** // Schema. NameList WsClientGenericSelectionCatalog::schema() const { dial__StringVectorResponse wres; int sstat = soap_call_dial__selection_schema( psoap(), curl(), "", type(), conn(), wres ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return NameList(); } NameList res = *wres.pvec; clean_soap(); return res; } //********************************************************************** // Has name. bool WsClientGenericSelectionCatalog::has_name(Name name) const { bool res; int sstat = soap_call_dial__selection_has_name( psoap(), curl(), "", type(), conn(), name, res ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return false; } clean_soap(); return res; } //********************************************************************** // Attributes. Attributes WsClientGenericSelectionCatalog:: attributes(Name name) const { dial__AttributeVectorResponse wres; Attributes res; int sstat = soap_call_dial__selection_attributes( psoap(), curl(), "", type(), conn(), name, wres ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return res; } if ( wres.pvec == 0 ) { return res; } for ( size_t iatt=0; iattsize(); ++iatt ) { string name = (*wres.pvec)[iatt].name; string value = (*wres.pvec)[iatt].value; res[name] = value; } clean_soap(); return res; } //********************************************************************** // ID. Id WsClientGenericSelectionCatalog::id(Name name) const { Id res; int sstat = soap_call_dial__selection_id( psoap(), curl(), "", type(), conn(), name, res ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return ""; } clean_soap(); return res; } //********************************************************************** // Size. size_type WsClientGenericSelectionCatalog::size() const { int wres; int sstat = soap_call_dial__selection_size( psoap(), curl(), "", type(), conn(), wres ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return 0; } clean_soap(); return wres; } //********************************************************************** // Query. NameList WsClientGenericSelectionCatalog:: query(SqlQuery query, size_type maxent) const { int wmaxent = maxent; dial__StringVectorResponse wres; int sstat = soap_call_dial__selection_query( psoap(), curl(), "", type(), conn(), query.to_string(), wmaxent, wres ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return NameList(); } if ( wres.pvec == 0 ) { //cerr << "WsClientGenericSelectionCatalog::query: " // << "Service returned a null pointer" << endl; return NameList(); } NameList res = *wres.pvec; clean_soap(); return res; } //********************************************************************** // Query count. size_type WsClientGenericSelectionCatalog:: query_count(SqlQuery query) const { int wres; int sstat = soap_call_dial__selection_query_count( psoap(), curl(), "", type(), conn(), query.to_string(), wres ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return 0; } clean_soap(); return wres; } //********************************************************************** // Insert. int WsClientGenericSelectionCatalog:: insert(Name name, const Attributes& atts) { AttributeList vatts(atts.size()); size_t ivatt = 0; for ( Attributes::const_iterator iatt=atts.begin(); iatt!=atts.end(); ++iatt ) { vatts[ivatt].name = iatt->first; vatts[ivatt].value = iatt->second; ++ivatt; } dial__AttributeVector watts; watts.pvec = &vatts; int res; int sstat = soap_call_dial__selection_insert( psoap(), curl(), "", type(), conn(), name, &watts, res ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return 101; } clean_soap(); return res; } //********************************************************************** // Update. int WsClientGenericSelectionCatalog:: update(Name name, const Attributes& atts) { AttributeList vatts(atts.size()); size_t ivatt = 0; for ( Attributes::const_iterator iatt=atts.begin(); iatt!=atts.end(); ++iatt ) { vatts[ivatt].name = iatt->first; vatts[ivatt].value = iatt->second; ++ivatt; } dial__AttributeVector watts; watts.pvec = &vatts; int res; int sstat = soap_call_dial__selection_update( psoap(), curl(), "", type(), conn(), name, &watts, res ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return 101; } clean_soap(); return res; } //********************************************************************** // Remove. int WsClientGenericSelectionCatalog::remove(Name name) { int res; int sstat = soap_call_dial__selection_remove( psoap(), curl(), "", type(), conn(), name, res ); if ( sstat != SOAP_OK ) { soap_print_fault(psoap(), stderr); clean_soap(); return 101; } clean_soap(); return res; } //********************************************************************** // Service methods. //********************************************************************** // Return the gsoap structure. soap* WsClientGenericSelectionCatalog::psoap() const { return m_client.psoap(); } //********************************************************************** // Return the URL. const char* WsClientGenericSelectionCatalog::curl() const { return m_client.curl(); } //********************************************************************** // Return the catalog type. const char* WsClientGenericSelectionCatalog::type() const { return m_type.c_str(); } //********************************************************************** // Return the connection string. const char* WsClientGenericSelectionCatalog::conn() const { return m_conn.c_str(); } //********************************************************************** // Terminate. void WsClientGenericSelectionCatalog::terminate_service() const { return m_client.terminate_service(); } //********************************************************************** // Cleanup gsoap. void WsClientGenericSelectionCatalog::clean_soap() const { m_client.clean_soap(); } //**********************************************************************