1 /*------------------------------------------------------------------------------
  2 Name:      SocketDriver.h
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 Comment:   The client driver for the socket protocol
  6 ------------------------------------------------------------------------------*/
  7 #ifndef _CLIENT_PROTOCOL_SOCKET_SOCKET_DRIVER
  8 #define _CLIENT_PROTOCOL_SOCKET_SOCKET_DRIVER
  9 
 10 #include <util/xmlBlasterDef.h>
 11 #include <string>
 12 #include <vector>
 13 #include <util/MessageUnit.h>
 14 #include <client/I_Callback.h>
 15 #include <client/protocol/I_CallbackServer.h>
 16 #include <client/protocol/I_XmlBlasterConnection.h>
 17 #include <util/XmlBlasterException.h>
 18 #include <util/qos/StatusQosFactory.h>
 19 #include <util/qos/MsgQosFactory.h>
 20 #include <util/key/MsgKeyFactory.h>
 21 #include <util/plugin/I_Plugin.h>
 22 //#include <util/Global.h>    // For org::xmlBlaster::util::ArgsStruct_T argsStruct_
 23 /* Don't include this in this header to avoid dependency: */
 24 //#include <XmlBlasterAccessUnparsed.h> // The C SOCKET client library
 25 
 26 struct XmlBlasterAccessUnparsed;
 27 struct ExceptionStruct;
 28 namespace org {
 29  namespace xmlBlaster {
 30    namespace util {
 31     struct ArgsStruct;
 32 }}}
 33 
 34 namespace org {
 35  namespace xmlBlaster {
 36   namespace client {
 37    namespace protocol {
 38     namespace socket {
 39 
 40    class Dll_Export SocketDriver
 41       : public virtual org::xmlBlaster::client::protocol::I_CallbackServer, 
 42         public virtual org::xmlBlaster::client::protocol::I_XmlBlasterConnection,
 43         public virtual org::xmlBlaster::util::plugin::I_Plugin
 44    {
 45    friend class SocketDriverFactory; // To be able to create a SocketDriver instance
 46 
 47    private:
 48       org::xmlBlaster::util::thread::Mutex mutex_;
 49       std::string instanceName_;
 50       struct ::XmlBlasterAccessUnparsed* connection_;
 51       std::string ME;
 52       struct org::xmlBlaster::util::ArgsStruct *argsStructP_;
 53       org::xmlBlaster::util::Global& global_;
 54       org::xmlBlaster::util::I_Log& log_;
 55       org::xmlBlaster::util::qos::StatusQosFactory statusQosFactory_;
 56       std::string secretSessionId_;
 57       std::string loginName_;
 58       org::xmlBlaster::util::key::MsgKeyFactory msgKeyFactory_;
 59       org::xmlBlaster::util::qos::MsgQosFactory msgQosFactory_;
 60       I_Callback* callbackClient_;
 61 
 62       /**
 63        * frees the resources used. It only frees the resource specified with
 64        * 'true'.
 65        */
 66       void freeResources(bool deleteConnection=true);
 67 
 68       /** 
 69        * Called on polling, try to reconnect to server
 70        */
 71       void reconnectOnIpLevel(void);
 72 
 73       /**
 74        * The only constructor. 
 75        * @param global
 76        * @param isRunning    Feedback is doRun has stopped
 77        * @param instanceName
 78        */
 79       SocketDriver(org::xmlBlaster::util::Global& global, const std::string instanceName);
 80 
 81       SocketDriver(const SocketDriver& socketDriver);
 82 
 83       SocketDriver& operator =(const SocketDriver& socketDriver);
 84 
 85       virtual ~SocketDriver();
 86 
 87    public:
 88       org::xmlBlaster::client::protocol::I_ProgressListener *progressListener_;
 89 
 90       // methods inherited from org::xmlBlaster::client::protocol::I_CallbackServer
 91       void initialize(const std::string& name, org::xmlBlaster::client::I_Callback &client);
 92       std::string getCbProtocol();
 93       std::string getCbAddress();
 94 
 95       org::xmlBlaster::util::I_Log& getLog() const { return log_; }
 96 
 97       /**
 98        * @return 0 if the client has not registered its update()
 99        */
100       I_Callback* getCallbackClient();
101       bool shutdownCb();
102 
103       //bool myUpdate(::MsgUnitArr *msgUnitArr, void *userData,
104       //               ::ExceptionStruct *exception);
105 
106       // methods inherited from org::xmlBlaster::client::protocol::I_XmlBlasterConnection
107       // Note: the const is cast away, the declaration should be changed
108       org::xmlBlaster::util::qos::ConnectReturnQosRef connect(const org::xmlBlaster::util::qos::ConnectQosRef& qos);
109             //throw (org::xmlBlaster::util::ExceptionStruct);
110       bool disconnect(const org::xmlBlaster::util::qos::DisconnectQos& qos);
111       std::string getProtocol();
112       bool shutdown();
113       std::string getLoginName();
114       bool isLoggedIn();
115 
116       std::string ping(const std::string& qos);
117 
118       org::xmlBlaster::client::qos::SubscribeReturnQos subscribe(const org::xmlBlaster::client::key::SubscribeKey& key, const org::xmlBlaster::client::qos::SubscribeQos& qos);
119 
120       std::vector<org::xmlBlaster::util::MessageUnit> get(const org::xmlBlaster::client::key::GetKey& key, const org::xmlBlaster::client::qos::GetQos& qos);
121 
122       std::vector<org::xmlBlaster::client::qos::UnSubscribeReturnQos> unSubscribe(const org::xmlBlaster::client::key::UnSubscribeKey& key, const org::xmlBlaster::client::qos::UnSubscribeQos& qos);
123 
124       org::xmlBlaster::client::qos::PublishReturnQos publish(const org::xmlBlaster::util::MessageUnit& msgUnit);
125 
126       void publishOneway(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr);
127 
128       std::vector<org::xmlBlaster::client::qos::PublishReturnQos> publishArr(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr);
129 
130       std::vector<org::xmlBlaster::client::qos::EraseReturnQos> erase(const org::xmlBlaster::client::key::EraseKey& key, const org::xmlBlaster::client::qos::EraseQos& qos);
131 
132       const std::string& me() { return ME; }
133       org::xmlBlaster::util::Global& getGlobal() { return global_; }
134       org::xmlBlaster::util::I_Log& getLog() { return log_; }
135       org::xmlBlaster::util::key::MsgKeyFactory& getMsgKeyFactory() { return msgKeyFactory_; }
136       org::xmlBlaster::util::qos::MsgQosFactory& getMsgQosFactory() { return msgQosFactory_; }
137 
138       // following methods are not defined in any parent class
139       static std::string usage();
140       // Exception conversion ....
141       org::xmlBlaster::util::XmlBlasterException
142         convertFromSocketException(const struct ::ExceptionStruct & ex) const;
143       static struct ::ExceptionStruct
144         convertToSocketException(org::xmlBlaster::util::XmlBlasterException& ex);
145 
146       /**
147        * Get the name of the plugin. 
148        * @return "SOCKET"
149        * @enforcedBy I_Plugin
150        */
151       std::string getType() { static std::string type = org::xmlBlaster::util::Constants::SOCKET; return type; }
152 
153       /**
154        * Get the version of the plugin. 
155        * @return "1.0"
156        * @enforcedBy I_Plugin
157        */
158       std::string getVersion() { static std::string version = "1.0"; return version; }
159 
160       /**
161        * @see org::xmlBlaster::client::protocol::I_CallbackServer#registerProgressListener
162        */
163       org::xmlBlaster::client::protocol::I_ProgressListener* registerProgressListener(org::xmlBlaster::client::protocol::I_ProgressListener *listener);
164    };
165 
166 }}}}} // namespaces
167 
168 #endif


syntax highlighted by Code2HTML, v. 0.9.1