From 8c0153e035caa90758a6773493d5859716521e30 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 5 May 2010 11:17:41 +0000 Subject: 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 --- cpp/examples/messaging/drain.cpp | 62 ++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) (limited to 'cpp/examples/messaging/drain.cpp') 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 #include #include -#include -#include -#include -#include #include +#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(); -- cgit v1.2.1