client/XmlBlasterAccess.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      XmlBlasterAccess.h
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 #ifndef _CLIENT_XMLBLASTERACCESS_H
00007 #define _CLIENT_XMLBLASTERACCESS_H
00008 
00009 #include <util/xmlBlasterDef.h>
00010 #include <util/Global.h>
00011 #include <util/qos/ConnectQos.h>
00012 #include <client/I_ConnectionProblems.h>
00013 #include <client/I_Callback.h>
00014 #include <util/thread/ThreadImpl.h>
00015 #include <util/dispatch/I_PostSendListener.h>
00016 #include <util/ReferenceCounterBase.h>
00017 #include <util/ReferenceHolder.h>
00018 #include <string>
00019 #include <vector>
00020 #include <map>
00021 
00022 /* The following comment is used by doxygen for the main html page: */
00048 // Note: I_ConnectionProblems.h includes I_ConnectionsHandler.h includes I_XmlBlasterConnection.h
00049 //       which includes all EraseQos, SubscribeKey etc.
00050 //       -> We could try to avoid this by forward declaration, but all cpp files must
00051 //          then include them thereselves.
00052 
00053 // Declare classes without the need to include them in this header file
00054 namespace org { namespace xmlBlaster { namespace util {
00055    class MessageUnit;
00056 }}}
00057 namespace org { namespace xmlBlaster { namespace util { namespace dispatch {
00058    class DispatchManager;
00059    class ConnectionsHandler;
00060 }}}}
00061 namespace org { namespace xmlBlaster { namespace client { namespace protocol {
00062    class I_CallbackServer;
00063 }}}}
00064 
00065 namespace org { namespace xmlBlaster { namespace client {
00066 
00067 /*
00068  * The interface org::xmlBlaster::client::I_CallbackRaw/I_Callback/I_CallbackExtended are enforced by AbstractCallbackExtended
00069  * is for the protocol drivers.
00070  */
00071 typedef std::map<std::string, I_Callback*> CallbackMapType;
00072 typedef std::map<std::string, std::string> StringMap;
00073 
00080 class Dll_Export XmlBlasterAccess : public org::xmlBlaster::client::I_Callback,
00081                                     public org::xmlBlaster::util::ReferenceCounterBase,
00082                                     public org::xmlBlaster::util::dispatch::I_PostSendListener
00083 {
00084 private:
00085    std::string ME;
00086 
00087    org::xmlBlaster::util::Global&   global_;
00088    org::xmlBlaster::util::GlobalRef globalRef_;
00089    org::xmlBlaster::util::I_Log&    log_;
00090    std::string  instanceName_;
00091 
00093    std::string serverNodeId_;
00094    org::xmlBlaster::util::qos::ConnectQosRef connectQos_;
00096    org::xmlBlaster::util::qos::ConnectReturnQosRef connectReturnQos_;
00098    org::xmlBlaster::util::dispatch::DispatchManager* dispatchManager_;
00100    org::xmlBlaster::client::protocol::I_CallbackServer* cbServer_;
00102    org::xmlBlaster::util::dispatch::ConnectionsHandler* connection_;
00103 
00105    org::xmlBlaster::client::I_Callback* updateClient_;
00106    
00112    org::xmlBlaster::client::I_ConnectionProblems* connectionProblems_;
00113    CallbackMapType subscriptionCallbackMap_;
00114    org::xmlBlaster::util::thread::Mutex updateMutex_;
00116    org::xmlBlaster::util::thread::Mutex invocationMutex_;
00117    
00118    org::xmlBlaster::util::dispatch::I_PostSendListener* postSendListener_; 
00119 
00123    XmlBlasterAccess(const XmlBlasterAccess &global);
00124 
00128    XmlBlasterAccess& operator =(const XmlBlasterAccess &);
00129 
00130    void cleanup(bool doLock);
00131    
00132 public:
00137    XmlBlasterAccess(org::xmlBlaster::util::Global& global);
00138 
00143    XmlBlasterAccess(org::xmlBlaster::util::GlobalRef global);
00144 
00145    virtual ~XmlBlasterAccess();
00146 
00152    org::xmlBlaster::util::Global& getGlobal();
00153 
00158    org::xmlBlaster::util::queue::I_Queue* getQueue();
00159 
00167    org::xmlBlaster::util::qos::ConnectReturnQos connect(const org::xmlBlaster::util::qos::ConnectQos& qos, org::xmlBlaster::client::I_Callback *clientCb);
00168 
00174    org::xmlBlaster::util::qos::ConnectQosRef getConnectQos();
00175    org::xmlBlaster::util::qos::ConnectReturnQosRef getConnectReturnQos();
00176 
00181    org::xmlBlaster::client::I_Callback* getCallback();
00182 
00187    void createDefaultCbServer();
00188 
00194    org::xmlBlaster::client::protocol::I_CallbackServer* initCbServer(const std::string& loginName, const std::string& type, const std::string& version);
00195 
00202    org::xmlBlaster::util::dispatch::I_PostSendListener* registerPostSendListener(org::xmlBlaster::util::dispatch::I_PostSendListener *listener);
00203 
00217    org::xmlBlaster::client::protocol::I_ProgressListener* registerProgressListener(org::xmlBlaster::client::protocol::I_ProgressListener *listener);
00218 
00233    void initSecuritySettings(const std::string& secMechanism, const std::string& secVersion);
00234 
00249    bool disconnect(const org::xmlBlaster::util::qos::DisconnectQos& qos, bool flush=true, bool shutdown=true, bool shutdownCb=true);
00250 
00254    void postSend(const org::xmlBlaster::util::queue::MsgQueueEntry &msgQueueEntry);
00255 
00260    std::string getId();
00261 
00265    std::string getSessionName();
00266 
00271    org::xmlBlaster::util::SessionNameRef getSessionNameRef();
00272 
00277    std::string getLoginName();
00278 
00282    void setServerNodeId(const std::string& nodeId);
00283 
00291    std::string getServerNodeId() const;
00292 
00296    // org::xmlBlaster::util::queue::MsgQueueEntry queueMessage(const org::xmlBlaster::util::queue::MsgQueueEntry& entry);
00297 
00301    // std::vector<MsgQueueEntry*> queueMessage(const std::vector<MsgQueueEntry*>& entries);
00302 
00303    // org::xmlBlaster::client::qos::SubscribeReturnQos
00304 //   std::string subscribe(const std::string& xmlKey, const std::string& qos);
00305    org::xmlBlaster::client::qos::SubscribeReturnQos subscribe(const org::xmlBlaster::client::key::SubscribeKey& key, const org::xmlBlaster::client::qos::SubscribeQos& qos, I_Callback *callback=0);
00306 
00307 //   std::vector<org::xmlBlaster::util::MessageUnit> get(const std::string&  xmlKey, const std::string& qos);
00308    std::vector<org::xmlBlaster::util::MessageUnit> get(const org::xmlBlaster::client::key::GetKey& key, const org::xmlBlaster::client::qos::GetQos& qos);
00309 
00340    std::vector<org::xmlBlaster::util::MessageUnit> receive(std::string oid, int maxEntries, long timeout, bool consumable);
00341 
00342 
00343    // org::xmlBlaster::client::qos::UnSubscribeReturnQos[]
00344 //   std::vector<std::string> unSubscribe(const std::string&  xmlKey, const std::string&  qos);
00345    std::vector<org::xmlBlaster::client::qos::UnSubscribeReturnQos> unSubscribe(const org::xmlBlaster::client::key::UnSubscribeKey& key, const org::xmlBlaster::client::qos::UnSubscribeQos& qos);
00346 
00347    // org::xmlBlaster::client::qos::PublishReturnQos
00348 //   std::string publish(const org::xmlBlaster::util::MessageUnit& msgUnit);
00349    org::xmlBlaster::client::qos::PublishReturnQos publish(const org::xmlBlaster::util::MessageUnit& msgUnit);
00350 
00351    void publishOneway(const std::vector<org::xmlBlaster::util::MessageUnit>& msgUnitArr);
00352 
00353 //   std::vector<std::string> publishArr(const std::vector<org::xmlBlaster::util::MessageUnit>& msgUnitArr);
00354    std::vector<org::xmlBlaster::client::qos::PublishReturnQos> publishArr(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr);
00355 
00356    // org::xmlBlaster::client::qos::EraseReturnQos[]
00357 //   std::vector<std::string> erase(const std::string& xmlKey, const std::string& qos);
00358    std::vector<org::xmlBlaster::client::qos::EraseReturnQos> erase(const org::xmlBlaster::client::key::EraseKey& key, const org::xmlBlaster::client::qos::EraseQos& qos);
00359 
00367    void setCallbackDispatcherActive(bool isActive);
00368 
00380    std::string sendAdministrativeCommand(const std::string &command);
00381 
00387    std::string update(const std::string &sessionId, org::xmlBlaster::client::key::UpdateKey &updateKey, const unsigned char *content, long contentSize, org::xmlBlaster::client::qos::UpdateQos &updateQos);
00388 
00392    static std::string usage();
00393 
00399     void initFailsafe(I_ConnectionProblems* connectionProblems=NULL);
00400 
00401     std::string ping();
00402 
00408    long flushQueue();
00409 
00414    bool isConnected() const;
00415 
00420    bool isAlive() const;
00421 
00426    bool isPolling() const;
00427 
00432    bool isDead() const;
00433 
00438    std::string getStatusString() const;
00439 
00455    void leaveServer(const StringMap &map);
00456 };
00457 
00458 typedef org::xmlBlaster::util::ReferenceHolder<org::xmlBlaster::client::XmlBlasterAccess> XmlBlasterAccessRef;
00459 
00460 }}} // namespaces
00461 
00462 #endif