qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r532791 - in /incubator/qpid/branches/M2/cpp: docs/man/qpidd.x lib/CommonOptions.cpp lib/CommonOptions.h lib/common/CommonOptions.cpp lib/common/CommonOptions.h src/qpidd.cpp
Date Thu, 26 Apr 2007 16:21:30 GMT
Author: aconway
Date: Thu Apr 26 09:21:23 2007
New Revision: 532791

URL: http://svn.apache.org/viewvc?view=rev&rev=532791
Log:

Merged revisions 532430 by hand from
https://svn.apache.org/repos/asf/incubator/qpid/branches/trunk/qpid/cpp

------------------------------------------------------------------------
r532750 | aconway | 2007-04-26 10:13:14 -0400 (Thu, 26 Apr 2007) | 4 lines


 - docs/man/qpidd.x: explain file and environment configuration. 
 - src/qpidd.cpp: read config from file.

------------------------------------------------------------------------
r532491 | aconway | 2007-04-25 17:26:53 -0400 (Wed, 25 Apr 2007) | 4 lines

Added environment variables as a source of Qpid configuration.
Option "foo-bar" will be read from env. QPID_FOO_BAR if
not specified on command line.

------------------------------------------------------------------------

Removed:
    incubator/qpid/branches/M2/cpp/lib/CommonOptions.cpp
    incubator/qpid/branches/M2/cpp/lib/CommonOptions.h
Modified:
    incubator/qpid/branches/M2/cpp/docs/man/qpidd.x
    incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.cpp
    incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.h
    incubator/qpid/branches/M2/cpp/src/qpidd.cpp

Modified: incubator/qpid/branches/M2/cpp/docs/man/qpidd.x
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/docs/man/qpidd.x?view=diff&rev=532791&r1=532790&r2=532791
==============================================================================
--- incubator/qpid/branches/M2/cpp/docs/man/qpidd.x (original)
+++ incubator/qpid/branches/M2/cpp/docs/man/qpidd.x Thu Apr 26 09:21:23 2007
@@ -1,5 +1,16 @@
 [NAME]
-qpidd \- the Qpid broker daemon
+qpidd \- the Qpid AMQP broker daemon
 
 [DESCRIPTION]
-.\" Add any additional description here
+
+Start the AMQP broker. The broker options can be specified on the command line (e.g. --worker-threads
10), in an environment variable (e.g. export QPID_WORKER_THREADS=10), or as a line in a configuration
file (e.g. worker-threads=10).
+
+Command line options take precedence over environment variables, which
+take precedence over the config file.
+
+
+
+
+
+
+

Modified: incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.cpp?view=diff&rev=532791&r1=532790&r2=532791
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.cpp (original)
+++ incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.cpp Thu Apr 26 09:21:23 2007
@@ -17,8 +17,28 @@
  */
 
 #include "CommonOptions.h"
+#include <algorithm>
 
 namespace qpid {
+
+namespace program_options {
+
+char env2optchar(char env) {
+    return (env=='_') ? '-' : tolower(env);
+}
+    
+const std::string envPrefix("QPID_");
+
+std::string env2option(const std::string& env) {
+    if (env.find(envPrefix) ==0) {
+        std::string opt = env.substr(envPrefix.size());
+        std::transform(opt.begin(), opt.end(), opt.begin(), env2optchar);
+        return opt;
+    }
+    return std::string();
+} 
+
+} // namespace program_options
 
 const int CommonOptions::DEFAULT_PORT=5672;
 

Modified: incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.h?view=diff&rev=532791&r1=532790&r2=532791
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.h (original)
+++ incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.h Thu Apr 26 09:21:23 2007
@@ -62,6 +62,11 @@
     return new OptionValue<T>(value, argName);
 }
 
+/** Environment-to-option name mapping.
+ * Maps env variable "QPID_SOME_VAR" to option "some-var"
+ */
+std::string env2option(const std::string& env);
+
 /**
  * Like boost::program_options::bool_switch but takes reference, not pointer.
  */

Modified: incubator/qpid/branches/M2/cpp/src/qpidd.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/src/qpidd.cpp?view=diff&rev=532791&r1=532790&r2=532791
==============================================================================
--- incubator/qpid/branches/M2/cpp/src/qpidd.cpp (original)
+++ incubator/qpid/branches/M2/cpp/src/qpidd.cpp Thu Apr 26 09:21:23 2007
@@ -24,7 +24,7 @@
 #include <memory>
 #include <config.h>
 #include <unistd.h>
-
+#include <fstream>
 
 using namespace qpid;
 using namespace qpid::broker;
@@ -37,34 +37,53 @@
     bool help;
     bool version;
     bool daemon;
+    string config;
     po::options_description desc;
     
     QpiddOptions() :
-        help(false), version(false), daemon(false), desc("Options")
+        help(false), version(false), daemon(false),
+        config("/etc/qpidd.conf"),
+        desc("Options")
     {
         using namespace po;
         desc.add_options()
             ("daemon,d", optValue(daemon), "Run as a daemon");
         Broker::Options::addTo(desc);
         desc.add_options()
+            ("config", optValue(config, "FILE"), "Configuation file")
             ("help,h", optValue(help), "Print help message")
             ("version,v", optValue(version), "Print version information");
     }
 
     void parse(int argc, char* argv[]) {
         po::variables_map vm;
+        // Earlier sources get precedence.
         po::store(po::parse_command_line(argc, argv, desc), vm);
+        try { 
+            po::store(po::parse_environment(desc, po::env2option), vm);
+        }
+        catch (const logic_error& e) {
+            throw logic_error(string("parsing environment variables: ")
+                              + e.what());
+        }
+        po::notify(vm);         // So we can use the value of config.
+        try {
+            ifstream conf(config.c_str());
+            po::store(po::parse_config_file(conf, desc), vm);
+        }
+        catch (const logic_error& e) {
+            throw logic_error(string("parsing config file: ")+ e.what());
+        }
         po::notify(vm);
     };
     
-    void usage(std::ostream& out) const {
-        out << "Usage: qpidd [OPTIONS]" << endl 
-            << "Start the Qpid AMQP broker." << endl << endl
+    void usage(ostream& out) const {
+        out << "Usage: qpidd [OPTIONS]" << endl << endl
             << desc << endl;
     };
 };
 
-std::ostream& operator<<(std::ostream& out, const QpiddOptions& config)
 {
+ostream& operator<<(ostream& out, const QpiddOptions& config)  {
     config.usage(out); return out;
 }
 



Mime
View raw message