00001 #ifndef _TestOptions_
00002 #define _TestOptions_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qpid/Options.h"
00025 #include "qpid/log/Options.h"
00026 #include "qpid/Url.h"
00027 #include "qpid/log/Logger.h"
00028 #include "qpid/client/Connection.h"
00029
00030 #include <iostream>
00031 #include <exception>
00032
00033 namespace qpid {
00034
00035 struct TestOptions : public qpid::Options
00036 {
00037 TestOptions(const std::string& helpText_=std::string()) :
00038 Options("Test Options"),
00039 host("localhost"), port(TcpAddress::DEFAULT_PORT),
00040 clientid("cpp"), username("guest"), password("guest"),
00041 help(false), helpText(helpText_)
00042 {
00043 addOptions()
00044 ("host,h", optValue(host, "HOST"), "Broker host to connect to")
00045
00046 ("broker,b", optValue(host, "HOST"), "Broker host to connect to")
00047 ("port,p", optValue(port, "PORT"), "Broker port to connect to")
00048 ("virtualhost,v", optValue(virtualhost, "VHOST"), "virtual host")
00049 ("clientname,n", optValue(clientid, "ID"), "unique client identifier")
00050 ("username", optValue(username, "USER"), "user name for broker log in.")
00051 ("password", optValue(password, "USER"), "password for broker log in.")
00052 ("help", optValue(help), "print this usage statement");
00053 add(log);
00054 }
00055
00057 void parse(int argc, char** argv) {
00058 try {
00059 qpid::Options::parse(argc, argv);
00060 } catch (const std::exception& e) {
00061 std::ostringstream msg;
00062 msg << *this << std::endl << std::endl << e.what() << std::endl;
00063 throw qpid::Options::Exception(msg.str());
00064 }
00065 trace = log.trace;
00066 qpid::log::Logger::instance().configure(log, argv[0]);
00067 if (help) {
00068 std::ostringstream msg;
00069 msg << *this << std::endl << std::endl << helpText << std::endl;
00070 throw qpid::Options::Exception(msg.str());
00071 }
00072 }
00073
00075 void open(qpid::client::Connection& connection) {
00076 connection.open(host, port, username, password, virtualhost);
00077 }
00078
00079
00080 std::string host;
00081 uint16_t port;
00082 std::string virtualhost;
00083 std::string clientid;
00084 std::string username;
00085 std::string password;
00086 bool trace;
00087 bool help;
00088 log::Options log;
00089 std::string helpText;
00090 };
00091
00092 }
00093
00094 #endif