diff options
Diffstat (limited to 'qpid')
-rw-r--r-- | qpid/cpp/examples/messaging/map_sender.cpp | 1 | ||||
-rw-r--r-- | qpid/cpp/examples/messaging/spout.cpp | 2 | ||||
-rw-r--r-- | qpid/cpp/include/qpid/framing/FieldValue.h | 16 | ||||
-rw-r--r-- | qpid/cpp/include/qpid/messaging/Uuid.h | 93 | ||||
-rw-r--r-- | qpid/cpp/include/qpid/messaging/Variant.h | 8 | ||||
-rw-r--r-- | qpid/cpp/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | qpid/cpp/src/Makefile.am | 2 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/amqp0_10/Codecs.cpp | 38 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/framing/FieldValue.cpp | 3 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/messaging/Uuid.cpp | 140 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/messaging/Variant.cpp | 28 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/sys/windows/uuid.cpp | 3 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/sys/windows/uuid.h | 1 | ||||
-rw-r--r-- | qpid/cpp/src/tests/CMakeLists.txt | 10 | ||||
-rw-r--r-- | qpid/cpp/src/tests/Uuid.cpp | 29 | ||||
-rw-r--r-- | qpid/cpp/src/tests/Variant.cpp | 7 |
16 files changed, 363 insertions, 19 deletions
diff --git a/qpid/cpp/examples/messaging/map_sender.cpp b/qpid/cpp/examples/messaging/map_sender.cpp index 02c6433836..50150fa3d5 100644 --- a/qpid/cpp/examples/messaging/map_sender.cpp +++ b/qpid/cpp/examples/messaging/map_sender.cpp @@ -53,6 +53,7 @@ int main(int argc, char** argv) { colours.push_back(Variant("green")); colours.push_back(Variant("white")); content["colours"] = colours; + content["uuid"] = Uuid(true); content.encode(); sender.send(message); diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 661397d232..62d72a8043 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -26,7 +26,6 @@ #include <qpid/messaging/Sender.h> #include <qpid/messaging/Session.h> #include <qpid/messaging/Variant.h> -#include <qpid/framing/Uuid.h> #include <qpid/Exception.h> #include <qpid/Options.h> #include <qpid/log/Logger.h> @@ -39,7 +38,6 @@ #include <boost/format.hpp> using namespace qpid::messaging; -using qpid::framing::Uuid; using qpid::sys::AbsTime; using qpid::sys::now; using qpid::sys::TIME_INFINITE; diff --git a/qpid/cpp/include/qpid/framing/FieldValue.h b/qpid/cpp/include/qpid/framing/FieldValue.h index 7b4dee1529..e5746c8065 100644 --- a/qpid/cpp/include/qpid/framing/FieldValue.h +++ b/qpid/cpp/include/qpid/framing/FieldValue.h @@ -99,6 +99,7 @@ class FieldValue { template <class T, int W> T getIntegerValue() const; template <class T, int W> T getFloatingPointValue() const; + template <int W> void getFixedWidthValue(unsigned char*) const; template <class T> bool get(T&) const; protected: @@ -209,6 +210,16 @@ inline T FieldValue::getFloatingPointValue() const { } } +template <int W> void FieldValue::getFixedWidthValue(unsigned char* value) const +{ + FixedWidthValue<W>* const fwv = dynamic_cast< FixedWidthValue<W>* const>(data.get()); + if (fwv) { + for (uint i = 0; i < W; ++i) value[i] = fwv->rawOctets()[i]; + } else { + throw InvalidConversionException(); + } +} + template <> inline float FieldValue::get<float>() const { return getFloatingPointValue<float, 4>(); @@ -417,6 +428,11 @@ class ListValue : public FieldValue { QPID_COMMON_EXTERN ListValue(const List&); }; +class UuidValue : public FieldValue { + public: + QPID_COMMON_EXTERN UuidValue(const unsigned char*); +}; + template <class T> bool getEncodedValue(FieldTable::ValuePtr vptr, T& value) { diff --git a/qpid/cpp/include/qpid/messaging/Uuid.h b/qpid/cpp/include/qpid/messaging/Uuid.h new file mode 100644 index 0000000000..d1caac6013 --- /dev/null +++ b/qpid/cpp/include/qpid/messaging/Uuid.h @@ -0,0 +1,93 @@ +#ifndef QPID_MESSAGING_UUID_H +#define QPID_MESSAGING_UUID_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 <iosfwd> + +namespace qpid { +namespace messaging { + +class Uuid +{ + public: + static const size_t SIZE; + /** + * If unique is true, this will generate a new unique uuid, if not + * it will construct a null uuid. + */ + QPID_CLIENT_EXTERN Uuid(bool unique=false); + QPID_CLIENT_EXTERN Uuid(const Uuid&); + QPID_CLIENT_EXTERN Uuid& operator=(const Uuid&); + /** Copy the UUID from data16, which must point to a 16-byte UUID */ + QPID_CLIENT_EXTERN Uuid(const unsigned char* data16); + + /** Set to a new unique identifier. */ + QPID_CLIENT_EXTERN void generate(); + + /** Set to all zeros. */ + QPID_CLIENT_EXTERN void clear(); + + /** Test for null (all zeros). */ + QPID_CLIENT_EXTERN bool isNull() const; + QPID_CLIENT_EXTERN operator bool() const; + QPID_CLIENT_EXTERN bool operator!() const; + + /** String value in format 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb. */ + QPID_CLIENT_EXTERN std::string str() const; + + QPID_CLIENT_EXTERN size_t size() const; + QPID_CLIENT_EXTERN const unsigned char* data() const; + + friend bool operator==(const Uuid&, const Uuid&); + friend bool operator!=(const Uuid&, const Uuid&); + friend bool operator<(const Uuid&, const Uuid&); + friend bool operator>(const Uuid&, const Uuid&); + friend bool operator<=(const Uuid&, const Uuid&); + friend bool operator>=(const Uuid&, const Uuid&); + friend std::ostream& operator<<(std::ostream&, Uuid); + friend std::istream& operator>>(std::istream&, Uuid&); + + private: + unsigned char bytes[16]; +}; + +/** Returns true if the uuids are equal, false otherwise. **/ +QPID_CLIENT_EXTERN bool operator==(const Uuid&, const Uuid&); +/** Returns true if the uuids are NOT equal, false if they are. **/ +QPID_CLIENT_EXTERN bool operator!=(const Uuid&, const Uuid&); + +QPID_CLIENT_EXTERN bool operator<(const Uuid&, const Uuid&); +QPID_CLIENT_EXTERN bool operator>(const Uuid&, const Uuid&); +QPID_CLIENT_EXTERN bool operator<=(const Uuid&, const Uuid&); +QPID_CLIENT_EXTERN bool operator>=(const Uuid&, const Uuid&); + +/** Print in format 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb. */ +QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream&, Uuid); + +/** Read from format 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb. */ +QPID_CLIENT_EXTERN std::istream& operator>>(std::istream&, Uuid&); + +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_UUID_H*/ diff --git a/qpid/cpp/include/qpid/messaging/Variant.h b/qpid/cpp/include/qpid/messaging/Variant.h index de5cef4d67..0bf62a9909 100644 --- a/qpid/cpp/include/qpid/messaging/Variant.h +++ b/qpid/cpp/include/qpid/messaging/Variant.h @@ -25,6 +25,7 @@ #include <map> #include <ostream> #include <string> +#include "Uuid.h" #include "qpid/Exception.h" #include "qpid/sys/IntegerTypes.h" #include "qpid/client/ClientImportExport.h" @@ -55,7 +56,8 @@ enum VariantType { VAR_DOUBLE, VAR_STRING, VAR_MAP, - VAR_LIST + VAR_LIST, + VAR_UUID }; class VariantImpl; @@ -86,6 +88,7 @@ class Variant QPID_CLIENT_EXTERN Variant(const Map&); QPID_CLIENT_EXTERN Variant(const List&); QPID_CLIENT_EXTERN Variant(const Variant&); + QPID_CLIENT_EXTERN Variant(const Uuid&); QPID_CLIENT_EXTERN ~Variant(); @@ -108,6 +111,7 @@ class Variant QPID_CLIENT_EXTERN Variant& operator=(const Map&); QPID_CLIENT_EXTERN Variant& operator=(const List&); QPID_CLIENT_EXTERN Variant& operator=(const Variant&); + QPID_CLIENT_EXTERN Variant& operator=(const Uuid&); QPID_CLIENT_EXTERN bool asBool() const; QPID_CLIENT_EXTERN uint8_t asUint8() const; @@ -121,6 +125,7 @@ class Variant QPID_CLIENT_EXTERN float asFloat() const; QPID_CLIENT_EXTERN double asDouble() const; QPID_CLIENT_EXTERN std::string asString() const; + QPID_CLIENT_EXTERN Uuid asUuid() const; QPID_CLIENT_EXTERN operator bool() const; QPID_CLIENT_EXTERN operator uint8_t() const; @@ -134,6 +139,7 @@ class Variant QPID_CLIENT_EXTERN operator float() const; QPID_CLIENT_EXTERN operator double() const; QPID_CLIENT_EXTERN operator const char*() const; + QPID_CLIENT_EXTERN operator Uuid() const; QPID_CLIENT_EXTERN const Map& asMap() const; QPID_CLIENT_EXTERN Map& asMap(); diff --git a/qpid/cpp/src/CMakeLists.txt b/qpid/cpp/src/CMakeLists.txt index d9e888bc30..c1b2f564c9 100644 --- a/qpid/cpp/src/CMakeLists.txt +++ b/qpid/cpp/src/CMakeLists.txt @@ -652,6 +652,7 @@ set (qpidclient_SOURCES qpid/messaging/SessionImpl.h qpid/messaging/Sender.cpp qpid/messaging/SenderImpl.h + qpid/messaging/Uuid.cpp qpid/messaging/Variant.cpp qpid/client/amqp0_10/AcceptTracker.h qpid/client/amqp0_10/AcceptTracker.cpp diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index 7f041e7825..da3d27cbe9 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -705,6 +705,7 @@ libqpidclient_la_SOURCES = \ qpid/messaging/Sender.cpp \ qpid/messaging/Receiver.cpp \ qpid/messaging/Session.cpp \ + qpid/messaging/Uuid.cpp \ qpid/messaging/Variant.cpp \ qpid/messaging/ConnectionImpl.h \ qpid/messaging/SenderImpl.h \ @@ -812,6 +813,7 @@ nobase_include_HEADERS += \ ../include/qpid/messaging/Sender.h \ ../include/qpid/messaging/Receiver.h \ ../include/qpid/messaging/Session.h \ + ../include/qpid/messaging/Uuid.h \ ../include/qpid/messaging/Variant.h \ ../include/qpid/client/amqp0_10/Codecs.h diff --git a/qpid/cpp/src/qpid/client/amqp0_10/Codecs.cpp b/qpid/cpp/src/qpid/client/amqp0_10/Codecs.cpp index ff72dfbf4e..835d80185a 100644 --- a/qpid/cpp/src/qpid/client/amqp0_10/Codecs.cpp +++ b/qpid/cpp/src/qpid/client/amqp0_10/Codecs.cpp @@ -112,6 +112,13 @@ void setEncodingFor(Variant& out, uint8_t code) } } +qpid::messaging::Uuid getUuid(FieldValue& value) +{ + unsigned char data[16]; + value.getFixedWidthValue<16>(data); + return qpid::messaging::Uuid(data); +} + Variant toVariant(boost::shared_ptr<FieldValue> in) { Variant out; @@ -123,19 +130,21 @@ Variant toVariant(boost::shared_ptr<FieldValue> in) case 0x03: out = in->getIntegerValue<uint8_t, 1>(); break; case 0x04: break; //TODO: iso-8859-15 char case 0x08: out = in->getIntegerValue<bool, 1>(); break; - case 0x010: out.setEncoding(amqp0_10_binary); - case 0x011: out = in->getIntegerValue<int16_t, 2>(); break; - case 0x012: out = in->getIntegerValue<uint16_t, 2>(); break; - case 0x020: out.setEncoding(amqp0_10_binary); - case 0x021: out = in->getIntegerValue<int32_t, 4>(); break; - case 0x022: out = in->getIntegerValue<uint32_t, 4>(); break; - case 0x023: out = in->get<float>(); break; - case 0x027: break; //TODO: utf-32 char - case 0x030: out.setEncoding(amqp0_10_binary); - case 0x031: out = in->getIntegerValue<int64_t, 8>(); break; - case 0x038: out.setEncoding(amqp0_10_datetime); //treat datetime as uint64_t, but set encoding - case 0x032: out = in->getIntegerValue<uint64_t, 8>(); break; - case 0x033:out = in->get<double>(); break; + case 0x10: out.setEncoding(amqp0_10_binary); + case 0x11: out = in->getIntegerValue<int16_t, 2>(); break; + case 0x12: out = in->getIntegerValue<uint16_t, 2>(); break; + case 0x20: out.setEncoding(amqp0_10_binary); + case 0x21: out = in->getIntegerValue<int32_t, 4>(); break; + case 0x22: out = in->getIntegerValue<uint32_t, 4>(); break; + case 0x23: out = in->get<float>(); break; + case 0x27: break; //TODO: utf-32 char + case 0x30: out.setEncoding(amqp0_10_binary); + case 0x31: out = in->getIntegerValue<int64_t, 8>(); break; + case 0x38: out.setEncoding(amqp0_10_datetime); //treat datetime as uint64_t, but set encoding + case 0x32: out = in->getIntegerValue<uint64_t, 8>(); break; + case 0x33: out = in->get<double>(); break; + + case 0x48: out = getUuid(*in); break; //TODO: figure out whether and how to map values with codes 0x40-0xd8 @@ -197,12 +206,11 @@ boost::shared_ptr<FieldValue> toFieldValue(const Variant& in) case VAR_DOUBLE: out = boost::shared_ptr<FieldValue>(new DoubleValue(in.asDouble())); break; //TODO: check encoding (and length?) when deciding what AMQP type to treat string as case VAR_STRING: out = boost::shared_ptr<FieldValue>(new Str16Value(in.asString())); break; + case VAR_UUID: out = boost::shared_ptr<FieldValue>(new UuidValue(in.asUuid().data())); break; case VAR_MAP: - //out = boost::shared_ptr<FieldValue>(toFieldValueCollection<FieldTableValue>(in.asMap(), &toFieldTableEntry)); out = boost::shared_ptr<FieldValue>(toFieldTableValue(in.asMap())); break; case VAR_LIST: - //out = boost::shared_ptr<FieldValue>(toFieldValueCollection<ListValue>(in.asList(), &toFieldValue)); out = boost::shared_ptr<FieldValue>(toListValue(in.asList())); break; } diff --git a/qpid/cpp/src/qpid/framing/FieldValue.cpp b/qpid/cpp/src/qpid/framing/FieldValue.cpp index 9c5c0c36a2..0b49748de8 100644 --- a/qpid/cpp/src/qpid/framing/FieldValue.cpp +++ b/qpid/cpp/src/qpid/framing/FieldValue.cpp @@ -197,6 +197,9 @@ Integer8Value::Integer8Value(int8_t v) : Integer16Value::Integer16Value(int16_t v) : FieldValue(0x11, new FixedWidthValue<2>(v)) {} +UuidValue::UuidValue(const unsigned char* v) : + FieldValue(0x48, new FixedWidthValue<16>(v)) +{} void FieldValue::print(std::ostream& out) const { data->print(out); diff --git a/qpid/cpp/src/qpid/messaging/Uuid.cpp b/qpid/cpp/src/qpid/messaging/Uuid.cpp new file mode 100644 index 0000000000..87eb34456f --- /dev/null +++ b/qpid/cpp/src/qpid/messaging/Uuid.cpp @@ -0,0 +1,140 @@ +/* + * + * 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/messaging/Uuid.h" +#include "qpid/sys/uuid.h" +#include <sstream> +#include <iostream> +#include <string.h> + +namespace qpid { +namespace messaging { + +using namespace std; + +const size_t Uuid::SIZE=16; +static const size_t UNPARSED_SIZE=36; + +Uuid::Uuid(bool unique) +{ + if (unique) { + generate(); + } else { + clear(); + } +} + +Uuid::Uuid(const Uuid& other) +{ + ::memcpy(bytes, other.bytes, Uuid::SIZE); +} + +Uuid::Uuid(const unsigned char* uuid) +{ + ::memcpy(bytes, uuid, Uuid::SIZE); +} + +Uuid& Uuid::operator=(const Uuid& other) +{ + if (this == &other) return *this; + ::memcpy(bytes, other.bytes, Uuid::SIZE); + return *this; +} + +void Uuid::generate() +{ + uuid_generate(bytes); +} + +void Uuid::clear() +{ + uuid_clear(bytes); +} + +// Force int 0/!0 to false/true; avoids compile warnings. +bool Uuid::isNull() const +{ + return !!uuid_is_null(bytes); +} + +Uuid::operator bool() const { return !isNull(); } +bool Uuid::operator!() const { return isNull(); } + +size_t Uuid::size() const { return SIZE; } + +const unsigned char* Uuid::data() const +{ + return bytes; +} + +bool operator==(const Uuid& a, const Uuid& b) +{ + return uuid_compare(a.bytes, b.bytes) == 0; +} + +bool operator!=(const Uuid& a, const Uuid& b) +{ + return !(a == b); +} + +bool operator<(const Uuid& a, const Uuid& b) +{ + return uuid_compare(a.bytes, b.bytes) < 0; +} + +bool operator>(const Uuid& a, const Uuid& b) +{ + return uuid_compare(a.bytes, b.bytes) > 0; +} + +bool operator<=(const Uuid& a, const Uuid& b) +{ + return uuid_compare(a.bytes, b.bytes) <= 0; +} + +bool operator>=(const Uuid& a, const Uuid& b) +{ + return uuid_compare(a.bytes, b.bytes) >= 0; +} + +ostream& operator<<(ostream& out, Uuid uuid) +{ + char unparsed[UNPARSED_SIZE + 1]; + uuid_unparse(uuid.bytes, unparsed); + return out << unparsed; +} + +istream& operator>>(istream& in, Uuid& uuid) +{ + char unparsed[UNPARSED_SIZE + 1] = {0}; + in.get(unparsed, sizeof(unparsed)); + if (uuid_parse(unparsed, uuid.bytes) != 0) + in.setstate(ios::failbit); + return in; +} + +std::string Uuid::str() const +{ + std::ostringstream os; + os << *this; + return os.str(); +} + +}} // namespace qpid::messaging diff --git a/qpid/cpp/src/qpid/messaging/Variant.cpp b/qpid/cpp/src/qpid/messaging/Variant.cpp index 9c2f92f47a..116018f797 100644 --- a/qpid/cpp/src/qpid/messaging/Variant.cpp +++ b/qpid/cpp/src/qpid/messaging/Variant.cpp @@ -52,6 +52,7 @@ class VariantImpl VariantImpl(const std::string&); VariantImpl(const Variant::Map&); VariantImpl(const Variant::List&); + VariantImpl(const Uuid&); ~VariantImpl(); VariantType getType() const; @@ -68,6 +69,7 @@ class VariantImpl float asFloat() const; double asDouble() const; std::string asString() const; + Uuid asUuid() const; const Variant::Map& asMap() const; Variant::Map& asMap(); @@ -130,6 +132,7 @@ VariantImpl::VariantImpl(double d) : type(VAR_DOUBLE) { value.d = d; } VariantImpl::VariantImpl(const std::string& s) : type(VAR_STRING) { value.v = new std::string(s); } VariantImpl::VariantImpl(const Variant::Map& m) : type(VAR_MAP) { value.v = new Variant::Map(m); } VariantImpl::VariantImpl(const Variant::List& l) : type(VAR_LIST) { value.v = new Variant::List(l); } +VariantImpl::VariantImpl(const Uuid& u) : type(VAR_UUID) { value.v = new Uuid(u); } VariantImpl::~VariantImpl() { switch (type) { @@ -142,6 +145,9 @@ VariantImpl::~VariantImpl() { case VAR_LIST: delete reinterpret_cast<Variant::List*>(value.v); break; + case VAR_UUID: + delete reinterpret_cast<Uuid*>(value.v); + break; default: break; } @@ -312,11 +318,19 @@ std::string VariantImpl::asString() const case VAR_DOUBLE: return boost::lexical_cast<std::string>(value.d); case VAR_FLOAT: return boost::lexical_cast<std::string>(value.f); case VAR_STRING: return *reinterpret_cast<std::string*>(value.v); + case VAR_UUID: return reinterpret_cast<Uuid*>(value.v)->str(); case VAR_LIST: return toString(asList()); case VAR_MAP: return toString(asMap()); default: throw InvalidConversion(QPID_MSG("Cannot convert from " << getTypeName(type) << " to " << getTypeName(VAR_STRING))); } } +Uuid VariantImpl::asUuid() const +{ + switch(type) { + case VAR_UUID: return *reinterpret_cast<Uuid*>(value.v); + default: throw InvalidConversion(QPID_MSG("Cannot convert from " << getTypeName(type) << " to " << getTypeName(VAR_UUID))); + } +} bool VariantImpl::isEqualTo(VariantImpl& other) const { @@ -336,6 +350,8 @@ bool VariantImpl::isEqualTo(VariantImpl& other) const case VAR_FLOAT: return value.f == other.value.f; case VAR_STRING: return *reinterpret_cast<std::string*>(value.v) == *reinterpret_cast<std::string*>(other.value.v); + case VAR_UUID: return *reinterpret_cast<Uuid*>(value.v) + == *reinterpret_cast<Uuid*>(other.value.v); case VAR_LIST: return equal(asList(), other.asList()); case VAR_MAP: return equal(asMap(), other.asMap()); } @@ -412,6 +428,7 @@ std::string VariantImpl::getTypeName(VariantType type) const case VAR_STRING: return "string"; case VAR_MAP: return "map"; case VAR_LIST: return "list"; + case VAR_UUID: return "uuid"; } return "<unknown>";//should never happen } @@ -433,6 +450,7 @@ VariantImpl* VariantImpl::create(const Variant& v) case VAR_STRING: return new VariantImpl(v.asString()); case VAR_MAP: return new VariantImpl(v.asMap()); case VAR_LIST: return new VariantImpl(v.asList()); + case VAR_UUID: return new VariantImpl(v.asUuid()); default: return new VariantImpl(); } } @@ -454,6 +472,7 @@ Variant::Variant(const char* s) : impl(new VariantImpl(std::string(s))) {} Variant::Variant(const Map& m) : impl(new VariantImpl(m)) {} Variant::Variant(const List& l) : impl(new VariantImpl(l)) {} Variant::Variant(const Variant& v) : impl(VariantImpl::create(v)) {} +Variant::Variant(const Uuid& u) : impl(new VariantImpl(u)) {} Variant::~Variant() { if (impl) delete impl; } @@ -548,6 +567,13 @@ Variant& Variant::operator=(const char* s) return *this; } +Variant& Variant::operator=(const Uuid& u) +{ + if (impl) delete impl; + impl = new VariantImpl(u); + return *this; +} + Variant& Variant::operator=(const Map& m) { if (impl) delete impl; @@ -583,6 +609,7 @@ int64_t Variant::asInt64() const { return impl->asInt64(); } float Variant::asFloat() const { return impl->asFloat(); } double Variant::asDouble() const { return impl->asDouble(); } std::string Variant::asString() const { return impl->asString(); } +Uuid Variant::asUuid() const { return impl->asUuid(); } const Variant::Map& Variant::asMap() const { return impl->asMap(); } Variant::Map& Variant::asMap() { return impl->asMap(); } const Variant::List& Variant::asList() const { return impl->asList(); } @@ -604,6 +631,7 @@ Variant::operator int64_t() const { return asInt64(); } Variant::operator float() const { return asFloat(); } Variant::operator double() const { return asDouble(); } Variant::operator const char*() const { return asString().c_str(); } +Variant::operator Uuid() const { return asUuid(); } std::ostream& operator<<(std::ostream& out, const Variant::Map& map) { diff --git a/qpid/cpp/src/qpid/sys/windows/uuid.cpp b/qpid/cpp/src/qpid/sys/windows/uuid.cpp index 6ff3a3cb8a..af202d60b6 100644 --- a/qpid/cpp/src/qpid/sys/windows/uuid.cpp +++ b/qpid/cpp/src/qpid/sys/windows/uuid.cpp @@ -57,3 +57,6 @@ void uuid_unparse (const uuid_t uu, char *out) { } } +int uuid_compare (const uuid_t a, const uuid_t b) { + return memcmp(a, b, qpid::sys::UuidSize) == 0; +} diff --git a/qpid/cpp/src/qpid/sys/windows/uuid.h b/qpid/cpp/src/qpid/sys/windows/uuid.h index c79abe95c6..249c534b91 100644 --- a/qpid/cpp/src/qpid/sys/windows/uuid.h +++ b/qpid/cpp/src/qpid/sys/windows/uuid.h @@ -34,5 +34,6 @@ QPID_COMMON_EXTERN void uuid_generate (uuid_t out); QPID_COMMON_EXTERN int uuid_is_null (const uuid_t uu); // Returns 1 if null, else 0 QPID_COMMON_EXTERN int uuid_parse (const char *in, uuid_t uu); // Returns 0 on success, else -1 QPID_COMMON_EXTERN void uuid_unparse (const uuid_t uu, char *out); +QPID_COMMON_EXTERN void uuid_compare (const uuid_t a, const uuid_t b); #endif /*!_sys_windows_uuid_h*/ diff --git a/qpid/cpp/src/tests/CMakeLists.txt b/qpid/cpp/src/tests/CMakeLists.txt index 469d777dce..957c10eeb4 100644 --- a/qpid/cpp/src/tests/CMakeLists.txt +++ b/qpid/cpp/src/tests/CMakeLists.txt @@ -264,6 +264,16 @@ target_link_libraries (sender qpidclient) #sender_SOURCES=sender.cpp TestOptions.h ConnectionOptions.h remember_location(sender) +add_executable (qpid_recv qpid_recv.cpp ${platform_test_additions}) +target_link_libraries (qpid_recv qpidclient) +#qpid_recv_SOURCES=qpid_recv.cpp TestOptions.h ConnectionOptions.h +remember_location(qpid_recv) + +add_executable (qpid_send qpid_send.cpp ${platform_test_additions}) +target_link_libraries (qpid_send qpidclient) +#qpid_send_SOURCES=qpid_send.cpp TestOptions.h ConnectionOptions.h +remember_location(qpid_send) + if (CMAKE_SYSTEM_NAME STREQUAL Windows) set (ENV{OUTDIR} ${EXECUTABLE_OUTPUT_PATH}) set (test_script_suffix ".ps1") diff --git a/qpid/cpp/src/tests/Uuid.cpp b/qpid/cpp/src/tests/Uuid.cpp index a6ddb9b5a5..6d6c07169f 100644 --- a/qpid/cpp/src/tests/Uuid.cpp +++ b/qpid/cpp/src/tests/Uuid.cpp @@ -18,6 +18,7 @@ #include "qpid/framing/Uuid.h" #include "qpid/framing/Buffer.h" +#include "qpid/messaging/Uuid.h" #include "qpid/sys/alloca.h" #include "unit_test.h" @@ -79,6 +80,34 @@ QPID_AUTO_TEST_CASE(testUuidEncodeDecode) { string(decoded.begin(), decoded.end())); } +QPID_AUTO_TEST_CASE(testMessagingUuid) +{ + //tests for the Uuid class in the messaging namespace (introduced + //to avoid pulling in dependencies from framing) + messaging::Uuid a; + messaging::Uuid b(true); + messaging::Uuid c(true); + messaging::Uuid d(b); + messaging::Uuid e; + e = c; + + BOOST_CHECK(!a); + BOOST_CHECK(b); + + BOOST_CHECK(a != b); + BOOST_CHECK(b != c); + + BOOST_CHECK_EQUAL(b, d); + BOOST_CHECK_EQUAL(c, e); + + ostringstream out; + out << b; + istringstream in(out.str()); + in >> a; + BOOST_CHECK(!in.fail()); + BOOST_CHECK_EQUAL(a, b); +} + QPID_AUTO_TEST_SUITE_END() }} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/Variant.cpp b/qpid/cpp/src/tests/Variant.cpp index 21005779f0..c0bb9772c8 100644 --- a/qpid/cpp/src/tests/Variant.cpp +++ b/qpid/cpp/src/tests/Variant.cpp @@ -136,12 +136,14 @@ QPID_AUTO_TEST_CASE(testMap) const std::string red("red"); const float pi(3.14f); const int16_t x(1000); + const Uuid u(true); Variant value = Variant::Map(); value.asMap()["colour"] = red; value.asMap()["pi"] = pi; value.asMap()["my-key"] = x; - BOOST_CHECK_EQUAL(3u, value.asMap().size()); + value.asMap()["id"] = u; + BOOST_CHECK_EQUAL(4u, value.asMap().size()); BOOST_CHECK_EQUAL(VAR_STRING, value.asMap()["colour"].getType()); BOOST_CHECK_EQUAL(red, value.asMap()["colour"].asString()); @@ -152,6 +154,9 @@ QPID_AUTO_TEST_CASE(testMap) BOOST_CHECK_EQUAL(VAR_INT16, value.asMap()["my-key"].getType()); BOOST_CHECK_EQUAL(x, value.asMap()["my-key"].asInt16()); + BOOST_CHECK_EQUAL(VAR_UUID, value.asMap()["id"].getType()); + BOOST_CHECK_EQUAL(u, value.asMap()["id"].asUuid()); + value.asMap()["my-key"] = "now it's a string"; BOOST_CHECK_EQUAL(VAR_STRING, value.asMap()["my-key"].getType()); BOOST_CHECK_EQUAL(std::string("now it's a string"), value.asMap()["my-key"].asString()); |