summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/Options.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-07-24 19:39:27 +0000
committerAlan Conway <aconway@apache.org>2007-07-24 19:39:27 +0000
commitb7c528b027bff7585481c9ce3a01144040c6de5a (patch)
tree6e4588e6b52a5a5457767ae9f8b59cddcfd28ef6 /cpp/src/qpid/Options.cpp
parent0dcc71862cb48a79263a05facd4c42453441cbb5 (diff)
downloadqpid-python-b7c528b027bff7585481c9ce3a01144040c6de5a.tar.gz
* Summary:
- Wiring (declare/delete/bind) is replicated via AIS. - TestOptions includes all logging options. - Logger automatically parses env vars so logging can be enabled for any program linked with libqpidcommon e.g. by setting QPID_TRACE=1. * src/qpid/cluster/SessionManager.cpp: Handle frames from cluster - Forward to BrokerAdapter for execution. - Suppress responses in proxy. * src/tests/TestOptions.h (Options): Logging options, --help option. * src/qpid/client/ClientConnection.cpp: Removed log initialization. Logs are initialized either in TestOptions or automatically from env vars, e.g. QPID_TRACE, * src/qpid/QpidError.h (class QpidError): Initialize Exception in constructor so messages can be logged. * src/qpid/framing/ChannelAdapter.h: Made send() virtual. * src/tests/Cluster_child.cpp: UUID corrected. * src/qpid/broker/Broker.cpp: Pass chains to updater by ref. * src/qpid/Options.cpp (parse): Fix log settings from environment. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@559171 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/Options.cpp')
-rw-r--r--cpp/src/qpid/Options.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/cpp/src/qpid/Options.cpp b/cpp/src/qpid/Options.cpp
index 7f4536ff7b..2b6cff44f6 100644
--- a/cpp/src/qpid/Options.cpp
+++ b/cpp/src/qpid/Options.cpp
@@ -18,6 +18,9 @@
#include "Options.h"
#include "qpid/Exception.h"
+
+#include <boost/bind.hpp>
+
#include <fstream>
#include <algorithm>
#include <iostream>
@@ -28,18 +31,26 @@ using namespace std;
namespace {
-char env2optchar(char env) { return (env=='_') ? '-' : tolower(env); }
+struct EnvOptMapper {
+ static bool matchChar(char env, char opt) {
+ return (env==toupper(opt)) || (strchr("-.", opt) && env=='_');
+ }
-struct Mapper {
- Mapper(const Options& o) : opts(o) {}
- string operator()(const string& env) {
+ static bool matchStr(const string& env, boost::shared_ptr<po::option_description> desc) {
+ return std::equal(env.begin(), env.end(), desc->long_name().begin(), &matchChar);
+ }
+
+ EnvOptMapper(const Options& o) : opts(o) {}
+
+ string operator()(const string& envVar) {
static const std::string prefix("QPID_");
- if (env.substr(0, prefix.size()) == prefix) {
- string opt = env.substr(prefix.size());
- transform(opt.begin(), opt.end(), opt.begin(), env2optchar);
- // Ignore env vars that don't match to known options.
- if (opts.find_nothrow(opt, false))
- return opt;
+ if (envVar.substr(0, prefix.size()) == prefix) {
+ string env = envVar.substr(prefix.size());
+ typedef const std::vector< boost::shared_ptr<po::option_description> > OptDescs;
+ OptDescs::const_iterator i =
+ find_if(opts.options().begin(), opts.options().end(), boost::bind(matchStr, env, _1));
+ if (i != opts.options().end())
+ return (*i)->long_name();
}
return string();
}
@@ -62,7 +73,7 @@ void Options::parse(int argc, char** argv, const std::string& configFile)
if (argc > 0 && argv != 0)
po::store(po::parse_command_line(argc, argv, *this), vm);
parsing="environment variables";
- po::store(po::parse_environment(*this, Mapper(*this)), vm);
+ po::store(po::parse_environment(*this, EnvOptMapper(*this)), vm);
po::notify(vm); // configFile may be updated from arg/env options.
if (!configFile.empty()) {
parsing="configuration file "+configFile;