00001 /*------------------------------------------------------------------------------ 00002 Name: CbServerPluginManager.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Manager to retrieve the correct callback protocol implementation 00006 ------------------------------------------------------------------------------*/ 00007 00017 #include <client/protocol/CbServerPluginManager.h> 00018 #ifdef COMPILE_CORBA_PLUGIN 00019 # include <client/protocol/corba/CorbaDriverFactory.h> 00020 #endif 00021 #ifdef COMPILE_SOCKET_PLUGIN 00022 # include <client/protocol/socket/SocketDriverFactory.h> 00023 #endif 00024 #include <util/Global.h> 00025 00026 namespace org { namespace xmlBlaster { namespace client { namespace protocol { 00027 00028 using namespace std; 00029 using namespace org::xmlBlaster::util; 00030 00031 CbServerPluginManager::CbServerPluginManager(Global& global) 00032 : ME("CbServerPluginManager"), 00033 global_(global), 00034 log_(global.getLog("org.xmlBlaster.client")) 00035 // serverMap_() 00036 { 00037 if (log_.call()) log_.call(ME, "::constructor"); 00038 } 00039 00040 00041 CbServerPluginManager::~CbServerPluginManager() 00042 { 00043 // should be synchronized ... 00044 /* 00045 ServerMap::iterator iter = serverMap_.begin(); 00046 while (iter != serverMap_.end()) { 00047 I_CallbackServer* el = (*iter).second; 00048 serverMap_.erase(iter); 00049 delete el; 00050 iter = serverMap_.begin(); 00051 } 00052 */ 00053 } 00054 00055 I_CallbackServer& CbServerPluginManager::getPlugin(const string& instanceName, const string& type, const string& version) 00056 { 00057 if (log_.call()) log_.call(ME, "::getPlugin"); 00058 if (log_.trace()) 00059 log_.trace(ME, string("getPlugin: type: '") + type + string("', version: '") + version + "' for instance '" + instanceName + "'"); 00060 // string completeName = /*string(instanceName) + "/" + */ type + "/" + version; 00061 if (type == Constants::IOR) { 00062 # ifdef COMPILE_CORBA_PLUGIN 00063 return org::xmlBlaster::client::protocol::corba::CorbaDriverFactory::getFactory(global_).getDriverInstance(&global_); 00064 # endif 00065 } 00066 else if (type == Constants::SOCKET) { 00067 # ifdef COMPILE_SOCKET_PLUGIN 00068 return org::xmlBlaster::client::protocol::socket::SocketDriverFactory::getFactory(global_).getDriverInstance(&global_); 00069 # endif 00070 } 00071 string embeddedMsg = string("plugin: '") + type + 00072 string("' and version: '") + version + 00073 string("' not supported"); 00074 throw XmlBlasterException(RESOURCE_CONFIGURATION_PLUGINFAILED, 00075 "client-c++", 00076 ME + string("::getPlugin"), 00077 "en", 00078 global_.getVersion() + " " + global_.getBuildTimestamp(), 00079 "", 00080 "", 00081 embeddedMsg); 00082 } 00083 00084 00085 00086 void CbServerPluginManager::releasePlugin(const string& instanceName, const string& type, const string& version) 00087 { 00088 if (log_.call()) log_.call(ME, "::releasePlugin"); 00089 if (log_.trace()) 00090 log_.trace(ME, string("releasePlugin: type: '") + type + string("', version: '") + version + "' for instance '" + instanceName + "'"); 00091 if (type == Constants::IOR) { 00092 # ifdef COMPILE_CORBA_PLUGIN 00093 org::xmlBlaster::client::protocol::corba::CorbaDriverFactory::getFactory(global_).killDriverInstance(&global_); 00094 return; 00095 # endif 00096 } 00097 else if (type == Constants::SOCKET) { 00098 # ifdef COMPILE_SOCKET_PLUGIN 00099 org::xmlBlaster::client::protocol::socket::SocketDriverFactory::getFactory(global_).killDriverInstance(&global_); 00100 return; 00101 # endif 00102 } 00103 string embeddedMsg = string("plugin: '") + type + 00104 string("' and version: '") + version + 00105 string("' not supported"); 00106 throw XmlBlasterException(RESOURCE_CONFIGURATION_PLUGINFAILED, 00107 "client-c++", 00108 ME + string("::getPlugin"), 00109 "en", 00110 global_.getVersion() + " " + global_.getBuildTimestamp(), 00111 "", 00112 "", 00113 embeddedMsg); 00114 } 00115 00116 00117 }}}} // namespaces 00118 00119 00120 #ifdef _XMLBLASTER_CLASSTEST 00121 00122 #include <assert.h> 00123 00124 using namespace std; 00125 using namespace org::xmlBlaster::util; 00126 using namespace org::xmlBlaster::client::protocol; 00127 00129 int main(int args, char* argv[]) 00130 { 00131 Global& glob = Global::getInstance(); 00132 glob.initialize(args, argv); 00133 CbServerPluginManager manager = glob.getCbServerPluginManager(); 00134 try { 00135 I_CallbackServer& cbServer = manager.getPlugin(Constants::IOR, "1.0"); 00136 } 00137 catch (XmlBlasterException &ex) { 00138 cout << ex.toXml() << endl; 00139 cout << "exception occured when retrieving a correct callback server" << endl; 00140 assert(0); 00141 } 00142 try { 00143 I_CallbackServer& cbServer = manager.getPlugin(Constants::SOCKET, "1.0"); 00144 cout << "The socket protocol is not implemented yet" << endl; 00145 assert(0); 00146 } 00147 catch (XmlBlasterException &ex) { 00148 cout << ex.toXml() << endl; 00149 cout << "The socket protocol is not implemented yet, so the exception was normal" << endl; 00150 } 00151 00152 return 0; 00153 } 00154 00155 #endif 00156 00157