📄 corbadriver.cpp
字号:
/*------------------------------------------------------------------------------Name: CorbaDriver.cppProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment: The client driver for the corba protocol------------------------------------------------------------------------------*/#include <client/protocol/corba/CorbaDriver.h>#include <util/ErrorCode.h>#include <util/XmlBlasterException.h>#include <util/Global.h>#include <util/lexical_cast.h>namespace org { namespace xmlBlaster { namespace client { namespace protocol { namespace corba {using namespace std;using namespace org::xmlBlaster::util;using namespace org::xmlBlaster::util::qos;using namespace org::xmlBlaster::util::thread;using namespace org::xmlBlaster::client::protocol;using namespace org::xmlBlaster::client::qos;using namespace org::xmlBlaster::client::key;void CorbaDriver::freeResources(bool deleteConnection, bool deleteCallback){ if (deleteConnection) { delete connection_; connection_ = NULL; } if (deleteCallback) { delete defaultCallback_; defaultCallback_ = NULL; }}#define _COMM_TRY try {#define _COMM_CATCH(methodName, deleteConnection, deleteCallback) \ } \ catch(serverIdl::XmlBlasterException &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw convertFromCorbaException(ex); \ } \ catch(const CosNaming::NamingContext::CannotProceed &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(COMMUNICATION_NOCONNECTION, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", to_string(ex)); \ } \ catch(const CosNaming::NamingContext::InvalidName &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(COMMUNICATION_NOCONNECTION, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", to_string(ex)); \ } \ catch(const CosNaming::NamingContext::AlreadyBound &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(COMMUNICATION_NOCONNECTION, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", to_string(ex)); \ } \ catch(const CosNaming::NamingContext::NotEmpty &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(COMMUNICATION_NOCONNECTION, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", to_string(ex)); \ } \ catch(const CosNaming::NamingContext::NotFound &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(COMMUNICATION_NOCONNECTION, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", to_string(ex)); \ } \ catch(const CORBA::Exception &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(COMMUNICATION_NOCONNECTION, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", to_string(ex)); \ } \ catch(const XmlBlasterException &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw ex; \ } \ catch(const XmlBlasterException *ex) { \ freeResources(deleteConnection, deleteCallback); \ throw ex; \ } \ catch(const exception &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(INTERNAL_UNKNOWN, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", \ string("type='exception', msg='") + ex.what() + "'"); \ } \ catch(const string &ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(INTERNAL_UNKNOWN, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", \ string("type='string', msg='") + ex + "'"); \ } \ catch(const char *ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(INTERNAL_UNKNOWN, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", \ string("type='char*', msg='") + ex + "'"); \ } \ catch(int ex) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(INTERNAL_UNKNOWN, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp(),\ "", "", \ string("type='int', msg='") + lexical_cast<std::string>(ex) + "'"); \ } \ catch (...) { \ freeResources(deleteConnection, deleteCallback); \ throw XmlBlasterException(INTERNAL_UNKNOWN, \ "unknown node", ME + string(methodName), "en", \ global_.getVersion() + " " + global_.getBuildTimestamp()); \ }/*static bool dummy;CorbaDriver::CorbaDriver() : doRun_(dummy), isRunning_(dummy), mutex_(), count_(0), ME("CorbaDriver"), global_(Global::getInstance()), log_(global_.getLog("org.xmlBlaster.client.protocol.corba")), statusQosFactory_(global_), { connection_ = NULL; defaultCallback_ = NULL; _COMM_TRY connection_ = new CorbaConnection(global_, false); _COMM_CATCH("::Constructor", true, false)}*/CorbaDriver::CorbaDriver(const CorbaDriver& corbaDriver) : mutex_(corbaDriver.mutex_), ME("CorbaDriver"), global_(corbaDriver.global_), log_(corbaDriver.log_), statusQosFactory_(corbaDriver.global_), orbIsThreadSafe_(ORB_IS_THREAD_SAFE){ // no instantiation of these since this should never be invoked (just to make it private) connection_ = NULL; defaultCallback_ = NULL; if (log_.call()) log_.call("CorbaDriver", string("Constructor orbIsThreadSafe_=") + lexical_cast<std::string>(orbIsThreadSafe_));}CorbaDriver& CorbaDriver::operator =(const CorbaDriver& /*corbaDriver*/){ return *this;}CorbaDriver::CorbaDriver(Global& global, Mutex& mutex, const string instanceName, CORBA::ORB_ptr orb) : mutex_(mutex), ME(string("CorbaDriver-") + instanceName), global_(global), log_(global.getLog("org.xmlBlaster.client.protocol.corba")), statusQosFactory_(global), orbIsThreadSafe_(ORB_IS_THREAD_SAFE){ connection_ = NULL; defaultCallback_ = NULL; if (log_.call()) log_.call("CorbaDriver", string("getInstance for ") + instanceName + " orbIsThreadSafe_=" + lexical_cast<std::string>(orbIsThreadSafe_)); _COMM_TRY connection_ = new CorbaConnection(global_, orb); _COMM_CATCH("::Constructor", true, false)}CorbaDriver::~CorbaDriver(){ if (log_.call()) log_.call(ME, "~CorbaDriver()"); try {// delete defaultCallback_; // Is a memory leak, but we need to track down the valgrind issue first delete connection_; } catch (...) { }}void CorbaDriver::initialize(const string& name, I_Callback &client){ Lock lock(mutex_, orbIsThreadSafe_); _COMM_TRY// if (defaultCallback_ != NULL) delete defaultCallback_; defaultCallback_ = NULL; defaultCallback_ = new DefaultCallback(global_, name, &client, 0);// if (connection_ != NULL) delete connection_;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -