diff options
author | Alan Conway <aconway@apache.org> | 2009-07-15 16:45:21 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2009-07-15 16:45:21 +0000 |
commit | e7881513358cf21203fdb0987807c18b599a5310 (patch) | |
tree | 5a98db4334ab6d232e8bc13cad1d6bcf5c64b176 /qpid/cpp/include/qpid | |
parent | 6bd0e9b3ff37431b539bf2db22117c5ee099a2f9 (diff) | |
download | qpid-python-e7881513358cf21203fdb0987807c18b599a5310.tar.gz |
Merge branch 'move_public_h_to_include' into trunk
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@794325 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/include/qpid')
84 files changed, 7959 insertions, 0 deletions
diff --git a/qpid/cpp/include/qpid/Address.h b/qpid/cpp/include/qpid/Address.h new file mode 100755 index 0000000000..fe82b21b9e --- /dev/null +++ b/qpid/cpp/include/qpid/Address.h @@ -0,0 +1,85 @@ +#ifndef QPID_ADDRESS_H +#define QPID_ADDRESS_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/sys/IntegerTypes.h" +#include "qpid/CommonImportExport.h" +#include <boost/variant.hpp> +#include <iosfwd> +#include <string> +#include <vector> + +namespace qpid { + +/** TCP address of a broker - host:port */ +struct TcpAddress { + static const uint16_t DEFAULT_PORT=5672; + QPID_COMMON_EXTERN explicit TcpAddress(const std::string& host_=std::string(),uint16_t port_=DEFAULT_PORT); + std::string host; + uint16_t port; +}; +bool operator==(const TcpAddress& x, const TcpAddress& y); +QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const TcpAddress& a); + +/**@internal Not a real address type, this is a placeholder to + * demonstrate and validate multi-protocol Urls for unit tests and + * developer education only. An example address holds just a char. + */ +struct ExampleAddress { + explicit ExampleAddress(char data); + char data; +}; +bool operator==(const ExampleAddress& x, const ExampleAddress& y); +std::ostream& operator<<(std::ostream& os, const ExampleAddress& a); + +/** + * Contains the address of an AMQP broker. Can any supported type of + * broker address. Currently only TcpAddress is supported. + */ +struct Address { +public: + Address(const Address& a) : value(a.value) {} + Address(const TcpAddress& tcp) : value(tcp) {} + Address(const ExampleAddress& eg) : value(eg) {} ///<@internal + + template <class AddressType> Address& operator=(const AddressType& t) { value=t; return *this; } + + /** Get the address of type AddressType. + *@return AddressType* pointing to the contained address or 0 if + *contained address is not of type AddressType. + */ + template <class AddressType> AddressType* get() { return boost::get<AddressType>(&value); } + + /** Get the address of type AddressType. + *@return AddressType* pointing to the contained address or 0 if + *contained address is not of type AddressType. + */ + template <class AddressType> const AddressType* get() const { return boost::get<AddressType>(&value); } + +private: + boost::variant<TcpAddress,ExampleAddress> value; + friend std::ostream& operator<<(std::ostream& os, const Address& addr); +}; + + + +} // namespace qpid + +#endif /*!QPID_ADDRESS_H*/ diff --git a/qpid/cpp/include/qpid/CommonImportExport.h b/qpid/cpp/include/qpid/CommonImportExport.h new file mode 100644 index 0000000000..02c06ed7af --- /dev/null +++ b/qpid/cpp/include/qpid/CommonImportExport.h @@ -0,0 +1,33 @@ +#ifndef QPID_COMMON_IMPORT_EXPORT_H +#define QPID_COMMON_IMPORT_EXPORT_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#if defined(WIN32) && !defined(QPID_DECLARE_STATIC) +#if defined(COMMON_EXPORT) || defined (qpidcommon_EXPORTS) +#define QPID_COMMON_EXTERN __declspec(dllexport) +#else +#define QPID_COMMON_EXTERN __declspec(dllimport) +#endif +#else +#define QPID_COMMON_EXTERN +#endif + +#endif diff --git a/qpid/cpp/include/qpid/Exception.h b/qpid/cpp/include/qpid/Exception.h new file mode 100644 index 0000000000..7b937c242a --- /dev/null +++ b/qpid/cpp/include/qpid/Exception.h @@ -0,0 +1,93 @@ +#ifndef _Exception_ +#define _Exception_ + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/framing/amqp_types.h" +#include "qpid/framing/constants.h" +#include "qpid/framing/enum.h" +#include "qpid/sys/StrError.h" +#include "qpid/Msg.h" +#include "qpid/CommonImportExport.h" +#include <memory> +#include <string> +#include <errno.h> + +namespace qpid +{ + +/** + * Base class for Qpid runtime exceptions. + */ +class Exception : public std::exception +{ + public: + QPID_COMMON_EXTERN explicit Exception(const std::string& message=std::string()) throw(); + QPID_COMMON_EXTERN virtual ~Exception() throw(); + QPID_COMMON_EXTERN virtual const char* what() const throw(); // prefix: message + QPID_COMMON_EXTERN virtual std::string getMessage() const; // Unprefixed message + QPID_COMMON_EXTERN virtual std::string getPrefix() const; // Prefix + + private: + std::string message; + mutable std::string whatStr; +}; + +/** Exception that includes an errno message. */ +struct ErrnoException : public Exception { + ErrnoException(const std::string& msg, int err) : Exception(msg+": "+qpid::sys::strError(err)) {} + ErrnoException(const std::string& msg) : Exception(msg+": "+qpid::sys::strError(errno)) {} +}; + +struct SessionException : public Exception { + const framing::execution::ErrorCode code; + SessionException(framing::execution::ErrorCode code_, const std::string& message) + : Exception(message), code(code_) {} +}; + +struct ChannelException : public Exception { + const framing::session::DetachCode code; + ChannelException(framing::session::DetachCode _code, const std::string& message) + : Exception(message), code(_code) {} +}; + +struct ConnectionException : public Exception { + const framing::connection::CloseCode code; + ConnectionException(framing::connection::CloseCode _code, const std::string& message) + : Exception(message), code(_code) {} +}; + +struct ClosedException : public Exception { + QPID_COMMON_EXTERN ClosedException(const std::string& msg=std::string()); + QPID_COMMON_EXTERN std::string getPrefix() const; +}; + +/** + * Exception representing transport failure + */ +struct TransportFailure : public Exception { + TransportFailure(const std::string& msg=std::string()) : Exception(msg) {} +}; + +} // namespace qpid + +#endif /*!_Exception_*/ diff --git a/qpid/cpp/include/qpid/InlineAllocator.h b/qpid/cpp/include/qpid/InlineAllocator.h new file mode 100644 index 0000000000..2502545dcb --- /dev/null +++ b/qpid/cpp/include/qpid/InlineAllocator.h @@ -0,0 +1,101 @@ +#ifndef QPID_INLINEALLOCATOR_H +#define QPID_INLINEALLOCATOR_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <memory> +#include <assert.h> +#include <boost/type_traits/type_with_alignment.hpp> +#include <boost/type_traits/alignment_of.hpp> + +namespace qpid { + +template <typename RequestedType, typename InlineType, typename BaseAllocator, size_t Max> +struct InlineRebind; + + +/** + * An allocator that has inline storage for up to Max objects + * of type BaseAllocator::value_type. + */ +template <class BaseAllocator, size_t Max> +class InlineAllocator : public BaseAllocator { + public: + typedef typename BaseAllocator::pointer pointer; + typedef typename BaseAllocator::size_type size_type; + typedef typename BaseAllocator::value_type value_type; + + InlineAllocator() : allocated(false) {} + InlineAllocator(const InlineAllocator& x) : BaseAllocator(x), allocated(false) {} + + pointer allocate(size_type n) { + if (n <= Max && !allocated) { + allocated=true; + return reinterpret_cast<value_type*>(address()); + } + else + return BaseAllocator::allocate(n, 0); + } + + void deallocate(pointer p, size_type n) { + if (p == address()) { + assert(allocated); + allocated=false; + } + else + BaseAllocator::deallocate(p, n); + } + + template<typename T1> + struct rebind { + typedef typename InlineRebind<T1, value_type, BaseAllocator, Max>::other other; + }; + + private: + // POD object with alignment and size to hold Max value_types. + static const size_t ALIGNMENT=boost::alignment_of<value_type>::value; + typedef typename boost::type_with_alignment<ALIGNMENT>::type Aligner; + union Store { + Aligner aligner_; + char sizer_[sizeof(value_type)*Max]; + } store; + value_type* address() { return reinterpret_cast<value_type*>(&store); } + bool allocated; +}; + + +// Rebind: if RequestedType == InlineType, use the InlineAllocator, +// otherwise, use the BaseAllocator without any inlining. + +template <typename RequestedType, typename InlineType, typename BaseAllocator, size_t Max> +struct InlineRebind { + typedef typename BaseAllocator::template rebind<RequestedType>::other other; +}; + +template <typename T, typename BaseAllocator, size_t Max> +struct InlineRebind<T, T, BaseAllocator, Max> { + typedef typename qpid::InlineAllocator<BaseAllocator, Max> other; +}; + +} // namespace qpid + +#endif /*!QPID_INLINEALLOCATOR_H*/ diff --git a/qpid/cpp/include/qpid/InlineVector.h b/qpid/cpp/include/qpid/InlineVector.h new file mode 100644 index 0000000000..c55db295f3 --- /dev/null +++ b/qpid/cpp/include/qpid/InlineVector.h @@ -0,0 +1,68 @@ +#ifndef QPID_INLINEVECTOR_H +#define QPID_INLINEVECTOR_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/InlineAllocator.h" +#include <vector> + +namespace qpid { + +/** + * A vector that stores up to Max elements in inline storage, + * otherwise uses normal vector allocation. + * + * NOTE: depends on some non-standard but highly probably assumptions + * about how std::vector uses its allocator, they are true for g++. + * - default constructor does not allocate. + * - reserve(N) does not allocate more than N elements. + * - vector never re-allocates when size() < capacity() + */ +template <class T, size_t Max, class Alloc=std::allocator<T> > +class InlineVector : public std::vector<T, InlineAllocator<Alloc, Max> > +{ + typedef std::vector<T, InlineAllocator<Alloc, Max> > Base; + public: + typedef typename Base::allocator_type allocator_type; + typedef typename Base::value_type value_type; + typedef typename Base::size_type size_type; + + explicit InlineVector(const allocator_type& a=allocator_type()) : Base(a) { + this->reserve(Max); + } + + explicit InlineVector(size_type n, const value_type& x = value_type(), + const allocator_type& a=allocator_type()) : Base(a) + { + this->reserve(std::max(n, Max)); + this->insert(this->end(), n, x); + } + + InlineVector(const InlineVector& x) : Base() { + this->reserve(std::max(x.size(), Max)); + *this = x; + } +}; + +} // namespace qpid + +#endif /*!QPID_INLINEVECTOR_H*/ diff --git a/qpid/cpp/include/qpid/Msg.h b/qpid/cpp/include/qpid/Msg.h new file mode 100644 index 0000000000..5149a94d7f --- /dev/null +++ b/qpid/cpp/include/qpid/Msg.h @@ -0,0 +1,61 @@ +#ifndef QPID_MSG_H +#define QPID_MSG_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <sstream> +#include <iostream> + +namespace qpid { + +/** A simple wrapper for std::ostringstream that allows + * in place construction of a message and automatic conversion + * to string. + * E.g. + *@code + * void foo(const std::string&); + * foo(Msg() << "hello " << 32); + *@endcode + * Will construct the string "hello 32" and pass it to foo() + */ +struct Msg { + std::ostringstream os; + Msg() {} + Msg(const Msg& m) : os(m.str()) {} + std::string str() const { return os.str(); } + operator std::string() const { return str(); } +}; + +template <class T> const Msg& operator<<(const Msg& m, const T& t) { + const_cast<std::ostringstream&>(m.os)<<t; return m; +} + +inline std::ostream& operator<<(std::ostream& o, const Msg& m) { + return o<<m.str(); +} + +/** Construct a message using operator << and append (file:line) */ +#define QPID_MSG(message) ::qpid::Msg() << message << " (" << __FILE__ << ":" << __LINE__ << ")" + +} // namespace qpid + +#endif /*!QPID_MSG_H*/ diff --git a/qpid/cpp/include/qpid/Options.h b/qpid/cpp/include/qpid/Options.h new file mode 100644 index 0000000000..078a6b4d95 --- /dev/null +++ b/qpid/cpp/include/qpid/Options.h @@ -0,0 +1,265 @@ +#ifndef QPID_COMMONOPTIONS_H +#define QPID_COMMONOPTIONS_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/Exception.h" + +// Disable warnings triggered by boost. +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4251 4275) +#endif + +#include <boost/program_options.hpp> +#include <boost/format.hpp> + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + +#include <sstream> +#include <iterator> +#include <algorithm> +#include <string> +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace po=boost::program_options; + + + +///@internal +QPID_COMMON_EXTERN std::string prettyArg(const std::string&, const std::string&); + +/** @internal Normally only constructed by optValue() */ +template <class T> +class OptionValue : public po::typed_value<T> { + public: + OptionValue(T& value, const std::string& arg) + : po::typed_value<T>(&value), argName(arg) {} + std::string name() const { return argName; } + + private: + std::string argName; +}; + + +/** Create an option value. + * name, value appear after the option name in help like this: + * <name> (=<value>) + * T must support operator <<. + *@see Options for example of use. + */ +template<class T> +po::value_semantic* optValue(T& value, const char* name) { + std::string valstr(boost::lexical_cast<std::string>(value)); + return new OptionValue<T>(value, prettyArg(name, valstr)); +} + +/** Create a vector value. Multiple occurences of the option are + * accumulated into the vector + */ +template <class T> +po::value_semantic* optValue(std::vector<T>& value, const char* name) { + using namespace std; + ostringstream os; + copy(value.begin(), value.end(), ostream_iterator<T>(os, " ")); + string val=os.str(); + if (!val.empty()) + val.erase(val.end()-1); // Remove trailing " " + return (new OptionValue<vector<T> >(value, prettyArg(name, val))); +} + +/** Create a boolean switch value. Presence of the option sets the value. */ +inline po::value_semantic* optValue(bool& value) { return po::bool_switch(&value); } + +/** + * Base class for options. + * Example of use: + @code + struct MySubOptions : public Options { + int x; + string y; + MySubOptions() : Options("Sub options") { + addOptions() + ("x", optValue(x,"XUNIT"), "Option X") + ("y", optValue(y, "YUNIT"), "Option Y"); + } + }; + + struct MyOptions : public Options { + bool z; + vector<string> foo; + MySubOptions subOptions; + MyOptions() : Options("My Options") { + addOptions() + ("z", boolSwitch(z), "Option Z") + ("foo", optValue(foo), "Multiple option foo"); + add(subOptions); + } + + main(int argc, char** argv) { + Options opts; + opts.parse(argc, char** argv); + // Use values + dosomething(opts.subOptions.x); + if (error) + cout << opts << end; // Help message. + } + + @endcode + */ + + + + +/* + * --------------------------------------------- + * Explanation for Boost 103200 conditional code + * --------------------------------------------- + * + * This boost version has an implementation of the program_options library + * that has no provision for allowing unregistered options to pass by. + * + * But that means that, if you have a program that loads optional modules + * after start-up, and those modules each have their own set of options, + * then if you parse the command line too soon, you will get spurious + * reports of unrecognized options -- and the program will exit! + * + * And we must process the command-line before module-loading, because we + * need to look at the "bootstrap" options. + * + * This conditional code: + * + * 1. implements it's own functor class, derived from the Boost + * "options_description_easy_init" class. This functor is used + * to process added options and do the functor chaining, so that + * I can snoop on the arguments before doing an explicit call + * to its parent. + * + * 2. It implements two static vectors, one to hold long names, and + * one for short names, so that options declared by modules are + * not forgotten when their options_description goes out of scope. + * + * I will be thrilled to personally delete this code if we ever decide + * that qpid doesn't really need to support this antique version of Boost. + * + */ + +#if ( BOOST_VERSION == 103200 ) +struct Options; + + +struct +options_description_less_easy_init + : public po::options_description_easy_init +{ + options_description_less_easy_init ( Options * my_owner, + po::options_description * my_parents_owner + ) + : po::options_description_easy_init(my_parents_owner) + { + owner = my_owner; + } + + + options_description_less_easy_init& + operator()(char const * name, + char const * description); + + + options_description_less_easy_init& + operator()(char const * name, + const po::value_semantic* s); + + + options_description_less_easy_init& + operator()(const char* name, + const po::value_semantic* s, + const char* description); + + + Options * owner; +}; +#endif + + +struct Options : public po::options_description { + + struct Exception : public qpid::Exception { + Exception(const std::string& msg) : qpid::Exception(msg) {} + }; + + QPID_COMMON_EXTERN Options(const std::string& name=std::string()); + + /** + * Parses options from argc/argv, environment variables and config file. + * Note the filename argument can reference an options variable that + * is updated by argc/argv or environment variable parsing. + */ + QPID_COMMON_EXTERN void parse(int argc, char const* const* argv, + const std::string& configfile=std::string(), + bool allowUnknown = false); + + + #if ( BOOST_VERSION == 103200 ) + options_description_less_easy_init m_less_easy; + + options_description_less_easy_init addOptions() { + return m_less_easy; + } + + bool + is_registered_option ( std::string s ); + + void + register_names ( std::string s ); + + static std::vector<std::string> long_names; + static std::vector<std::string> short_names; + #else + boost::program_options::options_description_easy_init addOptions() { + return add_options(); + } + #endif +}; + + + +/** + * Standard options for configuration + */ +struct CommonOptions : public Options { + QPID_COMMON_EXTERN CommonOptions(const std::string& name=std::string(), + const std::string& configfile=std::string()); + bool help; + bool version; + std::string config; +}; + + + + +} // namespace qpid + +#endif /*!QPID_COMMONOPTIONS_H*/ diff --git a/qpid/cpp/include/qpid/RangeSet.h b/qpid/cpp/include/qpid/RangeSet.h new file mode 100644 index 0000000000..1b2e4201a6 --- /dev/null +++ b/qpid/cpp/include/qpid/RangeSet.h @@ -0,0 +1,330 @@ +#ifndef QPID_RANGESET_H +#define QPID_RANGESET_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/InlineVector.h" +#include <boost/iterator/iterator_facade.hpp> +#include <boost/operators.hpp> +#include <boost/bind.hpp> +#include <algorithm> +#include <numeric> + +namespace qpid { + +/** A range of values, used in RangeSet. + * Range(begin, end) includes begin but excludes end. + * Range::makeClosed(first,last) includes both first and last. + */ +template <class T> +class Range { + public: + static Range makeClosed(const T& first, T last) { return Range(first, ++last); } + + Range() : begin_(), end_() {} + explicit Range(const T& t) : begin_(t), end_(t) { ++end_; } + Range(const T& b, const T& e) : begin_(b), end_(e) { assert(b <= e); } + + T begin() const { return begin_; } + /** End of _open_ range, i.e. !contains(end()) */ + T end() const { return end_; } + + T first() const { assert(!empty()); return begin_; } + /** Last in closed range, i.e. contains(end()) */ + T last() const { assert(!empty()); T ret=end_; return --ret; } + + void begin(const T& t) { begin_ = t; } + void end(const T& t) { end_ = t; } + size_t size() const { return end_ - begin_; } + bool empty() const { return begin_ == end_; } + + bool contains(const T& x) const { return begin_ <= x && x < end_; } + bool contains(const Range& r) const { return begin_ <= r.begin_ && r.end_ <= end_; } + bool strictContains(const Range& r) const { return begin_ < r.begin_ && r.end_ < end_; } + + bool operator==(const Range& x) { return begin_ == x.begin_ && end_== x.end_; } + + bool operator<(const T& t) const { return end_ < t; } + bool operator<(const Range<T>& r) const { return end_ < r.begin_; } + + /** touching ranges can be merged into a single range. */ + bool touching(const Range& r) const { + return std::max(begin_, r.begin_) <= std::min(end_, r.end_); + } + + /** @pre touching */ + void merge(const Range& r) { + assert(touching(r)); + begin_ = std::min(begin_, r.begin_); + end_ = std::max(end_, r.end_); + } + + operator bool() const { return !empty(); } + + template <class S> void serialize(S& s) { s(begin_)(end_); } + + private: + T begin_, end_; +}; + + +/** + * A set implemented as a list of [begin, end) ranges. + * T must be LessThanComparable and Incrementable. + * RangeSet only provides const iterators. + */ +template <class T> +class RangeSet + : boost::additive1<RangeSet<T>, + boost::additive2<RangeSet<T>, Range<T>, + boost::additive2<RangeSet<T>, T> > > +{ + typedef InlineVector<Range<T>, 3> Ranges; // TODO aconway 2008-04-21: what's the optimial inlined value? + + public: + + class iterator : public boost::iterator_facade< + iterator, + const T, + boost::forward_traversal_tag> + { + public: + iterator() : ranges(), iter(), value() {} + + private: + typedef typename Ranges::const_iterator RangesIter; + iterator(const Ranges& r, const RangesIter& i, const T& t) + : ranges(&r), iter(i), value(t) {} + + void increment(); + bool equal(const iterator& i) const; + const T& dereference() const { return value; } + + const Ranges* ranges; + RangesIter iter; + T value; + + friend class RangeSet<T>; + friend class boost::iterator_core_access; + }; + + typedef iterator const_iterator; + + RangeSet() {} + explicit RangeSet(const Range<T>& r) { *this += r; } + RangeSet(const T& a, const T& b) { *this += Range<T>(a,b); } + + bool contiguous() const { return ranges.size() <= 1; } + + bool contains(const T& t) const; + bool contains(const Range<T>&) const; + + /**@pre contiguous() */ + Range<T> toRange() const; + + bool operator==(const RangeSet<T>&) const; + + void addRange (const Range<T>&); + void addSet (const RangeSet<T>&); + + RangeSet<T>& operator+=(const T& t) { return *this += Range<T>(t); } + RangeSet<T>& operator+=(const Range<T>& r) { addRange(r); return *this; } + RangeSet<T>& operator+=(const RangeSet<T>& s) { addSet(s); return *this; } + + void removeRange (const Range<T>&); + void removeSet (const RangeSet<T>&); + + RangeSet<T>& operator-=(const T& t) { return *this -= Range<T>(t); } + RangeSet<T>& operator-=(const Range<T>& r) { removeRange(r); return *this; } + RangeSet<T>& operator-=(const RangeSet<T>& s) { removeSet(s); return *this; } + + T front() const { return ranges.front().begin(); } + T back() const { return ranges.back().end(); } + + // Iterate over elements in the set. + iterator begin() const; + iterator end() const; + + // Iterate over ranges in the set. + typedef typename Ranges::const_iterator RangeIterator; + RangeIterator rangesBegin() const { return ranges.begin(); } + RangeIterator rangesEnd() const { return ranges.end(); } + size_t rangesSize() const { return ranges.size(); } + + // The difference between the start and end of this range set + uint32_t span() const; + + size_t size() const; + bool empty() const { return ranges.empty(); } + void clear() { ranges.clear(); } + + /** Return the largest contiguous range containing x. + * Returns the empty range [x,x) if x is not in the set. + */ + Range<T> rangeContaining(const T&) const; + + template <class S> void serialize(S& s) { s.split(*this); s(ranges.begin(), ranges.end()); } + template <class S> void encode(S& s) const { s(uint16_t(ranges.size()*sizeof(Range<T>))); } + template <class S> void decode(S& s) { uint16_t sz; s(sz); ranges.resize(sz/sizeof(Range<T>)); } + + private: + static size_t accumulateSize(size_t s, const Range<T>& r) { return s+r.size(); } + Ranges ranges; + + template <class U> friend std::ostream& operator<<(std::ostream& o, const RangeSet<U>& r); + + friend class iterator; +}; + +template <class T> +std::ostream& operator<<(std::ostream& o, const Range<T>& r) { + return o << "[" << r.begin() << "," << r.end() << ")"; +} + +template <class T> +std::ostream& operator<<(std::ostream& o, const RangeSet<T>& rs) { + std::ostream_iterator<Range<T> > i(o, " "); + o << "{ "; + std::copy(rs.ranges.begin(), rs.ranges.end(), i); + return o << "}"; +} + +template <class T> +bool RangeSet<T>::contains(const T& t) const { + typename Ranges::const_iterator i = + std::lower_bound(ranges.begin(), ranges.end(), Range<T>(t)); + return i != ranges.end() && i->contains(t); +} + +template <class T> +bool RangeSet<T>::contains(const Range<T>& r) const { + typename Ranges::const_iterator i = + std::lower_bound(ranges.begin(), ranges.end(), r); + return i != ranges.end() && i->contains(r); +} + +template <class T> void RangeSet<T>::addRange(const Range<T>& r) { + if (r.empty()) return; + typename Ranges::iterator i = + std::lower_bound(ranges.begin(), ranges.end(), r); + if (i == ranges.end() || !i->touching(r)) + ranges.insert(i, r); + else { + i->merge(r); + typename Ranges::iterator j = i; + if (++j != ranges.end() && i->touching(*j)) { + i->merge(*j); + ranges.erase(j); + } + } +} + + +template <class T> void RangeSet<T>::addSet(const RangeSet<T>& s) { + typedef RangeSet<T>& (RangeSet<T>::*RangeSetRangeOp)(const Range<T>&); + std::for_each(s.ranges.begin(), s.ranges.end(), + boost::bind((RangeSetRangeOp)&RangeSet<T>::operator+=, this, _1)); +} + +template <class T> void RangeSet<T>::removeRange(const Range<T>& r) { + if (r.empty()) return; + typename Ranges::iterator i,j; + i = std::lower_bound(ranges.begin(), ranges.end(), r); + if (i == ranges.end() || i->begin() >= r.end()) + return; // Outside of set + if (*i == r) // Erase i + ranges.erase(i); + else if (i->strictContains(r)) { // Split i + Range<T> i1(i->begin(), r.begin()); + Range<T> i2(r.end(), i->end()); + *i = i2; + ranges.insert(i, i1); + } else { + if (i->begin() < r.begin()) { // Truncate i + i->end(r.begin()); + ++i; + } + for (j = i; j != ranges.end() && r.contains(*j); ++j) + ; // Ranges to erase. + if (j != ranges.end() && j->end() > r.end()) + j->begin(r.end()); // Truncate j + ranges.erase(i,j); + } +} + +template <class T> void RangeSet<T>::removeSet(const RangeSet<T>& r) { + std::for_each( + r.ranges.begin(), r.ranges.end(), + boost::bind(&RangeSet<T>::removeRange, this, _1)); +} + +template <class T> Range<T> RangeSet<T>::toRange() const { + assert(contiguous()); + return empty() ? Range<T>() : ranges.front(); +} + +template <class T> void RangeSet<T>::iterator::increment() { + assert(ranges && iter != ranges->end()); + if (!iter->contains(++value)) { + ++iter; + if (iter == ranges->end()) + *this=iterator(); // end() iterator + else + value=iter->begin(); + } +} + +template <class T> bool RangeSet<T>::operator==(const RangeSet<T>& r) const { + return ranges.size() == r.ranges.size() && std::equal(ranges.begin(), ranges.end(), r.ranges.begin()); +} + +template <class T> typename RangeSet<T>::iterator RangeSet<T>::begin() const { + return empty() ? end() : iterator(ranges, ranges.begin(), front()); +} + +template <class T> typename RangeSet<T>::iterator RangeSet<T>::end() const { + return iterator(); +} + +template <class T> bool RangeSet<T>::iterator::equal(const iterator& i) const { + return ranges==i.ranges && (ranges==0 || value==i.value); +} + +template <class T> Range<T> RangeSet<T>::rangeContaining(const T& t) const { + typename Ranges::const_iterator i = + std::lower_bound(ranges.begin(), ranges.end(), Range<T>(t)); + return (i != ranges.end() && i->contains(t)) ? *i : Range<T>(t,t); +} + +template <class T> uint32_t RangeSet<T>::span() const { + if (ranges.empty()) return 0; + return ranges.back().last() - ranges.front().first(); +} + +template <class T> size_t RangeSet<T>::size() const { + return std::accumulate(rangesBegin(), rangesEnd(), 0, &RangeSet<T>::accumulateSize); +} + +} // namespace qpid + + +#endif /*!QPID_RANGESET_H*/ diff --git a/qpid/cpp/include/qpid/SessionId.h b/qpid/cpp/include/qpid/SessionId.h new file mode 100644 index 0000000000..e18b360999 --- /dev/null +++ b/qpid/cpp/include/qpid/SessionId.h @@ -0,0 +1,60 @@ +#ifndef QPID_SESSIONID_H +#define QPID_SESSIONID_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <boost/operators.hpp> +#include <string> +#include <qpid/CommonImportExport.h> + +namespace qpid { + +/** Identifier for a session. + * There are two parts to a session identifier: + * + * getUserId() returns the authentication principal associated with + * the session's connection. + * + * getName() returns the session name. + * + * The name must be unique among sessions with the same authentication + * principal. + */ +class SessionId : boost::totally_ordered1<SessionId> { + std::string userId; + std::string name; + public: + QPID_COMMON_EXTERN SessionId(const std::string& userId=std::string(), const std::string& name=std::string()); + std::string getUserId() const { return userId; } + std::string getName() const { return name; } + QPID_COMMON_EXTERN bool operator<(const SessionId&) const ; + QPID_COMMON_EXTERN bool operator==(const SessionId& id) const; + // Convert to a string + QPID_COMMON_EXTERN std::string str() const; +}; + +QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const SessionId&); + + +} // namespace qpid + +#endif /*!QPID_SESSIONID_H*/ diff --git a/qpid/cpp/include/qpid/Url.h b/qpid/cpp/include/qpid/Url.h new file mode 100644 index 0000000000..d0f4bb0c22 --- /dev/null +++ b/qpid/cpp/include/qpid/Url.h @@ -0,0 +1,93 @@ +#ifndef QPID_URL_H +#define QPID_URL_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/Address.h" +#include "qpid/Exception.h" +#include <string> +#include <vector> +#include <new> +#include <ostream> +#include "qpid/CommonImportExport.h" + +namespace qpid { + +QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const TcpAddress& a); + +/** An AMQP URL contains a list of addresses */ +struct Url : public std::vector<Address> { + + /** Url with the hostname as returned by gethostname(2) */ + static Url getHostNameUrl(uint16_t port); + + /** Url with local IP address(es), may be more than one address + * on a multi-homed host. */ + QPID_COMMON_EXTERN static Url getIpAddressesUrl(uint16_t port); + + struct Invalid : public Exception { Invalid(const std::string& s); }; + + /** Convert to string form. */ + QPID_COMMON_EXTERN std::string str() const; + + /** Empty URL. */ + Url() {} + + /** URL containing a single address */ + explicit Url(const Address& addr) { push_back(addr); } + + /** Parse url, throw Invalid if invalid. */ + explicit Url(const std::string& url) { parse(url.c_str()); } + + /** Parse url, throw Invalid if invalid. */ + explicit Url(const char* url) { parse(url); } + + Url& operator=(const Url& u) { this->std::vector<Address>::operator=(u); cache=u.cache; return *this; } + Url& operator=(const char* s) { parse(s); return *this; } + Url& operator=(const std::string& s) { parse(s); return *this; } + + /** Throw Invalid if the URL does not contain any addresses. */ + QPID_COMMON_EXTERN void throwIfEmpty() const; + + /** Replace contents with parsed URL as defined in + * https://wiki.108.redhat.com/jira/browse/AMQP-95 + *@exception Invalid if the url is invalid. + */ + QPID_COMMON_EXTERN void parse(const char* url); + QPID_COMMON_EXTERN void parse(const std::string& url) { parse(url.c_str()); } + + /** Replace contesnts with parsed URL as defined in + * https://wiki.108.redhat.com/jira/browse/AMQP-95 + * url.empty() will be true if url is invalid. + */ + void parseNoThrow(const char* url); + + private: + mutable std::string cache; // cache string form for efficiency. +}; + +inline bool operator==(const Url& a, const Url& b) { return a.str()==b.str(); } +inline bool operator!=(const Url& a, const Url& b) { return a.str()!=b.str(); } + +QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const Url& url); +QPID_COMMON_EXTERN std::istream& operator>>(std::istream& is, Url& url); + +} // namespace qpid + +#endif /*!QPID_URL_H*/ diff --git a/qpid/cpp/include/qpid/agent/ManagementAgent.h b/qpid/cpp/include/qpid/agent/ManagementAgent.h new file mode 100644 index 0000000000..1a8d0c4025 --- /dev/null +++ b/qpid/cpp/include/qpid/agent/ManagementAgent.h @@ -0,0 +1,163 @@ +#ifndef _qpid_agent_ManagementAgent_ +#define _qpid_agent_ManagementAgent_ + +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +#include "qpid/agent/QmfAgentImportExport.h" +#include "qpid/management/ManagementObject.h" +#include "qpid/management/ManagementEvent.h" +#include "qpid/management/Manageable.h" +#include "qpid/sys/Mutex.h" +#include "qpid/client/ConnectionSettings.h" + +namespace qpid { +namespace management { + +class ManagementAgent +{ + public: + + class Singleton { + public: + QMF_AGENT_EXTERN Singleton(bool disableManagement = false); + QMF_AGENT_EXTERN ~Singleton(); + QMF_AGENT_EXTERN static ManagementAgent* getInstance(); + private: + static sys::Mutex lock; + static bool disabled; + static int refCount; + static ManagementAgent* agent; + }; + + typedef enum { + SEV_EMERG = 0, + SEV_ALERT = 1, + SEV_CRIT = 2, + SEV_ERROR = 3, + SEV_WARN = 4, + SEV_NOTE = 5, + SEV_INFO = 6, + SEV_DEBUG = 7, + SEV_DEFAULT = 8 + } severity_t; + + ManagementAgent() {} + virtual ~ManagementAgent() {} + + virtual int getMaxThreads() = 0; + + // Connect to a management broker + // + // brokerHost - Hostname or IP address (dotted-quad) of broker. + // + // brokerPort - TCP port of broker. + // + // intervalSeconds - The interval (in seconds) that this agent shall use + // between broadcast updates to the broker. + // + // useExternalThread - If true, the thread of control used for callbacks + // must be supplied by the user of the object (via the + // pollCallbacks method). + // + // If false, callbacks shall be invoked on the management + // agent's thread. In this case, the callback implementations + // MUST be thread safe. + // + // storeFile - File where this process has read and write access. This + // file shall be used to store persistent state. + // + virtual void init(const std::string& brokerHost = "localhost", + uint16_t brokerPort = 5672, + uint16_t intervalSeconds = 10, + bool useExternalThread = false, + const std::string& storeFile = "", + const std::string& uid = "guest", + const std::string& pwd = "guest", + const std::string& mech = "PLAIN", + const std::string& proto = "tcp") = 0; + + virtual void init(const client::ConnectionSettings& settings, + uint16_t intervalSeconds = 10, + bool useExternalThread = false, + const std::string& storeFile = "") = 0; + + // Register a schema with the management agent. This is normally called by the + // package initializer generated by the management code generator. + // + virtual void + registerClass(const std::string& packageName, + const std::string& className, + uint8_t* md5Sum, + management::ManagementObject::writeSchemaCall_t schemaCall) = 0; + + virtual void + registerEvent(const std::string& packageName, + const std::string& eventName, + uint8_t* md5Sum, + management::ManagementEvent::writeSchemaCall_t schemaCall) = 0; + + // Add a management object to the agent. Once added, this object shall be visible + // in the greater management context. + // + // Please note that ManagementObject instances are not explicitly deleted from + // the management agent. When the core object represented by a management object + // is deleted, the "resourceDestroy" method on the management object must be called. + // It will then be reclaimed in due course by the management agent. + // + // Once a ManagementObject instance is added to the agent, the agent then owns the + // instance. The caller MUST NOT free the resources of the instance at any time. + // When it is no longer needed, invoke its "resourceDestroy" method and discard the + // pointer. This allows the management agent to report the deletion of the object + // in an orderly way. + // + virtual ObjectId addObject(ManagementObject* objectPtr, uint64_t persistId = 0) = 0; + + // + // + virtual void raiseEvent(const ManagementEvent& event, + severity_t severity = SEV_DEFAULT) = 0; + + // If "useExternalThread" was set to true in init, this method must + // be called to provide a thread for any pending method calls that have arrived. + // The method calls for ManagementObject instances shall be invoked synchronously + // during the execution of this method. + // + // callLimit may optionally be used to limit the number of callbacks invoked. + // if 0, no limit is imposed. + // + // The return value is the number of callbacks that remain queued after this + // call is complete. It can be used to determine whether or not further calls + // to pollCallbacks are necessary to clear the backlog. If callLimit is zero, + // the return value will also be zero. + // + virtual uint32_t pollCallbacks(uint32_t callLimit = 0) = 0; + + // If "useExternalThread" was set to true in the constructor, this method provides + // a standard file descriptor that can be used in a select statement to signal that + // there are method callbacks ready (i.e. that "pollCallbacks" will result in at + // least one method call). When this fd is ready-for-read, pollCallbacks may be + // invoked. Calling pollCallbacks shall reset the ready-to-read state of the fd. + // + virtual int getSignalFd() = 0; +}; + +}} + +#endif /*!_qpid_agent_ManagementAgent_*/ diff --git a/qpid/cpp/include/qpid/agent/QmfAgentImportExport.h b/qpid/cpp/include/qpid/agent/QmfAgentImportExport.h new file mode 100644 index 0000000000..9eee4a18fd --- /dev/null +++ b/qpid/cpp/include/qpid/agent/QmfAgentImportExport.h @@ -0,0 +1,33 @@ +#ifndef QMF_AGENT_IMPORT_EXPORT_H +#define QMF_AGENT_IMPORT_EXPORT_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#if defined(WIN32) && !defined(QPID_DECLARE_STATIC) +#if defined(QMF_AGENT_EXPORT) || defined (qmfagent_EXPORTS) +#define QMF_AGENT_EXTERN __declspec(dllexport) +#else +#define QMF_AGENT_EXTERN __declspec(dllimport) +#endif +#else +#define QMF_AGENT_EXTERN +#endif + +#endif diff --git a/qpid/cpp/include/qpid/client/AsyncSession.h b/qpid/cpp/include/qpid/client/AsyncSession.h new file mode 100644 index 0000000000..d91efeb4f1 --- /dev/null +++ b/qpid/cpp/include/qpid/client/AsyncSession.h @@ -0,0 +1,38 @@ +#ifndef QPID_CLIENT_ASYNCSESSION_H +#define QPID_CLIENT_ASYNCSESSION_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "qpid/client/AsyncSession_0_10.h" + +namespace qpid { +namespace client { + +/** + * AsyncSession is an alias for Session_0_10 + * + * \ingroup clientapi + */ +typedef AsyncSession_0_10 AsyncSession; + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_ASYNCSESSION_H*/ diff --git a/qpid/cpp/include/qpid/client/ClientImportExport.h b/qpid/cpp/include/qpid/client/ClientImportExport.h new file mode 100644 index 0000000000..42b02e33c3 --- /dev/null +++ b/qpid/cpp/include/qpid/client/ClientImportExport.h @@ -0,0 +1,33 @@ +#ifndef QPID_CLIENT_IMPORT_EXPORT_H +#define QPID_CLIENT_IMPORT_EXPORT_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#if defined(WIN32) && !defined(QPID_DECLARE_STATIC) +#if defined(CLIENT_EXPORT) || defined (qpidclient_EXPORTS) +#define QPID_CLIENT_EXTERN __declspec(dllexport) +#else +#define QPID_CLIENT_EXTERN __declspec(dllimport) +#endif +#else +#define QPID_CLIENT_EXTERN +#endif + +#endif diff --git a/qpid/cpp/include/qpid/client/Completion.h b/qpid/cpp/include/qpid/client/Completion.h new file mode 100644 index 0000000000..99d940f031 --- /dev/null +++ b/qpid/cpp/include/qpid/client/Completion.h @@ -0,0 +1,71 @@ +#ifndef QPID_CLIENT_COMPLETION_H +#define QPID_CLIENT_COMPLETION_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/client/Handle.h" +#include "qpid/client/ClientImportExport.h" +#include <string> + +namespace qpid { +namespace client { + +class CompletionImpl; +template <class T> class PrivateImplRef; + +/** + * Asynchronous commands that do not return a result will return a + * Completion. You can use the completion to wait for that specific + * command to complete. + * + *@see TypedResult + * + *\ingroup clientapi + */ +class Completion : public Handle<CompletionImpl> +{ +public: + QPID_CLIENT_EXTERN Completion(CompletionImpl* = 0); + QPID_CLIENT_EXTERN Completion(const Completion&); + QPID_CLIENT_EXTERN ~Completion(); + QPID_CLIENT_EXTERN Completion& operator=(const Completion&); + + /** Wait for the asynchronous command that returned this + *Completion to complete. + * + *@exception If the command returns an error. + */ + QPID_CLIENT_EXTERN void wait(); + QPID_CLIENT_EXTERN bool isComplete(); + + protected: + QPID_CLIENT_EXTERN std::string getResult(); + + private: + typedef CompletionImpl Impl; + friend class PrivateImplRef<Completion>; +}; + +}} + + +#endif /*!QPID_CLIENT_COMPLETION_H*/ diff --git a/qpid/cpp/include/qpid/client/Connection.h b/qpid/cpp/include/qpid/client/Connection.h new file mode 100644 index 0000000000..b7b967d232 --- /dev/null +++ b/qpid/cpp/include/qpid/client/Connection.h @@ -0,0 +1,204 @@ +#ifndef QPID_CLIENT_CONNECTION_H +#define QPID_CLIENT_CONNECTION_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include <map> +#include <string> +#include "qpid/client/Session.h" +#include "qpid/client/ClientImportExport.h" +#include "qpid/client/ConnectionSettings.h" +#include "qpid/framing/ProtocolVersion.h" + +namespace qpid { + +struct Url; + +namespace client { + +class ConnectionImpl; + +/** + * Represents a connection to an AMQP broker. All communication is + * initiated by establishing a connection, then creating one or more + * Session objects using the connection. @see newSession() + * + * \ingroup clientapi + * + */ +class Connection +{ + framing::ProtocolVersion version; + + boost::function<void ()> failureCallback; + + + protected: + boost::shared_ptr<ConnectionImpl> impl; + + + public: + /** + * Creates a connection object, but does not open the connection. + * @see open() + */ + QPID_CLIENT_EXTERN Connection(); + + QPID_CLIENT_EXTERN ~Connection(); + + /** + * Opens a connection to a broker. + * + * @param host the host on which the broker is running. + * + * @param port the port on the which the broker is listening. + * + * @param uid the userid to connect with. + * + * @param pwd the password to connect with (currently SASL + * PLAIN is the only authentication method supported so this + * is sent in clear text). + * + * @param virtualhost the AMQP virtual host to use (virtual + * hosts, where implemented(!), provide namespace partitioning + * within a single broker). + */ + QPID_CLIENT_EXTERN void open(const std::string& host, int port = 5672, + const std::string& uid = "guest", + const std::string& pwd = "guest", + const std::string& virtualhost = "/", uint16_t maxFrameSize=65535); + + /** + * Opens a connection to a broker using a URL. + * If the URL contains multiple addresses, try each in turn + * till connection is successful. + * + * @url address of the broker to connect to. + * + * @param uid the userid to connect with. + * + * @param pwd the password to connect with (currently SASL + * PLAIN is the only authentication method supported so this + * is sent in clear text). + * + * @param virtualhost the AMQP virtual host to use (virtual + * hosts, where implemented(!), provide namespace partitioning + * within a single broker). + */ + QPID_CLIENT_EXTERN void open(const Url& url, + const std::string& uid = "guest", + const std::string& pwd = "guest", + const std::string& virtualhost = "/", uint16_t maxFrameSize=65535); + + /** + * Opens a connection to a broker using a URL. + * If the URL contains multiple addresses, try each in turn + * till connection is successful. + * + * @url address of the broker to connect to. + * + * @param settings used for any settings not provided by the URL. + * Settings provided by the url (e.g. host, port) are ignored. + */ + QPID_CLIENT_EXTERN void open(const Url& url, const ConnectionSettings& settings); + + /** + * Opens a connection to a broker. + * + * @param the settings to use (host, port etc). @see ConnectionSettings. + */ + QPID_CLIENT_EXTERN void open(const ConnectionSettings& settings); + + /** + * Close the connection. + * + * Any further use of this connection (without reopening it) will + * not succeed. + */ + QPID_CLIENT_EXTERN void close(); + + /** + * Create a new session on this connection. Sessions allow + * multiple streams of work to be multiplexed over the same + * connection. The returned Session provides functions to send + * commands to the broker. + * + * Session functions are synchronous. In other words, a Session + * function will send a command to the broker and does not return + * until it receives the broker's response confirming the command + * was executed. + * + * AsyncSession provides asynchronous versions of the same + * functions. These functions send a command to the broker but do + * not wait for a response. + * + * You can convert a Session s into an AsyncSession as follows: + * @code + * #include <qpid/client/AsyncSession.h> + * AsyncSession as = async(s); + * @endcode + * + * You can execute a single command asynchronously will a Session s + * like ths: + * @code + * async(s).messageTransfer(...); + * @endcode + * + * Using an AsyncSession is faster for sending large numbers of + * commands, since each command is sent as soon as possible + * without waiting for the previous command to be confirmed. + * + * However with AsyncSession you cannot assume that a command has + * completed until you explicitly synchronize. The simplest way to + * do this is to call Session::sync() or AsyncSession::sync(). + * Both of these functions wait for the broker to confirm all + * commands issued so far on the session. + * + *@param name: A name to identify the session. @see qpid::SessionId + * If the name is empty (the default) then a unique name will be + * chosen using a Universally-unique identifier (UUID) algorithm. + */ + QPID_CLIENT_EXTERN Session newSession(const std::string& name=std::string(), uint32_t timeoutSeconds = 0); + + /** + * Resume a suspended session. A session may be resumed + * on a different connection to the one that created it. + */ + QPID_CLIENT_EXTERN void resume(Session& session); + + QPID_CLIENT_EXTERN bool isOpen() const; + + QPID_CLIENT_EXTERN std::vector<Url> getKnownBrokers(); + QPID_CLIENT_EXTERN void registerFailureCallback ( boost::function<void ()> fn ); + + /** + * Return the set of client negotiated settings + */ + QPID_CLIENT_EXTERN const ConnectionSettings& getNegotiatedSettings(); + + friend class ConnectionAccess; ///<@internal + friend class SessionBase_0_10; ///<@internal +}; + +}} // namespace qpid::client + + +#endif /*!QPID_CLIENT_CONNECTION_H*/ diff --git a/qpid/cpp/include/qpid/client/ConnectionSettings.h b/qpid/cpp/include/qpid/client/ConnectionSettings.h new file mode 100644 index 0000000000..46053e1fa8 --- /dev/null +++ b/qpid/cpp/include/qpid/client/ConnectionSettings.h @@ -0,0 +1,133 @@ +#ifndef QPID_CLIENT_CONNECTIONSETTINGS_H +#define QPID_CLIENT_CONNECTIONSETTINGS_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/Options.h" +#include "qpid/log/Options.h" +#include "qpid/Url.h" +#include "qpid/client/ClientImportExport.h" + +#include <iostream> +#include <exception> + +namespace qpid { + +namespace sys { +class Socket; +} + +namespace client { + +/** + * Settings for a Connection. + */ +struct ConnectionSettings { + + QPID_CLIENT_EXTERN ConnectionSettings(); + QPID_CLIENT_EXTERN virtual ~ConnectionSettings(); + + /** + * Allows socket to be configured; default only sets tcp-nodelay + * based on the flag set. Can be overridden. + */ + QPID_CLIENT_EXTERN virtual void configureSocket(qpid::sys::Socket&) const; + + /** + * The protocol used for the connection (defaults to 'tcp') + */ + std::string protocol; + + /** + * The host (or ip address) to connect to (defaults to 'localhost'). + */ + std::string host; + /** + * The port to connect to (defaults to 5672). + */ + uint16_t port; + /** + * Allows an AMQP 'virtual host' to be specified for the + * connection. + */ + std::string virtualhost; + + /** + * The username to use when authenticating the connection. If not + * specified the current users login is used if available. + */ + std::string username; + /** + * The password to use when authenticating the connection. + */ + std::string password; + /** + * The SASL mechanism to use when authenticating the connection; + * the options are currently PLAIN or ANONYMOUS. + */ + std::string mechanism; + /** + * Allows a locale to be specified for the connection. + */ + std::string locale; + /** + * Allows a heartbeat frequency to be specified + */ + uint16_t heartbeat; + /** + * The maximum number of channels that the client will request for + * use on this connection. + */ + uint16_t maxChannels; + /** + * The maximum frame size that the client will request for this + * connection. + */ + uint16_t maxFrameSize; + /** + * Limit the size of the connections send buffer . The buffer + * is limited to bounds * maxFrameSize. + */ + uint bounds; + /** + * If true, TCP_NODELAY will be set for the connection. + */ + bool tcpNoDelay; + /** + * SASL service name + */ + std::string service; + /** + * Minimum acceptable strength of any SASL negotiated security + * layer. 0 means no security layer required. + */ + uint minSsf; + /** + * Maximum acceptable strength of any SASL negotiated security + * layer. 0 means no security layer allowed. + */ + uint maxSsf; +}; + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_CONNECTIONSETTINGS_H*/ diff --git a/qpid/cpp/include/qpid/client/FailoverManager.h b/qpid/cpp/include/qpid/client/FailoverManager.h new file mode 100644 index 0000000000..d50fcff8bb --- /dev/null +++ b/qpid/cpp/include/qpid/client/FailoverManager.h @@ -0,0 +1,135 @@ +#ifndef QPID_CLIENT_FAILOVERMANAGER_H +#define QPID_CLIENT_FAILOVERMANAGER_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/client/Connection.h" +#include "qpid/client/ConnectionSettings.h" +#include "qpid/Exception.h" +#include "qpid/client/AsyncSession.h" +#include "qpid/sys/Monitor.h" +#include "qpid/client/ClientImportExport.h" +#include <vector> + +namespace qpid { +namespace client { + +struct CannotConnectException : qpid::Exception +{ + CannotConnectException(const std::string& m) : qpid::Exception(m) {} +}; + +/** + * Utility to manage failover. + */ +class FailoverManager +{ + public: + /** + * Interface to implement for doing work that can be resumed on + * failover + */ + struct Command + { + /** + * This method will be called with isRetry=false when the + * command is first executed. The session to use for the work + * will be passed to the implementing class. If the connection + * fails while the execute call is in progress, the + * FailoverManager controlling the execution will re-establish + * a connection, open a new session and call back to the + * Command implementations execute method with the new session + * and isRetry=true. + */ + virtual void execute(AsyncSession& session, bool isRetry) = 0; + virtual ~Command() {} + }; + + struct ReconnectionStrategy + { + /** + * This method is called by the FailoverManager prior to + * establishing a connection (or re-connection) and can be + * used if the application wishes to edit or re-order the list + * which will default to the list of known brokers for the + * last connection. + */ + virtual void editUrlList(std::vector<Url>& urls) = 0; + virtual ~ReconnectionStrategy() {} + }; + + /** + * Create a manager to control failover for a logical connection. + * + * @param settings the initial connection settings + * @param strategy optional stratgey callback allowing application + * to edit or reorder the list of urls to which reconnection is + * attempted + */ + QPID_CLIENT_EXTERN FailoverManager(const ConnectionSettings& settings, ReconnectionStrategy* strategy = 0); + /** + * Return the current connection if open or attept to reconnect to + * the specified list of urls. If no list is specified the list of + * known brokers from the last connection will be used. If no list + * is specified and this is the first connect attempt, the host + * and port from the initial settings will be used. + * + * If the full list is tried and all attempts fail, + * CannotConnectException is thrown. + */ + QPID_CLIENT_EXTERN Connection& connect(std::vector<Url> brokers = std::vector<Url>()); + /** + * Return the current connection whether open or not + */ + QPID_CLIENT_EXTERN Connection& getConnection(); + /** + * Close the current connection + */ + QPID_CLIENT_EXTERN void close(); + /** + * Reliably execute the specified command. This involves creating + * a session on which to carry out the work of the command, + * handling failover occuring while exeuting that command and + * re-starting the work. + * + * Multiple concurrent threads can call execute with different + * commands; each thread will be allocated its own + * session. FailoverManager will coordinate the different threads + * on failover to ensure they continue to use the same logical + * connection. + */ + QPID_CLIENT_EXTERN void execute(Command&); + private: + enum State {IDLE, CONNECTING, CANT_CONNECT}; + + qpid::sys::Monitor lock; + Connection connection; + ConnectionSettings settings; + ReconnectionStrategy* strategy; + State state; + + void attempt(Connection&, ConnectionSettings settings, std::vector<Url> urls); + void attempt(Connection&, ConnectionSettings settings); +}; +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_FAILOVERMANAGER_H*/ diff --git a/qpid/cpp/include/qpid/client/FlowControl.h b/qpid/cpp/include/qpid/client/FlowControl.h new file mode 100644 index 0000000000..bff7071b3b --- /dev/null +++ b/qpid/cpp/include/qpid/client/FlowControl.h @@ -0,0 +1,75 @@ +#ifndef QPID_CLIENT_FLOWCONTROL_H +#define QPID_CLIENT_FLOWCONTROL_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <qpid/sys/IntegerTypes.h> + +namespace qpid { +namespace client { + +/** + * Flow control works by associating a finite amount of "credit" + * with a subscription. + * + * Credit includes a message count and a byte count. Each message + * received decreases the message count by one, and the byte count by + * the size of the message. Either count can have the special value + * UNLIMITED which is never decreased. + * + * A subscription's credit is exhausted when the message count is 0 or + * the byte count is too small for the next available message. The + * subscription will not receive any further messages until is credit + * is renewed. + * + * In "window mode" credit is automatically renewed when a message is + * completed (which by default happens when it is accepted). In + * non-window mode credit is not automatically renewed, it must be + * explicitly re-set (@see Subscription) + */ +struct FlowControl { + static const uint32_t UNLIMITED=0xFFFFFFFF; + FlowControl(uint32_t messages_=0, uint32_t bytes_=0, bool window_=false) + : messages(messages_), bytes(bytes_), window(window_) {} + + static FlowControl messageCredit(uint32_t messages_) { return FlowControl(messages_,UNLIMITED,false); } + static FlowControl messageWindow(uint32_t messages_) { return FlowControl(messages_,UNLIMITED,true); } + static FlowControl byteCredit(uint32_t bytes_) { return FlowControl(UNLIMITED,bytes_,false); } + static FlowControl byteWindow(uint32_t bytes_) { return FlowControl(UNLIMITED,bytes_,true); } + static FlowControl unlimited() { return FlowControl(UNLIMITED, UNLIMITED, false); } + static FlowControl zero() { return FlowControl(0, 0, false); } + + /** Message credit: subscription can accept up to this many messages. */ + uint32_t messages; + /** Byte credit: subscription can accept up to this many bytes of message content. */ + uint32_t bytes; + /** Window mode. If true credit is automatically renewed as messages are acknowledged. */ + bool window; + + bool operator==(const FlowControl& x) { + return messages == x.messages && bytes == x.bytes && window == x.window; + }; +}; + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_FLOWCONTROL_H*/ diff --git a/qpid/cpp/include/qpid/client/Future.h b/qpid/cpp/include/qpid/client/Future.h new file mode 100644 index 0000000000..09088e68f6 --- /dev/null +++ b/qpid/cpp/include/qpid/client/Future.h @@ -0,0 +1,59 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#ifndef _Future_ +#define _Future_ + +#include <boost/bind.hpp> +#include <boost/shared_ptr.hpp> +#include "qpid/Exception.h" +#include "qpid/framing/SequenceNumber.h" +#include "qpid/client/FutureCompletion.h" +#include "qpid/client/FutureResult.h" +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace client { + +/**@internal */ +class Future +{ + framing::SequenceNumber command; + boost::shared_ptr<FutureResult> result; + bool complete; + +public: + Future() : complete(false) {} + Future(const framing::SequenceNumber& id) : command(id), complete(false) {} + + std::string getResult(SessionImpl& session) { + if (result) return result->getResult(session); + else throw Exception("Result not expected"); + } + + QPID_CLIENT_EXTERN void wait(SessionImpl& session); + QPID_CLIENT_EXTERN bool isComplete(SessionImpl& session); + QPID_CLIENT_EXTERN void setFutureResult(boost::shared_ptr<FutureResult> r); +}; + +}} + +#endif diff --git a/qpid/cpp/include/qpid/client/FutureCompletion.h b/qpid/cpp/include/qpid/client/FutureCompletion.h new file mode 100644 index 0000000000..0970f494b7 --- /dev/null +++ b/qpid/cpp/include/qpid/client/FutureCompletion.h @@ -0,0 +1,49 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#ifndef _FutureCompletion_ +#define _FutureCompletion_ + +#include "qpid/framing/amqp_framing.h" +#include "qpid/sys/Monitor.h" + +namespace qpid { +namespace client { + +///@internal +class FutureCompletion +{ +protected: + mutable sys::Monitor lock; + bool complete; + +public: + FutureCompletion(); + virtual ~FutureCompletion(){} + bool isComplete() const; + void waitForCompletion() const; + void completed(); +}; + +}} + + +#endif diff --git a/qpid/cpp/include/qpid/client/FutureResult.h b/qpid/cpp/include/qpid/client/FutureResult.h new file mode 100644 index 0000000000..b2b663daa1 --- /dev/null +++ b/qpid/cpp/include/qpid/client/FutureResult.h @@ -0,0 +1,49 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#ifndef _FutureResult_ +#define _FutureResult_ + +#include <string> + +#include "qpid/client/ClientImportExport.h" +#include "qpid/framing/amqp_framing.h" +#include "qpid/client/FutureCompletion.h" + +namespace qpid { +namespace client { + +class SessionImpl; + +///@internal +class FutureResult : public FutureCompletion +{ + std::string result; +public: + QPID_CLIENT_EXTERN const std::string& getResult(SessionImpl& session) const; + void received(const std::string& result); +}; + +}} + + + +#endif diff --git a/qpid/cpp/include/qpid/client/Handle.h b/qpid/cpp/include/qpid/client/Handle.h new file mode 100644 index 0000000000..088e836fcf --- /dev/null +++ b/qpid/cpp/include/qpid/client/Handle.h @@ -0,0 +1,71 @@ +#ifndef QPID_CLIENT_HANDLE_H +#define QPID_CLIENT_HANDLE_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace client { + +template <class> class PrivateImplRef; + +/** + * A handle is like a pointer: refers to an underlying implementation object. + * Copying the handle does not copy the object. + * + * Handles can be null, like a 0 pointer. Use isValid(), isNull() or the + * conversion to bool to test for a null handle. + */ +template <class T> class Handle { + public: + + /**@return true if handle is valid, i.e. not null. */ + QPID_CLIENT_EXTERN bool isValid() const { return impl; } + + /**@return true if handle is null. It is an error to call any function on a null handle. */ + QPID_CLIENT_EXTERN bool isNull() const { return !impl; } + + /** Conversion to bool supports idiom if (handle) { handle->... } */ + QPID_CLIENT_EXTERN operator bool() const { return impl; } + + /** Operator ! supports idiom if (!handle) { do_if_handle_is_null(); } */ + QPID_CLIENT_EXTERN bool operator !() const { return !impl; } + + void swap(Handle<T>& h) { T* t = h.impl; h.impl = impl; impl = t; } + + protected: + typedef T Impl; + QPID_CLIENT_EXTERN Handle() :impl() {} + + // Not implemented,subclasses must implement. + QPID_CLIENT_EXTERN Handle(const Handle&); + QPID_CLIENT_EXTERN Handle& operator=(const Handle&); + + Impl* impl; + + friend class PrivateImplRef<T>; // FIXME aconway 2009-04-30: Specify +}; + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_HANDLE_H*/ diff --git a/qpid/cpp/include/qpid/client/LocalQueue.h b/qpid/cpp/include/qpid/client/LocalQueue.h new file mode 100644 index 0000000000..70e4cebcf1 --- /dev/null +++ b/qpid/cpp/include/qpid/client/LocalQueue.h @@ -0,0 +1,120 @@ +#ifndef QPID_CLIENT_LOCALQUEUE_H +#define QPID_CLIENT_LOCALQUEUE_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/client/ClientImportExport.h" +#include "qpid/client/Handle.h" +#include "qpid/client/Message.h" +#include "qpid/sys/Time.h" + +namespace qpid { +namespace client { + +class LocalQueueImpl; +template <class T> class PrivateImplRef; + +/** + * A local queue to collect messages retrieved from a remote broker + * queue. Create a queue and subscribe it using the SubscriptionManager. + * Messages from the remote queue on the broker will be stored in the + * local queue until you retrieve them. + * + * \ingroup clientapi + * + * \details Using a Local Queue + * + * <pre> + * LocalQueue local_queue; + * subscriptions.subscribe(local_queue, string("message_queue")); + * for (int i=0; i<10; i++) { + * Message message = local_queue.get(); + * std::cout << message.getData() << std::endl; + * } + * </pre> + * + * <h2>Getting Messages</h2> + * + * <ul><li> + * <p>get()</p> + * <pre>Message message = local_queue.get();</pre> + * <pre>// Specifying timeouts (TIME_SEC, TIME_MSEC, TIME_USEC, TIME_NSEC) + *#include <qpid/sys/Time.h> + *Message message; + *local_queue.get(message, 5*sys::TIME_SEC);</pre></li></ul> + * + * <h2>Checking size</h2> + * <ul><li> + * <p>empty()</p> + * <pre>if (local_queue.empty()) { ... }</pre></li> + * <li><p>size()</p> + * <pre>std::cout << local_queue.size();</pre></li> + * </ul> + */ + +class LocalQueue : public Handle<LocalQueueImpl> { + public: + /** Create a local queue. Subscribe the local queue to a remote broker + * queue with a SubscriptionManager. + * + * LocalQueue is an alternative to implementing a MessageListener. + */ + QPID_CLIENT_EXTERN LocalQueue(); + QPID_CLIENT_EXTERN LocalQueue(const LocalQueue&); + QPID_CLIENT_EXTERN ~LocalQueue(); + QPID_CLIENT_EXTERN LocalQueue& operator=(const LocalQueue&); + + /** Wait up to timeout for the next message from the local queue. + *@param result Set to the message from the queue. + *@param timeout wait up this timeout for a message to appear. + *@return true if result was set, false if queue was empty after timeout. + */ + QPID_CLIENT_EXTERN bool get(Message& result, sys::Duration timeout=0); + + /** Get the next message off the local queue, or wait up to the timeout + * for message from the broker queue. + *@param timeout wait up this timeout for a message to appear. + *@return message from the queue. + *@throw ClosedException if subscription is closed or timeout exceeded. + */ + QPID_CLIENT_EXTERN Message get(sys::Duration timeout=sys::TIME_INFINITE); + + /** Synonym for get() */ + QPID_CLIENT_EXTERN Message pop(sys::Duration timeout=sys::TIME_INFINITE); + + /** Return true if local queue is empty. */ + QPID_CLIENT_EXTERN bool empty() const; + + /** Number of messages on the local queue */ + QPID_CLIENT_EXTERN size_t size() const; + + LocalQueue(LocalQueueImpl*); ///<@internal + + + private: + typedef LocalQueueImpl Impl; + friend class PrivateImplRef<LocalQueue>; +}; + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_LOCALQUEUE_H*/ diff --git a/qpid/cpp/include/qpid/client/Message.h b/qpid/cpp/include/qpid/client/Message.h new file mode 100644 index 0000000000..2401cbdc92 --- /dev/null +++ b/qpid/cpp/include/qpid/client/Message.h @@ -0,0 +1,175 @@ +#ifndef QPID_CLIENT_MESSAGE_H +#define QPID_CLIENT_MESSAGE_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/client/ClientImportExport.h" +#include "qpid/framing/MessageProperties.h" +#include "qpid/framing/DeliveryProperties.h" +#include <string> + +namespace qpid { + +namespace framing { +class FieldTable; +class SequenceNumber; // FIXME aconway 2009-04-17: remove with getID? +} + +namespace client { + +class MessageImpl; + +/** + * A message sent to or received from the broker. + * + * \ingroup clientapi + * \details + * + * <h2>Getting and setting message contents</h2> + * + * <ul> + * <li> + * <p>getData()</p> + * <pre>std::cout << "Response: " << message.getData() << std::endl;</pre> + * </li> + * <li> + * <p>setData()</p> + * <pre>message.setData("That's all, folks!");</pre></li> + * <li> + * <p>appendData()</p> + * <pre>message.appendData(" ... let's add a bit more ...");</pre></li> + * </ul> + * + * <h2>Getting and Setting Delivery Properties</h2> + * + * <ul> + * <li> + * <p>getDeliveryProperties()</p> + * <pre>message.getDeliveryProperties().setRoutingKey("control");</pre> + * <pre>message.getDeliveryProperties().setDeliveryMode(PERSISTENT);</pre> + * <pre>message.getDeliveryProperties().setPriority(9);</pre> + * <pre>message.getDeliveryProperties().setTtl(100);</pre></li> + * + * <li> + * <p>hasDeliveryProperties()</p> + * <pre>if (! message.hasDeliveryProperties()) { + * ... + *}</pre></li> + * </ul> + * + * <h2>Getting and Setting Message Properties</h2> + * + * <ul> + * <li> + * <p>getMessageProperties()</p> + * <pre> + *request.getMessageProperties().setReplyTo(ReplyTo("amq.direct", response_queue.str())); + * </pre> + * <pre> + *routingKey = request.getMessageProperties().getReplyTo().getRoutingKey(); + *exchange = request.getMessageProperties().getReplyTo().getExchange(); + * </pre> + * <pre>message.getMessageProperties().setContentType("text/plain");</pre> + * <pre>message.getMessageProperties().setContentEncoding("text/plain");</pre> + * </li> + * <li> + * <p>hasMessageProperties()</p> + * <pre>request.getMessageProperties().hasReplyTo();</pre> + * </li> + * </ul> + * + * <h2>Getting and Setting Application Headers</h2> + * + * <ul> + * <li> + * <p>getHeaders()</p> + * <pre> + *message.getHeaders().getString("control"); + * </pre> + * <pre> + *message.getHeaders().setString("control","continue"); + * </pre></li> + * </ul> + * + * + */ +class Message +{ +public: + /** Create a Message. + *@param data Data for the message body. + *@param routingKey Passed to the exchange that routes the message. + */ + QPID_CLIENT_EXTERN Message( + const std::string& data=std::string(), + const std::string& routingKey=std::string()); + Message(MessageImpl*); ///< @internal + QPID_CLIENT_EXTERN Message(const Message&); + QPID_CLIENT_EXTERN ~Message(); + QPID_CLIENT_EXTERN Message& operator=(const Message&); + QPID_CLIENT_EXTERN void swap(Message&); + + QPID_CLIENT_EXTERN void setData(const std::string&); + QPID_CLIENT_EXTERN const std::string& getData() const; + QPID_CLIENT_EXTERN std::string& getData(); + + QPID_CLIENT_EXTERN void appendData(const std::string&); + + QPID_CLIENT_EXTERN bool hasMessageProperties() const; + QPID_CLIENT_EXTERN framing::MessageProperties& getMessageProperties(); + QPID_CLIENT_EXTERN const framing::MessageProperties& getMessageProperties() const; + + QPID_CLIENT_EXTERN bool hasDeliveryProperties() const; + QPID_CLIENT_EXTERN framing::DeliveryProperties& getDeliveryProperties(); + QPID_CLIENT_EXTERN const framing::DeliveryProperties& getDeliveryProperties() const; + + + /** The destination of messages sent to the broker is the exchange + * name. The destination of messages received from the broker is + * the delivery tag identifyig the local subscription (often this + * is the name of the subscribed queue.) + */ + QPID_CLIENT_EXTERN std::string getDestination() const; + + /** Check the redelivered flag. */ + QPID_CLIENT_EXTERN bool isRedelivered() const; + /** Set the redelivered flag. */ + QPID_CLIENT_EXTERN void setRedelivered(bool redelivered); + + /** Get a modifyable reference to the message headers. */ + QPID_CLIENT_EXTERN framing::FieldTable& getHeaders(); + + /** Get a non-modifyable reference to the message headers. */ + QPID_CLIENT_EXTERN const framing::FieldTable& getHeaders() const; + + // FIXME aconway 2009-04-17: does this need to be in public API? + ///@internal + QPID_CLIENT_EXTERN const framing::SequenceNumber& getId() const; + + private: + MessageImpl* impl; + friend class MessageImpl; // Helper template for implementation +}; + +}} + +#endif /*!QPID_CLIENT_MESSAGE_H*/ diff --git a/qpid/cpp/include/qpid/client/MessageListener.h b/qpid/cpp/include/qpid/client/MessageListener.h new file mode 100644 index 0000000000..d200f8cf21 --- /dev/null +++ b/qpid/cpp/include/qpid/client/MessageListener.h @@ -0,0 +1,101 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include <string> +#include "qpid/client/ClientImportExport.h" + +#ifndef _MessageListener_ +#define _MessageListener_ + +#include "qpid/client/Message.h" + +namespace qpid { +namespace client { + + /** + * Implement a subclass of MessageListener and subscribe it using + * the SubscriptionManager to receive messages. + * + * Another way to receive messages is by using a LocalQueue. + * + * \ingroup clientapi + * \details + * + * <h2>Using a MessageListener</h2> + * + * <ul> + * <li> + * <p>The received() function is called when a message arrives:</p> + * <pre>virtual void received(Message& message)=0;</pre> + * </li> + * <li> + * <p>Derive your own listener, implement the received() function:</p> + * <pre> + * class Listener : public MessageListener { + * private: + * SubscriptionManager& subscriptions; + * public: + * Listener(SubscriptionManager& subscriptions); + * virtual void received(Message& message); + * }; + * + * Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) + * {} + * + * void Listener::received(Message& message) { + * std::cout << "Message: " << message.getData() << std::endl; + * if (message.getData() == "That's all, folks!") { + * std::cout << "Shutting down listener for " << message.getDestination() + * << std::endl; + * subscriptions.cancel(message.getDestination()); + * } + * } + *</pre> + * <pre> + * SubscriptionManager subscriptions(session); + * + * // Create a listener and subscribe it to the queue named "message_queue" + * Listener listener(subscriptions); + * subscriptions.subscribe(listener, "message_queue"); + * + * // Receive messages until the subscription is cancelled + * // by Listener::received() + * subscriptions.run(); + * </pre> + * </li> + * </ul> + * + */ + + class MessageListener{ + public: + QPID_CLIENT_EXTERN virtual ~MessageListener(); + + /** Called for each message arriving from the broker. Override + * in your own subclass to process messages. + */ + virtual void received(Message& msg) = 0; + }; + +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/client/MessageReplayTracker.h b/qpid/cpp/include/qpid/client/MessageReplayTracker.h new file mode 100644 index 0000000000..6f5a0f4ac3 --- /dev/null +++ b/qpid/cpp/include/qpid/client/MessageReplayTracker.h @@ -0,0 +1,73 @@ +#ifndef QPID_CLIENT_MESSAGEREPLAYTRACKER_H +#define QPID_CLIENT_MESSAGEREPLAYTRACKER_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "qpid/client/AsyncSession.h" +#include "qpid/client/Message.h" +#include "qpid/client/ClientImportExport.h" +#include <list> +#include <string> + +namespace qpid { +namespace client { + +/** + * Utility to track messages sent asynchronously, allowing those that + * are indoubt to be replayed over a new session. + */ +class MessageReplayTracker +{ + public: + QPID_CLIENT_EXTERN MessageReplayTracker(uint flushInterval); + QPID_CLIENT_EXTERN void send(const Message& message, const std::string& destination = ""); + QPID_CLIENT_EXTERN void init(AsyncSession session); + QPID_CLIENT_EXTERN void replay(AsyncSession session); + QPID_CLIENT_EXTERN void setFlushInterval(uint interval); + QPID_CLIENT_EXTERN uint getFlushInterval(); + QPID_CLIENT_EXTERN void checkCompletion(); + + template <class F> void foreach(F& f) { + for (std::list<ReplayRecord>::const_iterator i = buffer.begin(); i != buffer.end(); i++) { + f(i->message); + } + } + + private: + struct ReplayRecord + { + Completion status; + Message message; + std::string destination; + + ReplayRecord(const Message& message, const std::string& destination); + void send(MessageReplayTracker&); + bool isComplete(); + }; + + AsyncSession session; + uint flushInterval; + uint count; + std::list<ReplayRecord> buffer; +}; +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_MESSAGEREPLAYTRACKER_H*/ diff --git a/qpid/cpp/include/qpid/client/QueueOptions.h b/qpid/cpp/include/qpid/client/QueueOptions.h new file mode 100644 index 0000000000..9418cb092d --- /dev/null +++ b/qpid/cpp/include/qpid/client/QueueOptions.h @@ -0,0 +1,114 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/client/ClientImportExport.h" +#include "qpid/framing/FieldTable.h" + +#ifndef _QueueOptions_ +#define _QueueOptions_ + +namespace qpid { +namespace client { + +enum QueueSizePolicy {NONE, REJECT, FLOW_TO_DISK, RING, RING_STRICT}; +enum QueueOrderingPolicy {FIFO, LVQ, LVQ_NO_BROWSE}; + +/** + * A help class to set options on the Queue. Create a configured args while + * still allowing any custom configuration via the FieldTable base class + */ +class QueueOptions: public framing::FieldTable +{ + public: + QPID_CLIENT_EXTERN QueueOptions(); + QPID_CLIENT_EXTERN virtual ~QueueOptions(); + + /** + * Sets the queue sizing policy + * + * @param sp SizePolicy + * REJECT - reject if queue greater than size/count + * FLOW_TO_DISK - page messages to disk from this point is greater than size/count + * RING - limit the queue to size/count and over-write old messages round a ring + * RING_STRICT - limit the queue to size/count and reject is head == tail + * NONE - Use default broker sizing policy + * @param maxSize Set the max number of bytes for the sizing policies + * @param setMaxCount Set the max number of messages for the sizing policies + */ + QPID_CLIENT_EXTERN void setSizePolicy(QueueSizePolicy sp, uint64_t maxSize, uint32_t maxCount ); + + /** + * Enables the persisting of a queue to the store module when a cluster fails down to it's last + * node. Does so optimistically. Will start persisting when cluster count >1 again. + */ + QPID_CLIENT_EXTERN void setPersistLastNode(); + + /** + * Sets the odering policy on the Queue, default ordering is FIFO. + */ + QPID_CLIENT_EXTERN void setOrdering(QueueOrderingPolicy op); + + /** + * Use broker defualt sizing ploicy + */ + QPID_CLIENT_EXTERN void clearSizePolicy(); + + /** + * Clear Persist Last Node Policy + */ + QPID_CLIENT_EXTERN void clearPersistLastNode(); + + /** + * get the key used match LVQ in args for message transfer + */ + QPID_CLIENT_EXTERN void getLVQKey(std::string& key); + + /** + * Use default odering policy + */ + QPID_CLIENT_EXTERN void clearOrdering(); + + /** + * Turns on event generation for this queue (either enqueue only + * or for enqueue and dequeue events); the events can then be + * processed by a regsitered broker plugin. + */ + QPID_CLIENT_EXTERN void enableQueueEvents(bool enqueueOnly); + + static QPID_CLIENT_EXTERN const std::string strMaxCountKey; + static QPID_CLIENT_EXTERN const std::string strMaxSizeKey; + static QPID_CLIENT_EXTERN const std::string strTypeKey; + static QPID_CLIENT_EXTERN const std::string strREJECT; + static QPID_CLIENT_EXTERN const std::string strFLOW_TO_DISK; + static QPID_CLIENT_EXTERN const std::string strRING; + static QPID_CLIENT_EXTERN const std::string strRING_STRICT; + static QPID_CLIENT_EXTERN const std::string strLastValueQueue; + static QPID_CLIENT_EXTERN const std::string strPersistLastNode; + static QPID_CLIENT_EXTERN const std::string strLVQMatchProperty; + static QPID_CLIENT_EXTERN const std::string strLastValueQueueNoBrowse; + static QPID_CLIENT_EXTERN const std::string strQueueEventMode; +}; + +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/client/Session.h b/qpid/cpp/include/qpid/client/Session.h new file mode 100644 index 0000000000..c40549bbc5 --- /dev/null +++ b/qpid/cpp/include/qpid/client/Session.h @@ -0,0 +1,39 @@ +#ifndef QPID_CLIENT_SESSION_H +#define QPID_CLIENT_SESSION_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "qpid/client/Session_0_10.h" + +namespace qpid { +namespace client { + +/** + * Session is an alias for Session_0_10 + * + * \ingroup clientapi + */ +typedef Session_0_10 Session; + + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_SESSION_H*/ diff --git a/qpid/cpp/include/qpid/client/SessionBase_0_10.h b/qpid/cpp/include/qpid/client/SessionBase_0_10.h new file mode 100644 index 0000000000..afa458bcee --- /dev/null +++ b/qpid/cpp/include/qpid/client/SessionBase_0_10.h @@ -0,0 +1,109 @@ +#ifndef QPID_CLIENT_SESSIONBASE_H +#define QPID_CLIENT_SESSIONBASE_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/SessionId.h" +#include "qpid/framing/amqp_structs.h" +#include "qpid/client/Message.h" +#include "qpid/client/Completion.h" +#include "qpid/client/TypedResult.h" +#include "qpid/client/ClientImportExport.h" +#include <string> + +namespace qpid { +namespace client { + +class Connection; +class SessionImpl; + +using std::string; +using framing::Content; +using framing::FieldTable; +using framing::SequenceNumber; +using framing::SequenceSet; +using framing::SequenceNumberSet; +using qpid::SessionId; +using framing::Xid; + +/** Unit of message credit: messages or bytes */ +enum CreditUnit { MESSAGE_CREDIT=0, BYTE_CREDIT=1, UNLIMITED_CREDIT=0xFFFFFFFF }; + +/** + * Base class for handles to an AMQP session. + * + * Subclasses provide the AMQP commands for a given + * version of the protocol. + */ +class SessionBase_0_10 { + public: + + ///@internal + QPID_CLIENT_EXTERN SessionBase_0_10(); + QPID_CLIENT_EXTERN ~SessionBase_0_10(); + + /** Get the session ID */ + QPID_CLIENT_EXTERN SessionId getId() const; + + /** Close the session. + * A session is automatically closed when all handles to it are destroyed. + */ + QPID_CLIENT_EXTERN void close(); + + /** + * Synchronize the session: sync() waits until all commands issued + * on this session so far have been completed by the broker. + * + * Note sync() is always synchronous, even on an AsyncSession object + * because that's almost always what you want. You can call + * AsyncSession::executionSync() directly in the unusual event + * that you want to do an asynchronous sync. + */ + QPID_CLIENT_EXTERN void sync(); + + /** Set the timeout for this session. */ + QPID_CLIENT_EXTERN uint32_t timeout(uint32_t seconds); + + /** Suspend the session - detach it from its connection */ + QPID_CLIENT_EXTERN void suspend(); + + /** Resume a suspended session with a new connection */ + QPID_CLIENT_EXTERN void resume(Connection); + + /** Get the channel associated with this session */ + QPID_CLIENT_EXTERN uint16_t getChannel() const; + + QPID_CLIENT_EXTERN void flush(); + QPID_CLIENT_EXTERN void markCompleted(const framing::SequenceSet& ids, bool notifyPeer); + QPID_CLIENT_EXTERN void markCompleted(const framing::SequenceNumber& id, bool cumulative, bool notifyPeer); + QPID_CLIENT_EXTERN void sendCompletion(); + + QPID_CLIENT_EXTERN bool isValid() const; + + protected: + boost::shared_ptr<SessionImpl> impl; + friend class SessionBase_0_10Access; +}; + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_SESSIONBASE_H*/ diff --git a/qpid/cpp/include/qpid/client/Subscription.h b/qpid/cpp/include/qpid/client/Subscription.h new file mode 100644 index 0000000000..425b6b92e2 --- /dev/null +++ b/qpid/cpp/include/qpid/client/Subscription.h @@ -0,0 +1,123 @@ +#ifndef QPID_CLIENT_SUBSCRIPTION_H +#define QPID_CLIENT_SUBSCRIPTION_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/client/Handle.h" +#include "qpid/client/Session.h" +#include "qpid/client/SubscriptionSettings.h" +#include "qpid/client/Message.h" +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace client { + +template <class> class PrivateImplRef; +class SubscriptionImpl; +class SubscriptionManager; + +/** + * A handle to an active subscription. Provides methods to query the subscription status + * and control acknowledgement (acquire and accept) of messages. + */ +class Subscription : public Handle<SubscriptionImpl> { + public: + QPID_CLIENT_EXTERN Subscription(SubscriptionImpl* = 0); + QPID_CLIENT_EXTERN Subscription(const Subscription&); + QPID_CLIENT_EXTERN ~Subscription(); + QPID_CLIENT_EXTERN Subscription& operator=(const Subscription&); + + + /** The name of the subscription, used as the "destination" for messages from the broker. + * Usually the same as the queue name but can be set differently. + */ + QPID_CLIENT_EXTERN std::string getName() const; + + /** Name of the queue this subscription subscribes to */ + QPID_CLIENT_EXTERN std::string getQueue() const; + + /** Get the flow control and acknowledgement settings for this subscription */ + QPID_CLIENT_EXTERN const SubscriptionSettings& getSettings() const; + + /** Set the flow control parameters */ + QPID_CLIENT_EXTERN void setFlowControl(const FlowControl&); + + /** Automatically acknowledge (acquire and accept) batches of n messages. + * You can disable auto-acknowledgement by setting n=0, and use acquire() and accept() + * to manually acquire and accept messages. + */ + QPID_CLIENT_EXTERN void setAutoAck(unsigned int n); + + /** Get the set of ID's for messages received by this subscription but not yet acquired. + * This will always be empty if getSettings().acquireMode=ACQUIRE_MODE_PRE_ACQUIRED + */ + QPID_CLIENT_EXTERN SequenceSet getUnacquired() const; + + /** Get the set of ID's for messages received by this subscription but not yet accepted. */ + QPID_CLIENT_EXTERN SequenceSet getUnaccepted() const; + + /** Acquire messageIds and remove them from the unacquired set. + * oAdd them to the unaccepted set if getSettings().acceptMode == ACCEPT_MODE_EXPLICIT. + */ + QPID_CLIENT_EXTERN void acquire(const SequenceSet& messageIds); + + /** Accept messageIds and remove them from the unaccepted set. + *@pre messageIds is a subset of getUnaccepted() + */ + QPID_CLIENT_EXTERN void accept(const SequenceSet& messageIds); + + /** Release messageIds and remove them from the unaccepted set. + *@pre messageIds is a subset of getUnaccepted() + */ + QPID_CLIENT_EXTERN void release(const SequenceSet& messageIds); + + /* Acquire a single message */ + QPID_CLIENT_EXTERN void acquire(const Message& m) { acquire(SequenceSet(m.getId())); } + + /* Accept a single message */ + QPID_CLIENT_EXTERN void accept(const Message& m) { accept(SequenceSet(m.getId())); } + + /* Release a single message */ + QPID_CLIENT_EXTERN void release(const Message& m) { release(SequenceSet(m.getId())); } + + /** Get the session associated with this subscription */ + QPID_CLIENT_EXTERN Session getSession() const; + + /** Get the subscription manager associated with this subscription */ + QPID_CLIENT_EXTERN SubscriptionManager getSubscriptionManager(); + + /** Cancel the subscription. */ + QPID_CLIENT_EXTERN void cancel(); + + /** Grant the specified amount of message credit */ + QPID_CLIENT_EXTERN void grantMessageCredit(uint32_t); + + /** Grant the specified amount of byte credit */ + QPID_CLIENT_EXTERN void grantByteCredit(uint32_t); + + private: + friend class PrivateImplRef<Subscription>; + friend class SubscriptionManager; +}; +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_SUBSCRIPTION_H*/ diff --git a/qpid/cpp/include/qpid/client/SubscriptionManager.h b/qpid/cpp/include/qpid/client/SubscriptionManager.h new file mode 100644 index 0000000000..632efe0f70 --- /dev/null +++ b/qpid/cpp/include/qpid/client/SubscriptionManager.h @@ -0,0 +1,286 @@ +#ifndef QPID_CLIENT_SUBSCRIPTIONMANAGER_H +#define QPID_CLIENT_SUBSCRIPTIONMANAGER_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/client/Session.h" +#include "qpid/client/Subscription.h" +#include "qpid/sys/Runnable.h" +#include "qpid/sys/Thread.h" +#include "qpid/client/ClientImportExport.h" +#include "qpid/client/MessageListener.h" +#include "qpid/client/LocalQueue.h" +#include "qpid/client/Handle.h" +#include <string> + +namespace qpid { +namespace client { + +class SubscriptionManagerImpl; + +/** + * A class to help create and manage subscriptions. + * + * Set up your subscriptions, then call run() to have messages + * delivered. + * + * \ingroup clientapi + * + * \details + * + * <h2>Subscribing and canceling subscriptions</h2> + * + * <ul> + * <li> + * <p>subscribe()</p> + * <pre> SubscriptionManager subscriptions(session); + * Listener listener(subscriptions); + * subscriptions.subscribe(listener, myQueue);</pre> + * <pre> SubscriptionManager subscriptions(session); + * LocalQueue local_queue; + * subscriptions.subscribe(local_queue, string("message_queue"));</pre></li> + * <li> + * <p>cancel()</p> + * <pre>subscriptions.cancel();</pre></li> + * </ul> + * + * <h2>Waiting for messages (and returning)</h2> + * + * <ul> + * <li> + * <p>run()</p> + * <pre> // Give up control to receive messages + * subscriptions.run();</pre></li> + * <li> + * <p>stop()</p> + * <pre>.// Use this code in a listener to return from run() + * subscriptions.stop();</pre></li> + * <li> + * <p>setAutoStop()</p> + * <pre>.// Return from subscriptions.run() when last subscription is cancelled + *.subscriptions.setAutoStop(true); + *.subscriptons.run(); + * </pre></li> + * <li> + * <p>Ending a subscription in a listener</p> + * <pre> + * void Listener::received(Message& message) { + * + * if (message.getData() == "That's all, folks!") { + * subscriptions.cancel(message.getDestination()); + * } + * } + * </pre> + * </li> + * </ul> + * + */ +class SubscriptionManager : public sys::Runnable, public Handle<SubscriptionManagerImpl> +{ + public: + /** Create a new SubscriptionManager associated with a session */ + QPID_CLIENT_EXTERN SubscriptionManager(const Session& session); + QPID_CLIENT_EXTERN SubscriptionManager(const SubscriptionManager&); + QPID_CLIENT_EXTERN ~SubscriptionManager(); + QPID_CLIENT_EXTERN SubscriptionManager& operator=(const SubscriptionManager&); + + /** + * Subscribe a MessagesListener to receive messages from queue. + * + * Provide your own subclass of MessagesListener to process + * incoming messages. It will be called for each message received. + * + *@param listener Listener object to receive messages. + *@param queue Name of the queue to subscribe to. + *@param settings settings for the subscription. + *@param name unique destination name for the subscription, defaults to queue name. + */ + QPID_CLIENT_EXTERN Subscription subscribe(MessageListener& listener, + const std::string& queue, + const SubscriptionSettings& settings, + const std::string& name=std::string()); + + /** + * Subscribe a LocalQueue to receive messages from queue. + * + * Incoming messages are stored in the queue for you to retrieve. + * + *@param queue Name of the queue to subscribe to. + *@param flow initial FlowControl for the subscription. + *@param name unique destination name for the subscription, defaults to queue name. + * If not specified, the queue name is used. + */ + QPID_CLIENT_EXTERN Subscription subscribe(LocalQueue& localQueue, + const std::string& queue, + const SubscriptionSettings& settings, + const std::string& name=std::string()); + + /** + * Subscribe a MessagesListener to receive messages from queue. + * + * Provide your own subclass of MessagesListener to process + * incoming messages. It will be called for each message received. + * + *@param listener Listener object to receive messages. + *@param queue Name of the queue to subscribe to. + *@param name unique destination name for the subscription, defaults to queue name. + * If not specified, the queue name is used. + */ + QPID_CLIENT_EXTERN Subscription subscribe(MessageListener& listener, + const std::string& queue, + const std::string& name=std::string()); + + /** + * Subscribe a LocalQueue to receive messages from queue. + * + * Incoming messages are stored in the queue for you to retrieve. + * + *@param queue Name of the queue to subscribe to. + *@param name unique destination name for the subscription, defaults to queue name. + * If not specified, the queue name is used. + */ + QPID_CLIENT_EXTERN Subscription subscribe(LocalQueue& localQueue, + const std::string& queue, + const std::string& name=std::string()); + + + /** Get a single message from a queue. + *@param result is set to the message from the queue. + *@param timeout wait up this timeout for a message to appear. + *@return true if result was set, false if no message available after timeout. + */ + QPID_CLIENT_EXTERN bool get(Message& result, const std::string& queue, sys::Duration timeout=0); + + /** Get a single message from a queue. + *@param timeout wait up this timeout for a message to appear. + *@return message from the queue. + *@throw Exception if the timeout is exceeded. + */ + QPID_CLIENT_EXTERN Message get(const std::string& queue, sys::Duration timeout=sys::TIME_INFINITE); + + /** Get a subscription by name. + *@throw Exception if not found. + */ + QPID_CLIENT_EXTERN Subscription getSubscription(const std::string& name) const; + + /** Cancel a subscription. See also: Subscription.cancel() */ + QPID_CLIENT_EXTERN void cancel(const std::string& name); + + /** Deliver messages in the current thread until stop() is called. + * Only one thread may be running in a SubscriptionManager at a time. + * @see run + */ + QPID_CLIENT_EXTERN void run(); + + /** Start a new thread to deliver messages. + * Only one thread may be running in a SubscriptionManager at a time. + * @see start + */ + QPID_CLIENT_EXTERN void start(); + + /** + * Wait for the thread started by a call to start() to complete. + */ + QPID_CLIENT_EXTERN void wait(); + + /** If set true, run() will stop when all subscriptions + * are cancelled. If false, run will only stop when stop() + * is called. True by default. + */ + QPID_CLIENT_EXTERN void setAutoStop(bool set=true); + + /** Stop delivery. Causes run() to return, or the thread started with start() to exit. */ + QPID_CLIENT_EXTERN void stop(); + + static const uint32_t UNLIMITED=0xFFFFFFFF; + + /** Set the flow control for a subscription. */ + QPID_CLIENT_EXTERN void setFlowControl(const std::string& name, const FlowControl& flow); + + /** Set the flow control for a subscription. + *@param name: name of the subscription. + *@param messages: message credit. + *@param bytes: byte credit. + *@param window: if true use window-based flow control. + */ + QPID_CLIENT_EXTERN void setFlowControl(const std::string& name, uint32_t messages, uint32_t bytes, bool window=true); + + /** Set the default settings for subscribe() calls that don't + * include a SubscriptionSettings parameter. + */ + QPID_CLIENT_EXTERN void setDefaultSettings(const SubscriptionSettings& s); + + /** Get the default settings for subscribe() calls that don't + * include a SubscriptionSettings parameter. + */ + QPID_CLIENT_EXTERN const SubscriptionSettings& getDefaultSettings() const; + + /** Get the default settings for subscribe() calls that don't + * include a SubscriptionSettings parameter. + */ + QPID_CLIENT_EXTERN SubscriptionSettings& getDefaultSettings(); + + /** + * Set the default flow control settings for subscribe() calls + * that don't include a SubscriptionSettings parameter. + * + *@param messages: message credit. + *@param bytes: byte credit. + *@param window: if true use window-based flow control. + */ + QPID_CLIENT_EXTERN void setFlowControl(uint32_t messages, uint32_t bytes, bool window=true); + + /** + *Set the default accept-mode for subscribe() calls that don't + *include a SubscriptionSettings parameter. + */ + QPID_CLIENT_EXTERN void setAcceptMode(AcceptMode mode); + + /** + * Set the default acquire-mode subscribe()s that don't specify SubscriptionSettings. + */ + QPID_CLIENT_EXTERN void setAcquireMode(AcquireMode mode); + + QPID_CLIENT_EXTERN void registerFailoverHandler ( boost::function<void ()> fh ); + + QPID_CLIENT_EXTERN Session getSession() const; + + SubscriptionManager(SubscriptionManagerImpl*); ///<@internal + + private: + typedef SubscriptionManagerImpl Impl; + friend class PrivateImplRef<SubscriptionManager>; +}; + +/** AutoCancel cancels a subscription in its destructor */ +class AutoCancel { + public: + AutoCancel(SubscriptionManager& sm_, const std::string& tag_) : sm(sm_), tag(tag_) {} + ~AutoCancel() { sm.cancel(tag); } + private: + SubscriptionManager& sm; + std::string tag; +}; + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_SUBSCRIPTIONMANAGER_H*/ diff --git a/qpid/cpp/include/qpid/client/SubscriptionSettings.h b/qpid/cpp/include/qpid/client/SubscriptionSettings.h new file mode 100644 index 0000000000..4d64119d3a --- /dev/null +++ b/qpid/cpp/include/qpid/client/SubscriptionSettings.h @@ -0,0 +1,92 @@ +#ifndef QPID_CLIENT_SUBSCRIPTIONSETTINGS_H +#define QPID_CLIENT_SUBSCRIPTIONSETTINGS_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "qpid/client/FlowControl.h" +#include "qpid/framing/enum.h" + +namespace qpid { +namespace client { + +/** Bring AMQP enum definitions for message class into this namespace. */ +using namespace qpid::framing::message; + +enum CompletionMode { + MANUAL_COMPLETION = 0, + COMPLETE_ON_DELIVERY = 1, + COMPLETE_ON_ACCEPT = 2 +}; +/** + * Settings for a subscription. + */ +struct SubscriptionSettings +{ + SubscriptionSettings( + FlowControl flow=FlowControl::unlimited(), + AcceptMode accept=ACCEPT_MODE_EXPLICIT, + AcquireMode acquire=ACQUIRE_MODE_PRE_ACQUIRED, + unsigned int autoAck_=1, + CompletionMode completion=COMPLETE_ON_DELIVERY + ) : flowControl(flow), acceptMode(accept), acquireMode(acquire), autoAck(autoAck_), completionMode(completion), exclusive(false) {} + + FlowControl flowControl; ///@< Flow control settings. @see FlowControl + AcceptMode acceptMode; ///@< ACCEPT_MODE_EXPLICIT or ACCEPT_MODE_NONE + AcquireMode acquireMode; ///@< ACQUIRE_MODE_PRE_ACQUIRED or ACQUIRE_MODE_NOT_ACQUIRED + + /** Automatically acknowledge (accept) batches of autoAck + * messages. 0 means no automatic acknowledgement. This has no + * effect for messsages received for a subscription with + * ACCEPT_MODE_NODE.*/ + unsigned int autoAck; + /** + * In windowing mode, completion of a message will cause the + * credit used up by that message to be reallocated. The + * subscriptions completion mode controls how completion is + * managed. + * + * If set to COMPLETE_ON_DELIVERY (which is the default), messages + * will be marked as completed once they have been received. The + * server will be explicitly notified of all completed messages + * for the session when the next accept is sent through the + * subscription (either explictly or through autAck). However the + * server may also periodically request information on the + * completed messages. + * + * If set to COMPLETE_ON_ACCEPT, messages will be marked as + * completed once they are accepted (via the Subscription class) + * and the server will also be notified of all completed messages + * for the session. + * + * If set to MANUAL_COMPLETION the application is responsible for + * completing messages (@see Session::markCompleted()). + */ + CompletionMode completionMode; + /** + * If set, requests that no other subscriber be allowed to access + * the queue while this subscription is active. + */ + bool exclusive; +}; + +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_SUBSCRIPTIONSETTINGS_H*/ diff --git a/qpid/cpp/include/qpid/client/TypedResult.h b/qpid/cpp/include/qpid/client/TypedResult.h new file mode 100644 index 0000000000..8e1a16580c --- /dev/null +++ b/qpid/cpp/include/qpid/client/TypedResult.h @@ -0,0 +1,65 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#ifndef _TypedResult_ +#define _TypedResult_ + +#include "qpid/client/Completion.h" +#include "qpid/framing/StructHelper.h" + +namespace qpid { +namespace client { + +/** + * Returned by asynchronous commands that return a result. + * You can use get() to wait for completion and get the result value. + * \ingroup clientapi + */ +template <class T> class TypedResult : public Completion +{ + T result; + bool decoded; + +public: + ///@internal + TypedResult(const Completion& c) : Completion(c), decoded(false) {} + + /** + * Wait for the asynchronous command that returned this TypedResult to complete + * and return its result. + * + *@return The result returned by the command. + *@exception If the command returns an error, get() throws an exception. + * + */ + T& get() { + if (!decoded) { + framing::StructHelper helper; + helper.decode(result, getResult()); + decoded = true; + } + return result; + } +}; + +}} + +#endif diff --git a/qpid/cpp/include/qpid/console/Agent.h b/qpid/cpp/include/qpid/console/Agent.h new file mode 100644 index 0000000000..97d75da250 --- /dev/null +++ b/qpid/cpp/include/qpid/console/Agent.h @@ -0,0 +1,58 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_AGENT_H_ +#define _QPID_CONSOLE_AGENT_H_ + +#include "qpid/console/Broker.h" +#include "qpid/console/ConsoleImportExport.h" + +namespace qpid { +namespace console { + + /** + * + * \ingroup qmfconsoleapi + */ + class QPID_CONSOLE_EXTERN Agent { + public: + typedef std::vector<Agent*> Vector; + + Agent(Broker* _broker, uint32_t _bank, const std::string& _label) : + broker(_broker), brokerBank(broker->getBrokerBank()), + agentBank(_bank), label(_label) {} + Broker* getBroker() const { return broker; } + uint32_t getBrokerBank() const { return brokerBank; } + uint32_t getAgentBank() const { return agentBank; } + const std::string& getLabel() const { return label; } + + private: + Broker* broker; + const uint32_t brokerBank; + const uint32_t agentBank; + const std::string label; + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Agent& agent); +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/console/Broker.h b/qpid/cpp/include/qpid/console/Broker.h new file mode 100644 index 0000000000..af163b8bfd --- /dev/null +++ b/qpid/cpp/include/qpid/console/Broker.h @@ -0,0 +1,133 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_BROKER_H_ +#define _QPID_CONSOLE_BROKER_H_ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/client/Connection.h" +#include "qpid/client/ConnectionSettings.h" +#include "qpid/client/SubscriptionManager.h" +#include "qpid/client/Session.h" +#include "qpid/client/AsyncSession.h" +#include "qpid/client/Message.h" +#include "qpid/client/MessageListener.h" +#include "qpid/sys/Thread.h" +#include "qpid/sys/Runnable.h" +#include "qpid/sys/Mutex.h" +#include "qpid/sys/Condition.h" +#include "qpid/Url.h" +#include "qpid/framing/Buffer.h" +#include "qpid/framing/Uuid.h" +#include <string> +#include <iostream> + +namespace qpid { +namespace console { + class SessionManager; + class Agent; + class Object; + + /** + * + * \ingroup qpidconsoleapi + */ + class Broker : public client::MessageListener { + public: + QPID_CONSOLE_EXTERN Broker(SessionManager& sm, + client::ConnectionSettings& settings); + QPID_CONSOLE_EXTERN ~Broker(); + + bool isConnected() const { return connected; } + const std::string& getError() const { return error; } + const std::string& getSessionId() const { return amqpSessionId; } + const framing::Uuid& getBrokerId() const { return brokerId; } + uint32_t getBrokerBank() const { return 1; } + void addBinding(const std::string& key) { + connThreadBody.bindExchange("qpid.management", key); + } + QPID_CONSOLE_EXTERN std::string getUrl() const; + + private: + friend class SessionManager; + friend class Object; + typedef std::map<uint64_t,Agent*> AgentMap; + static const int SYNC_TIME = 60; + + SessionManager& sessionManager; + AgentMap agents; + bool connected; + std::string error; + std::string amqpSessionId; + client::ConnectionSettings connectionSettings; + sys::Mutex lock; + sys::Condition cond; + framing::Uuid brokerId; + uint32_t reqsOutstanding; + bool syncInFlight; + bool topicBound; + Object* methodObject; + + friend class ConnectionThread; + class ConnectionThread : public sys::Runnable { + bool operational; + bool shuttingDown; + Broker& broker; + framing::Uuid sessionId; + client::Connection connection; + client::Session session; + client::SubscriptionManager* subscriptions; + std::stringstream queueName; + sys::Mutex connLock; + void run(); + public: + ConnectionThread(Broker& _broker) : + operational(false), shuttingDown(false), broker(_broker), subscriptions(0) {} + ~ConnectionThread(); + void sendBuffer(qpid::framing::Buffer& buf, + uint32_t length, + const std::string& exchange = "qpid.management", + const std::string& routingKey = "broker"); + void bindExchange(const std::string& exchange, const std::string& key); + void shutdown(); + }; + + ConnectionThread connThreadBody; + sys::Thread connThread; + + void encodeHeader(framing::Buffer& buf, uint8_t opcode, uint32_t seq = 0) const; + bool checkHeader(framing::Buffer& buf, uint8_t *opcode, uint32_t *seq) const; + void received(client::Message& msg); + void resetAgents(); + void updateAgent(const Object& object); + void waitForStable(); + void incOutstanding(); + void decOutstanding(); + void setBrokerId(const framing::Uuid& id) { brokerId = id; } + void appendAgents(std::vector<Agent*>& agents) const; + + friend QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Broker& k); + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Broker& k); +} +} + +#endif diff --git a/qpid/cpp/include/qpid/console/ClassKey.h b/qpid/cpp/include/qpid/console/ClassKey.h new file mode 100644 index 0000000000..95cd2627f1 --- /dev/null +++ b/qpid/cpp/include/qpid/console/ClassKey.h @@ -0,0 +1,66 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_CLASSKEY_H_ +#define _QPID_CONSOLE_CLASSKEY_H_ + +#include <string> +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/Package.h" +#include "qpid/framing/Buffer.h" + +namespace qpid { +namespace console { + + /** + * + * \ingroup qmfconsoleapi + */ + class QPID_CONSOLE_EXTERN ClassKey { + public: + static const int HASH_SIZE = 16; + + ClassKey(const std::string& package, const std::string& name, const uint8_t* hash); + + const std::string& getPackageName() const { return package; } + const std::string& getClassName() const { return name; } + const uint8_t* getHash() const { return hash; } + std::string getHashString() const; + std::string str() const; + bool operator==(const ClassKey& other) const; + bool operator!=(const ClassKey& other) const; + bool operator<(const ClassKey& other) const; + bool operator>(const ClassKey& other) const; + bool operator<=(const ClassKey& other) const; + bool operator>=(const ClassKey& other) const; + void encode(framing::Buffer& buffer) const; + + private: + std::string package; + std::string name; + uint8_t hash[HASH_SIZE]; + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const ClassKey& k); +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/console/ConsoleImportExport.h b/qpid/cpp/include/qpid/console/ConsoleImportExport.h new file mode 100644 index 0000000000..c2d7cb3a14 --- /dev/null +++ b/qpid/cpp/include/qpid/console/ConsoleImportExport.h @@ -0,0 +1,33 @@ +#ifndef QPID_CONSOLE_IMPORT_EXPORT_H +#define QPID_CONSOLE_IMPORT_EXPORT_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#if defined(WIN32) && !defined(QPID_DECLARE_STATIC) +#if defined(CONSOLE_EXPORT) || defined (qmfconsole_EXPORTS) +#define QPID_CONSOLE_EXTERN __declspec(dllexport) +#else +#define QPID_CONSOLE_EXTERN __declspec(dllimport) +#endif +#else +#define QPID_CONSOLE_EXTERN +#endif + +#endif diff --git a/qpid/cpp/include/qpid/console/ConsoleListener.h b/qpid/cpp/include/qpid/console/ConsoleListener.h new file mode 100644 index 0000000000..7a649da657 --- /dev/null +++ b/qpid/cpp/include/qpid/console/ConsoleListener.h @@ -0,0 +1,97 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_CONSOLE_LISTENER_H_ +#define _QPID_CONSOLE_CONSOLE_LISTENER_H_ + +#include <string> +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/Broker.h" +#include "qpid/console/ClassKey.h" +#include "qpid/console/Object.h" +#include "qpid/console/Event.h" + +namespace qpid { +namespace console { + + /** + * Implement a subclass of ConsoleListener and subscribe it using + * the SessionManager to receive indications. + * + * \ingroup qmfconsoleapi + */ + class QPID_CONSOLE_EXTERN ConsoleListener{ + public: + virtual ~ConsoleListener() {}; + + /** Invoked when a connection is established to a broker + */ + virtual void brokerConnected(const Broker&) {} + + /** Invoked when the connection to a broker is lost + */ + virtual void brokerDisconnected(const Broker&) {} + + /** Invoked when a QMF package is discovered. + */ + virtual void newPackage(const std::string&) {} + + /** Invoked when a new class is discovered. Session.getSchema can be + * used to obtain details about the class. + */ + virtual void newClass(const ClassKey&) {} + + /** Invoked when a QMF agent is discovered. + */ + virtual void newAgent(const Agent&) {} + + /** Invoked when a QMF agent disconects. + */ + virtual void delAgent(const Agent&) {} + + /** Invoked when an object is updated. + */ + virtual void objectProps(Broker&, Object&) {} + + /** Invoked when an object is updated. + */ + virtual void objectStats(Broker&, Object&) {} + + /** Invoked when an event is raised. + */ + virtual void event(Event&) {} + + /** + */ + //virtual void heartbeat(Agent&, uint64_t) {} + + /** + */ + virtual void brokerInfo(Broker&) {} + + /** + */ + //virtual void methodResponse(Broker&, uint32_t seq, MethodResponse&) {} + }; +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/console/Event.h b/qpid/cpp/include/qpid/console/Event.h new file mode 100644 index 0000000000..ef4ecc791c --- /dev/null +++ b/qpid/cpp/include/qpid/console/Event.h @@ -0,0 +1,86 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_EVENT_H_ +#define _QPID_CONSOLE_EVENT_H_ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/Object.h" +#include "qpid/framing/Uuid.h" +#include "qpid/framing/FieldTable.h" + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + + class Broker; + struct SchemaClass; + class ClassKey; + + /** + * + * \ingroup qmfconsoleapi + */ + class Event { + public: + typedef enum { + SEV_EMERGENCY = 0, SEV_ALERT = 1, SEV_CRITICAL = 2, SEV_ERROR = 3, + SEV_WARNING = 4, SEV_NOTICE = 5, SEV_INFO = 6, SEV_DEBUG = 7 + } Severity; + + QPID_CONSOLE_EXTERN Event(Broker* broker, + SchemaClass* schemaClass, + framing::Buffer& buffer); + Broker* getBroker() const { return broker; } + QPID_CONSOLE_EXTERN const ClassKey& getClassKey() const; + SchemaClass* getSchema() const { return schema; } + const Object::AttributeMap& getAttributes() const { return attributes; } + uint64_t getTimestamp() const { return timestamp; } + uint8_t getSeverity() const { return severity; } + QPID_CONSOLE_EXTERN std::string getSeverityString() const; + + QPID_CONSOLE_EXTERN ObjectId attrRef(const std::string& key) const; + QPID_CONSOLE_EXTERN uint32_t attrUint(const std::string& key) const; + QPID_CONSOLE_EXTERN int32_t attrInt(const std::string& key) const; + QPID_CONSOLE_EXTERN uint64_t attrUint64(const std::string& key) const; + QPID_CONSOLE_EXTERN int64_t attrInt64(const std::string& key) const; + QPID_CONSOLE_EXTERN std::string attrString(const std::string& key) const; + QPID_CONSOLE_EXTERN bool attrBool(const std::string& key) const; + QPID_CONSOLE_EXTERN float attrFloat(const std::string& key) const; + QPID_CONSOLE_EXTERN double attrDouble(const std::string& key) const; + QPID_CONSOLE_EXTERN framing::Uuid attrUuid(const std::string& key) const; + QPID_CONSOLE_EXTERN framing::FieldTable attrMap(const std::string& key) const; + + private: + Broker* broker; + SchemaClass* schema; + uint64_t timestamp; + Severity severity; + Object::AttributeMap attributes; + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Event& event); +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/console/Object.h b/qpid/cpp/include/qpid/console/Object.h new file mode 100644 index 0000000000..5a29fdf792 --- /dev/null +++ b/qpid/cpp/include/qpid/console/Object.h @@ -0,0 +1,123 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_OBJECT_H_ +#define _QPID_CONSOLE_OBJECT_H_ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/ObjectId.h" +#include "qpid/framing/Uuid.h" +#include "qpid/framing/FieldTable.h" +#include <boost/shared_ptr.hpp> +#include <map> +#include <set> +#include <vector> + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + + class Broker; + struct SchemaClass; + struct SchemaMethod; + class ObjectId; + class ClassKey; + class Value; + + /** + * \ingroup qmfconsoleapi + */ + struct MethodResponse { + uint32_t code; + std::string text; + std::map<std::string, boost::shared_ptr<Value> > arguments; + }; + + class Object { + public: + typedef std::vector<Object> Vector; + struct AttributeMap : public std::map<std::string, boost::shared_ptr<Value> > { + QPID_CONSOLE_EXTERN void addRef(const std::string& key, const ObjectId& val); + QPID_CONSOLE_EXTERN void addUint(const std::string& key, uint32_t val); + QPID_CONSOLE_EXTERN void addInt(const std::string& key, int32_t val); + QPID_CONSOLE_EXTERN void addUint64(const std::string& key, uint64_t val); + QPID_CONSOLE_EXTERN void addInt64(const std::string& key, int64_t val); + QPID_CONSOLE_EXTERN void addString(const std::string& key, const std::string& val); + QPID_CONSOLE_EXTERN void addBool(const std::string& key, bool val); + QPID_CONSOLE_EXTERN void addFloat(const std::string& key, float val); + QPID_CONSOLE_EXTERN void addDouble(const std::string& key, double val); + QPID_CONSOLE_EXTERN void addUuid(const std::string& key, const framing::Uuid& val); + QPID_CONSOLE_EXTERN void addMap(const std::string& key, const framing::FieldTable& val); + }; + + QPID_CONSOLE_EXTERN Object(Broker* broker, SchemaClass* schemaClass, framing::Buffer& buffer, bool prop, bool stat); + QPID_CONSOLE_EXTERN ~Object(); + + Broker* getBroker() const { return broker; } + const ObjectId& getObjectId() const { return objectId; } + QPID_CONSOLE_EXTERN const ClassKey& getClassKey() const; + SchemaClass* getSchema() const { return schema; } + uint64_t getCurrentTime() const { return currentTime; } + uint64_t getCreateTime() const { return createTime; } + uint64_t getDeleteTime() const { return deleteTime; } + bool isDeleted() const { return deleteTime != 0; } + QPID_CONSOLE_EXTERN std::string getIndex() const; + QPID_CONSOLE_EXTERN void mergeUpdate(const Object& updated); + const AttributeMap& getAttributes() const { return attributes; } + QPID_CONSOLE_EXTERN void invokeMethod(const std::string name, + const AttributeMap& args, + MethodResponse& result); + QPID_CONSOLE_EXTERN void handleMethodResp(framing::Buffer& buffer, + uint32_t sequence); + + QPID_CONSOLE_EXTERN ObjectId attrRef(const std::string& key) const; + QPID_CONSOLE_EXTERN uint32_t attrUint(const std::string& key) const; + QPID_CONSOLE_EXTERN int32_t attrInt(const std::string& key) const; + QPID_CONSOLE_EXTERN uint64_t attrUint64(const std::string& key) const; + QPID_CONSOLE_EXTERN int64_t attrInt64(const std::string& key) const; + QPID_CONSOLE_EXTERN std::string attrString(const std::string& key) const; + QPID_CONSOLE_EXTERN bool attrBool(const std::string& key) const; + QPID_CONSOLE_EXTERN float attrFloat(const std::string& key) const; + QPID_CONSOLE_EXTERN double attrDouble(const std::string& key) const; + QPID_CONSOLE_EXTERN framing::Uuid attrUuid(const std::string& key) const; + QPID_CONSOLE_EXTERN framing::FieldTable attrMap(const std::string& key) const; + + private: + Broker* broker; + SchemaClass* schema; + ObjectId objectId; + uint64_t currentTime; + uint64_t createTime; + uint64_t deleteTime; + AttributeMap attributes; + SchemaMethod* pendingMethod; + MethodResponse methodResponse; + + void parsePresenceMasks(framing::Buffer& buffer, std::set<std::string>& excludeList); + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Object& object); +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/console/ObjectId.h b/qpid/cpp/include/qpid/console/ObjectId.h new file mode 100644 index 0000000000..7904c85598 --- /dev/null +++ b/qpid/cpp/include/qpid/console/ObjectId.h @@ -0,0 +1,69 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_OBJECTID_H +#define _QPID_CONSOLE_OBJECTID_H + +#include <iostream> +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/sys/IntegerTypes.h" + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + + /** + * + * \ingroup qmfconsoleapi + */ + class QPID_CONSOLE_EXTERN ObjectId { + public: + ObjectId() : first(0), second(0) {} + ObjectId(framing::Buffer& buffer); + + uint8_t getFlags() const { return (first & 0xF000000000000000LL) >> 60; } + uint16_t getSequence() const { return (first & 0x0FFF000000000000LL) >> 48; } + uint32_t getBrokerBank() const { return (first & 0x0000FFFFF0000000LL) >> 28; } + uint32_t getAgentBank() const { return first & 0x000000000FFFFFFFLL; } + uint64_t getObject() const { return second; } + bool isDurable() const { return getSequence() == 0; } + void decode(framing::Buffer& buffer); + void encode(framing::Buffer& buffer); + void setValue(uint64_t f, uint64_t s) { first = f; second = s; } + + bool operator==(const ObjectId& other) const; + bool operator!=(const ObjectId& other) const; + bool operator<(const ObjectId& other) const; + bool operator>(const ObjectId& other) const; + bool operator<=(const ObjectId& other) const; + bool operator>=(const ObjectId& other) const; + + private: + uint64_t first; + uint64_t second; + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const ObjectId& id); +} +} + +#endif diff --git a/qpid/cpp/include/qpid/console/Package.h b/qpid/cpp/include/qpid/console/Package.h new file mode 100644 index 0000000000..3b59e366ff --- /dev/null +++ b/qpid/cpp/include/qpid/console/Package.h @@ -0,0 +1,78 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_PACKAGE_H_ +#define _QPID_CONSOLE_PACKAGE_H_ + +#include <string> +#include <map> +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/sys/IntegerTypes.h" + +namespace qpid { +namespace console { + struct SchemaClass; + + /** + * + * \ingroup qmfconsoleapi + */ + class Package { + public: + Package(const std::string& n) : name(n) {} + const std::string& getName() const { return name; } + + private: + friend class SessionManager; + struct NameHash { + std::string name; + uint8_t hash[16]; + NameHash(const std::string& n, const uint8_t* h) : name(n) { + for (int i = 0; i < 16; i++) + hash[i] = h[i]; + } + }; + + struct NameHashComp { + bool operator() (const NameHash& lhs, const NameHash& rhs) const + { + if (lhs.name != rhs.name) + return lhs.name < rhs.name; + else + for (int i = 0; i < 16; i++) + if (lhs.hash[i] != rhs.hash[i]) + return lhs.hash[i] < rhs.hash[i]; + return false; + } + }; + + typedef std::map<NameHash, SchemaClass*, NameHashComp> ClassMap; + + const std::string name; + ClassMap classes; + + SchemaClass* getClass(const std::string& className, uint8_t* hash); + void addClass(const std::string& className, uint8_t* hash, + SchemaClass* schemaClass); + }; +} +} + +#endif diff --git a/qpid/cpp/include/qpid/console/Schema.h b/qpid/cpp/include/qpid/console/Schema.h new file mode 100644 index 0000000000..6d4e41ab3e --- /dev/null +++ b/qpid/cpp/include/qpid/console/Schema.h @@ -0,0 +1,105 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_SCHEMA_H_ +#define _QPID_CONSOLE_SCHEMA_H_ + +#include "qpid/console/ClassKey.h" +#include <boost/shared_ptr.hpp> +#include <vector> + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + class Value; + + struct SchemaArgument { + SchemaArgument(framing::Buffer& buffer, bool forMethod = false); + boost::shared_ptr<Value> decodeValue(framing::Buffer& buffer); + + std::string name; + uint8_t typeCode; + bool dirInput; + bool dirOutput; + std::string unit; + int min; + int max; + int maxLen; + std::string desc; + std::string defaultVal; + }; + + struct SchemaProperty { + SchemaProperty(framing::Buffer& buffer); + boost::shared_ptr<Value> decodeValue(framing::Buffer& buffer); + + std::string name; + uint8_t typeCode; + uint8_t accessCode; + bool isIndex; + bool isOptional; + std::string unit; + int min; + int max; + int maxLen; + std::string desc; + }; + + struct SchemaStatistic { + SchemaStatistic(framing::Buffer& buffer); + boost::shared_ptr<Value> decodeValue(framing::Buffer& buffer); + + std::string name; + uint8_t typeCode; + std::string unit; + std::string desc; + }; + + struct SchemaMethod { + SchemaMethod(framing::Buffer& buffer); + ~SchemaMethod(); + + std::string name; + std::string desc; + std::vector<SchemaArgument*> arguments; + }; + + struct SchemaClass { + static const uint8_t KIND_TABLE = 1; + static const uint8_t KIND_EVENT = 2; + + SchemaClass(const uint8_t kind, const ClassKey& key, framing::Buffer& buffer); + ~SchemaClass(); + const ClassKey& getClassKey() const { return key; } + + const uint8_t kind; + const ClassKey key; + std::vector<SchemaProperty*> properties; + std::vector<SchemaStatistic*> statistics; + std::vector<SchemaMethod*> methods; + std::vector<SchemaArgument*> arguments; + }; +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/console/SequenceManager.h b/qpid/cpp/include/qpid/console/SequenceManager.h new file mode 100644 index 0000000000..ea0ccf3f77 --- /dev/null +++ b/qpid/cpp/include/qpid/console/SequenceManager.h @@ -0,0 +1,54 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_SEQUENCEMANAGER_H_ +#define _QPID_CONSOLE_SEQUENCEMANAGER_H_ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/sys/Mutex.h" +#include <map> +#include <string> +#include <set> + +namespace qpid { +namespace console { + + /** + * + * \ingroup qpidconsoleapi + */ + class SequenceManager { + public: + typedef std::set<uint32_t> set; + + SequenceManager() : sequence(0) {} + QPID_CONSOLE_EXTERN uint32_t reserve(const std::string& context = ""); + QPID_CONSOLE_EXTERN std::string release(uint32_t seq); + + private: + sys::Mutex lock; + uint32_t sequence; + std::map<uint32_t, std::string> pending; + }; +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/console/SessionManager.h b/qpid/cpp/include/qpid/console/SessionManager.h new file mode 100644 index 0000000000..f27037a559 --- /dev/null +++ b/qpid/cpp/include/qpid/console/SessionManager.h @@ -0,0 +1,205 @@ +#ifndef _QPID_CONSOLE_SESSION_MANAGER_H +#define _QPID_CONSOLE_SESSION_MANAGER_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/Broker.h" +#include "qpid/console/Package.h" +#include "qpid/console/SequenceManager.h" +#include "qpid/console/ClassKey.h" +#include "qpid/console/Schema.h" +#include "qpid/console/Agent.h" +#include "qpid/console/Object.h" +#include "qpid/console/ObjectId.h" +#include "qpid/console/Value.h" +#include "qpid/sys/Mutex.h" +#include "qpid/sys/Condition.h" +#include "qpid/client/ConnectionSettings.h" +#include <string> +#include <vector> + +namespace qpid { +namespace console { + +class ConsoleListener; + +/** + * + * \ingroup qmfconsoleapi + */ +class SessionManager +{ + public: + typedef std::vector<std::string> NameVector; + typedef std::vector<ClassKey> KeyVector; + QPID_CONSOLE_EXTERN ~SessionManager(); + + struct Settings { + bool rcvObjects; + bool rcvEvents; + bool rcvHeartbeats; + bool userBindings; + uint32_t methodTimeout; + uint32_t getTimeout; + + Settings() : rcvObjects(true), rcvEvents(true), rcvHeartbeats(true), + userBindings(false), methodTimeout(20), getTimeout(20) + {} + }; + + /** Create a new SessionManager + * + * Provide your own subclass of ConsoleListener to receive updates and indications + * asynchronously or leave it as its default and use only synchronous methods. + * + *@param listener Listener object to receive asynchronous indications. + *@param settings.rcvObjects Listener wishes to receive managed object data. + *@param settings.rcvEvents Listener wishes to receive events. + *@param settings.rcvHeartbeats Listener wishes to receive agent heartbeats. + *@param settings.userBindings If rcvObjects is true, userBindings allows the + * console client to control which object classes are received. See the bindPackage + * and bindClass methods. If userBindings is false, the listener will receive + * updates for all object classes. + */ + QPID_CONSOLE_EXTERN SessionManager(ConsoleListener* listener = 0, + Settings settings = Settings()); + + /** Connect a broker to the console session + * + *@param settings Connection settings for client access + *@return broker object if operation is successful + * an exception shall be thrown. + */ + QPID_CONSOLE_EXTERN Broker* addBroker(client::ConnectionSettings& settings); + + /** Disconnect a broker from the console session + * + *@param broker The broker object returned from an earlier call to addBroker. + */ + QPID_CONSOLE_EXTERN void delBroker(Broker* broker); + + /** Get a list of known management packages + * + *@param packages Vector of package names returned by the session manager. + */ + QPID_CONSOLE_EXTERN void getPackages(NameVector& packages); + + /** Get a list of class keys associated with a package + * + *@param classKeys List of class keys returned by the session manager. + *@param packageName Name of package being queried. + */ + QPID_CONSOLE_EXTERN void getClasses(KeyVector& classKeys, + const std::string& packageName); + + /** Get the schema of a class given its class key + * + *@param classKey Class key of the desired schema. + */ + QPID_CONSOLE_EXTERN SchemaClass& getSchema(const ClassKey& classKey); + + /** Request that updates be received for all classes within a package + * + * Note that this method is only meaningful if a ConsoleListener was provided at session + * creation and if the 'userBindings' flag was set to true. + * + *@param packageName Name of the package to which to bind. + */ + QPID_CONSOLE_EXTERN void bindPackage(const std::string& packageName); + + /** Request update to be received for a particular class + * + * Note that this method is only meaningful if a ConsoleListener was provided at session + * creation and if the 'userBindings' flag was set to true. + * + *@param classKey Class key of class to which to bind. + */ + QPID_CONSOLE_EXTERN void bindClass(const ClassKey& classKey); + QPID_CONSOLE_EXTERN void bindClass(const std::string& packageName, + const std::string& className); + + /** Get a list of qmf agents known to the session manager. + * + *@param agents Vector of Agent objects returned by the session manager. + *@param broker Return agents registered with this broker only. If NULL, return agents + * from all connected brokers. + */ + QPID_CONSOLE_EXTERN void getAgents(Agent::Vector& agents, + Broker* broker = 0); + + /** Get objects from agents. There are four variants of this method with different ways of + * specifying from which class objects are being queried. + * + *@param objects List of objects received. + *@param classKey ClassKey object identifying class to be queried. + *@param className Class name identifying class to be queried. + *@param objectId Object Id of the single object to be queried. + *@param broker Restrict the query to this broker, or all brokers if NULL. + *@param agent Restrict the query to this agent, or all agents if NULL. + */ + QPID_CONSOLE_EXTERN void getObjects(Object::Vector& objects, + const std::string& className, + Broker* broker = 0, + Agent* agent = 0); + //void getObjects(Object::Vector& objects, const ClassKey& classKey, + // Broker* broker = 0, Agent* agent = 0); + //void getObjects(Object::Vector& objects, const ObjectId& objectId, + // Broker* broker = 0, Agent* agent = 0); + +private: + friend class Broker; + friend class Broker::ConnectionThread; + friend class Object; + sys::Mutex lock; + sys::Mutex brokerListLock; + ConsoleListener* listener; + std::vector<Broker*> brokers; + std::map<std::string, Package*> packages; + SequenceManager sequenceManager; + sys::Condition cv; + SequenceManager::set syncSequenceList; + Object::Vector getResult; + std::string error; + Settings settings; + NameVector bindingKeyList; + + void bindingKeys(); + void allBrokersStable(); + void startProtocol(Broker* broker); + void handleBrokerResp(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handlePackageInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleCommandComplete(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleClassInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleMethodResp(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleHeartbeatInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleEventInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleSchemaResp(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleContentInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence, bool prop, bool stat); + void handleBrokerConnect(Broker* broker); + void handleBrokerDisconnect(Broker* broker); + +}; + +}} // namespace qpid::console + +#endif /*!_QPID_CONSOLE_SESSION_MANAGER_H*/ diff --git a/qpid/cpp/include/qpid/console/Value.h b/qpid/cpp/include/qpid/console/Value.h new file mode 100644 index 0000000000..d9eb65053b --- /dev/null +++ b/qpid/cpp/include/qpid/console/Value.h @@ -0,0 +1,213 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _QPID_CONSOLE_VALUE_H_ +#define _QPID_CONSOLE_VALUE_H_ + +#include "qpid/Exception.h" +#include "qpid/framing/Uuid.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/console/ObjectId.h" +#include <boost/shared_ptr.hpp> + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + + /** + * \ingroup qmfconsoleapi + */ + class Value { + + public: + typedef boost::shared_ptr<Value> Ptr; + virtual ~Value() {} + virtual std::string str() const = 0; + + virtual bool isNull() const { return false; } + virtual bool isObjectId() const { return false; } + virtual bool isUint() const { return false; } + virtual bool isInt() const { return false; } + virtual bool isUint64() const { return false; } + virtual bool isInt64() const { return false; } + virtual bool isString() const { return false; } + virtual bool isBool() const { return false; } + virtual bool isFloat() const { return false; } + virtual bool isDouble() const { return false; } + virtual bool isUuid() const { return false; } + virtual bool isMap() const { return false; } + + virtual ObjectId asObjectId() const { incompatible(); return ObjectId(); } + virtual uint32_t asUint() const { incompatible(); return 0; } + virtual int32_t asInt() const { incompatible(); return 0; } + virtual uint64_t asUint64() const { incompatible(); return 0; } + virtual int64_t asInt64() const { incompatible(); return 0; } + virtual std::string asString() const { incompatible(); return std::string(); } + virtual bool asBool() const { incompatible(); return false; } + virtual float asFloat() const { incompatible(); return 0.0; } + virtual double asDouble() const { incompatible(); return 0.0; } + virtual framing::Uuid asUuid() const { incompatible(); return framing::Uuid(); } + virtual framing::FieldTable asMap() const { incompatible(); return framing::FieldTable(); } + + private: + void incompatible() const { + throw Exception("Incompatible Type"); + } + }; + + class NullValue : public Value { + public: + NullValue() {} + std::string str() const; + bool isNull() const { return true; } + }; + + class RefValue : public Value { + public: + RefValue(ObjectId v) : value(v) {} + RefValue(framing::Buffer& buffer); + std::string str() const; + bool isObjectId() const { return true; } + ObjectId asObjectId() const { return value; } + private: + ObjectId value; + }; + + class UintValue : public Value { + public: + UintValue(uint32_t v) : value(v) {} + std::string str() const; + bool isUint() const { return true; } + uint32_t asUint() const { return value; } + bool isUint64() const { return true; } + uint64_t asUint64() const { return (uint64_t) value; } + private: + uint32_t value; + }; + + class IntValue : public Value { + public: + IntValue(int32_t v) : value(v) {} + std::string str() const; + bool isInt() const { return true; } + int32_t asInt() const { return value; } + bool isInt64() const { return true; } + int64_t asInt64() const { return (int64_t) value; } + private: + int32_t value; + }; + + class Uint64Value : public Value { + public: + Uint64Value(uint64_t v) : value(v) {} + std::string str() const; + bool isUint64() const { return true; } + uint64_t asUint64() const { return value; } + private: + uint64_t value; + }; + + class Int64Value : public Value { + public: + Int64Value(int64_t v) : value(v) {} + std::string str() const; + bool isInt64() const { return true; } + int64_t asInt64() const { return value; } + private: + int64_t value; + }; + + class StringValue : public Value { + public: + StringValue(const std::string& v) : value(v) {} + StringValue(framing::Buffer& buffer, int tc); + std::string str() const { return value; } + bool isString() const { return true; } + std::string asString() const { return value; } + private: + std::string value; + }; + + class BoolValue : public Value { + public: + BoolValue(bool v) : value(v) {} + BoolValue(uint8_t v) : value(v != 0) {} + std::string str() const; + bool isBool() const { return true; } + bool asBool() const { return value; } + private: + bool value; + }; + + class FloatValue : public Value { + public: + FloatValue(float v) : value(v) {} + std::string str() const; + bool isFloat() const { return true; } + float asFloat() const { return value; } + bool isDouble() const { return true; } + double asDouble() const { return (double) value; } + private: + float value; + }; + + class DoubleValue : public Value { + public: + DoubleValue(double v) : value(v) {} + std::string str() const; + bool isDouble() const { return true; } + double asDouble() const { return value; } + private: + double value; + }; + + class UuidValue : public Value { + public: + UuidValue(const framing::Uuid& v) : value(v) {} + UuidValue(framing::Buffer& buffer); + std::string str() const { return value.str(); } + bool isUuid() const { return true; } + framing::Uuid asUuid() const { return value; } + private: + framing::Uuid value; + }; + + class MapValue : public Value { + public: + MapValue(const framing::FieldTable& v) : value(v) {} + MapValue(framing::Buffer& buffer); + std::string str() const; + bool isMap() const { return true; } + framing::FieldTable asMap() const { return value; } + private: + framing::FieldTable value; + }; + + class ValueFactory { + public: + static Value::Ptr newValue(int typeCode, framing::Buffer& buffer); + static void encodeValue(int typeCode, Value::Ptr value, framing::Buffer& buffer); + }; +} +} + +#endif diff --git a/qpid/cpp/include/qpid/framing/Array.h b/qpid/cpp/include/qpid/framing/Array.h new file mode 100644 index 0000000000..d3bdd36aa6 --- /dev/null +++ b/qpid/cpp/include/qpid/framing/Array.h @@ -0,0 +1,97 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "qpid/framing/amqp_types.h" +#include "qpid/framing/FieldValue.h" +#include "qpid/framing/TypeCode.h" +#include <boost/shared_ptr.hpp> +#include <iostream> +#include <vector> +#include "qpid/CommonImportExport.h" + +#ifndef _Array_ +#define _Array_ + +namespace qpid { +namespace framing { + +class Buffer; + +class Array +{ + public: + typedef boost::shared_ptr<FieldValue> ValuePtr; + typedef std::vector<ValuePtr> ValueVector; + typedef ValueVector::const_iterator const_iterator; + typedef ValueVector::iterator iterator; + + QPID_COMMON_EXTERN uint32_t encodedSize() const; + QPID_COMMON_EXTERN void encode(Buffer& buffer) const; + QPID_COMMON_EXTERN void decode(Buffer& buffer); + + QPID_COMMON_EXTERN int count() const; + QPID_COMMON_EXTERN bool operator==(const Array& other) const; + + QPID_COMMON_EXTERN Array(); + QPID_COMMON_EXTERN Array(TypeCode type); + QPID_COMMON_EXTERN Array(uint8_t type); + //creates a longstr array + QPID_COMMON_EXTERN Array(const std::vector<std::string>& in); + + QPID_COMMON_EXTERN TypeCode getType() const { return type; } + + // std collection interface. + QPID_COMMON_EXTERN const_iterator begin() const { return values.begin(); } + QPID_COMMON_EXTERN const_iterator end() const { return values.end(); } + QPID_COMMON_EXTERN iterator begin() { return values.begin(); } + QPID_COMMON_EXTERN iterator end(){ return values.end(); } + + QPID_COMMON_EXTERN ValuePtr front() const { return values.front(); } + QPID_COMMON_EXTERN ValuePtr back() const { return values.back(); } + QPID_COMMON_EXTERN size_t size() const { return values.size(); } + + QPID_COMMON_EXTERN void insert(iterator i, ValuePtr value); + QPID_COMMON_EXTERN void erase(iterator i) { values.erase(i); } + QPID_COMMON_EXTERN void push_back(ValuePtr value) { values.insert(end(), value); } + QPID_COMMON_EXTERN void pop_back() { values.pop_back(); } + + // Non-std interface + QPID_COMMON_EXTERN void add(ValuePtr value) { push_back(value); } + + template <class T> + void collect(std::vector<T>& out) const + { + for (ValueVector::const_iterator i = values.begin(); i != values.end(); ++i) { + out.push_back((*i)->get<T>()); + } + } + + private: + TypeCode type; + ValueVector values; + + friend QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& out, const Array& body); +}; + +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/framing/Buffer.h b/qpid/cpp/include/qpid/framing/Buffer.h new file mode 100644 index 0000000000..8a6a5c0d5f --- /dev/null +++ b/qpid/cpp/include/qpid/framing/Buffer.h @@ -0,0 +1,136 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "qpid/framing/amqp_types.h" +#include "qpid/Exception.h" +#include "qpid/CommonImportExport.h" +#include <boost/iterator/iterator_facade.hpp> + +#ifndef _Buffer_ +#define _Buffer_ + +namespace qpid { +namespace framing { + +struct OutOfBounds : qpid::Exception { + OutOfBounds() : qpid::Exception(std::string("Out of Bounds")) {} +}; + +class Content; +class FieldTable; + +class Buffer +{ + uint32_t size; + char* data; + uint32_t position; + uint32_t r_position; + + void checkAvailable(uint32_t count) { if (position + count > size) throw OutOfBounds(); } + + public: + + /** Buffer input/output iterator. + * Supports using an amqp_0_10::Codec with a framing::Buffer. + */ + class Iterator : public boost::iterator_facade< + Iterator, char, boost::random_access_traversal_tag> + { + public: + Iterator(Buffer& b) : buffer(&b) {} + + private: + friend class boost::iterator_core_access; + char& dereference() const { return buffer->data[buffer->position]; } + void increment() { ++buffer->position; } + bool equal(const Iterator& x) const { return buffer == x.buffer; } + + Buffer* buffer; + }; + + friend class Iterator; + + QPID_COMMON_EXTERN Buffer(char* data=0, uint32_t size=0); + + QPID_COMMON_EXTERN void record(); + QPID_COMMON_EXTERN void restore(bool reRecord = false); + QPID_COMMON_EXTERN void reset(); + + QPID_COMMON_EXTERN uint32_t available() { return size - position; } + QPID_COMMON_EXTERN uint32_t getSize() { return size; } + QPID_COMMON_EXTERN uint32_t getPosition() { return position; } + QPID_COMMON_EXTERN Iterator getIterator() { return Iterator(*this); } + QPID_COMMON_EXTERN char* getPointer() { return data; } + + QPID_COMMON_EXTERN void putOctet(uint8_t i); + QPID_COMMON_EXTERN void putShort(uint16_t i); + QPID_COMMON_EXTERN void putLong(uint32_t i); + QPID_COMMON_EXTERN void putLongLong(uint64_t i); + QPID_COMMON_EXTERN void putInt8(int8_t i); + QPID_COMMON_EXTERN void putInt16(int16_t i); + QPID_COMMON_EXTERN void putInt32(int32_t i); + QPID_COMMON_EXTERN void putInt64(int64_t i); + QPID_COMMON_EXTERN void putFloat(float f); + QPID_COMMON_EXTERN void putDouble(double f); + QPID_COMMON_EXTERN void putBin128(const uint8_t* b); + + QPID_COMMON_EXTERN uint8_t getOctet(); + QPID_COMMON_EXTERN uint16_t getShort(); + QPID_COMMON_EXTERN uint32_t getLong(); + QPID_COMMON_EXTERN uint64_t getLongLong(); + QPID_COMMON_EXTERN int8_t getInt8(); + QPID_COMMON_EXTERN int16_t getInt16(); + QPID_COMMON_EXTERN int32_t getInt32(); + QPID_COMMON_EXTERN int64_t getInt64(); + QPID_COMMON_EXTERN float getFloat(); + QPID_COMMON_EXTERN double getDouble(); + + template <int n> + QPID_COMMON_EXTERN uint64_t getUInt(); + + template <int n> + QPID_COMMON_EXTERN void putUInt(uint64_t); + + QPID_COMMON_EXTERN void putShortString(const string& s); + QPID_COMMON_EXTERN void putMediumString(const string& s); + QPID_COMMON_EXTERN void putLongString(const string& s); + QPID_COMMON_EXTERN void getShortString(string& s); + QPID_COMMON_EXTERN void getMediumString(string& s); + QPID_COMMON_EXTERN void getLongString(string& s); + QPID_COMMON_EXTERN void getBin128(uint8_t* b); + + QPID_COMMON_EXTERN void putRawData(const string& s); + QPID_COMMON_EXTERN void getRawData(string& s, uint32_t size); + + QPID_COMMON_EXTERN void putRawData(const uint8_t* data, size_t size); + QPID_COMMON_EXTERN void getRawData(uint8_t* data, size_t size); + + template <class T> void put(const T& data) { data.encode(*this); } + template <class T> void get(T& data) { data.decode(*this); } + + QPID_COMMON_EXTERN void dump(std::ostream&) const; +}; + +std::ostream& operator<<(std::ostream&, const Buffer&); + +}} // namespace qpid::framing + + +#endif diff --git a/qpid/cpp/include/qpid/framing/FieldTable.h b/qpid/cpp/include/qpid/framing/FieldTable.h new file mode 100644 index 0000000000..a3a5c8a4ee --- /dev/null +++ b/qpid/cpp/include/qpid/framing/FieldTable.h @@ -0,0 +1,125 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include <iostream> +#include <vector> +#include <boost/shared_ptr.hpp> +#include <map> +#include "qpid/framing/amqp_types.h" +#include "qpid/CommonImportExport.h" + +#ifndef _FieldTable_ +#define _FieldTable_ + +namespace qpid { + /** + * The framing namespace contains classes that are used to create, + * send and receive the basic packets from which AMQP is built. + */ +namespace framing { + +class Array; +class FieldValue; +class Buffer; + +/** + * A set of name-value pairs. (See the AMQP spec for more details on + * AMQP field tables). + * + * \ingroup clientapi + */ +class FieldTable +{ + public: + typedef boost::shared_ptr<FieldValue> ValuePtr; + typedef std::map<std::string, ValuePtr> ValueMap; + typedef ValueMap::iterator iterator; + + QPID_COMMON_EXTERN FieldTable() {}; + QPID_COMMON_EXTERN FieldTable(const FieldTable& ft); + QPID_COMMON_EXTERN ~FieldTable(); + QPID_COMMON_EXTERN FieldTable& operator=(const FieldTable& ft); + QPID_COMMON_EXTERN uint32_t encodedSize() const; + QPID_COMMON_EXTERN void encode(Buffer& buffer) const; + QPID_COMMON_EXTERN void decode(Buffer& buffer); + + QPID_COMMON_EXTERN uint32_t qmfEncodedSize() const; + QPID_COMMON_EXTERN void qmfEncode(Buffer& buffer) const; + QPID_COMMON_EXTERN void qmfDecode(Buffer& buffer); + + QPID_COMMON_EXTERN int count() const; + QPID_COMMON_EXTERN void set(const std::string& name, const ValuePtr& value); + QPID_COMMON_EXTERN ValuePtr get(const std::string& name) const; + QPID_COMMON_EXTERN bool isSet(const std::string& name) const { return get(name).get() != 0; } + + QPID_COMMON_EXTERN void setString(const std::string& name, const std::string& value); + QPID_COMMON_EXTERN void setInt(const std::string& name, const int value); + QPID_COMMON_EXTERN void setInt64(const std::string& name, const int64_t value); + QPID_COMMON_EXTERN void setTimestamp(const std::string& name, const uint64_t value); + QPID_COMMON_EXTERN void setUInt64(const std::string& name, const uint64_t value); + QPID_COMMON_EXTERN void setTable(const std::string& name, const FieldTable& value); + QPID_COMMON_EXTERN void setArray(const std::string& name, const Array& value); + QPID_COMMON_EXTERN void setFloat(const std::string& name, const float value); + QPID_COMMON_EXTERN void setDouble(const std::string& name, const double value); + //void setDecimal(string& name, xxx& value); + + QPID_COMMON_EXTERN int getAsInt(const std::string& name) const; + QPID_COMMON_EXTERN uint64_t getAsUInt64(const std::string& name) const; + QPID_COMMON_EXTERN int64_t getAsInt64(const std::string& name) const; + QPID_COMMON_EXTERN std::string getAsString(const std::string& name) const; + + QPID_COMMON_EXTERN bool getTable(const std::string& name, FieldTable& value) const; + QPID_COMMON_EXTERN bool getArray(const std::string& name, Array& value) const; + QPID_COMMON_EXTERN bool getFloat(const std::string& name, float& value) const; + QPID_COMMON_EXTERN bool getDouble(const std::string& name, double& value) const; + //bool getTimestamp(const std::string& name, uint64_t& value) const; + //bool getDecimal(string& name, xxx& value); + QPID_COMMON_EXTERN void erase(const std::string& name); + + + QPID_COMMON_EXTERN bool operator==(const FieldTable& other) const; + + // Map-like interface. + // TODO: may need to duplicate into versions that return mutable iterator + ValueMap::const_iterator begin() const { return values.begin(); } + ValueMap::const_iterator end() const { return values.end(); } + ValueMap::const_iterator find(const std::string& s) const { return values.find(s); } + + std::pair <ValueMap::iterator, bool> insert(const ValueMap::value_type&); + void clear() { values.clear(); } + + // ### Hack Alert + + ValueMap::iterator getValues() { return values.begin(); } + + private: + ValueMap values; + + QPID_COMMON_EXTERN friend std::ostream& operator<<(std::ostream& out, const FieldTable& body); +}; + +//class FieldNotFoundException{}; +//class UnknownFieldName : public FieldNotFoundException{}; +//class IncorrectFieldType : public FieldNotFoundException{}; +} +} + + +#endif diff --git a/qpid/cpp/include/qpid/framing/FieldValue.h b/qpid/cpp/include/qpid/framing/FieldValue.h new file mode 100644 index 0000000000..97fc56d606 --- /dev/null +++ b/qpid/cpp/include/qpid/framing/FieldValue.h @@ -0,0 +1,321 @@ +#ifndef _framing_FieldValue_h +#define _framing_FieldValue_h +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/Exception.h" +#include "qpid/framing/amqp_types.h" +#include "qpid/framing/Buffer.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/CommonImportExport.h" + +#include <iostream> +#include <memory> +#include <vector> + +#include <assert.h> + +namespace qpid { +namespace framing { + +//class Array; +/** + * Exception that is the base exception for all field table errors. + * + * \ingroup clientapi + */ +class FieldValueException : public qpid::Exception {}; + +/** + * Exception thrown when we can't perform requested conversion + * + * \ingroup clientapi + */ +struct InvalidConversionException : public FieldValueException { + InvalidConversionException() {} +}; + +/** + * Value that can appear in an AMQP field table + * + * \ingroup clientapi + */ +class FieldValue { + public: + /* + * Abstract type for content of different types + */ + class Data { + public: + virtual ~Data() {}; + virtual uint32_t encodedSize() const = 0; + virtual void encode(Buffer& buffer) = 0; + virtual void decode(Buffer& buffer) = 0; + virtual bool operator==(const Data&) const = 0; + + virtual bool convertsToInt() const { return false; } + virtual bool convertsToString() const { return false; } + virtual int64_t getInt() const { throw InvalidConversionException();} + virtual std::string getString() const { throw InvalidConversionException(); } + + virtual void print(std::ostream& out) const = 0; + }; + + FieldValue(): data(0) {}; + // Default assignment operator is fine + void setType(uint8_t type); + uint8_t getType(); + Data& getData() { return *data; } + uint32_t encodedSize() const { return 1 + data->encodedSize(); }; + bool empty() const { return data.get() == 0; } + void encode(Buffer& buffer); + void decode(Buffer& buffer); + QPID_COMMON_EXTERN bool operator==(const FieldValue&) const; + QPID_COMMON_EXTERN bool operator!=(const FieldValue& v) const { return !(*this == v); } + + void print(std::ostream& out) const; + + template <typename T> bool convertsTo() const { return false; } + template <typename T> T get() const { throw InvalidConversionException(); } + + protected: + FieldValue(uint8_t t, Data* d): typeOctet(t), data(d) {} + + private: + uint8_t typeOctet; + std::auto_ptr<Data> data; +}; + +template <> +inline bool FieldValue::convertsTo<int>() const { return data->convertsToInt(); } + +template <> +inline bool FieldValue::convertsTo<int64_t>() const { return data->convertsToInt(); } + +template <> +inline bool FieldValue::convertsTo<std::string>() const { return data->convertsToString(); } + +template <> +inline int FieldValue::get<int>() const { return data->getInt(); } + +template <> +inline int64_t FieldValue::get<int64_t>() const { return data->getInt(); } + +template <> +inline std::string FieldValue::get<std::string>() const { return data->getString(); } + +inline std::ostream& operator<<(std::ostream& out, const FieldValue& v) { + v.print(out); + return out; +} + +template <int width> +class FixedWidthValue : public FieldValue::Data { + uint8_t octets[width]; + + public: + FixedWidthValue() {} + FixedWidthValue(const uint8_t (&data)[width]) : octets(data) {} + FixedWidthValue(const uint8_t* const data) + { + for (int i = 0; i < width; i++) octets[i] = data[i]; + } + FixedWidthValue(uint64_t v) + { + for (int i = width; i > 1; --i) { + octets[i-1] = (uint8_t) (0xFF & v); v >>= 8; + } + octets[0] = (uint8_t) (0xFF & v); + } + uint32_t encodedSize() const { return width; } + void encode(Buffer& buffer) { buffer.putRawData(octets, width); } + void decode(Buffer& buffer) { buffer.getRawData(octets, width); } + bool operator==(const Data& d) const { + const FixedWidthValue<width>* rhs = dynamic_cast< const FixedWidthValue<width>* >(&d); + if (rhs == 0) return false; + else return std::equal(&octets[0], &octets[width], &rhs->octets[0]); + } + + bool convertsToInt() const { return true; } + int64_t getInt() const + { + int64_t v = 0; + for (int i = 0; i < width-1; ++i) { + v |= octets[i]; v <<= 8; + } + v |= octets[width-1]; + return v; + } + uint8_t* rawOctets() { return octets; } + + void print(std::ostream& o) const { o << "F" << width << ":"; }; +}; + +template <> +class FixedWidthValue<0> : public FieldValue::Data { + public: + // Implicit default constructor is fine + uint32_t encodedSize() const { return 0; } + void encode(Buffer&) {}; + void decode(Buffer&) {}; + bool operator==(const Data& d) const { + const FixedWidthValue<0>* rhs = dynamic_cast< const FixedWidthValue<0>* >(&d); + return rhs != 0; + } + void print(std::ostream& o) const { o << "F0"; }; +}; + +template <int lenwidth> +class VariableWidthValue : public FieldValue::Data { + std::vector<uint8_t> octets; + + public: + VariableWidthValue() {} + VariableWidthValue(const std::vector<uint8_t>& data) : octets(data) {} + VariableWidthValue(const uint8_t* start, const uint8_t* end) : octets(start, end) {} + uint32_t encodedSize() const { return lenwidth + octets.size(); } + void encode(Buffer& buffer) { + buffer.putUInt<lenwidth>(octets.size()); + if (octets.size() > 0) + buffer.putRawData(&octets[0], octets.size()); + }; + void decode(Buffer& buffer) { + uint32_t len = buffer.getUInt<lenwidth>(); + octets.resize(len); + if (len > 0) + buffer.getRawData(&octets[0], len); + } + bool operator==(const Data& d) const { + const VariableWidthValue<lenwidth>* rhs = dynamic_cast< const VariableWidthValue<lenwidth>* >(&d); + if (rhs == 0) return false; + else return octets==rhs->octets; + } + + bool convertsToString() const { return true; } + std::string getString() const { return std::string(octets.begin(), octets.end()); } + + void print(std::ostream& o) const { o << "V" << lenwidth << ":" << octets.size() << ":"; }; +}; + +template <class T> +class EncodedValue : public FieldValue::Data { + T value; + public: + + EncodedValue() {} + EncodedValue(const T& v) : value(v) {} + + T& getValue() { return value; } + const T& getValue() const { return value; } + + uint32_t encodedSize() const { return value.encodedSize(); } + + void encode(Buffer& buffer) { + value.encode(buffer); + }; + void decode(Buffer& buffer) { + value.decode(buffer); + } + bool operator==(const Data& d) const { + const EncodedValue<T>* rhs = dynamic_cast< const EncodedValue<T>* >(&d); + if (rhs == 0) return false; + else return value==rhs->value; + } + + void print(std::ostream& o) const { o << "[" << value << "]"; }; +}; + +class Str8Value : public FieldValue { + public: + QPID_COMMON_EXTERN Str8Value(const std::string& v); +}; + +class Str16Value : public FieldValue { + public: + QPID_COMMON_EXTERN Str16Value(const std::string& v); +}; + +class Struct32Value : public FieldValue { + public: + QPID_COMMON_EXTERN Struct32Value(const std::string& v); +}; + +class FloatValue : public FieldValue +{ + public: + QPID_COMMON_EXTERN FloatValue(float f); +}; +class DoubleValue : public FieldValue +{ + public: + QPID_COMMON_EXTERN DoubleValue(double f); +}; + +/* + * Basic integer value encodes as signed 32 bit + */ +class IntegerValue : public FieldValue { + public: + QPID_COMMON_EXTERN IntegerValue(int v); +}; + +class TimeValue : public FieldValue { + public: + QPID_COMMON_EXTERN TimeValue(uint64_t v); +}; + +class Integer64Value : public FieldValue { + public: + QPID_COMMON_EXTERN Integer64Value(int64_t v); +}; + +class Unsigned64Value : public FieldValue { + public: + QPID_COMMON_EXTERN Unsigned64Value(uint64_t v); +}; + +class FieldTableValue : public FieldValue { + public: + QPID_COMMON_EXTERN FieldTableValue(const FieldTable&); +}; + +class ArrayValue : public FieldValue { + public: + QPID_COMMON_EXTERN ArrayValue(const Array&); +}; + +template <class T> +bool getEncodedValue(FieldTable::ValuePtr vptr, T& value) +{ + if (vptr) { + const EncodedValue<T>* ev = dynamic_cast< EncodedValue<T>* >(&(vptr->getData())); + if (ev != 0) { + value = ev->getValue(); + return true; + } + } + return false; +} + + +}} // qpid::framing + +#endif diff --git a/qpid/cpp/include/qpid/framing/ProtocolVersion.h b/qpid/cpp/include/qpid/framing/ProtocolVersion.h new file mode 100644 index 0000000000..e7e75d75f6 --- /dev/null +++ b/qpid/cpp/include/qpid/framing/ProtocolVersion.h @@ -0,0 +1,58 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _ProtocolVersion_ +#define _ProtocolVersion_ + +#include "qpid/framing/amqp_types.h" +#include "qpid/CommonImportExport.h" + +namespace qpid +{ +namespace framing +{ + +class ProtocolVersion +{ +private: + uint8_t major_; + uint8_t minor_; + +public: + explicit ProtocolVersion(uint8_t _major=0, uint8_t _minor=0) + : major_(_major), minor_(_minor) {} + + QPID_COMMON_EXTERN uint8_t getMajor() const { return major_; } + QPID_COMMON_EXTERN void setMajor(uint8_t major) { major_ = major; } + QPID_COMMON_EXTERN uint8_t getMinor() const { return minor_; } + QPID_COMMON_EXTERN void setMinor(uint8_t minor) { minor_ = minor; } + QPID_COMMON_EXTERN const std::string toString() const; + + QPID_COMMON_EXTERN ProtocolVersion& operator=(ProtocolVersion p); + + QPID_COMMON_EXTERN bool operator==(ProtocolVersion p) const; + QPID_COMMON_EXTERN bool operator!=(ProtocolVersion p) const { return ! (*this == p); } +}; + +} // namespace framing +} // namespace qpid + + +#endif // ifndef _ProtocolVersion_ diff --git a/qpid/cpp/include/qpid/framing/SequenceNumber.h b/qpid/cpp/include/qpid/framing/SequenceNumber.h new file mode 100644 index 0000000000..1e53058df8 --- /dev/null +++ b/qpid/cpp/include/qpid/framing/SequenceNumber.h @@ -0,0 +1,79 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _framing_SequenceNumber_h +#define _framing_SequenceNumber_h + +#include "qpid/framing/amqp_types.h" +#include <boost/operators.hpp> +#include <iosfwd> +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace framing { + +class Buffer; + +/** + * 4-byte sequence number that 'wraps around'. + */ +class SequenceNumber : public +boost::equality_comparable< + SequenceNumber, boost::less_than_comparable< + SequenceNumber, boost::incrementable< + SequenceNumber, boost::decrementable<SequenceNumber> > > > +{ + int32_t value; + + public: + SequenceNumber(uint32_t v=0) : value(v) {} + + SequenceNumber& operator++() { ++value; return *this; } + SequenceNumber& operator--() { --value; return *this; } + bool operator==(const SequenceNumber& other) const { return value == other.value; } + bool operator<(const SequenceNumber& other) const { return (value - other.value) < 0; } + uint32_t getValue() const { return uint32_t(value); } + operator uint32_t() const { return uint32_t(value); } + + void encode(Buffer& buffer) const; + void decode(Buffer& buffer); + uint32_t encodedSize() const; + + template <class S> void serialize(S& s) { s(value); } + + friend inline int32_t operator-(const SequenceNumber& a, const SequenceNumber& b); +}; + +inline int32_t operator-(const SequenceNumber& a, const SequenceNumber& b) { + return int32_t(a.value - b.value); +} + +struct Window +{ + SequenceNumber hwm; + SequenceNumber lwm; +}; + +QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& o, const SequenceNumber& n); + +}} // namespace qpid::framing + + +#endif diff --git a/qpid/cpp/include/qpid/framing/SequenceSet.h b/qpid/cpp/include/qpid/framing/SequenceSet.h new file mode 100644 index 0000000000..39395e9ad7 --- /dev/null +++ b/qpid/cpp/include/qpid/framing/SequenceSet.h @@ -0,0 +1,69 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _framing_SequenceSet_h +#define _framing_SequenceSet_h + +#include "qpid/framing/SequenceNumber.h" +#include "qpid/RangeSet.h" +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace framing { +class Buffer; + +class SequenceSet : public RangeSet<SequenceNumber> { + public: + SequenceSet() {} + SequenceSet(const RangeSet<SequenceNumber>& r) + : RangeSet<SequenceNumber>(r) {} + SequenceSet(const SequenceNumber& s) { add(s); } + SequenceSet(const SequenceNumber& start, const SequenceNumber finish) { add(start,finish); } + + + void encode(Buffer& buffer) const; + void decode(Buffer& buffer); + uint32_t encodedSize() const; + + QPID_COMMON_EXTERN bool contains(const SequenceNumber& s) const; + QPID_COMMON_EXTERN void add(const SequenceNumber& s); + QPID_COMMON_EXTERN void add(const SequenceNumber& start, const SequenceNumber& finish); // Closed range + QPID_COMMON_EXTERN void add(const SequenceSet& set); + QPID_COMMON_EXTERN void remove(const SequenceNumber& s); + QPID_COMMON_EXTERN void remove(const SequenceNumber& start, const SequenceNumber& finish); // Closed range + QPID_COMMON_EXTERN void remove(const SequenceSet& set); + + template <class T> void for_each(T& t) const { + for (RangeIterator i = rangesBegin(); i != rangesEnd(); i++) + t(i->first(), i->last()); + } + + template <class T> void for_each(const T& t) const { + for (RangeIterator i = rangesBegin(); i != rangesEnd(); i++) + t(i->first(), i->last()); + } + + friend QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const SequenceSet&); +}; + +}} // namespace qpid::framing + + +#endif diff --git a/qpid/cpp/include/qpid/framing/StructHelper.h b/qpid/cpp/include/qpid/framing/StructHelper.h new file mode 100644 index 0000000000..fc9a7909cc --- /dev/null +++ b/qpid/cpp/include/qpid/framing/StructHelper.h @@ -0,0 +1,57 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#ifndef _StructHelper_ +#define _StructHelper_ + +#include "qpid/Exception.h" +#include "qpid/CommonImportExport.h" +#include "qpid/framing/Buffer.h" + +#include <stdlib.h> // For alloca + +namespace qpid { +namespace framing { + +class StructHelper +{ +public: + + template <class T> void encode(const T t, std::string& data) { + uint32_t size = t.bodySize() + 2/*type*/; + data.resize(size); + Buffer wbuffer(const_cast<char*>(data.data()), size); + wbuffer.putShort(T::TYPE); + t.encodeStructBody(wbuffer); + } + + template <class T> void decode(T& t, const std::string& data) { + Buffer rbuffer(const_cast<char*>(data.data()), data.length()); + uint16_t type = rbuffer.getShort(); + if (type == T::TYPE) { + t.decodeStructBody(rbuffer); + } else { + throw Exception("Type code does not match"); + } + } +}; + +}} +#endif diff --git a/qpid/cpp/include/qpid/framing/Uuid.h b/qpid/cpp/include/qpid/framing/Uuid.h new file mode 100644 index 0000000000..0dfa7a58e7 --- /dev/null +++ b/qpid/cpp/include/qpid/framing/Uuid.h @@ -0,0 +1,91 @@ +#ifndef QPID_FRAMING_UUID_H +#define QPID_FRAMING_UUID_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/CommonImportExport.h" +#include "qpid/sys/uuid.h" +#include "qpid/sys/IntegerTypes.h" + +#include <boost/array.hpp> + +#include <ostream> +#include <istream> + +namespace qpid { +namespace framing { + +class Buffer; + +/** + * A UUID is represented as a boost::array of 16 bytes. + * + * Full value semantics, operators ==, < etc. are provided by + * boost::array so Uuid can be the key type in a map etc. + */ +struct Uuid : public boost::array<uint8_t, 16> { + /** If unique is true, generate a unique ID else a null ID. */ + Uuid(bool unique=false) { if (unique) generate(); else clear(); } + + /** Copy from 16 bytes of data. */ + Uuid(const uint8_t* data) { assign(data); } + + /** Copy from 16 bytes of data. */ + void assign(const uint8_t* data) { + uuid_copy(c_array(), data); + } + + /** Set to a new unique identifier. */ + void generate() { uuid_generate(c_array()); } + + /** Set to all zeros. */ + void clear() { uuid_clear(c_array()); } + + /** Test for null (all zeros). */ + // Force int 0/!0 to false/true; avoids compile warnings. + bool isNull() { + return !!uuid_is_null(data()); + } + + // Default op= and copy ctor are fine. + // boost::array gives us ==, < etc. + + QPID_COMMON_EXTERN void encode(framing::Buffer& buf) const; + QPID_COMMON_EXTERN void decode(framing::Buffer& buf); + QPID_COMMON_EXTERN uint32_t encodedSize() const { return size(); } + + /** String value in format 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb. */ + QPID_COMMON_EXTERN std::string str() const; + + template <class S> void serialize(S& s) { + s.raw(begin(), size()); + } +}; + +/** Print in format 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb. */ +QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, Uuid); + +/** Read from format 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb. */ +QPID_COMMON_EXTERN std::istream& operator>>(std::istream&, Uuid&); + +}} // namespace qpid::framing + + + +#endif /*!QPID_FRAMING_UUID_H*/ diff --git a/qpid/cpp/include/qpid/framing/amqp_types.h b/qpid/cpp/include/qpid/framing/amqp_types.h new file mode 100644 index 0000000000..d9088b7a12 --- /dev/null +++ b/qpid/cpp/include/qpid/framing/amqp_types.h @@ -0,0 +1,66 @@ +#ifndef AMQP_TYPES_H +#define AMQP_TYPES_H +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +/** \file + * Definitions and forward declarations of all types used + * in AMQP messages. + */ + +#include "qpid/sys/IntegerTypes.h" +#include <string> + +namespace qpid { +namespace framing { + +using std::string; +typedef uint8_t FrameType; +typedef uint16_t ChannelId; +typedef uint32_t BatchOffset; +typedef uint8_t ClassId; +typedef uint8_t MethodId; +typedef uint16_t ReplyCode; + +// Types represented by classes. +class Content; +class FieldTable; +class SequenceNumberSet; +struct Uuid; + +// Useful constants + +/** Maximum channel ID used by broker. Reserve high bit for internal use.*/ +const ChannelId CHANNEL_MAX=(ChannelId(~1))>>1; +const ChannelId CHANNEL_HIGH_BIT= ChannelId(~CHANNEL_MAX); + +// Forward declare class types +class FramingContent; +class FieldTable; +class SequenceNumberSet; +class SequenceSet; +struct Uuid; + +// Enum types +enum DeliveryMode { TRANSIENT = 1, PERSISTENT = 2}; + +}} // namespace qpid::framing +#endif diff --git a/qpid/cpp/include/qpid/framing/amqp_types_full.h b/qpid/cpp/include/qpid/framing/amqp_types_full.h new file mode 100644 index 0000000000..c5d84dedea --- /dev/null +++ b/qpid/cpp/include/qpid/framing/amqp_types_full.h @@ -0,0 +1,38 @@ +#ifndef _framing_amqp_types_decl_h +#define _framing_amqp_types_decl_h + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** \file + * Definitions and full declarations of all types used + * in AMQP messages. + * + * It's better to include amqp_types.h in another header instead of this file + * unless the header actually needs the full declarations. Including + * full declarations when forward declarations would increase compile + * times. + */ + +#include "qpid/framing/amqp_types.h" +#include "qpid/framing/Array.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/framing/SequenceSet.h" +#include "qpid/framing/Uuid.h" + +#endif /*!_framing_amqp_types_decl_h*/ diff --git a/qpid/cpp/include/qpid/log/Logger.h b/qpid/cpp/include/qpid/log/Logger.h new file mode 100644 index 0000000000..d7da1f077a --- /dev/null +++ b/qpid/cpp/include/qpid/log/Logger.h @@ -0,0 +1,114 @@ +#ifndef QPID_LOG_LOGGER_H +#define QPID_LOG_LOGGER_H + +/* + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/log/Selector.h" +#include "qpid/log/Options.h" +#include "qpid/sys/Mutex.h" +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/noncopyable.hpp> +#include <set> +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace log { + +/** + * Central logging agent. + * + * Thread safe, singleton. + * + * The Logger provides all needed functionality for selecting and + * formatting logging output. The actual outputting of log records + * is handled by Logger::Output-derived classes instantiated by the + * platform's sink-related options. + */ +class Logger : private boost::noncopyable { + public: + /** Flags indicating what to include in the log output */ + enum FormatFlag { FILE=1, LINE=2, FUNCTION=4, LEVEL=8, TIME=16, THREAD=32}; + + /** + * Logging output sink. + * + * The Output sink provides an interface to direct logging output to. + * Logging sinks are primarily platform-specific as provided for on + * each platform. + * + * Implementations of Output must be thread safe. + */ + class Output { + public: + QPID_COMMON_EXTERN Output(); + QPID_COMMON_EXTERN virtual ~Output(); + /** Receives the statemnt of origin and formatted message to log. */ + virtual void log(const Statement&, const std::string&) =0; + }; + + QPID_COMMON_EXTERN static Logger& instance(); + + QPID_COMMON_EXTERN Logger(); + QPID_COMMON_EXTERN ~Logger(); + + /** Select the messages to be logged. */ + QPID_COMMON_EXTERN void select(const Selector& s); + + /** Set the formatting flags, bitwise OR of FormatFlag values. */ + QPID_COMMON_EXTERN void format(int formatFlags); + + /** Set format flags from options object. + *@returns computed flags. + */ + QPID_COMMON_EXTERN int format(const Options&); + + /** Configure logger from Options */ + QPID_COMMON_EXTERN void configure(const Options& o); + + /** Add a statement. */ + QPID_COMMON_EXTERN void add(Statement& s); + + /** Log a message. */ + QPID_COMMON_EXTERN void log(const Statement&, const std::string&); + + /** Add an output destination for messages */ + QPID_COMMON_EXTERN void output(std::auto_ptr<Output> out); + + /** Set a prefix for all messages */ + QPID_COMMON_EXTERN void setPrefix(const std::string& prefix); + + /** Reset the logger. */ + QPID_COMMON_EXTERN void clear(); + + /** Get the options used to configure the logger. */ + QPID_COMMON_EXTERN const Options& getOptions() const { return options; } + + + private: + typedef boost::ptr_vector<Output> Outputs; + typedef std::set<Statement*> Statements; + + sys::Mutex lock; + inline void enable_unlocked(Statement* s); + + Statements statements; + Outputs outputs; + Selector selector; + int flags; + std::string prefix; + Options options; +}; + +}} // namespace qpid::log + + +#endif /*!QPID_LOG_LOGGER_H*/ diff --git a/qpid/cpp/include/qpid/log/Options.h b/qpid/cpp/include/qpid/log/Options.h new file mode 100644 index 0000000000..bbc47b47d3 --- /dev/null +++ b/qpid/cpp/include/qpid/log/Options.h @@ -0,0 +1,50 @@ +#ifndef QPID_LOG_OPTIONS_H +#define QPID_LOG_OPTIONS_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "qpid/Options.h" +#include "qpid/CommonImportExport.h" +#include "qpid/log/SinkOptions.h" +#include <iosfwd> +#include <memory> + +namespace qpid { +namespace log { + +/** Logging options for config parser. */ +struct Options : public qpid::Options { + /** Pass argv[0] for use in syslog output */ + QPID_COMMON_EXTERN Options(const std::string& argv0_=std::string(), + const std::string& name_="Logging options"); + QPID_COMMON_EXTERN Options(const Options &); + + QPID_COMMON_EXTERN Options& operator=(const Options&); + + std::string argv0; + std::string name; + std::vector<std::string> selectors; + bool time, level, thread, source, function; + bool trace; + std::string prefix; + std::auto_ptr<SinkOptions> sinkOptions; +}; + +}} // namespace qpid::log + +#endif /*!QPID_LOG_OPTIONS_H*/ diff --git a/qpid/cpp/include/qpid/log/Selector.h b/qpid/cpp/include/qpid/log/Selector.h new file mode 100644 index 0000000000..061152d7e2 --- /dev/null +++ b/qpid/cpp/include/qpid/log/Selector.h @@ -0,0 +1,71 @@ +#ifndef SELECTOR_H +#define SELECTOR_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/log/Statement.h" +#include "qpid/CommonImportExport.h" +#include <vector> + +namespace qpid { +namespace log { +struct Options; + +/** + * A selector identifies the set of log messages to enable. + * + * Thread object unsafe, pass-by-value type. + */ +class Selector { + public: + /** Empty selector selects nothing */ + Selector() {} + + /** Set selector from Options */ + QPID_COMMON_EXTERN Selector(const Options&); + + /** Equavlient to: Selector s; s.enable(l, s) */ + Selector(Level l, const std::string& s=std::string()) { + enable(l,s); + } + + Selector(const std::string& enableStr) { enable(enableStr); } + /** + * Enable messages with level in levels where the file + * name contains substring. Empty string matches all. + */ + void enable(Level level, const std::string& substring=std::string()) { + substrings[level].push_back(substring); + } + + /** Enable based on a 'level[+]:file' string */ + QPID_COMMON_EXTERN void enable(const std::string& enableStr); + + /** True if level is enabled for file. */ + QPID_COMMON_EXTERN bool isEnabled(Level level, const char* function); + + private: + std::vector<std::string> substrings[LevelTraits::COUNT]; +}; + + +}} // namespace qpid::log + + +#endif /*!SELECTOR_H*/ diff --git a/qpid/cpp/include/qpid/log/SinkOptions.h b/qpid/cpp/include/qpid/log/SinkOptions.h new file mode 100644 index 0000000000..7ec2cfbc17 --- /dev/null +++ b/qpid/cpp/include/qpid/log/SinkOptions.h @@ -0,0 +1,64 @@ +#ifndef QPID_LOG_SINKOPTIONS_H +#define QPID_LOG_SINKOPTIONS_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/Options.h" +#include <string> + +namespace qpid { +namespace log { + +class Logger; + +/** + * Logging sink options. + * + * Most logging sink options will be platform-specific, even if some are + * duplicated. The range of platforms to which this code may be ported + * can't be assumed to all have C++ iostreams or files. Thus, this class + * is primarily for implementing in a platform-specific way. + */ +struct SinkOptions : public qpid::Options { + + // Create a platform's SinkOptions. Pass argv0 as the program name, + // useful for syslog-type logging. + static SinkOptions *create(const std::string& argv0=std::string()); + + SinkOptions(const std::string& name="Logging sink options") + : qpid::Options(name) + {} + virtual ~SinkOptions() {} + + virtual SinkOptions& operator=(const SinkOptions&) = 0; + + // This allows the caller to indicate that there's no normal outputs + // available. For example, when running as a daemon. In these cases, the + // platform's "syslog"-type output should replace the default stderr + // unless some other sink has been selected. + virtual void detached(void) = 0; + + // The Logger acting on these options calls setup() to request any + // Sinks be set up and fed back to the logger. + virtual void setup(Logger *logger) = 0; +}; + +}} // namespace qpid::log + +#endif /*!QPID_LOG_OPTIONS_H*/ diff --git a/qpid/cpp/include/qpid/log/Statement.h b/qpid/cpp/include/qpid/log/Statement.h new file mode 100644 index 0000000000..8f73175630 --- /dev/null +++ b/qpid/cpp/include/qpid/log/Statement.h @@ -0,0 +1,121 @@ +#ifndef STATEMENT_H +#define STATEMENT_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/Msg.h" +#include "qpid/CommonImportExport.h" +#include <boost/current_function.hpp> + +namespace qpid { +namespace log { + +/** Debugging severity levels + * - trace: High-volume debugging messages. + * - debug: Debugging messages. + * - info: Informational messages. + * - notice: Normal but significant condition. + * - warning: Warn of a possible problem. + * - error: A definite error has occured. + * - critical: System in danger of severe failure. + */ +enum Level { trace, debug, info, notice, warning, error, critical }; +struct LevelTraits { + static const int COUNT=critical+1; + + /** Get level from string name. + *@exception if name invalid. + */ + static Level level(const char* name); + + /** Get level from string name. + *@exception if name invalid. + */ + static Level level(const std::string& name) { + return level(name.c_str()); + } + + /** String name of level */ + static const char* name(Level); +}; + +/** POD struct representing a logging statement in source code. */ +struct Statement { + bool enabled; + const char* file; + int line; + const char* function; + Level level; + + QPID_COMMON_EXTERN void log(const std::string& message); + + struct Initializer { + QPID_COMMON_EXTERN Initializer(Statement& s); + Statement& statement; + }; +}; + +///@internal static initializer for a Statement. +#define QPID_LOG_STATEMENT_INIT(level) \ + { 0, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, (::qpid::log::level) } + +/** + * Like QPID_LOG but computes an additional boolean test expression + * to determine if the message should be logged. Evaluation of both + * the test and message expressions occurs only if the requested log level + * is enabled. + *@param LEVEL severity Level for message, should be one of: + * debug, info, notice, warning, error, critical. NB no qpid::log:: prefix. + *@param TEST message is logged only if expression TEST evaluates to true. + *@param MESSAGE any object with an @eostream operator<<, or a sequence + * like of ostreamable objects separated by @e<<. + */ +#define QPID_LOG_IF(LEVEL, TEST, MESSAGE) \ + do { \ + using ::qpid::log::Statement; \ + static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \ + static Statement::Initializer init_(stmt_); \ + if (stmt_.enabled && (TEST)) \ + stmt_.log(::qpid::Msg() << MESSAGE); \ + } while(0) + +/** + * Macro for log statements. Example of use: + * @code + * QPID_LOG(debug, "There are " << foocount << " foos in the bar."); + * QPID_LOG(error, boost::format("Dohickey %s exploded") % dohicky.name()); + * @endcode + * + * You can subscribe to log messages by level, by component, by filename + * or a combination @see Configuration. + + *@param LEVEL severity Level for message, should be one of: + * debug, info, notice, warning, error, critical. NB no qpid::log:: prefix. + *@param MESSAGE any object with an @eostream operator<<, or a sequence + * like of ostreamable objects separated by @e<<. + */ +#define QPID_LOG(LEVEL, MESSAGE) QPID_LOG_IF(LEVEL, true, MESSAGE); + +}} // namespace qpid::log + + + + +#endif /*!STATEMENT_H*/ + diff --git a/qpid/cpp/include/qpid/management/Args.h b/qpid/cpp/include/qpid/management/Args.h new file mode 100644 index 0000000000..5d1cb7e01d --- /dev/null +++ b/qpid/cpp/include/qpid/management/Args.h @@ -0,0 +1,44 @@ +#ifndef _Args_ +#define _Args_ + +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + + +namespace qpid { +namespace management { + +class Args +{ + public: + + virtual ~Args (void) = 0; + +}; + +inline Args::~Args (void) {} + +class ArgsNone : public Args +{ +}; + +}} + + +#endif /*!_Args_*/ diff --git a/qpid/cpp/include/qpid/management/Manageable.h b/qpid/cpp/include/qpid/management/Manageable.h new file mode 100644 index 0000000000..8062479ac6 --- /dev/null +++ b/qpid/cpp/include/qpid/management/Manageable.h @@ -0,0 +1,72 @@ +#ifndef _Manageable_ +#define _Manageable_ + +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +#include "qpid/management/ManagementObject.h" +#include "qpid/management/Args.h" +#include <string> +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace management { + +class QPID_COMMON_EXTERN Manageable +{ + public: + + virtual ~Manageable(void) = 0; + + // status_t is a type used to pass completion status from the method handler. + // + typedef uint32_t status_t; + static std::string StatusText(status_t status, std::string text = std::string()); + + static const status_t STATUS_OK = 0; + static const status_t STATUS_UNKNOWN_OBJECT = 1; + static const status_t STATUS_UNKNOWN_METHOD = 2; + static const status_t STATUS_NOT_IMPLEMENTED = 3; + static const status_t STATUS_INVALID_PARAMETER = 4; + static const status_t STATUS_FEATURE_NOT_IMPLEMENTED = 5; + static const status_t STATUS_FORBIDDEN = 6; + static const status_t STATUS_EXCEPTION = 7; + static const status_t STATUS_USER = 0x00010000; + + // Every "Manageable" object must hold a reference to exactly one + // management object. This object is always of a class derived from + // the pure-virtual "ManagementObject". + // + // This accessor function returns a pointer to the management object. + // + virtual ManagementObject* GetManagementObject(void) const = 0; + + // Every "Manageable" object must implement ManagementMethod. This + // function is called when a remote management client invokes a method + // on this object. The input and output arguments are specific to the + // method being called and must be down-cast to the appropriate sub class + // before use. + virtual status_t ManagementMethod(uint32_t methodId, Args& args, std::string& text); +}; + +inline Manageable::~Manageable(void) {} + +}} + +#endif /*!_Manageable_*/ diff --git a/qpid/cpp/include/qpid/management/ManagementEvent.h b/qpid/cpp/include/qpid/management/ManagementEvent.h new file mode 100644 index 0000000000..01b9ae49ec --- /dev/null +++ b/qpid/cpp/include/qpid/management/ManagementEvent.h @@ -0,0 +1,49 @@ +#ifndef _ManagementEvent_ +#define _ManagementEvent_ + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/management/ManagementObject.h" +#include <qpid/framing/Buffer.h> +#include <string> + +namespace qpid { +namespace management { + +class ManagementAgent; + +class ManagementEvent : public ManagementItem { +public: + typedef void (*writeSchemaCall_t)(qpid::framing::Buffer&); + virtual ~ManagementEvent() {} + + virtual writeSchemaCall_t getWriteSchemaCall(void) = 0; + virtual std::string& getEventName() const = 0; + virtual std::string& getPackageName() const = 0; + virtual uint8_t* getMd5Sum() const = 0; + virtual uint8_t getSeverity() const = 0; + virtual void encode(qpid::framing::Buffer&) const = 0; +}; + +}} + +#endif /*!_ManagementEvent_*/ diff --git a/qpid/cpp/include/qpid/management/ManagementObject.h b/qpid/cpp/include/qpid/management/ManagementObject.h new file mode 100644 index 0000000000..d0a443d6cb --- /dev/null +++ b/qpid/cpp/include/qpid/management/ManagementObject.h @@ -0,0 +1,187 @@ +#ifndef _ManagementObject_ +#define _ManagementObject_ + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/sys/Time.h" +#include "qpid/sys/Mutex.h" +#include <qpid/framing/Buffer.h> +#include "qpid/CommonImportExport.h" +#include <map> + +namespace qpid { +namespace management { + +class Manageable; +class ObjectId; + + +class AgentAttachment { + friend class ObjectId; +private: + uint64_t first; +public: + AgentAttachment() : first(0) {} + QPID_COMMON_EXTERN void setBanks(uint32_t broker, uint32_t bank); + uint64_t getFirst() const { return first; } +}; + + +class ObjectId { +protected: + const AgentAttachment* agent; + uint64_t first; + uint64_t second; + void fromString(const std::string&); +public: + QPID_COMMON_EXTERN ObjectId() : agent(0), first(0), second(0) {} + QPID_COMMON_EXTERN ObjectId(framing::Buffer& buf) : agent(0) { decode(buf); } + QPID_COMMON_EXTERN ObjectId(uint8_t flags, uint16_t seq, uint32_t broker, uint32_t bank, uint64_t object); + QPID_COMMON_EXTERN ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq, uint64_t object); + QPID_COMMON_EXTERN ObjectId(std::istream&); + QPID_COMMON_EXTERN ObjectId(const std::string&); + QPID_COMMON_EXTERN bool operator==(const ObjectId &other) const; + QPID_COMMON_EXTERN bool operator<(const ObjectId &other) const; + QPID_COMMON_EXTERN void encode(framing::Buffer& buffer); + QPID_COMMON_EXTERN void decode(framing::Buffer& buffer); + friend QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const ObjectId&); +}; + +class ManagementItem { +public: + static const uint8_t TYPE_U8 = 1; + static const uint8_t TYPE_U16 = 2; + static const uint8_t TYPE_U32 = 3; + static const uint8_t TYPE_U64 = 4; + static const uint8_t TYPE_SSTR = 6; + static const uint8_t TYPE_LSTR = 7; + static const uint8_t TYPE_ABSTIME = 8; + static const uint8_t TYPE_DELTATIME = 9; + static const uint8_t TYPE_REF = 10; + static const uint8_t TYPE_BOOL = 11; + static const uint8_t TYPE_FLOAT = 12; + static const uint8_t TYPE_DOUBLE = 13; + static const uint8_t TYPE_UUID = 14; + static const uint8_t TYPE_FTABLE = 15; + static const uint8_t TYPE_S8 = 16; + static const uint8_t TYPE_S16 = 17; + static const uint8_t TYPE_S32 = 18; + static const uint8_t TYPE_S64 = 19; + + static const uint8_t ACCESS_RC = 1; + static const uint8_t ACCESS_RW = 2; + static const uint8_t ACCESS_RO = 3; + + static const uint8_t DIR_I = 1; + static const uint8_t DIR_O = 2; + static const uint8_t DIR_IO = 3; + + static const uint8_t FLAG_CONFIG = 0x01; + static const uint8_t FLAG_INDEX = 0x02; + static const uint8_t FLAG_END = 0x80; + + const static uint8_t CLASS_KIND_TABLE = 1; + const static uint8_t CLASS_KIND_EVENT = 2; + + + +public: + virtual ~ManagementItem() {} +}; + +class ManagementObject : public ManagementItem +{ +protected: + + uint64_t createTime; + uint64_t destroyTime; + uint64_t updateTime; + ObjectId objectId; + bool configChanged; + bool instChanged; + bool deleted; + Manageable* coreObject; + sys::Mutex accessLock; + uint32_t flags; + + static int nextThreadIndex; + bool forcePublish; + + QPID_COMMON_EXTERN int getThreadIndex(); + QPID_COMMON_EXTERN void writeTimestamps(qpid::framing::Buffer& buf); + + public: + QPID_COMMON_EXTERN static int maxThreads; + typedef void (*writeSchemaCall_t) (qpid::framing::Buffer&); + + ManagementObject(Manageable* _core) : + createTime(uint64_t(qpid::sys::Duration(qpid::sys::now()))), + destroyTime(0), updateTime(createTime), configChanged(true), + instChanged(true), deleted(false), + coreObject(_core), forcePublish(false) {} + virtual ~ManagementObject() {} + + virtual writeSchemaCall_t getWriteSchemaCall() = 0; + virtual void writeProperties(qpid::framing::Buffer& buf) = 0; + virtual void writeStatistics(qpid::framing::Buffer& buf, + bool skipHeaders = false) = 0; + virtual void doMethod(std::string& methodName, + qpid::framing::Buffer& inBuf, + qpid::framing::Buffer& outBuf) = 0; + QPID_COMMON_EXTERN virtual void setReference(ObjectId objectId); + + virtual std::string& getClassName() const = 0; + virtual std::string& getPackageName() const = 0; + virtual uint8_t* getMd5Sum() const = 0; + + void setObjectId(ObjectId oid) { objectId = oid; } + ObjectId getObjectId() { return objectId; } + inline bool getConfigChanged() { return configChanged; } + virtual bool getInstChanged() { return instChanged; } + virtual bool hasInst() { return true; } + inline void setForcePublish(bool f) { forcePublish = f; } + inline bool getForcePublish() { return forcePublish; } + inline void setUpdateTime() { updateTime = (uint64_t(sys::Duration(sys::now()))); } + + inline void resourceDestroy() { + destroyTime = uint64_t (qpid::sys::Duration(qpid::sys::now())); + deleted = true; + } + inline bool isDeleted() { return deleted; } + inline void setFlags(uint32_t f) { flags = f; } + inline uint32_t getFlags() { return flags; } + bool isSameClass(ManagementObject& other) { + for (int idx = 0; idx < 16; idx++) + if (other.getMd5Sum()[idx] != getMd5Sum()[idx]) + return false; + return other.getClassName() == getClassName() && + other.getPackageName() == getPackageName(); + } +}; + +typedef std::map<ObjectId, ManagementObject*> ManagementObjectMap; + +}} + + + +#endif /*!_ManagementObject_*/ diff --git a/qpid/cpp/include/qpid/sys/Condition.h b/qpid/cpp/include/qpid/sys/Condition.h new file mode 100644 index 0000000000..9be4b357fe --- /dev/null +++ b/qpid/cpp/include/qpid/sys/Condition.h @@ -0,0 +1,33 @@ +#ifndef _sys_Condition_h +#define _sys_Condition_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#ifdef USE_APR_PLATFORM +#include "apr/Condition.h" +#elif defined (_WIN32) +#include "windows/Condition.h" +#else +#include "posix/Condition.h" +#endif + +#endif /*!_sys_Condition_h*/ diff --git a/qpid/cpp/include/qpid/sys/IOHandle.h b/qpid/cpp/include/qpid/sys/IOHandle.h new file mode 100644 index 0000000000..283e021162 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/IOHandle.h @@ -0,0 +1,61 @@ +#ifndef _sys_IOHandle_h +#define _sys_IOHandle_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace sys { + +/** + * This is a class intended to abstract the Unix concept of file descriptor + * or the Windows concept of HANDLE + */ +// Windows-related classes +class AsynchAcceptorPrivate; +class AsynchAcceptResult; +namespace windows { + class AsynchIO; +} + +// General classes +class PollerHandle; +class IOHandlePrivate; +class IOHandle { + + friend class AsynchAcceptorPrivate; + friend class AsynchAcceptResult; + friend class windows::AsynchIO; + + friend class PollerHandle; + +protected: + IOHandlePrivate* const impl; + + IOHandle(IOHandlePrivate*); + QPID_COMMON_EXTERN virtual ~IOHandle(); +}; + +}} + +#endif // _sys_IOHandle_h diff --git a/qpid/cpp/include/qpid/sys/IntegerTypes.h b/qpid/cpp/include/qpid/sys/IntegerTypes.h new file mode 100755 index 0000000000..89635f033e --- /dev/null +++ b/qpid/cpp/include/qpid/sys/IntegerTypes.h @@ -0,0 +1,31 @@ +#ifndef QPID_SYS_INTEGERTYPES_H +#define QPID_SYS_INTEGERTYPES_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#if (defined(_WINDOWS) || defined (WIN32)) && defined(_MSC_VER) +#include "qpid/sys/windows/IntegerTypes.h" +#endif +#if !defined _WINDOWS && !defined WIN32 +#include "qpid/sys/posix/IntegerTypes.h" +#endif + +#endif /*!QPID_SYS_INTEGERTYPES_H*/ diff --git a/qpid/cpp/include/qpid/sys/Monitor.h b/qpid/cpp/include/qpid/sys/Monitor.h new file mode 100644 index 0000000000..123bf92dcb --- /dev/null +++ b/qpid/cpp/include/qpid/sys/Monitor.h @@ -0,0 +1,49 @@ +#ifndef _sys_Monitor_h +#define _sys_Monitor_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/sys/Condition.h" + +namespace qpid { +namespace sys { + +/** + * A monitor is a condition variable and a mutex + */ +class Monitor : public Mutex, public Condition { + public: + inline void wait(); + inline bool wait(const AbsTime& absoluteTime); +}; + + +void Monitor::wait() { + Condition::wait(*this); +} + +bool Monitor::wait(const AbsTime& absoluteTime) { + return Condition::wait(*this, absoluteTime); +} + +}} +#endif /*!_sys_Monitor_h*/ diff --git a/qpid/cpp/include/qpid/sys/Mutex.h b/qpid/cpp/include/qpid/sys/Mutex.h new file mode 100644 index 0000000000..43a83d4fc3 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/Mutex.h @@ -0,0 +1,91 @@ +#ifndef _sys_Mutex_h +#define _sys_Mutex_h + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace qpid { +namespace sys { + +/** + * Scoped lock template: calls lock() in ctor, unlock() in dtor. + * L can be any class with lock() and unlock() functions. + */ +template <class L> +class ScopedLock +{ + public: + ScopedLock(L& l) : mutex(l) { l.lock(); } + ~ScopedLock() { mutex.unlock(); } + private: + L& mutex; +}; + +template <class L> +class ScopedUnlock +{ + public: + ScopedUnlock(L& l) : mutex(l) { l.unlock(); } + ~ScopedUnlock() { mutex.lock(); } + private: + L& mutex; +}; + +template <class L> +class ScopedRlock +{ + public: + ScopedRlock(L& l) : mutex(l) { l.rlock(); } + ~ScopedRlock() { mutex.unlock(); } + private: + L& mutex; +}; + +template <class L> +class ScopedWlock +{ + public: + ScopedWlock(L& l) : mutex(l) { l.wlock(); } + ~ScopedWlock() { mutex.unlock(); } + private: + L& mutex; +}; + +template <class L> +class ConditionalScopedLock +{ + public: + ConditionalScopedLock(L& l) : mutex(l) { acquired = l.trylock(); } + ~ConditionalScopedLock() { if (acquired) mutex.unlock(); } + bool lockAcquired() { return acquired; } + private: + L& mutex; + bool acquired; +}; + +}} + +#ifdef USE_APR_PLATFORM +#include "apr/Mutex.h" +#elif defined (_WIN32) +#include "windows/Mutex.h" +#else +#include "posix/Mutex.h" +#endif + +#endif /*!_sys_Mutex_h*/ diff --git a/qpid/cpp/include/qpid/sys/Runnable.h b/qpid/cpp/include/qpid/sys/Runnable.h new file mode 100644 index 0000000000..0f1243a277 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/Runnable.h @@ -0,0 +1,51 @@ +#ifndef _Runnable_ +#define _Runnable_ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <boost/function.hpp> +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace sys { + +/** + * Interface for objects that can be run, e.g. in a thread. + */ +class Runnable +{ + public: + /** Type to represent a runnable as a Functor */ + typedef boost::function0<void> Functor; + + QPID_COMMON_EXTERN virtual ~Runnable(); + + /** Derived classes override run(). */ + virtual void run() = 0; + + /** Create a functor object that will call this->run(). */ + Functor functor(); +}; + +}} + + +#endif diff --git a/qpid/cpp/include/qpid/sys/StrError.h b/qpid/cpp/include/qpid/sys/StrError.h new file mode 100644 index 0000000000..36489dd0fc --- /dev/null +++ b/qpid/cpp/include/qpid/sys/StrError.h @@ -0,0 +1,36 @@ +#ifndef _sys_StrError_h +#define _sys_StrError_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <string> +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace sys { + +/** Get the error message for a system number err, e.g. errno. */ +QPID_COMMON_EXTERN std::string strError(int err); + +}} // namespace qpid + +#endif // _sys_StrError_h diff --git a/qpid/cpp/include/qpid/sys/SystemInfo.h b/qpid/cpp/include/qpid/sys/SystemInfo.h new file mode 100644 index 0000000000..09f9980173 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/SystemInfo.h @@ -0,0 +1,85 @@ +#ifndef QPID_SYS_SYSTEMINFO_H +#define QPID_SYS_SYSTEMINFO_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/sys/IntegerTypes.h" +#include "qpid/Address.h" +#include "qpid/CommonImportExport.h" + +namespace qpid { +namespace sys { + +/** + * Retrieve information about the system we are running on. + * Results may be dependent on OS/hardware. + */ +namespace SystemInfo { + /** + * Estimate available concurrency, e.g. number of CPU cores. + * -1 means estimate not available on this platform. + */ + QPID_COMMON_EXTERN long concurrency(); + + /** + * Get the local host name and set it in the specified TcpAddress. + * Returns false if it can't be obtained and sets errno to any error value. + */ + QPID_COMMON_EXTERN bool getLocalHostname (TcpAddress &address); + + QPID_COMMON_EXTERN void getLocalIpAddresses (uint16_t port, std::vector<Address> &addrList); + + /** + * Retrieve system identifiers and versions. This is information that can + * generally be retrieved via POSIX uname(). + * + * @param osName Receives the OS name; e.g., GNU/Linux or Windows + * @param nodeName Receives the nodename. This may or may not match the + * set hostname from getLocalHostname(). + * @param release Receives the OS release identifier. + * @param version Receives the OS release version (kernel, build, sp, etc.) + * @param machine Receives the hardware type. + */ + QPID_COMMON_EXTERN void getSystemId (std::string &osName, + std::string &nodeName, + std::string &release, + std::string &version, + std::string &machine); + + /** + * Get the process ID of the current process. + */ + QPID_COMMON_EXTERN uint32_t getProcessId(); + + /** + * Get the process ID of the parent of the current process. + */ + QPID_COMMON_EXTERN uint32_t getParentProcessId(); + + /** + * Get the name of the current process (i.e. the name of the executable) + */ + QPID_COMMON_EXTERN std::string getProcessName(); + + +}}} // namespace qpid::sys::SystemInfo + +#endif /*!QPID_SYS_SYSTEMINFO_H*/ diff --git a/qpid/cpp/include/qpid/sys/Thread.h b/qpid/cpp/include/qpid/sys/Thread.h new file mode 100644 index 0000000000..bfea4b4944 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/Thread.h @@ -0,0 +1,65 @@ +#ifndef _sys_Thread_h +#define _sys_Thread_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include <boost/shared_ptr.hpp> +#include "qpid/CommonImportExport.h" + +#ifdef _WIN32 +# define QPID_TSS __declspec(thread) +#elif defined (__GNUC__) +# define QPID_TSS __thread +#elif defined (__SUNPRO_CC) +# define QPID_TSS __thread +#else +# error "Dont know how to define QPID_TSS for this platform" +#endif + +namespace qpid { +namespace sys { + +class Runnable; +class ThreadPrivate; + +class Thread +{ + boost::shared_ptr<ThreadPrivate> impl; + + public: + QPID_COMMON_EXTERN Thread(); + QPID_COMMON_EXTERN explicit Thread(qpid::sys::Runnable*); + QPID_COMMON_EXTERN explicit Thread(qpid::sys::Runnable&); + + QPID_COMMON_EXTERN void join(); + + QPID_COMMON_EXTERN unsigned long id(); + + QPID_COMMON_EXTERN static Thread current(); + + /** ID of current thread for logging. + * Workaround for broken Thread::current() in APR + */ + static unsigned long logId() { return current().id(); } +}; + +}} +#endif /*!_sys_Thread_h*/ diff --git a/qpid/cpp/include/qpid/sys/Time.h b/qpid/cpp/include/qpid/sys/Time.h new file mode 100644 index 0000000000..c19757747b --- /dev/null +++ b/qpid/cpp/include/qpid/sys/Time.h @@ -0,0 +1,173 @@ +#ifndef _sys_Time_h +#define _sys_Time_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/sys/IntegerTypes.h" +/* + * The platform defines its notion of time as a TimePrivate type. The + * platform's implementation knows how to handle this type. + */ +#if defined (_WIN32) +# include "windows/Time.h" +#else +# include "posix/Time.h" +#endif + +#include "qpid/CommonImportExport.h" + +#include <limits> +#include <iosfwd> + +namespace qpid { +namespace sys { + +class Duration; + +/** + * @class AbsTime + * + * Class to represent an instant in time. + * + * The time resolution is in nanosecs, and this is held with 64 bits + * giving a total time span from about 25 million years ago to 25 million + * years hence. As an aside the internal time can sensibly be negative + * meaning before the epoch (probably 1/1/1970 although this class doesn't + * care). + * + * The AbsTime class is a value class and so you don't need to add any + * accessors to its internal state. If you think you want to replace its value, + * you need to construct a new AbsTime and assign it, viz: + * + * AbsTime when = AbsTime::now(); + * ... + * when = AbsTime(when, 2*TIME_SEC); // Advance timer 2 secs + * + * If for some reason you need access to the internal nanosec value you need + * to convert the AbsTime to a Duration and use its conversion to int64_t, viz: + * + * AbsTime now = AbsTime::now(); + * + * int64_t ns = Duration(now); + * + * However note that the nanosecond value that is returned here is not + * defined to be anything in particular and could vary from platform to + * platform. + * + * There are some sensible operations that are currently missing from + * AbsTime, but nearly all that's needed can be done with a mixture of + * AbsTimes and Durations. + * + * For example, convenience operators to add a Duration and AbsTime returning + * an AbsTime would fit here (although you can already perform the operation + * with one of the AbsTime constructors). However trying to add 2 AbsTimes + * doesn't make sense. + */ +class AbsTime { + friend class Duration; + + TimePrivate timepoint; + +public: + QPID_COMMON_EXTERN inline AbsTime() {} + QPID_COMMON_EXTERN AbsTime(const AbsTime& time0, const Duration& duration); + // Default assignment operation fine + // Default copy constructor fine + + QPID_COMMON_EXTERN static AbsTime now(); + QPID_COMMON_EXTERN static AbsTime FarFuture(); + const TimePrivate& getPrivate(void) const { return timepoint; } + bool operator==(const AbsTime& t) const { return t.timepoint == timepoint; } + template <class S> void serialize(S& s) { s(timepoint); } + + friend bool operator<(const AbsTime& a, const AbsTime& b); + friend bool operator>(const AbsTime& a, const AbsTime& b); + QPID_COMMON_EXTERN friend std::ostream& operator << (std::ostream&, const AbsTime&); +}; + +QPID_COMMON_EXTERN std::ostream& operator << (std::ostream&, const AbsTime&); + +/** + * @class Duration + * Class to represent the duration between instants of time. + * + * As AbsTime, this class also uses nanosecs for its time + * resolution where possible. For the most part a duration can be dealt + * with like a 64 bit integer, and indeed there is an implicit conversion which + * makes this quite convenient. + */ +class Duration { + static int64_t max() { return std::numeric_limits<int64_t>::max(); } + int64_t nanosecs; + + friend class AbsTime; + +public: + QPID_COMMON_EXTERN inline Duration(int64_t time0); + QPID_COMMON_EXTERN explicit Duration(const AbsTime& time0); + QPID_COMMON_EXTERN explicit Duration(const AbsTime& start, const AbsTime& finish); + inline operator int64_t() const; +}; + +std::ostream& operator << (std::ostream&, const Duration&); + +inline AbsTime now() { return AbsTime::now(); } + +inline bool operator<(const AbsTime& a, const AbsTime& b) +{ return a.timepoint < b.timepoint; } +inline bool operator>(const AbsTime& a, const AbsTime& b) +{ return a.timepoint > b.timepoint; } + +Duration::Duration(int64_t time0) : + nanosecs(time0) +{} + +Duration::operator int64_t() const +{ return nanosecs; } + +/** Nanoseconds per second. */ +const Duration TIME_SEC = 1000*1000*1000; +/** Nanoseconds per millisecond */ +const Duration TIME_MSEC = 1000*1000; +/** Nanoseconds per microseconds. */ +const Duration TIME_USEC = 1000; +/** Nanoseconds per nanosecond. */ +const Duration TIME_NSEC = 1; + +/** Value to represent an infinite timeout */ +const Duration TIME_INFINITE = std::numeric_limits<int64_t>::max(); + +/** Time greater than any other time */ +const AbsTime FAR_FUTURE = AbsTime::FarFuture(); + +/** Portable sleep for a number of seconds */ +QPID_COMMON_EXTERN void sleep(int secs); + +/** Portable sleep for a number of microseconds */ +QPID_COMMON_EXTERN void usleep(uint64_t usecs); + +/** Output formatted date/time for now*/ +void outputFormattedNow(std::ostream&); + +}} + +#endif /*!_sys_Time_h*/ diff --git a/qpid/cpp/include/qpid/sys/posix/Condition.h b/qpid/cpp/include/qpid/sys/posix/Condition.h new file mode 100644 index 0000000000..279039735a --- /dev/null +++ b/qpid/cpp/include/qpid/sys/posix/Condition.h @@ -0,0 +1,86 @@ +#ifndef _sys_posix_Condition_h +#define _sys_posix_Condition_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/sys/posix/PrivatePosix.h" + +#include "qpid/sys/Mutex.h" +#include "qpid/sys/Time.h" + +#include <time.h> +#include <sys/errno.h> +#include <boost/noncopyable.hpp> + +namespace qpid { +namespace sys { + +/** + * A condition variable for thread synchronization. + */ +class Condition +{ + public: + inline Condition(); + inline ~Condition(); + inline void wait(Mutex&); + inline bool wait(Mutex&, const AbsTime& absoluteTime); + inline void notify(); + inline void notifyAll(); + + private: + pthread_cond_t condition; +}; + +Condition::Condition() { + QPID_POSIX_ASSERT_THROW_IF(pthread_cond_init(&condition, 0)); +} + +Condition::~Condition() { + QPID_POSIX_ABORT_IF(pthread_cond_destroy(&condition)); +} + +void Condition::wait(Mutex& mutex) { + QPID_POSIX_ASSERT_THROW_IF(pthread_cond_wait(&condition, &mutex.mutex)); +} + +bool Condition::wait(Mutex& mutex, const AbsTime& absoluteTime){ + struct timespec ts; + toTimespec(ts, Duration(absoluteTime)); + int status = pthread_cond_timedwait(&condition, &mutex.mutex, &ts); + if (status != 0) { + if (status == ETIMEDOUT) return false; + throw QPID_POSIX_ERROR(status); + } + return true; +} + +void Condition::notify(){ + QPID_POSIX_ASSERT_THROW_IF(pthread_cond_signal(&condition)); +} + +void Condition::notifyAll(){ + QPID_POSIX_ASSERT_THROW_IF(pthread_cond_broadcast(&condition)); +} + +}} +#endif /*!_sys_posix_Condition_h*/ diff --git a/qpid/cpp/include/qpid/sys/posix/IntegerTypes.h b/qpid/cpp/include/qpid/sys/posix/IntegerTypes.h new file mode 100755 index 0000000000..ce97f7bde8 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/posix/IntegerTypes.h @@ -0,0 +1,26 @@ +#ifndef QPID_SYS_POSIX_INTEGERTYPES_H +#define QPID_SYS_POSIX_INTEGERTYPES_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <stdint.h> + +#endif /*!QPID_SYS_INTEGERTYPES_H*/ diff --git a/qpid/cpp/include/qpid/sys/posix/Mutex.h b/qpid/cpp/include/qpid/sys/posix/Mutex.h new file mode 100644 index 0000000000..e2b21b5a56 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/posix/Mutex.h @@ -0,0 +1,158 @@ +#ifndef _sys_posix_Mutex_h +#define _sys_posix_Mutex_h + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/sys/posix/check.h" + +#include <pthread.h> +#include <boost/noncopyable.hpp> + +namespace qpid { +namespace sys { + +class Condition; + +/** + * Mutex lock. + */ +class Mutex : private boost::noncopyable { + friend class Condition; + static const pthread_mutexattr_t* getAttribute(); + +public: + typedef ::qpid::sys::ScopedLock<Mutex> ScopedLock; + typedef ::qpid::sys::ScopedUnlock<Mutex> ScopedUnlock; + + inline Mutex(); + inline ~Mutex(); + inline void lock(); + inline void unlock(); + inline bool trylock(); + + +protected: + pthread_mutex_t mutex; +}; + +/** + * RW lock. + */ +class RWlock : private boost::noncopyable { + friend class Condition; + +public: + typedef ::qpid::sys::ScopedRlock<RWlock> ScopedRlock; + typedef ::qpid::sys::ScopedWlock<RWlock> ScopedWlock; + + inline RWlock(); + inline ~RWlock(); + inline void wlock(); // will write-lock + inline void rlock(); // will read-lock + inline void unlock(); + inline void trywlock(); // will write-try + inline void tryrlock(); // will read-try + +protected: + pthread_rwlock_t rwlock; +}; + + +/** + * PODMutex is a POD, can be static-initialized with + * PODMutex m = QPID_PODMUTEX_INITIALIZER + */ +struct PODMutex +{ + typedef ::qpid::sys::ScopedLock<PODMutex> ScopedLock; + + inline void lock(); + inline void unlock(); + inline bool trylock(); + + // Must be public to be a POD: + pthread_mutex_t mutex; +}; + +#define QPID_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } + +void PODMutex::lock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_lock(&mutex)); +} + +void PODMutex::unlock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_unlock(&mutex)); +} + +bool PODMutex::trylock() { + return pthread_mutex_trylock(&mutex) == 0; +} + +Mutex::Mutex() { + QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_init(&mutex, getAttribute())); +} + +Mutex::~Mutex(){ + QPID_POSIX_ABORT_IF(pthread_mutex_destroy(&mutex)); +} + +void Mutex::lock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_lock(&mutex)); +} + +void Mutex::unlock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_unlock(&mutex)); +} + +bool Mutex::trylock() { + return pthread_mutex_trylock(&mutex) == 0; +} + + +RWlock::RWlock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_init(&rwlock, NULL)); +} + +RWlock::~RWlock(){ + QPID_POSIX_ABORT_IF(pthread_rwlock_destroy(&rwlock)); +} + +void RWlock::wlock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_wrlock(&rwlock)); +} + +void RWlock::rlock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_rdlock(&rwlock)); +} + +void RWlock::unlock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_unlock(&rwlock)); +} + +void RWlock::trywlock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_trywrlock(&rwlock)); +} + +void RWlock::tryrlock() { + QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_tryrdlock(&rwlock)); +} + + +}} +#endif /*!_sys_posix_Mutex_h*/ diff --git a/qpid/cpp/include/qpid/sys/posix/PrivatePosix.h b/qpid/cpp/include/qpid/sys/posix/PrivatePosix.h new file mode 100644 index 0000000000..6ffd3d8383 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/posix/PrivatePosix.h @@ -0,0 +1,72 @@ +#ifndef _sys_posix_PrivatePosix_h +#define _sys_posix_PrivatePosix_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/sys/Time.h" +#include "qpid/sys/IOHandle.h" + +struct timespec; +struct timeval; + +namespace qpid { +namespace sys { + +// Private Time related implementation details +struct timespec& toTimespec(struct timespec& ts, const Duration& t); +struct timeval& toTimeval(struct timeval& tv, const Duration& t); +Duration toTime(const struct timespec& ts); + +// Private fd related implementation details +class IOHandlePrivate { +public: + IOHandlePrivate(int f = -1) : + fd(f) + {} + + int fd; +}; + +int toFd(const IOHandlePrivate* h); + +// Posix fd as an IOHandle +class PosixIOHandle : public IOHandle { +public: + PosixIOHandle(int fd) : + IOHandle(new IOHandlePrivate(fd)) + {} +}; + +// Dummy IOHandle for places it's required in the API +// but we promise not to actually try to do any operations on the IOHandle +class NullIOHandle : public IOHandle { +public: + NullIOHandle() : + IOHandle(new IOHandlePrivate) + {} +}; + +extern NullIOHandle DummyIOHandle; + +}} + +#endif /*!_sys_posix_PrivatePosix_h*/ diff --git a/qpid/cpp/include/qpid/sys/posix/Time.h b/qpid/cpp/include/qpid/sys/posix/Time.h new file mode 100755 index 0000000000..62d734c816 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/posix/Time.h @@ -0,0 +1,34 @@ +#ifndef QPID_SYS_POSIX_TIME_H +#define QPID_SYS_POSIX_TIME_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/sys/IntegerTypes.h" + +namespace qpid { +namespace sys { + +/** + * Class to represent an instant in time. + */ +typedef int64_t TimePrivate; + +}} // namespace qpid::sys + +#endif /*!QPID_SYS_POSIX_TIME_H*/ diff --git a/qpid/cpp/include/qpid/sys/posix/check.h b/qpid/cpp/include/qpid/sys/posix/check.h new file mode 100644 index 0000000000..bbc66d389b --- /dev/null +++ b/qpid/cpp/include/qpid/sys/posix/check.h @@ -0,0 +1,52 @@ +#ifndef _posix_check_h +#define _posix_check_h + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/Exception.h" + +#include <cerrno> +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::sys::strError(ERRNO))) + +/** THROW QPID_POSIX_ERROR(errno) if RESULT is less than zero */ +#define QPID_POSIX_CHECK(RESULT) \ + if ((RESULT) < 0) throw QPID_POSIX_ERROR((errno)) + +/** Throw a posix error if ERRNO is non-zero */ +#define QPID_POSIX_THROW_IF(ERRNO) \ + do { int e=(ERRNO); if (e) throw QPID_POSIX_ERROR(e); } while(0) + +/** Same as _THROW_IF in a release build, but abort a debug build */ +#ifdef NDEBUG +#define QPID_POSIX_ASSERT_THROW_IF(ERRNO) QPID_POSIX_THROW_IF(ERRNO) +#else +#define QPID_POSIX_ASSERT_THROW_IF(ERRNO) \ + do { int e=(ERRNO); if (e) { errno=e; ::perror(0); assert(0); } } while(0) +#endif + +#define QPID_POSIX_ABORT_IF(ERRNO) if ((int) ERRNO) { errno=ERRNO; ::perror(0); abort(); } + +#endif /*!_posix_check_h*/ diff --git a/qpid/cpp/include/qpid/sys/uuid.h b/qpid/cpp/include/qpid/sys/uuid.h new file mode 100644 index 0000000000..804ab34463 --- /dev/null +++ b/qpid/cpp/include/qpid/sys/uuid.h @@ -0,0 +1,28 @@ +#ifndef _sys_uuid_h +#define _sys_uuid_h + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifdef _WIN32 +# include "qpid/sys/windows/uuid.h" +#else +# include <uuid/uuid.h> +#endif /* _WIN32 */ + +#endif /* _sys_uuid_h */ |