diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Makefile.am | 6 | ||||
-rw-r--r-- | cpp/src/qpid/framing/Uuid.cpp | 31 | ||||
-rw-r--r-- | cpp/src/qpid/sys/uuid.h | 28 | ||||
-rw-r--r-- | cpp/src/qpid/sys/windows/uuid.h | 38 | ||||
-rw-r--r-- | cpp/src/tests/txtest.cpp | 9 |
5 files changed, 103 insertions, 9 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index 3bfd405416..744e3b7a42 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -54,7 +54,7 @@ windows_dist = \ qpid/sys/windows/Time.cpp \ ../include/qpid/sys/windows/Time.h \ qpid/sys/windows/uuid.cpp \ - ../include/qpid/sys/windows/uuid.h \ + qpid/sys/windows/uuid.h \ windows/QpiddBroker.cpp \ qpid/broker/windows/BrokerDefaults.cpp \ qpid/broker/windows/SaslAuthenticator.cpp @@ -461,7 +461,8 @@ libqpidcommon_la_SOURCES += \ qpid/sys/Timer.cpp \ qpid/sys/Timer.h \ qpid/sys/Waitable.h \ - qpid/sys/alloca.h + qpid/sys/alloca.h \ + qpid/sys/uuid.h if HAVE_SASL libqpidcommon_la_SOURCES += qpid/sys/cyrus/CyrusSecurityLayer.h @@ -782,7 +783,6 @@ nobase_include_HEADERS += \ ../include/qpid/sys/SystemInfo.h \ ../include/qpid/sys/Thread.h \ ../include/qpid/sys/Time.h \ - ../include/qpid/sys/uuid.h \ ../include/qpid/messaging/Address.h \ ../include/qpid/messaging/Connection.h \ ../include/qpid/messaging/Codec.h \ diff --git a/cpp/src/qpid/framing/Uuid.cpp b/cpp/src/qpid/framing/Uuid.cpp index c0b41c6906..71fa6a7329 100644 --- a/cpp/src/qpid/framing/Uuid.cpp +++ b/cpp/src/qpid/framing/Uuid.cpp @@ -17,6 +17,8 @@ */ #include "qpid/framing/Uuid.h" + +#include "qpid/sys/uuid.h" #include "qpid/Exception.h" #include "qpid/framing/Buffer.h" #include "qpid/framing/reply_exceptions.h" @@ -28,6 +30,35 @@ using namespace std; static const size_t UNPARSED_SIZE=36; +Uuid::Uuid(bool unique) { + if (unique) { + generate(); + } else { + clear(); + } +} + +Uuid::Uuid(const uint8_t* data) { + assign(data); +} + +void Uuid::assign(const uint8_t* data) { + uuid_copy(c_array(), data); +} + +void Uuid::generate() { + uuid_generate(c_array()); +} + +void Uuid::clear() { + uuid_clear(c_array()); +} + +// Force int 0/!0 to false/true; avoids compile warnings. +bool Uuid::isNull() { + return !!uuid_is_null(data()); +} + void Uuid::encode(Buffer& buf) const { buf.putRawData(data(), size()); } diff --git a/cpp/src/qpid/sys/uuid.h b/cpp/src/qpid/sys/uuid.h new file mode 100644 index 0000000000..804ab34463 --- /dev/null +++ b/cpp/src/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 */ diff --git a/cpp/src/qpid/sys/windows/uuid.h b/cpp/src/qpid/sys/windows/uuid.h new file mode 100644 index 0000000000..c79abe95c6 --- /dev/null +++ b/cpp/src/qpid/sys/windows/uuid.h @@ -0,0 +1,38 @@ +#ifndef _sys_windows_uuid_h +#define _sys_windows_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/CommonImportExport.h" +#include <qpid/sys/IntegerTypes.h> + +namespace qpid { namespace sys { const size_t UuidSize = 16; }} +typedef uint8_t uuid_t[qpid::sys::UuidSize]; + +QPID_COMMON_EXTERN void uuid_clear (uuid_t uu); +QPID_COMMON_EXTERN void uuid_copy (uuid_t dst, const uuid_t src); +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); + +#endif /*!_sys_windows_uuid_h*/ diff --git a/cpp/src/tests/txtest.cpp b/cpp/src/tests/txtest.cpp index c1ee246e2c..f604df7e21 100644 --- a/cpp/src/tests/txtest.cpp +++ b/cpp/src/tests/txtest.cpp @@ -33,7 +33,7 @@ #include "qpid/client/SubscriptionManager.h" #include "qpid/framing/Array.h" #include "qpid/framing/Buffer.h" -#include "qpid/sys/uuid.h" +#include "qpid/framing/Uuid.h" #include "qpid/sys/Thread.h" using namespace qpid; @@ -130,8 +130,6 @@ struct Transfer : public Client, public Runnable std::string src; std::string dest; Thread thread; - uuid_t uuid; - char uuidStr[37]; // Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + trailing \0 framing::Xid xid; Transfer(const std::string& to, const std::string& from) : src(to), dest(from), xid(0x4c414e47, "", from) {} @@ -184,9 +182,8 @@ struct Transfer : public Client, public Runnable } void setNewXid(framing::Xid& xid) { - ::uuid_generate(uuid); - ::uuid_unparse(uuid, uuidStr); - xid.setGlobalId(uuidStr); + framing::Uuid uuid(true); + xid.setGlobalId(uuid.str()); } }; |