/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/tests/TestOptions.h

00001 #ifndef _TestOptions_
00002 #define _TestOptions_
00003 /*
00004  *
00005  * Licensed to the Apache Software Foundation (ASF) under one
00006  * or more contributor license agreements.  See the NOTICE file
00007  * distributed with this work for additional information
00008  * regarding copyright ownership.  The ASF licenses this file
00009  * to you under the Apache License, Version 2.0 (the
00010  * "License"); you may not use this file except in compliance
00011  * with the License.  You may obtain a copy of the License at
00012  * 
00013  *   http://www.apache.org/licenses/LICENSE-2.0
00014  * 
00015  * Unless required by applicable law or agreed to in writing,
00016  * software distributed under the License is distributed on an
00017  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00018  * KIND, either express or implied.  See the License for the
00019  * specific language governing permissions and limitations
00020  * under the License.
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             // TODO aconway 2007-06-26: broker is synonym for host. Drop broker?
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

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7