client/protocol/corba/CorbaConnection.h

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------
00002 Name:      CorbaConnection.h
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Helper to connect to xmlBlaster: for now a simplified version 
00006            without caching and without failsafe mode.
00007 Author:    <Michele Laghi> laghi@swissinfo.org
00008 -----------------------------------------------------------------------------*/
00009 
00010 #ifndef _CLIENT_PROTOCOL_CORBA_CORBACONNECTION_H
00011 #define _CLIENT_PROTOCOL_CORBA_CORBACONNECTION_H
00012 
00013 #include <util/xmlBlasterDef.h>
00014 
00015 #include <string>
00016 #include <vector>
00017 #include <fstream>
00018 #include <client/protocol/corba/DefaultCallback.h>
00019 #include <util/I_Log.h>
00020 #include <client/protocol/corba/NameServerControl.h>
00021 #include <util/qos/address/CallbackAddress.h>
00022 #include <util/MessageUnit.h>
00023 #include <util/qos/ConnectQosFactory.h>
00024 #include <util/qos/MsgQosFactory.h>
00025 #include <util/key/MsgKeyFactory.h>
00026 
00027 #include <client/protocol/corba/CompatibleCorba.h>  // client side headers
00028 #include COSNAMING
00029 
00030  // org::xmlBlaster::util::qos::ConnectQos + org::xmlBlaster::util::qos::ConnectReturnQos
00031 
00032 namespace org {
00033  namespace xmlBlaster {
00034   namespace client {
00035    namespace protocol {
00036     namespace corba {
00037 
00038    class Dll_Export CorbaConnection {
00039       
00040    private:
00041       
00042       std::string me() const {
00043          return std::string("CorbaConnection");
00044       }
00045       /* static*/ CORBA::ORB_ptr           orb_;
00046       /*static*/ PortableServer::POA_ptr  poa_;
00047       NameServerControl*              nameServerControl_;
00048       authenticateIdl::AuthServer_ptr authServer_;
00049       serverIdl::Server_ptr           xmlBlaster_;
00050       clientIdl::BlasterCallback_ptr  callback_;
00051       std::string                          loginName_;
00052       std::string                          passwd_;
00053       int                             numLogins_;
00054       DefaultCallback*                defaultCallback_;
00055       org::xmlBlaster::util::qos::ConnectReturnQosRef connectReturnQos_;
00056       std::string                          sessionId_;
00057       std::string                          xmlBlasterIOR_;
00058       std::string                          callbackIOR_;
00059       org::xmlBlaster::util::Global&       global_;
00060       /* mutable */ org::xmlBlaster::util::I_Log&     log_;
00061       org::xmlBlaster::util::key::MsgKeyFactory msgKeyFactory_;
00062       org::xmlBlaster::util::qos::MsgQosFactory msgQosFactory_;
00063 
00064    public:
00080       CorbaConnection(org::xmlBlaster::util::Global& global, CORBA::ORB_ptr orb=NULL);
00081 
00082       ~CorbaConnection();
00083 
00084       std::string getAddress() const;
00085 
00086       std::string getCbAddress() const;
00087 
00092       bool orbPerformWork() {
00093          if (orb_ != NULL) {
00094             bool ret = (orb_->work_pending() != 0);
00095             if (ret) orb_->perform_work();
00096             return ret;
00097          }
00098          else
00099             return false;
00100       }
00101 
00102 
00106       void run() {
00107          if (orb_ != NULL)
00108             orb_->run();
00109       }
00110     
00111 
00112       /*
00113        * Accessing the xmlBlaster handle.
00114        * @return Server
00115        * @exception if not logged in
00116       serverIdl::Server_ptr getXmlBlaster();
00117        */
00118       
00119 private:
00128       void initNamingService();
00129 
00130 public:
00154       void initAuthenticationService();
00155 
00159        org::xmlBlaster::util::qos::ConnectReturnQosRef connect(const org::xmlBlaster::util::qos::ConnectQosRef& connectQos);
00160 
00165        bool disconnect(const std::string& qos="");
00166 
00170        bool shutdown();
00171 
00172        bool shutdownCb();
00173 
00178       void createCallbackServer(POA_clientIdl::BlasterCallback *implObj);
00179 
00180 
00185       const std::string &getLoginName() const {
00186          return loginName_;
00187       }
00188       
00189       
00193       bool isLoggedIn() {
00194          if (CORBA::is_nil(authServer_)) initAuthenticationService();
00195          return (!CORBA::is_nil(xmlBlaster_ /*.in()*/ ));
00196       }
00197       
00198       
00205       std::string subscribe(const std::string &xmlKey, const std::string &qos=std::string("<qos/>"));
00206       
00207  
00208       std::vector<std::string> unSubscribe(const std::string &xmlKey, const std::string &qos=std::string("<qos/>"));
00209       
00210       
00221       std::string publish(const serverIdl::MessageUnit &msgUnit);
00222 
00232       std::string publish(const util::MessageUnit &msgUnitUtil);
00233       
00244       std::vector<std::string> publishArr(const std::vector<util::MessageUnit> &msgVec);
00245      
00249       serverIdl::XmlTypeArr* publishArr(const serverIdl::MessageUnitArr& msgUnitArr);
00250 
00260       void publishOneway(const std::vector<util::MessageUnit>& msgVec);
00261 
00267       void publishOneway(const serverIdl::MessageUnitArr& msgUnitArr);
00268 
00272       std::vector<std::string> erase(const std::string &xmlKey, const std::string &qos=std::string("<qos/>"));
00273 
00274       
00283       std::vector<util::MessageUnit> get(const std::string &xmlKey, const std::string &qos=std::string("<qos/>"));
00284 
00285       //serverIdl::MessageUnitArr* get(const std::string &xmlKey, const std::string &qos);
00286       
00287       
00298       std::string ping(const std::string &qos=std::string("<qos/>"));
00299 
00303       void copyToCorba(serverIdl::MessageUnit &dest, const util::MessageUnit &src) const;
00304 
00308       void copyToCorba(serverIdl::MessageUnitArr_var &units, const std::vector<util::MessageUnit> &msgVec) const;
00309 
00310       void copyFromCorba(std::vector<util::MessageUnit> &vecArr, serverIdl::MessageUnitArr_var &units);
00311 
00318       static std::string usage();
00319    
00320    }; // class CorbaConnection
00321 }}}}} // namespace
00322 
00323 
00324 #endif
00325 
00326