diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/client/Connection.cpp | 3 | ||||
-rw-r--r-- | cpp/src/qpid/client/ConnectionSettings.cpp | 30 | ||||
-rw-r--r-- | cpp/src/qpid/client/ConnectionSettings.h | 20 | ||||
-rw-r--r-- | cpp/src/tests/BasicP2PTest.cpp | 4 | ||||
-rw-r--r-- | cpp/src/tests/BasicP2PTest.h | 2 | ||||
-rw-r--r-- | cpp/src/tests/BasicPubSubTest.cpp | 6 | ||||
-rw-r--r-- | cpp/src/tests/BasicPubSubTest.h | 2 | ||||
-rw-r--r-- | cpp/src/tests/ConnectionOptions.h | 53 | ||||
-rw-r--r-- | cpp/src/tests/Makefile.am | 3 | ||||
-rw-r--r-- | cpp/src/tests/SimpleTestCaseBase.cpp | 4 | ||||
-rw-r--r-- | cpp/src/tests/SimpleTestCaseBase.h | 8 | ||||
-rw-r--r-- | cpp/src/tests/TestCase.h | 4 | ||||
-rw-r--r-- | cpp/src/tests/TestOptions.h | 13 | ||||
-rw-r--r-- | cpp/src/tests/client_test.cpp | 1 | ||||
-rw-r--r-- | cpp/src/tests/interop_runner.cpp | 12 |
15 files changed, 92 insertions, 73 deletions
diff --git a/cpp/src/qpid/client/Connection.cpp b/cpp/src/qpid/client/Connection.cpp index 6994c7a400..752cb9095c 100644 --- a/cpp/src/qpid/client/Connection.cpp +++ b/cpp/src/qpid/client/Connection.cpp @@ -53,8 +53,7 @@ void Connection::open( const std::string& vhost, uint16_t maxFrameSize) { - // FIXME aconway 2008-06-02: refactor ConnectionSettings to separate out command line parsing. - ConnectionSettings settings(""); + ConnectionSettings settings; settings.host = host; settings.port = port; settings.username = uid; diff --git a/cpp/src/qpid/client/ConnectionSettings.cpp b/cpp/src/qpid/client/ConnectionSettings.cpp index 26a11c3b9d..2de2f92e45 100644 --- a/cpp/src/qpid/client/ConnectionSettings.cpp +++ b/cpp/src/qpid/client/ConnectionSettings.cpp @@ -29,8 +29,7 @@ namespace qpid { namespace client { -ConnectionSettings::ConnectionSettings(const std::string& argv0) : - Options("Connection Settings"), +ConnectionSettings::ConnectionSettings() : host("localhost"), port(TcpAddress::DEFAULT_PORT), clientid("cpp"), @@ -42,34 +41,11 @@ ConnectionSettings::ConnectionSettings(const std::string& argv0) : maxChannels(32767), maxFrameSize(65535), bounds(2), - tcpNoDelay(false), - log(argv0) -{ - addOptions() - ("broker,b", optValue(host, "HOST"), "Broker host to connect to") - ("port,p", optValue(port, "PORT"), "Broker port to connect to") - ("virtualhost,v", optValue(virtualhost, "VHOST"), "virtual host") - ("clientname,n", optValue(clientid, "ID"), "unique client identifier") - ("username", optValue(username, "USER"), "user name for broker log in.") - ("password", optValue(password, "PASSWORD"), "password for broker log in.") - ("mechanism", optValue(mechanism, "MECH"), "SASL mechanism to use when authenticating.") - ("locale", optValue(locale, "LOCALE"), "locale to use.") - ("max-channels", optValue(maxChannels, "N"), "the maximum number of channels the client requires.") - ("max-frame-size", optValue(maxFrameSize, "N"), "the maximum frame size to request.") - ("bounds-multiplier", optValue(bounds, "N"), - "restricts the total size of outgoing frames queued up for writing (as a multiple of the max frame size)."); - add(log); -} + tcpNoDelay(false) +{} ConnectionSettings::~ConnectionSettings() {} -void ConnectionSettings::parse(int argc, char** argv) -{ - qpid::Options::parse(argc, argv); - qpid::log::Logger::instance().configure(log); -} - - void ConnectionSettings::configurePosixTcpSocket(int fd) const { if (tcpNoDelay) { diff --git a/cpp/src/qpid/client/ConnectionSettings.h b/cpp/src/qpid/client/ConnectionSettings.h index d35b8bc0e7..bc3d79e1c6 100644 --- a/cpp/src/qpid/client/ConnectionSettings.h +++ b/cpp/src/qpid/client/ConnectionSettings.h @@ -34,12 +34,11 @@ namespace qpid { namespace client { /** - * Used to hold seetings for a connection (and parse these from - * command line options etc if desired). + * Settings for a Connection. */ -struct ConnectionSettings : qpid::Options, qpid::sys::Socket::Configuration { - // FIXME aconway 2008-06-02: separate option parsing from settings as subclass. - ConnectionSettings(const std::string& argv0=std::string()); +struct ConnectionSettings : public sys::Socket::Configuration { + + ConnectionSettings(); virtual ~ConnectionSettings(); /** @@ -47,12 +46,6 @@ struct ConnectionSettings : qpid::Options, qpid::sys::Socket::Configuration { */ virtual void configurePosixTcpSocket(int fd) const; - /** - * Parse options from command line arguments (will throw exception - * if arguments cannot be parsed). - */ - void parse(int argc, char** argv); - /** * The host (or ip address) to connect to (defaults to 'localhost'). */ @@ -110,11 +103,6 @@ struct ConnectionSettings : qpid::Options, qpid::sys::Socket::Configuration { * If true, TCP_NODELAY will be set for the connection. */ bool tcpNoDelay; - - /** - * Logging settings to use. - */ - log::Options log; }; }} // namespace qpid::client diff --git a/cpp/src/tests/BasicP2PTest.cpp b/cpp/src/tests/BasicP2PTest.cpp index 9f5f1acccb..f4a4cce7f2 100644 --- a/cpp/src/tests/BasicP2PTest.cpp +++ b/cpp/src/tests/BasicP2PTest.cpp @@ -29,7 +29,7 @@ class BasicP2PTest::Receiver : public Worker, public MessageListener const std::string queue; std::string tag; public: - Receiver(ConnectionSettings& options, const std::string& _queue, const int _messages) + Receiver(ConnectionOptions& options, const std::string& _queue, const int _messages) : Worker(options, _messages), queue(_queue){} void init() { @@ -51,7 +51,7 @@ public: } }; -void BasicP2PTest::assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options) +void BasicP2PTest::assign(const std::string& role, framing::FieldTable& params, ConnectionOptions& options) { std::string queue = params.getString("P2P_QUEUE_AND_KEY_NAME"); int messages = params.getInt("P2P_NUM_MESSAGES"); diff --git a/cpp/src/tests/BasicP2PTest.h b/cpp/src/tests/BasicP2PTest.h index 8f957187b0..b2611f0301 100644 --- a/cpp/src/tests/BasicP2PTest.h +++ b/cpp/src/tests/BasicP2PTest.h @@ -38,7 +38,7 @@ class BasicP2PTest : public SimpleTestCaseBase { class Receiver; public: - void assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options); + void assign(const std::string& role, framing::FieldTable& params, ConnectionOptions& options); }; } diff --git a/cpp/src/tests/BasicPubSubTest.cpp b/cpp/src/tests/BasicPubSubTest.cpp index aed47b419c..1e9ff364f1 100644 --- a/cpp/src/tests/BasicPubSubTest.cpp +++ b/cpp/src/tests/BasicPubSubTest.cpp @@ -30,7 +30,7 @@ class BasicPubSubTest::Receiver : public Worker, public MessageListener const std::string key; std::string tag; public: - Receiver(ConnectionSettings& options, const Exchange& _exchange, const std::string& _queue, const std::string& _key, const int _messages) + Receiver(ConnectionOptions& options, const Exchange& _exchange, const std::string& _queue, const std::string& _key, const int _messages) : Worker(options, _messages), exchange(_exchange), queue(_queue), key(_key){} void init() @@ -58,7 +58,7 @@ class BasicPubSubTest::MultiReceiver : public Worker, public MessageListener ReceiverList receivers; public: - MultiReceiver(ConnectionSettings& options, const Exchange& exchange, const std::string& key, const int _messages, int receiverCount) + MultiReceiver(ConnectionOptions& options, const Exchange& exchange, const std::string& key, const int _messages, int receiverCount) : Worker(options, _messages) { for (int i = 0; i != receiverCount; i++) { @@ -104,7 +104,7 @@ public: } }; -void BasicPubSubTest::assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options) +void BasicPubSubTest::assign(const std::string& role, framing::FieldTable& params, ConnectionOptions& options) { std::string key = params.getString("PUBSUB_KEY"); int messages = params.getInt("PUBSUB_NUM_MESSAGES"); diff --git a/cpp/src/tests/BasicPubSubTest.h b/cpp/src/tests/BasicPubSubTest.h index a6d794c5b6..242d2847d7 100644 --- a/cpp/src/tests/BasicPubSubTest.h +++ b/cpp/src/tests/BasicPubSubTest.h @@ -43,7 +43,7 @@ class BasicPubSubTest : public SimpleTestCaseBase class Receiver; class MultiReceiver; public: - void assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options); + void assign(const std::string& role, framing::FieldTable& params, ConnectionOptions& options); }; } diff --git a/cpp/src/tests/ConnectionOptions.h b/cpp/src/tests/ConnectionOptions.h new file mode 100644 index 0000000000..3be0528612 --- /dev/null +++ b/cpp/src/tests/ConnectionOptions.h @@ -0,0 +1,53 @@ +#ifndef QPID_CLIENT_CONNECTIONOPTIONS_H +#define QPID_CLIENT_CONNECTIONOPTIONS_H + +/* + * + * 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 "ConnectionOptions.h" +#include "qpid/Options.h" + +/** + * Options parser for ConnectionOptions. + */ +struct ConnectionOptions : public qpid::Options, + public qpid::client::ConnectionSettings +{ + ConnectionOptions() : qpid::Options("Connection Settings") + { + using namespace qpid; + addOptions() + ("broker,b", optValue(host, "HOST"), "Broker host to connect to") + ("port,p", optValue(port, "PORT"), "Broker port to connect to") + ("virtualhost,v", optValue(virtualhost, "VHOST"), "virtual host") + ("clientname,n", optValue(clientid, "ID"), "unique client identifier") + ("username", optValue(username, "USER"), "user name for broker log in.") + ("password", optValue(password, "PASSWORD"), "password for broker log in.") + ("mechanism", optValue(mechanism, "MECH"), "SASL mechanism to use when authenticating.") + ("locale", optValue(locale, "LOCALE"), "locale to use.") + ("max-channels", optValue(maxChannels, "N"), "the maximum number of channels the client requires.") + ("max-frame-size", optValue(maxFrameSize, "N"), "the maximum frame size to request.") + ("bounds-multiplier", optValue(bounds, "N"), + "bound size of write queue (as a multiple of the max frame size)."); + } +}; + +#endif /*!QPID_CLIENT_CONNECTIONOPTIONS_H*/ diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index 41e7c525cf..1751d26808 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -63,7 +63,8 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \ TxAckTest.cpp \ TxBufferTest.cpp \ TxPublishTest.cpp \ - MessageBuilderTest.cpp + MessageBuilderTest.cpp \ + ConnectionOptions.h if HAVE_XML unit_test_SOURCES+= XmlClientSessionTest.cpp diff --git a/cpp/src/tests/SimpleTestCaseBase.cpp b/cpp/src/tests/SimpleTestCaseBase.cpp index 0111e030fb..2739734731 100644 --- a/cpp/src/tests/SimpleTestCaseBase.cpp +++ b/cpp/src/tests/SimpleTestCaseBase.cpp @@ -47,7 +47,7 @@ void SimpleTestCaseBase::report(client::Message& report) } } -SimpleTestCaseBase::Sender::Sender(ConnectionSettings& options, +SimpleTestCaseBase::Sender::Sender(ConnectionOptions& options, const Exchange& _exchange, const std::string& _key, const int _messages) @@ -67,7 +67,7 @@ void SimpleTestCaseBase::Sender::start(){ stop(); } -SimpleTestCaseBase::Worker::Worker(ConnectionSettings& options, const int _messages) : +SimpleTestCaseBase::Worker::Worker(ConnectionOptions& options, const int _messages) : messages(_messages), count(0) { connection.open(options.host, options.port); diff --git a/cpp/src/tests/SimpleTestCaseBase.h b/cpp/src/tests/SimpleTestCaseBase.h index e2c328437e..0c1052d0c2 100644 --- a/cpp/src/tests/SimpleTestCaseBase.h +++ b/cpp/src/tests/SimpleTestCaseBase.h @@ -28,7 +28,7 @@ #include "qpid/client/Channel.h" #include "qpid/client/Message.h" #include "qpid/client/Connection.h" -#include "qpid/client/ConnectionSettings.h" +#include "ConnectionOptions.h" #include "qpid/client/MessageListener.h" #include "TestCase.h" @@ -50,7 +50,7 @@ protected: public: - Worker(ConnectionSettings& options, const int messages); + Worker(ConnectionOptions& options, const int messages); virtual ~Worker(){} virtual void stop(); @@ -64,7 +64,7 @@ protected: const Exchange& exchange; const std::string key; public: - Sender(ConnectionSettings& options, + Sender(ConnectionOptions& options, const Exchange& exchange, const std::string& key, const int messages); @@ -75,7 +75,7 @@ protected: std::auto_ptr<Worker> worker; public: - virtual void assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options) = 0; + virtual void assign(const std::string& role, framing::FieldTable& params, ConnectionOptions& options) = 0; virtual ~SimpleTestCaseBase() {} diff --git a/cpp/src/tests/TestCase.h b/cpp/src/tests/TestCase.h index 7926c4fe1d..ba3330c951 100644 --- a/cpp/src/tests/TestCase.h +++ b/cpp/src/tests/TestCase.h @@ -21,7 +21,7 @@ * */ -#include "qpid/client/ConnectionSettings.h" +#include "ConnectionOptions.h" #include "qpid/client/Message.h" @@ -39,7 +39,7 @@ public: * may be 'activated' at this stage others may require an explicit * start request. */ - virtual void assign(const std::string& role, framing::FieldTable& params, client::ConnectionSettings& options) = 0; + virtual void assign(const std::string& role, framing::FieldTable& params, client::ConnectionOptions& options) = 0; /** * Each test will be started on its own thread, which should block * until the test completes (this may or may not require an diff --git a/cpp/src/tests/TestOptions.h b/cpp/src/tests/TestOptions.h index 3013ffa773..a400fe5ecb 100644 --- a/cpp/src/tests/TestOptions.h +++ b/cpp/src/tests/TestOptions.h @@ -26,7 +26,7 @@ #include "qpid/Url.h" #include "qpid/log/Logger.h" #include "qpid/client/Connection.h" -#include "qpid/client/ConnectionSettings.h" +#include "ConnectionOptions.h" #include <iostream> #include <exception> @@ -35,12 +35,14 @@ namespace qpid { struct TestOptions : public qpid::Options { - TestOptions(const std::string& helpText_=std::string()) : - Options("Test Options"), help(false), helpText(helpText_) + TestOptions(const std::string& helpText_=std::string(), + const std::string& argv0=std::string()) + : Options("Test Options"), help(false), log(argv0), helpText(helpText_) { addOptions() ("help", optValue(help), "print this usage statement"); add(con); + add(log); } /** As well as parsing, throw help message if requested. */ @@ -52,7 +54,7 @@ struct TestOptions : public qpid::Options msg << *this << std::endl << std::endl << e.what() << std::endl; throw qpid::Options::Exception(msg.str()); } - qpid::log::Logger::instance().configure(con.log); + qpid::log::Logger::instance().configure(log); if (help) { std::ostringstream msg; msg << *this << std::endl << std::endl << helpText << std::endl; @@ -67,7 +69,8 @@ struct TestOptions : public qpid::Options bool help; - client::ConnectionSettings con; + ConnectionOptions con; + qpid::log::Options log; std::string helpText; }; diff --git a/cpp/src/tests/client_test.cpp b/cpp/src/tests/client_test.cpp index 04269b299d..204c2c4b71 100644 --- a/cpp/src/tests/client_test.cpp +++ b/cpp/src/tests/client_test.cpp @@ -30,7 +30,6 @@ #include "TestOptions.h" #include "qpid/client/Connection.h" -#include "qpid/client/ConnectionSettings.h" #include "qpid/client/Message.h" #include "qpid/client/Session.h" #include "qpid/framing/FrameSet.h" diff --git a/cpp/src/tests/interop_runner.cpp b/cpp/src/tests/interop_runner.cpp index 9435b8169f..8c6e0a6991 100644 --- a/cpp/src/tests/interop_runner.cpp +++ b/cpp/src/tests/interop_runner.cpp @@ -24,7 +24,7 @@ #include "qpid/Exception.h" #include "qpid/client/Channel.h" #include "qpid/client/Connection.h" -#include "qpid/client/ConnectionSettings.h" +#include "qpid/client/ConnectionOptions.h" #include "qpid/client/Exchange.h" #include "qpid/client/MessageListener.h" #include "qpid/client/Queue.h" @@ -54,7 +54,7 @@ class DummyRun : public TestCase { public: DummyRun() {} - void assign(const string&, FieldTable&, ConnectionSettings&) {} + void assign(const string&, FieldTable&, ConnectionOptions&) {} void start() {} void stop() {} void report(qpid::client::Message&) {} @@ -68,7 +68,7 @@ class Listener : public MessageListener, private Runnable{ typedef boost::ptr_map<string, TestCase> TestMap; Channel& channel; - ConnectionSettings& options; + ConnectionOptions& options; TestMap tests; const string name; const string topic; @@ -86,13 +86,13 @@ class Listener : public MessageListener, private Runnable{ void sendSimpleResponse(const string& type, Message& request); void sendReport(); public: - Listener(Channel& channel, ConnectionSettings& options); + Listener(Channel& channel, ConnectionOptions& options); void received(Message& msg); void bindAndConsume(); void registerTest(string name, TestCase* test); }; -struct TestSettings : ConnectionSettings +struct TestSettings : ConnectionOptions { bool help; @@ -131,7 +131,7 @@ int main(int argc, char** argv) { } } -Listener::Listener(Channel& _channel, ConnectionSettings& _options) : channel(_channel), options(_options), name(options.clientid), topic("iop.control." + name) +Listener::Listener(Channel& _channel, ConnectionOptions& _options) : channel(_channel), options(_options), name(options.clientid), topic("iop.control." + name) {} void Listener::registerTest(string name, TestCase* test) |