// UniqueIdGenerator.cxx #include "dataset_id/UniqueIdGenerator.h" #include #include #include using std::string; using std::map; using std::ostream; using std::cerr; using std::endl; typedef UniqueIdGenerator::Create Create; typedef map CreateMap; //********************************************************************** // Local definitions. //********************************************************************** namespace { //********************************************************************** // Creator map. CreateMap& cmap() { static CreateMap cm; return cm; } //********************************************************************** // Connection string. string& uidconnection() { static string conn; return conn; } //********************************************************************** } // end unnamed namespace //********************************************************************** // Static functions. //********************************************************************** // Find a generator. UniqueIdGenerator* UniqueIdGenerator::find_generator(string context) { // Find name. string::size_type ipos = uidconnection().find(":"); if ( ipos == string::npos ) return 0; string name = uidconnection().substr(0, ipos); // Find creator. CreateMap::const_iterator icre = cmap().find(name); if ( icre == cmap().end() ) return 0; // Find generator. Create cre = icre->second; if ( cre == 0 ) return 0; return cre(context, uidconnection()); } //********************************************************************** // Register a creator. int UniqueIdGenerator::register_creator(string name, Create pfun) { CreateMap::const_iterator icre = cmap().find(name); if ( icre != cmap().end() ) { Create cre = icre->second; if ( pfun == cre ) return 0; return 1; } cmap()[name] = pfun; return 0; } //********************************************************************** // Set the generator. int UniqueIdGenerator::set_generator(string conn) { // Check connection is not yet defined. if ( uidconnection().size() ) return 1; // Check connection name. if ( conn.size() == 0 ) return 2; string::size_type ipos = conn.find(":"); if ( ipos == string::npos ) return 3; string name = conn.substr(0, ipos); CreateMap::const_iterator icre = cmap().find(name); if ( icre == cmap().end() ) { // Temporary patch to load library for unique ID web service. if ( name == "WsClientUniqueIdGenerator" ) { std::vector pkgs; pkgs.push_back("gsoap"); pkgs.push_back("globus_gss_assist_gcc32dbg"); pkgs.push_back("globus_common_gcc32dbg"); pkgs.push_back("gsoap_gsi"); pkgs.push_back("dial_ws"); pkgs.push_back("dial_ws_uid"); for ( std::vector::const_iterator ipkg=pkgs.begin(); ipkg!=pkgs.end(); ++ipkg ) { string lib = "lib" + *ipkg + ".so"; void* handle = dlopen(lib.c_str(), RTLD_NOW|RTLD_GLOBAL); if ( handle == 0 ) { cerr << "UniqueId: Unable to open library " << lib << endl; cerr << "UniqueId: " << dlerror() << endl; return 5; } } } icre = cmap().find(name); } if ( icre == cmap().end() ) return 4; uidconnection() = conn; return 0; } //********************************************************************** // Return the connection string. string UniqueIdGenerator::connection() { return uidconnection(); } //********************************************************************** // Member functions. //********************************************************************** // Constructor. UniqueIdGenerator::UniqueIdGenerator() { } //********************************************************************** // Destructor. UniqueIdGenerator::~UniqueIdGenerator() { } //********************************************************************** // Free functions. //********************************************************************** // Output stream. ostream& operator<<(ostream& lhs, const UniqueIdGenerator& rhs) { return rhs.ostr(lhs); } //**********************************************************************