diff options
| author | Ted Ross <tross@apache.org> | 2009-08-21 21:19:22 +0000 |
|---|---|---|
| committer | Ted Ross <tross@apache.org> | 2009-08-21 21:19:22 +0000 |
| commit | 2ad1a5da3732b280d9b780313969bef4da05f113 (patch) | |
| tree | 17c318c1d32a51117556196aa2a1b3407053088f /cpp/src | |
| parent | 03f4fe803f86ea88f62b685622b110a9785cf8d0 (diff) | |
| download | qpid-python-2ad1a5da3732b280d9b780313969bef4da05f113.tar.gz | |
Implemented the new QMF ConnectionSettings and incorporated into the bindings.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@806725 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
| -rw-r--r-- | cpp/src/CMakeLists.txt | 33 | ||||
| -rw-r--r-- | cpp/src/qmf.mk | 2 | ||||
| -rw-r--r-- | cpp/src/qmf/ConnectionSettingsImpl.cpp | 323 | ||||
| -rw-r--r-- | cpp/src/qmf/ConnectionSettingsImpl.h | 60 | ||||
| -rw-r--r-- | cpp/src/qmf/ObjectId.h | 1 | ||||
| -rw-r--r-- | cpp/src/qmf/ObjectIdImpl.cpp | 5 | ||||
| -rw-r--r-- | cpp/src/qmf/ResilientConnection.cpp | 19 | ||||
| -rw-r--r-- | cpp/src/qmf/ResilientConnection.h | 8 |
8 files changed, 421 insertions, 30 deletions
diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index 7445e495b8..a0f177dbd7 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -616,10 +616,10 @@ target_link_libraries (qpidd qpidbroker qpidcommon ${Boost_PROGRAM_OPTIONS_LIBRA # qpid/agent/ManagementAgent.h \ # qpid/agent/ManagementAgentImpl.h set (qmfagent_SOURCES - ../include/qpid/agent/ManagementAgent.h - qpid/agent/ManagementAgentImpl.cpp - qpid/agent/ManagementAgentImpl.h - qmf/AgentEngine.cpp + qmf/AgentEngine.cpp + qmf/AgentEngine.h + qpid/agent/ManagementAgentImpl.cpp + qpid/agent/ManagementAgentImpl.h ) add_library (qmfagent SHARED ${qmfagent_SOURCES}) target_link_libraries (qmfagent qmfcommon) @@ -627,14 +627,31 @@ set_target_properties (qmfagent PROPERTIES VERSION ${qpidc_version}) set (qmfcommon_SOURCES - qmf/AgentEngine.cpp - qmf/ResilientConnection.cpp + qmf/ConnectionSettingsImpl.cpp + qmf/ConnectionSettingsImpl.h + qmf/ConsoleEngine.h + qmf/Event.h + qmf/Message.h qmf/MessageImpl.cpp - qmf/SchemaImpl.cpp - qmf/ValueImpl.cpp + qmf/MessageImpl.h + qmf/Object.h + qmf/ObjectId.h qmf/ObjectIdImpl.cpp + qmf/ObjectIdImpl.h qmf/ObjectImpl.cpp + qmf/ObjectImpl.h + qmf/Query.h qmf/QueryImpl.cpp + qmf/QueryImpl.h + qmf/ResilientConnection.cpp + qmf/ResilientConnection.h + qmf/Schema.h + qmf/SchemaImpl.cpp + qmf/SchemaImpl.h + qmf/Typecode.h + qmf/Value.h + qmf/ValueImpl.cpp + qmf/ValueImpl.h ) add_library (qmfcommon SHARED ${qmfcommon_SOURCES}) target_link_libraries (qmfcommon qpidclient) diff --git a/cpp/src/qmf.mk b/cpp/src/qmf.mk index 8ccc1f4a95..9d24709b6e 100644 --- a/cpp/src/qmf.mk +++ b/cpp/src/qmf.mk @@ -35,6 +35,8 @@ nobase_include_HEADERS += \ ../include/qmf/AgentObject.h libqmfcommon_la_SOURCES = \ + qmf/ConnectionSettingsImpl.cpp \ + qmf/ConnectionSettingsImpl.h \ qmf/ConsoleEngine.h \ qmf/Event.h \ qmf/Message.h \ diff --git a/cpp/src/qmf/ConnectionSettingsImpl.cpp b/cpp/src/qmf/ConnectionSettingsImpl.cpp new file mode 100644 index 0000000000..034ab18395 --- /dev/null +++ b/cpp/src/qmf/ConnectionSettingsImpl.cpp @@ -0,0 +1,323 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "qmf/ConnectionSettingsImpl.h" +#include "qmf/Typecode.h" + +using namespace std; +using namespace qmf; +using namespace qpid; + +const string attrProtocol("protocol"); +const string attrHost("host"); +const string attrPort("port"); +const string attrVirtualhost("virtualhost"); +const string attrUsername("username"); +const string attrPassword("password"); +const string attrMechanism("mechanism"); +const string attrLocale("locale"); +const string attrHeartbeat("heartbeat"); +const string attrMaxChannels("maxChannels"); +const string attrMaxFrameSize("maxFrameSize"); +const string attrBounds("bounds"); +const string attrTcpNoDelay("tcpNoDelay"); +const string attrService("service"); +const string attrMinSsf("minSsf"); +const string attrMaxSsf("maxSsf"); +const string attrRetryDelayMin("retryDelayMin"); +const string attrRetryDelayMax("retryDelayMax"); +const string attrRetryDelayFactor("retryDelayFactor"); + +ConnectionSettingsImpl::ConnectionSettingsImpl(ConnectionSettings* e) : + envelope(e), retryDelayMin(1), retryDelayMax(64), retryDelayFactor(2) +{ +} + +ConnectionSettingsImpl::ConnectionSettingsImpl(ConnectionSettings* e, const string& /*url*/) : + envelope(e), retryDelayMin(1), retryDelayMax(64), retryDelayFactor(2) +{ + // TODO: Parse the URL +} + +void ConnectionSettingsImpl::setAttr(const string& key, const Value& value) +{ + if (key == attrProtocol) clientSettings.protocol = value.asString(); + else if (key == attrHost) clientSettings.host = value.asString(); + else if (key == attrPort) clientSettings.port = value.asUint(); + else if (key == attrVirtualhost) clientSettings.virtualhost = value.asString(); + else if (key == attrUsername) clientSettings.username = value.asString(); + else if (key == attrPassword) clientSettings.password = value.asString(); + else if (key == attrMechanism) clientSettings.mechanism = value.asString(); + else if (key == attrLocale) clientSettings.locale = value.asString(); + else if (key == attrHeartbeat) clientSettings.heartbeat = value.asUint(); + else if (key == attrMaxChannels) clientSettings.maxChannels = value.asUint(); + else if (key == attrMaxFrameSize) clientSettings.maxFrameSize = value.asUint(); + else if (key == attrBounds) clientSettings.bounds = value.asUint(); + else if (key == attrTcpNoDelay) clientSettings.tcpNoDelay = value.asBool(); + else if (key == attrService) clientSettings.service = value.asString(); + else if (key == attrMinSsf) clientSettings.minSsf = value.asUint(); + else if (key == attrMaxSsf) clientSettings.maxSsf = value.asUint(); + + else if (key == attrRetryDelayMin) retryDelayMin = value.asUint(); + else if (key == attrRetryDelayMax) retryDelayMax = value.asUint(); + else if (key == attrRetryDelayFactor) retryDelayFactor = value.asUint(); +} + +Value ConnectionSettingsImpl::getAttr(const string& key) const +{ + Value strval(TYPE_LSTR); + Value intval(TYPE_UINT32); + Value boolval(TYPE_BOOL); + + if (key == attrProtocol) { + strval.setString(clientSettings.protocol.c_str()); + return strval; + } + + if (key == attrHost) { + strval.setString(clientSettings.host.c_str()); + return strval; + } + + if (key == attrPort) { + intval.setUint(clientSettings.port); + return intval; + } + + if (key == attrVirtualhost) { + strval.setString(clientSettings.virtualhost.c_str()); + return strval; + } + + if (key == attrUsername) { + strval.setString(clientSettings.username.c_str()); + return strval; + } + + if (key == attrPassword) { + strval.setString(clientSettings.password.c_str()); + return strval; + } + + if (key == attrMechanism) { + strval.setString(clientSettings.mechanism.c_str()); + return strval; + } + + if (key == attrLocale) { + strval.setString(clientSettings.locale.c_str()); + return strval; + } + + if (key == attrHeartbeat) { + intval.setUint(clientSettings.heartbeat); + return intval; + } + + if (key == attrMaxChannels) { + intval.setUint(clientSettings.maxChannels); + return intval; + } + + if (key == attrMaxFrameSize) { + intval.setUint(clientSettings.maxFrameSize); + return intval; + } + + if (key == attrBounds) { + intval.setUint(clientSettings.bounds); + return intval; + } + + if (key == attrTcpNoDelay) { + boolval.setBool(clientSettings.tcpNoDelay); + return boolval; + } + + if (key == attrService) { + strval.setString(clientSettings.service.c_str()); + return strval; + } + + if (key == attrMinSsf) { + intval.setUint(clientSettings.minSsf); + return intval; + } + + if (key == attrMaxSsf) { + intval.setUint(clientSettings.maxSsf); + return intval; + } + + if (key == attrRetryDelayMin) { + intval.setUint(retryDelayMin); + return intval; + } + + if (key == attrRetryDelayMax) { + intval.setUint(retryDelayMax); + return intval; + } + + if (key == attrRetryDelayFactor) { + intval.setUint(retryDelayFactor); + return intval; + } + + return strval; +} + +const string& ConnectionSettingsImpl::getAttrString() const +{ + // TODO: build and return attribute string + return attrString; +} + +void ConnectionSettingsImpl::transportTcp(uint16_t port) +{ + clientSettings.protocol = "tcp"; + clientSettings.port = port; +} + +void ConnectionSettingsImpl::transportSsl(uint16_t port) +{ + clientSettings.protocol = "ssl"; + clientSettings.port = port; +} + +void ConnectionSettingsImpl::transportRdma(uint16_t port) +{ + clientSettings.protocol = "rdma"; + clientSettings.port = port; +} + +void ConnectionSettingsImpl::authAnonymous(const string& username) +{ + clientSettings.mechanism = "ANONYMOUS"; + clientSettings.username = username; +} + +void ConnectionSettingsImpl::authPlain(const string& username, const string& password) +{ + clientSettings.mechanism = "PLAIN"; + clientSettings.username = username; + clientSettings.password = password; +} + +void ConnectionSettingsImpl::authGssapi(const string& serviceName, uint32_t minSsf, uint32_t maxSsf) +{ + clientSettings.mechanism = "GSSAPI"; + clientSettings.service = serviceName; + clientSettings.minSsf = minSsf; + clientSettings.maxSsf = maxSsf; +} + +void ConnectionSettingsImpl::setRetry(int delayMin, int delayMax, int delayFactor) +{ + retryDelayMin = delayMin; + retryDelayMax = delayMax; + retryDelayFactor = delayFactor; +} + +const client::ConnectionSettings& ConnectionSettingsImpl::getClientSettings() const +{ + return clientSettings; +} + +void ConnectionSettingsImpl::getRetrySettings(int* min, int* max, int* factor) const +{ + *min = retryDelayMin; + *max = retryDelayMax; + *factor = retryDelayFactor; +} + +//================================================================== +// Wrappers +//================================================================== + +ConnectionSettings::ConnectionSettings(const ConnectionSettings& from) +{ + impl = new ConnectionSettingsImpl(*from.impl); +} + +ConnectionSettings::ConnectionSettings() +{ + impl = new ConnectionSettingsImpl(this); +} + +ConnectionSettings::ConnectionSettings(const char* url) +{ + impl = new ConnectionSettingsImpl(this, url); +} + +ConnectionSettings::~ConnectionSettings() +{ + delete impl; +} + +void ConnectionSettings::setAttr(const char* key, const Value& value) +{ + impl->setAttr(key, value); +} + +Value ConnectionSettings::getAttr(const char* key) const +{ + return impl->getAttr(key); +} + +const char* ConnectionSettings::getAttrString() const +{ + return impl->getAttrString().c_str(); +} + +void ConnectionSettings::transportTcp(uint16_t port) +{ + impl->transportTcp(port); +} + +void ConnectionSettings::transportSsl(uint16_t port) +{ + impl->transportSsl(port); +} + +void ConnectionSettings::transportRdma(uint16_t port) +{ + impl->transportRdma(port); +} + +void ConnectionSettings::authAnonymous(const char* username) +{ + impl->authAnonymous(username); +} + +void ConnectionSettings::authPlain(const char* username, const char* password) +{ + impl->authPlain(username, password); +} + +void ConnectionSettings::authGssapi(const char* serviceName, uint32_t minSsf, uint32_t maxSsf) +{ + impl->authGssapi(serviceName, minSsf, maxSsf); +} + +void ConnectionSettings::setRetry(int delayMin, int delayMax, int delayFactor) +{ + impl->setRetry(delayMin, delayMax, delayFactor); +} + diff --git a/cpp/src/qmf/ConnectionSettingsImpl.h b/cpp/src/qmf/ConnectionSettingsImpl.h new file mode 100644 index 0000000000..a177233cf3 --- /dev/null +++ b/cpp/src/qmf/ConnectionSettingsImpl.h @@ -0,0 +1,60 @@ +#ifndef _QmfConnectionSettingsImpl_ +#define _QmfConnectionSettingsImpl_ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "qmf/ConnectionSettings.h" +#include "qmf/Value.h" +#include "qpid/client/ConnectionSettings.h" +#include <string> +#include <map> + +namespace qmf { + + class ConnectionSettingsImpl { + ConnectionSettings* envelope; + qpid::client::ConnectionSettings clientSettings; + mutable std::string attrString; + int retryDelayMin; + int retryDelayMax; + int retryDelayFactor; + + public: + ConnectionSettingsImpl(ConnectionSettings* e); + ConnectionSettingsImpl(ConnectionSettings* e, const std::string& url); + ~ConnectionSettingsImpl() {} + void setAttr(const std::string& key, const Value& value); + Value getAttr(const std::string& key) const; + const std::string& getAttrString() const; + void transportTcp(uint16_t port); + void transportSsl(uint16_t port); + void transportRdma(uint16_t port); + void authAnonymous(const std::string& username); + void authPlain(const std::string& username, const std::string& password); + void authGssapi(const std::string& serviceName, uint32_t minSsf, uint32_t maxSsf); + void setRetry(int delayMin, int delayMax, int delayFactor); + + const qpid::client::ConnectionSettings& getClientSettings() const; + void getRetrySettings(int* delayMin, int* delayMax, int* delayFactor) const; + }; + +} + +#endif diff --git a/cpp/src/qmf/ObjectId.h b/cpp/src/qmf/ObjectId.h index 1ceae20bd8..ffd1b6978b 100644 --- a/cpp/src/qmf/ObjectId.h +++ b/cpp/src/qmf/ObjectId.h @@ -39,7 +39,6 @@ namespace qmf { bool isDurable() const; bool operator==(const ObjectId& other) const; - bool operator!=(const ObjectId& other) const; bool operator<(const ObjectId& other) const; bool operator>(const ObjectId& other) const; bool operator<=(const ObjectId& other) const; diff --git a/cpp/src/qmf/ObjectIdImpl.cpp b/cpp/src/qmf/ObjectIdImpl.cpp index efa8e7119b..75661fdb47 100644 --- a/cpp/src/qmf/ObjectIdImpl.cpp +++ b/cpp/src/qmf/ObjectIdImpl.cpp @@ -166,11 +166,6 @@ bool ObjectId::operator==(const ObjectId& other) const return *impl == *other.impl; } -bool ObjectId::operator!=(const ObjectId& other) const -{ - return !(*impl == *other.impl); -} - bool ObjectId::operator<(const ObjectId& other) const { return *impl < *other.impl; diff --git a/cpp/src/qmf/ResilientConnection.cpp b/cpp/src/qmf/ResilientConnection.cpp index 610306f896..3531e104b0 100644 --- a/cpp/src/qmf/ResilientConnection.cpp +++ b/cpp/src/qmf/ResilientConnection.cpp @@ -19,6 +19,8 @@ #include "qmf/ResilientConnection.h" #include "qmf/MessageImpl.h" +#include "qmf/ConnectionSettingsImpl.h" +#include <qpid/client/Connection.h> #include <qpid/client/Session.h> #include <qpid/client/MessageListener.h> #include <qpid/client/SubscriptionManager.h> @@ -77,8 +79,7 @@ namespace qmf { class ResilientConnectionImpl : public qpid::sys::Runnable { public: - ResilientConnectionImpl(ConnectionSettings& settings, - int dmin, int dmax, int dfactor); + ResilientConnectionImpl(ConnectionSettings& settings); ~ResilientConnectionImpl(); bool isConnected() const; @@ -174,12 +175,11 @@ void RCSession::received(qpid::client::Message& msg) connImpl.EnqueueEvent(ResilientConnectionEvent::RECV, userContext, qmsg); } -ResilientConnectionImpl::ResilientConnectionImpl(ConnectionSettings& _settings, - int dmin, int dmax, int dfactor) : - notifyFd(-1), connected(false), shutdown(false), settings(_settings), - delayMin(dmin), delayMax(dmax), delayFactor(dfactor), connThread(*this) +ResilientConnectionImpl::ResilientConnectionImpl(ConnectionSettings& _settings) : + notifyFd(-1), connected(false), shutdown(false), settings(_settings), connThread(*this) { connection.registerFailureCallback(boost::bind(&ResilientConnectionImpl::failure, this)); + settings.impl->getRetrySettings(&delayMin, &delayMax, &delayFactor); } ResilientConnectionImpl::~ResilientConnectionImpl() @@ -318,7 +318,7 @@ void ResilientConnectionImpl::run() while (true) { try { - connection.open(settings); + connection.open(settings.impl->getClientSettings()); { Mutex::ScopedLock _lock(lock); connected = true; @@ -396,10 +396,9 @@ void ResilientConnectionImpl::EnqueueEvent(ResilientConnectionEvent::EventKind k // Wrappers //================================================================== -ResilientConnection::ResilientConnection(ConnectionSettings& settings, - int delayMin, int delayMax, int delayFactor) +ResilientConnection::ResilientConnection(ConnectionSettings& settings) { - impl = new ResilientConnectionImpl(settings, delayMin, delayMax, delayFactor); + impl = new ResilientConnectionImpl(settings); } ResilientConnection::~ResilientConnection() diff --git a/cpp/src/qmf/ResilientConnection.h b/cpp/src/qmf/ResilientConnection.h index bb565e27ae..6e05541253 100644 --- a/cpp/src/qmf/ResilientConnection.h +++ b/cpp/src/qmf/ResilientConnection.h @@ -21,8 +21,7 @@ */ #include <qmf/Message.h> -#include <qpid/client/Connection.h> -#include <qpid/client/ConnectionSettings.h> +#include <qmf/ConnectionSettings.h> #include <string> namespace qmf { @@ -68,10 +67,7 @@ namespace qmf { *@param delayMax Maximum delay (in seconds) between retries. *@param delayFactor Factor to multiply retry delay by after each failure. */ - ResilientConnection(qpid::client::ConnectionSettings& settings, - int delayMin = 1, - int delayMax = 128, - int delayFactor = 2); + ResilientConnection(ConnectionSettings& settings); ~ResilientConnection(); /** |
