1 /*------------------------------------------------------------------------------
  2 Name:      CbServerPluginManager.cpp
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 Comment:   Manager to retrieve the correct callback protocol implementation
  6 ------------------------------------------------------------------------------*/
  7 
  8 /**
  9  * It returns the appropriate implementation of the I_CallbackServer
 10  * interface (note that this is a class in c++) for the given protocol.
 11  * with your own lowlevel SOCKET or CORBA coding as well.
 12  *
 13  * @see org.xmlBlaster.client.protocol.I_CallbackServer
 14  * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a>.
 15  */
 16 
 17 #include <client/protocol/CbServerPluginManager.h>
 18 #ifdef COMPILE_CORBA_PLUGIN
 19 #  include <client/protocol/corba/CorbaDriverFactory.h>
 20 #endif
 21 #ifdef COMPILE_SOCKET_PLUGIN
 22 #   include <client/protocol/socket/SocketDriverFactory.h>
 23 #endif
 24 #include <util/Global.h>
 25 
 26 namespace org { namespace xmlBlaster { namespace client { namespace protocol {
 27 
 28 using namespace std;
 29 using namespace org::xmlBlaster::util;
 30 
 31 CbServerPluginManager::CbServerPluginManager(Global& global)
 32    : ME("CbServerPluginManager"),
 33      global_(global),
 34      log_(global.getLog("org.xmlBlaster.client"))
 35 //     serverMap_()
 36 {
 37    if (log_.call()) log_.call(ME, "::constructor");
 38 }
 39 
 40 
 41 CbServerPluginManager::~CbServerPluginManager()
 42 {
 43    // should be synchronized ...
 44 /*
 45    ServerMap::iterator iter = serverMap_.begin();
 46    while (iter != serverMap_.end()) {
 47       I_CallbackServer* el = (*iter).second;
 48       serverMap_.erase(iter);
 49       delete el;
 50       iter = serverMap_.begin();
 51    }
 52 */
 53 }
 54 
 55 I_CallbackServer& CbServerPluginManager::getPlugin(const string& instanceName, const string& type, const string& version)
 56 {
 57    if (log_.call()) log_.call(ME, "::getPlugin");
 58    if (log_.trace())
 59       log_.trace(ME, string("getPlugin: type: '") + type + string("', version: '") + version + "' for instance '" + instanceName + "'");
 60 //   string completeName = /*string(instanceName) + "/" + */ type + "/" + version;
 61    if (type == Constants::IOR) {
 62 #     ifdef COMPILE_CORBA_PLUGIN
 63       return org::xmlBlaster::client::protocol::corba::CorbaDriverFactory::getFactory(global_).getDriverInstance(&global_);
 64 #     endif
 65    }
 66    else if (type == Constants::SOCKET) {
 67 #     ifdef COMPILE_SOCKET_PLUGIN
 68       return org::xmlBlaster::client::protocol::socket::SocketDriverFactory::getFactory(global_).getDriverInstance(&global_);
 69 #     endif
 70    }
 71    string embeddedMsg = string("plugin: '") + type +
 72                         string("' and version: '") + version +
 73                         string("' not supported");
 74    throw XmlBlasterException(RESOURCE_CONFIGURATION_PLUGINFAILED,
 75                     "client-c++",
 76                     ME + string("::getPlugin"),
 77                     "en",
 78                     global_.getVersion() + " " + global_.getBuildTimestamp(),
 79                     "",
 80                     "",
 81                     embeddedMsg);
 82 }
 83 
 84 
 85 
 86 void CbServerPluginManager::releasePlugin(const string& instanceName, const string& type, const string& version)
 87 {
 88    if (log_.call()) log_.call(ME, "::releasePlugin");
 89    if (log_.trace())
 90       log_.trace(ME, string("releasePlugin: type: '") + type + string("', version: '") + version + "' for instance '" + instanceName + "'");
 91    if (type == Constants::IOR) {
 92 #     ifdef COMPILE_CORBA_PLUGIN
 93       org::xmlBlaster::client::protocol::corba::CorbaDriverFactory::getFactory(global_).killDriverInstance(&global_);
 94       return;
 95 #     endif
 96    }
 97    else if (type == Constants::SOCKET) {
 98 #     ifdef COMPILE_SOCKET_PLUGIN
 99       org::xmlBlaster::client::protocol::socket::SocketDriverFactory::getFactory(global_).killDriverInstance(&global_);
100       return;
101 #     endif
102    }
103    string embeddedMsg = string("plugin: '") + type +
104                         string("' and version: '") + version +
105                         string("' not supported");
106    throw XmlBlasterException(RESOURCE_CONFIGURATION_PLUGINFAILED,
107                     "client-c++",
108                     ME + string("::getPlugin"),
109                     "en",
110                     global_.getVersion() + " " + global_.getBuildTimestamp(),
111                     "",
112                     "",
113                     embeddedMsg);
114 }
115 
116 
117 }}}} // namespaces
118 
119 
120 #ifdef _XMLBLASTER_CLASSTEST
121 
122 #include <assert.h>
123 
124 using namespace std;
125 using namespace org::xmlBlaster::util;
126 using namespace org::xmlBlaster::client::protocol;
127 
128 /** For testing: java org.xmlBlaster.authentication.plugins.simple.SecurityQos */
129 int main(int args, char* argv[])
130 {
131     Global& glob = Global::getInstance();
132     glob.initialize(args, argv);
133     CbServerPluginManager manager = glob.getCbServerPluginManager();
134     try {
135        I_CallbackServer& cbServer = manager.getPlugin(Constants::IOR, "1.0");
136     }
137     catch (XmlBlasterException &ex) {
138        cout << ex.toXml() << endl;
139        cout << "exception occured when retrieving a correct callback server" << endl;
140        assert(0);
141     }
142     try {
143        I_CallbackServer& cbServer = manager.getPlugin(Constants::SOCKET, "1.0");
144        cout << "The socket protocol is not implemented yet" << endl;
145        assert(0);
146     }
147     catch (XmlBlasterException &ex) {
148        cout << ex.toXml() << endl;
149        cout << "The socket protocol is not implemented yet, so the exception was normal" << endl;
150     }
151 
152    return 0;
153 }
154 
155 #endif


syntax highlighted by Code2HTML, v. 0.9.1