diff options
Diffstat (limited to 'cpp/lib')
-rw-r--r-- | cpp/lib/broker/Configuration.cpp | 16 | ||||
-rw-r--r-- | cpp/lib/broker/Configuration.h | 263 | ||||
-rw-r--r-- | cpp/lib/common/doxygen_mainpage.h | 45 |
3 files changed, 193 insertions, 131 deletions
diff --git a/cpp/lib/broker/Configuration.cpp b/cpp/lib/broker/Configuration.cpp index 65d60ae1ca..e83c359f2d 100644 --- a/cpp/lib/broker/Configuration.cpp +++ b/cpp/lib/broker/Configuration.cpp @@ -26,7 +26,8 @@ using namespace qpid::broker; using namespace std; Configuration::Configuration() : - trace('t', "trace", "Print incoming & outgoing frames to the console (default=false)", false), + daemon('d', "daemon", "Run as system daemon, detached from terminal.", false), + trace('t', "trace", "Print incoming & outgoing frames to the console", false), port('p', "port", "Set the port to listen on (default=5672)", 5672), workerThreads("worker-threads", "Set the number of worker threads to use (default=5).", 5), maxConnections("max-connections", "Set the maximum number of connections the broker can accept (default=500).", 500), @@ -36,6 +37,7 @@ Configuration::Configuration() : help("help", "Print usage information", false), version("version", "Print version information", false) { + options.push_back(&daemon); options.push_back(&trace); options.push_back(&port); options.push_back(&workerThreads); @@ -57,16 +59,16 @@ void Configuration::parse(char const *progName, int argc, char** argv){ for(op_iterator i = options.begin(); i < options.end() && !matched; i++){ matched = (*i)->parse(position, argv, argc); } - if(!matched){ - std::cerr<< "Warning: skipping unrecognised option " << argv[position] << std::endl; - position++; + if(!matched) { + throw BadOptionException( + std::string("Unrecognised option: ")+argv[position]); } } } void Configuration::usage(){ std::cout << "Usage: " << programName << " [OPTION]..." << std::endl - << "Start the Qpid broker daemon." << std::endl << std::endl + << "Start the Qpid AMQP broker daemon." << std::endl << std::endl << "Options:" << std::endl; for(op_iterator i = options.begin(); i < options.end(); i++){ (*i)->print(std::cout); @@ -84,6 +86,10 @@ bool Configuration::isVersion() const { return version.getValue(); } +bool Configuration::isDaemon() const { + return daemon.getValue(); +} + bool Configuration::isTrace() const { return trace.getValue(); } diff --git a/cpp/lib/broker/Configuration.h b/cpp/lib/broker/Configuration.h index 0351601807..15f2117f5e 100644 --- a/cpp/lib/broker/Configuration.h +++ b/cpp/lib/broker/Configuration.h @@ -27,132 +27,143 @@ #include <Exception.h> namespace qpid { - namespace broker { - class Configuration{ - class Option { - const std::string flag; - const std::string name; - const std::string desc; - - bool match(const std::string& arg); - - protected: - virtual bool needsValue() const = 0; - virtual void setValue(const std::string& value) = 0; - - public: - Option(const char flag, const std::string& name, const std::string& desc); - Option(const std::string& name, const std::string& desc); - virtual ~Option(); - - bool parse(int& i, char** argv, int argc); - void print(std::ostream& out) const; - }; - - class IntOption : public Option{ - const int defaultValue; - int value; - public: - IntOption(char flag, const std::string& name, const std::string& desc, const int value = 0); - IntOption(const std::string& name, const std::string& desc, const int value = 0); - virtual ~IntOption(); - - int getValue() const; - virtual bool needsValue() const; - virtual void setValue(const std::string& value); - virtual void setValue(int _value) { value = _value; } - }; - - class LongOption : public Option{ - const long defaultValue; - int value; - public: - LongOption(char flag, const std::string& name, const std::string& desc, const long value = 0); - LongOption(const std::string& name, const std::string& desc, const long value = 0); - virtual ~LongOption(); - - long getValue() const; - virtual bool needsValue() const; - virtual void setValue(const std::string& value); - virtual void setValue(int _value) { value = _value; } - }; - - class StringOption : public Option{ - const std::string defaultValue; - std::string value; - public: - StringOption(char flag, const std::string& name, const std::string& desc, const std::string value = ""); - StringOption(const std::string& name, const std::string& desc, const std::string value = ""); - virtual ~StringOption(); - - const std::string& getValue() const; - virtual bool needsValue() const; - virtual void setValue(const std::string& value); - }; - - class BoolOption : public Option{ - const bool defaultValue; - bool value; - public: - BoolOption(char flag, const std::string& name, const std::string& desc, const bool value = 0); - BoolOption(const std::string& name, const std::string& desc, const bool value = 0); - virtual ~BoolOption(); - - bool getValue() const; - virtual bool needsValue() const; - virtual void setValue(const std::string& value); - virtual void setValue(bool _value) { value = _value; } - }; - - BoolOption trace; - IntOption port; - IntOption workerThreads; - IntOption maxConnections; - IntOption connectionBacklog; - StringOption store; - LongOption stagingThreshold; - BoolOption help; - BoolOption version; - char const *programName; - - typedef std::vector<Option*>::iterator op_iterator; - std::vector<Option*> options; - - public: - class ParseException : public Exception { - public: - ParseException(const std::string& msg) : Exception(msg) {} - }; - - - Configuration(); - ~Configuration(); - - void parse(char const*, int argc, char** argv); - - bool isHelp() const; - bool isVersion() const; - bool isTrace() const; - int getPort() const; - int getWorkerThreads() const; - int getMaxConnections() const; - int getConnectionBacklog() const; - const std::string& getStore() const; - long getStagingThreshold() const; - - void setHelp(bool b) { help.setValue(b); } - void setVersion(bool b) { version.setValue(b); } - void setTrace(bool b) { trace.setValue(b); } - void setPort(int i) { port.setValue(i); } - void setWorkerThreads(int i) { workerThreads.setValue(i); } - void setMaxConnections(int i) { maxConnections.setValue(i); } - void setConnectionBacklog(int i) { connectionBacklog.setValue(i); } - void setStore(const std::string& s) { store.setValue(s); } - void setStagingThreshold(long l) { stagingThreshold.setValue(l); } - - void usage(); - }; - } +namespace broker { +class Configuration{ + + class Option { + const std::string flag; + const std::string name; + const std::string desc; + + bool match(const std::string& arg); + + protected: + virtual bool needsValue() const = 0; + virtual void setValue(const std::string& value) = 0; + + public: + Option(const char flag, const std::string& name, const std::string& desc); + Option(const std::string& name, const std::string& desc); + virtual ~Option(); + + bool parse(int& i, char** argv, int argc); + void print(std::ostream& out) const; + }; + + class IntOption : public Option{ + const int defaultValue; + int value; + public: + IntOption(char flag, const std::string& name, const std::string& desc, const int value = 0); + IntOption(const std::string& name, const std::string& desc, const int value = 0); + virtual ~IntOption(); + + int getValue() const; + virtual bool needsValue() const; + virtual void setValue(const std::string& value); + virtual void setValue(int _value) { value = _value; } + }; + + class LongOption : public Option{ + const long defaultValue; + int value; + public: + LongOption(char flag, const std::string& name, const std::string& desc, const long value = 0); + LongOption(const std::string& name, const std::string& desc, const long value = 0); + virtual ~LongOption(); + + long getValue() const; + virtual bool needsValue() const; + virtual void setValue(const std::string& value); + virtual void setValue(int _value) { value = _value; } + }; + + class StringOption : public Option{ + const std::string defaultValue; + std::string value; + public: + StringOption(char flag, const std::string& name, const std::string& desc, const std::string value = ""); + StringOption(const std::string& name, const std::string& desc, const std::string value = ""); + virtual ~StringOption(); + + const std::string& getValue() const; + virtual bool needsValue() const; + virtual void setValue(const std::string& value); + }; + + class BoolOption : public Option{ + const bool defaultValue; + bool value; + public: + BoolOption(char flag, const std::string& name, const std::string& desc, const bool value = 0); + BoolOption(const std::string& name, const std::string& desc, const bool value = 0); + virtual ~BoolOption(); + + bool getValue() const; + virtual bool needsValue() const; + virtual void setValue(const std::string& value); + virtual void setValue(bool _value) { value = _value; } + }; + + BoolOption daemon; + BoolOption trace; + IntOption port; + IntOption workerThreads; + IntOption maxConnections; + IntOption connectionBacklog; + StringOption store; + LongOption stagingThreshold; + BoolOption help; + BoolOption version; + char const *programName; + + typedef std::vector<Option*>::iterator op_iterator; + std::vector<Option*> options; + + public: + + struct BadOptionException : public qpid::Exception { + BadOptionException(const std::string& msg) + : qpid::Exception(msg) {} + }; + + + class ParseException : public Exception { + public: + ParseException(const std::string& msg) : Exception(msg) {} + }; + + + Configuration(); + ~Configuration(); + + void parse(char const*, int argc, char** argv); + + bool isHelp() const; + bool isVersion() const; + bool isDaemon() const; + bool isTrace() const; + int getPort() const; + int getWorkerThreads() const; + int getMaxConnections() const; + int getConnectionBacklog() const; + const std::string& getStore() const; + long getStagingThreshold() const; + + void setHelp(bool b) { help.setValue(b); } + void setVersion(bool b) { version.setValue(b); } + void setDaemon(bool b) { daemon.setValue(b); } + void setTrace(bool b) { trace.setValue(b); } + void setPort(int i) { port.setValue(i); } + void setWorkerThreads(int i) { workerThreads.setValue(i); } + void setMaxConnections(int i) { maxConnections.setValue(i); } + void setConnectionBacklog(int i) { connectionBacklog.setValue(i); } + void setStore(const std::string& s) { store.setValue(s); } + void setStagingThreshold(long l) { stagingThreshold.setValue(l); } + + void usage(); +}; +} } diff --git a/cpp/lib/common/doxygen_mainpage.h b/cpp/lib/common/doxygen_mainpage.h new file mode 100644 index 0000000000..b354238cd0 --- /dev/null +++ b/cpp/lib/common/doxygen_mainpage.h @@ -0,0 +1,45 @@ +// This header file is just for doxygen documentation purposes. + +/*!\mainpage Qpid C++ Developer Kit. + * + *\section intro_sec Introduction + * + * The <a href=http://incubator.apache.org/qpid/index.html>Qpid project</a> provides implementations of the <a href="http://amqp.org/">AMQP messaging specification</a> in several programming language. + * + * Qpidc provides APIs and libraries to implement AMQP + * clients in C++. Qpidc clients can interact with any compliant AMQP + * message broker. The Qpid project also provides an AMQP broker + * daemon called qpidd that you can use with your qpidc clients. + * + *\section install_sec Installation + * + * If you are installing from the source distribution + <pre> + > ./configure && make + > make install </pre> + * This will build and install the client development kit and the broker + * in standard places. Use + * <code>./configure --help</code> for more options. + * + * You can also install from RPMs with the <code>rpm -i</code> command. + * You will need + * - <code>qpidc</code> for core libraries. + * - <code>qpidc-devel</code> for header files and developer documentation. + * - <code>qpidd</code> for the broker daemon. + * + *\section getstart_sec Getting Started + * + * If you have installed in the standard places you should use + * these compile flags: + * + *<code> -I/usr/include/qpidc -I/usr/include/qpidc/framing -I/usr/include/qpidc/sys</code> + * + * and these link flags: + * + *<code> -lqpidcommon -lqpidclient</code> + * + * If you have installed somewhere else you should modify the flags + * appropriately. + * + * See the \ref clientapi "client API module" for more on the client API. + */ |