client/protocol/socket/SocketDriver.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      SocketDriver.h
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   The client driver for the socket protocol
00006 ------------------------------------------------------------------------------*/
00007 #ifndef _CLIENT_PROTOCOL_SOCKET_SOCKET_DRIVER
00008 #define _CLIENT_PROTOCOL_SOCKET_SOCKET_DRIVER
00009 
00010 #include <util/xmlBlasterDef.h>
00011 #include <string>
00012 #include <vector>
00013 #include <util/MessageUnit.h>
00014 #include <client/I_Callback.h>
00015 #include <client/protocol/I_CallbackServer.h>
00016 #include <client/protocol/I_XmlBlasterConnection.h>
00017 #include <util/XmlBlasterException.h>
00018 #include <util/qos/StatusQosFactory.h>
00019 #include <util/qos/MsgQosFactory.h>
00020 #include <util/key/MsgKeyFactory.h>
00021 #include <util/plugin/I_Plugin.h>
00022 //#include <util/Global.h>    // For org::xmlBlaster::util::ArgsStruct_T argsStruct_
00023 /* Don't include this in this header to avoid dependency: */
00024 //#include <XmlBlasterAccessUnparsed.h> // The C SOCKET client library
00025 
00026 struct XmlBlasterAccessUnparsed;
00027 struct ExceptionStruct;
00028 namespace org {
00029  namespace xmlBlaster {
00030    namespace util {
00031     struct ArgsStruct;
00032 }}}
00033 
00034 namespace org {
00035  namespace xmlBlaster {
00036   namespace client {
00037    namespace protocol {
00038     namespace socket {
00039 
00040    class Dll_Export SocketDriver
00041       : public virtual org::xmlBlaster::client::protocol::I_CallbackServer, 
00042         public virtual org::xmlBlaster::client::protocol::I_XmlBlasterConnection,
00043         public virtual org::xmlBlaster::util::plugin::I_Plugin
00044    {
00045    friend class SocketDriverFactory; // To be able to create a SocketDriver instance
00046 
00047    private:
00048       org::xmlBlaster::util::thread::Mutex mutex_;
00049       std::string instanceName_;
00050       struct ::XmlBlasterAccessUnparsed* connection_;
00051       std::string ME;
00052       struct org::xmlBlaster::util::ArgsStruct *argsStructP_;
00053       org::xmlBlaster::util::Global& global_;
00054       org::xmlBlaster::util::I_Log& log_;
00055       org::xmlBlaster::util::qos::StatusQosFactory statusQosFactory_;
00056       std::string secretSessionId_;
00057       std::string loginName_;
00058       org::xmlBlaster::util::key::MsgKeyFactory msgKeyFactory_;
00059       org::xmlBlaster::util::qos::MsgQosFactory msgQosFactory_;
00060       I_Callback* callbackClient_;
00061 
00066       void freeResources(bool deleteConnection=true);
00067 
00071       void reconnectOnIpLevel(void);
00072 
00079       SocketDriver(org::xmlBlaster::util::Global& global, const std::string instanceName);
00080 
00081       SocketDriver(const SocketDriver& socketDriver);
00082 
00083       SocketDriver& operator =(const SocketDriver& socketDriver);
00084 
00085       virtual ~SocketDriver();
00086 
00087    public:
00088       org::xmlBlaster::client::protocol::I_ProgressListener *progressListener_;
00089 
00090       // methods inherited from org::xmlBlaster::client::protocol::I_CallbackServer
00091       void initialize(const std::string& name, org::xmlBlaster::client::I_Callback &client);
00092       std::string getCbProtocol();
00093       std::string getCbAddress();
00094 
00095       org::xmlBlaster::util::I_Log& getLog() const { return log_; }
00096 
00100       I_Callback* getCallbackClient();
00101       bool shutdownCb();
00102 
00103       //bool myUpdate(::MsgUnitArr *msgUnitArr, void *userData,
00104       //               ::ExceptionStruct *exception);
00105 
00106       // methods inherited from org::xmlBlaster::client::protocol::I_XmlBlasterConnection
00107       // Note: the const is cast away, the declaration should be changed
00108       org::xmlBlaster::util::qos::ConnectReturnQosRef connect(const org::xmlBlaster::util::qos::ConnectQosRef& qos);
00109             //throw (org::xmlBlaster::util::ExceptionStruct);
00110       bool disconnect(const org::xmlBlaster::util::qos::DisconnectQos& qos);
00111       std::string getProtocol();
00112       bool shutdown();
00113       std::string getLoginName();
00114       bool isLoggedIn();
00115 
00116       std::string ping(const std::string& qos);
00117 
00118       org::xmlBlaster::client::qos::SubscribeReturnQos subscribe(const org::xmlBlaster::client::key::SubscribeKey& key, const org::xmlBlaster::client::qos::SubscribeQos& qos);
00119 
00120       std::vector<org::xmlBlaster::util::MessageUnit> get(const org::xmlBlaster::client::key::GetKey& key, const org::xmlBlaster::client::qos::GetQos& qos);
00121 
00122       std::vector<org::xmlBlaster::client::qos::UnSubscribeReturnQos> unSubscribe(const org::xmlBlaster::client::key::UnSubscribeKey& key, const org::xmlBlaster::client::qos::UnSubscribeQos& qos);
00123 
00124       org::xmlBlaster::client::qos::PublishReturnQos publish(const org::xmlBlaster::util::MessageUnit& msgUnit);
00125 
00126       void publishOneway(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr);
00127 
00128       std::vector<org::xmlBlaster::client::qos::PublishReturnQos> publishArr(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr);
00129 
00130       std::vector<org::xmlBlaster::client::qos::EraseReturnQos> erase(const org::xmlBlaster::client::key::EraseKey& key, const org::xmlBlaster::client::qos::EraseQos& qos);
00131 
00132       const std::string& me() { return ME; }
00133       org::xmlBlaster::util::Global& getGlobal() { return global_; }
00134       org::xmlBlaster::util::I_Log& getLog() { return log_; }
00135       org::xmlBlaster::util::key::MsgKeyFactory& getMsgKeyFactory() { return msgKeyFactory_; }
00136       org::xmlBlaster::util::qos::MsgQosFactory& getMsgQosFactory() { return msgQosFactory_; }
00137 
00138       // following methods are not defined in any parent class
00139       static std::string usage();
00140       // Exception conversion ....
00141       org::xmlBlaster::util::XmlBlasterException
00142         convertFromSocketException(const struct ::ExceptionStruct & ex) const;
00143       static struct ::ExceptionStruct
00144         convertToSocketException(org::xmlBlaster::util::XmlBlasterException& ex);
00145 
00151       std::string getType() { static std::string type = org::xmlBlaster::util::Constants::SOCKET; return type; }
00152 
00158       std::string getVersion() { static std::string version = "1.0"; return version; }
00159 
00163       org::xmlBlaster::client::protocol::I_ProgressListener* registerProgressListener(org::xmlBlaster::client::protocol::I_ProgressListener *listener);
00164    };
00165 
00166 }}}}} // namespaces
00167 
00168 #endif