1 /*------------------------------------------------------------------------------
  2 Name:      ConnectQos.h
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 Comment:   Defines ConnectQos, ReturnConnectQos and ConnectQosData
  6 ------------------------------------------------------------------------------*/
  7 
  8 #ifndef _UTIL_QOS_CONNECTQOS_H
  9 #define _UTIL_QOS_CONNECTQOS_H
 10 
 11 #include <util/xmlBlasterDef.h>
 12 #include <string>
 13 #include <util/XmlQoSBase.h>
 14 #include <util/ServerRef.h>
 15 #include <util/qos/SessionQos.h>
 16 #include <authentication/SecurityQos.h>
 17 #include <util/qos/address/AddressFactory.h>
 18 #include <util/qos/address/Address.h>
 19 #include <util/qos/address/CallbackAddress.h>
 20 #include <util/qos/storage/QueuePropertyFactory.h>
 21 #include <util/qos/storage/ClientQueueProperty.h>
 22 #include <util/qos/storage/CbQueueProperty.h>
 23 #include <util/qos/ClientProperty.h>
 24 #include <util/ReferenceCounterBase.h>
 25 #include <util/ReferenceHolder.h>
 26 
 27 #include <vector>
 28 #include <map>
 29 
 30 namespace org { namespace xmlBlaster { namespace util { namespace qos {
 31 
 32 /**
 33  * Holds the connect() QoS XML markup. 
 34  * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.connect.html">The interface.connect requirement</a>
 35  */
 36 class Dll_Export ConnectQosData : public org::xmlBlaster::util::ReferenceCounterBase
 37 {
 38 
 39 public:   typedef std::map<std::string, org::xmlBlaster::util::qos::ClientProperty> ClientPropertyMap;
 40 
 41 private:
 42    org::xmlBlaster::util::Global&     global_;
 43    org::xmlBlaster::util::I_Log&        log_;
 44    mutable org::xmlBlaster::authentication::SecurityQos securityQos_;
 45    mutable org::xmlBlaster::util::qos::SessionQosRef  sessionQos_;
 46    bool        ptp_;
 47    bool        clusterNode_;
 48    bool        refreshSession_;
 49    bool        duplicateUpdates_;
 50    bool        reconnected_;
 51    std::string instanceId_;
 52    bool        persistent_;
 53 
 54    //std::vector<org::xmlBlaster::util::qos::address::Address>         addresses_;
 55    //std::vector<org::xmlBlaster::util::qos::address::CallbackAddress> cbAddresses_;
 56    std::vector<org::xmlBlaster::util::qos::storage::ClientQueueProperty>   clientQueueProperties_;
 57    org::xmlBlaster::util::qos::storage::CbQueueProperty         sessionCbQueueProperty_;
 58    std::vector<ServerRef>       serverReferences_;
 59 
 60 
 61    friend class ConnectQosFactory;
 62 
 63    /**
 64     * Used by xml parser only, the ServerRef is returned by xmlBlaster in ConnectReturnQos
 65     */
 66    void addServerRef(const org::xmlBlaster::util::ServerRef& serverRef);
 67 
 68    void copy(const ConnectQosData& data)
 69    {
 70       securityQos_            = data.securityQos_;
 71       org::xmlBlaster::util::qos::SessionQosData* p = data.sessionQos_.getElement();
 72       org::xmlBlaster::util::qos::SessionQosData* p2 = new org::xmlBlaster::util::qos::SessionQosData(*p);
 73       org::xmlBlaster::util::qos::SessionQosRef r(p2);
 74       sessionQos_             = r;
 75       ptp_                    = data.ptp_;
 76       clusterNode_            = data.clusterNode_;
 77       refreshSession_         = data.refreshSession_;
 78       duplicateUpdates_       = data.duplicateUpdates_;
 79       serverReferences_       = data.serverReferences_;
 80       //addresses_              = data.addresses_;
 81       //cbAddresses_            = data.cbAddresses_;
 82       clientQueueProperties_  = data.clientQueueProperties_;
 83       sessionCbQueueProperty_ = data.sessionCbQueueProperty_;
 84       clientProperties_       = data.clientProperties_;
 85       reconnected_            = data.reconnected_;
 86       instanceId_             = data.instanceId_;
 87       persistent_             = data.persistent_;
 88    }
 89 
 90 protected:
 91    ClientPropertyMap clientProperties_; 
 92 
 93 public:
 94    ConnectQosData(org::xmlBlaster::util::Global& global, const std::string& user="", const std::string& passwd="", long publicSessionId=0);
 95    ConnectQosData(const ConnectQosData& data);
 96    ConnectQosData& operator =(const ConnectQosData& data);
 97    virtual ~ConnectQosData();
 98 
 99    bool getPtp() const;
100    const std::string& getBoolAsString(bool boolVal) const;
101    void setPtp(bool ptp);
102    void setSessionQos(const org::xmlBlaster::util::qos::SessionQos& sessionQos);
103    org::xmlBlaster::util::qos::SessionQos& getSessionQos() const;
104    void setSessionQos(org::xmlBlaster::util::qos::SessionQosRef sessionQos);
105    org::xmlBlaster::util::qos::SessionQosRef getSessionQosRef() const;
106    std::string getSecretSessionId() const;
107    std::string getUserId() const;
108    std::string getCallbackType() const;
109    void setSecurityQos(const org::xmlBlaster::authentication::SecurityQos& securityQos);
110    org::xmlBlaster::authentication::SecurityQos& getSecurityQos() const;
111    void setClusterNode(bool clusterNode);
112    bool isClusterNode() const;
113    /**
114     * Extend the session lifetime. 
115     * @param refreshSession true: The client notifies xmlBlaster that it is alive
116     * and the login session is extended
117     */
118    void setRefreshSession(bool refreshSession);
119    bool isRefreshSession() const;
120    void setDuplicateUpdates(bool duplicateUpdates);
121    bool isDuplicateUpdates() const;
122    /**
123     * Returned in ConnectReturnQos from xmlBlaster showing all access addresses. 
124     */
125    const std::vector<ServerRef> getServerReferences() const;
126 
127    /**
128     * Used for ConnetReturnQos only. 
129     * @return true A client has reconnected to an existing session
130     */
131    bool isReconnected() const;
132    void setReconnected(bool reconnected);
133 
134    /**
135     * Unique id of the xmlBlaster server (or a client), changes on each restart. 
136     * If 'node/heron' is restarted, the instanceId changes.
137     * @return nodeId + timestamp, '/node/heron/instanceId/33470080380'
138     */
139    std::string getInstanceId() const;
140    void setInstanceId(std::string instanceId);
141 
142    bool isPersistent() const;
143    void setPersistent(bool persistent);
144    
145    /**
146     * returns the first found server reference
147     * delivered with return QoS of a connect() call.
148     */
149    org::xmlBlaster::util::ServerRef getServerRef();
150 
151    std::string toXml(const std::string& extraOffset="") const;
152 
153    // methods for queues and addresses ...
154 
155    /**
156     * @param address You need to create the address with 'new Address()', we take care to delete it.
157     *                Don't pass any Address instance from the stack.
158     */
159    void setAddress(const org::xmlBlaster::util::qos::address::AddressBaseRef& address);
160    org::xmlBlaster::util::qos::address::AddressBaseRef getAddress();
161 
162    /**
163     * @param cbAddress We take a copy of this so you can destroy your address after setting.
164     *                Note that if you work on your address object later it does not change
165     *                the address in ConnectQos
166     */
167    void addCbAddress(const org::xmlBlaster::util::qos::address::AddressBaseRef& cbAddress);
168    org::xmlBlaster::util::qos::address::AddressBaseRef getCbAddress();
169 
170    /**
171     * @param prop We take a copy of this so you can destroy your property after setting.
172     *             Note that if you work on your object later it does not change
173     *             the setting in ConnectQos
174     */
175    void addClientQueueProperty(const org::xmlBlaster::util::qos::storage::ClientQueueProperty& prop);
176 
177    /**
178     * Access the configuration settings of the client side queue and server address. 
179     * @return If no instance exists it will be created on the fly and initialized
180     * with the current environment settings and command line arguments
181     */
182    org::xmlBlaster::util::qos::storage::ClientQueueProperty& getClientQueueProperty();
183 
184    /**
185     * @param prop We take a copy of this so you can destroy your property after setting.
186     *             Note that if you work on your object later it does not change
187     *             the setting in ConnectQos
188     */
189    void setSessionCbQueueProperty(const org::xmlBlaster::util::qos::storage::CbQueueProperty& prop);
190 
191    /**
192     * Access the configuration settings of the server side callback queue and callback address. 
193     * @return If no instance exists it will be created on the fly and initialized
194     * with the current environment settings and command line arguments
195     */
196    org::xmlBlaster::util::qos::storage::CbQueueProperty& getSessionCbQueueProperty();
197 
198    std::string dumpClientProperties(const std::string& extraOffset, bool clearText=false) const;
199 
200    /**
201     * Add a client property. 
202     * @param clientProperty
203     * @see ClientProperty
204     */
205    void addClientProperty(const ClientProperty& clientProperty);
206 
207    /**
208     * Add a client property key and value
209     * @param name
210     * @param value "vector<unsigned char>" and "unsigned char *" is treated as a blob
211     * @see ClientProperty::#ClientProperty
212     */
213    template <typename T_VALUE> void addClientProperty(
214             const std::string& name,
215             const T_VALUE& value,
216             const std::string& type="",
217             const std::string& encoding="");
218 
219    /**
220     * Access the value for the given name, if not found returns the defaultValue. 
221     * @return A copy of the given defaultValue if none was found
222     */
223    template <typename T_VALUE> T_VALUE getClientProperty(
224             const std::string& name,
225             const T_VALUE& defaultValue);
226         
227    const ClientPropertyMap& getClientProperties() const;
228 };
229 
230 template <typename T_VALUE> void ConnectQosData::addClientProperty(
231                const std::string& name, const T_VALUE& value,
232                                         const std::string& type, const std::string& encoding)
233 {
234    org::xmlBlaster::util::qos::ClientProperty clientProperty(name, value, type, encoding);
235    clientProperties_.insert(ClientPropertyMap::value_type(name, clientProperty));   
236 }
237 
238 template <typename T_VALUE> T_VALUE ConnectQosData::getClientProperty(
239                const std::string& name, const T_VALUE& defaultValue)
240 {
241    ClientPropertyMap::const_iterator iter = clientProperties_.find(name);
242    if (iter != clientProperties_.end()) {
243       T_VALUE tmp;
244       (*iter).second.getValue(tmp);
245       return tmp;
246    }
247    return defaultValue;
248 }
249 
250 typedef org::xmlBlaster::util::ReferenceHolder<ConnectQosData> ConnectQosDataRef;
251 
252 typedef ConnectQosData ConnectQos;
253 typedef org::xmlBlaster::util::ReferenceHolder<ConnectQos> ConnectQosRef;
254 
255 typedef ConnectQosData ConnectReturnQos;
256 typedef org::xmlBlaster::util::ReferenceHolder<ConnectReturnQos> ConnectReturnQosRef;
257 
258 }}}} // namespaces
259 
260 #endif


syntax highlighted by Code2HTML, v. 0.9.1