diff options
author | Gordon Sim <gsim@apache.org> | 2010-05-05 11:17:41 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2010-05-05 11:17:41 +0000 |
commit | 8c0153e035caa90758a6773493d5859716521e30 (patch) | |
tree | 78077da73151b357a20a07d2f83fd98ed1ac66e1 /cpp/examples/messaging/drain.cpp | |
parent | 685d4c67f1282166294a6f8b4d0710b55f0aba5d (diff) | |
download | qpid-python-8c0153e035caa90758a6773493d5859716521e30.tar.gz |
Some cleanup on examples:
* removed obsolete examples (queue-/topic-sender/receiver)
* removed the need to include headers with boost dependencies
* moved the argument handling in darin and spout closer to that of python (and update docs to reflect that)
* changed to ship a manually constructed makefile for messaging examples (generated one doesn't work and maintaining that seems like more work with little benefit)
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@941250 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/examples/messaging/drain.cpp')
-rw-r--r-- | cpp/examples/messaging/drain.cpp | 62 |
1 files changed, 21 insertions, 41 deletions
diff --git a/cpp/examples/messaging/drain.cpp b/cpp/examples/messaging/drain.cpp index ba613ec364..6edcac2789 100644 --- a/cpp/examples/messaging/drain.cpp +++ b/cpp/examples/messaging/drain.cpp @@ -23,76 +23,56 @@ #include <qpid/messaging/Message.h> #include <qpid/messaging/Receiver.h> #include <qpid/messaging/Session.h> -#include <qpid/Exception.h> -#include <qpid/Options.h> -#include <qpid/log/Logger.h> -#include <qpid/log/Options.h> #include <iostream> +#include "OptionParser.h" + using namespace qpid::messaging; using namespace qpid::types; -struct Options : public qpid::Options +struct Options : OptionParser { - bool help; std::string url; std::string address; std::string connectionOptions; - int64_t timeout; + int timeout; bool forever; - qpid::log::Options log; - Options(const std::string& argv0=std::string()) - : qpid::Options("Options"), - help(false), - url("amqp:tcp:127.0.0.1"), + Options() + : OptionParser("Usage: drain [OPTIONS] ADDRESS", "Drains messages from the specified address"), + url("127.0.0.1"), timeout(0), - forever(false), - log(argv0) + forever(false) { - addOptions() - ("broker,b", qpid::optValue(url, "URL"), "url of broker to connect to") - ("address,a", qpid::optValue(address, "ADDRESS"), "address to drain from") - ("timeout,t", qpid::optValue(timeout, "TIMEOUT"), "timeout in seconds to wait before exiting") - ("forever,f", qpid::optValue(forever), "ignore timeout and wait forever") - ("connection-options", qpid::optValue(connectionOptions,"OPTIONS"), "connection options string in the form {name1=value1, name2=value2}") - ("help", qpid::optValue(help), "print this usage statement"); - add(log); + add("broker,b", url, "url of broker to connect to"); + add("timeout,t", timeout, "timeout in seconds to wait before exiting"); + add("forever,f", forever, "ignore timeout and wait forever"); + add("connection-options", connectionOptions, "connection options string in the form {name1=value1, name2=value2}"); } Duration getTimeout() { if (forever) return Duration::FOREVER; else return timeout*Duration::SECOND; - } - bool parse(int argc, char** argv) + + bool checkAddress() { - try { - qpid::Options::parse(argc, argv); - if (address.empty()) throw qpid::Exception("Address must be specified!"); - qpid::log::Logger::instance().configure(log); - if (help) { - std::ostringstream msg; - std::cout << msg << *this << std::endl << std::endl - << "Drains messages from the specified address" << std::endl; - return false; - } else { - return true; - } - } catch (const std::exception& e) { - std::cerr << *this << std::endl << std::endl << e.what() << std::endl; + if (getArguments().empty()) { + error("Address is required"); return false; + } else { + address = getArguments()[0]; + return true; } } }; - int main(int argc, char** argv) { - Options options(argv[0]); - if (options.parse(argc, argv)) { + Options options; + if (options.parse(argc, argv) && options.checkAddress()) { Connection connection(options.url, options.connectionOptions); try { connection.open(); |