Commit d660d1d6 authored by jacobgladish's avatar jacobgladish

Added better version of Guid (needs tested)

parent 629c1550
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace namespace
{ {
common::Guid const kDefaultAppGuid = common::Guid::FromString("DA9C7763-C3E0-4B3B-B190-5BEF8DF96E4D"); common::Guid const kDefaultAppGuid = common::Guid::Parse("DA9C7763-C3E0-4B3B-B190-5BEF8DF96E4D");
char const* kDefaultLanguageForAbout = "en"; char const* kDefaultLanguageForAbout = "en";
char const* kUnknownAdapter = "Unknown Device"; char const* kUnknownAdapter = "Unknown Device";
char const* kUnknownManufacturer = "Unknown"; char const* kUnknownManufacturer = "Unknown";
...@@ -108,7 +108,7 @@ AllJoynAbout::ReadDeviceId(std::string&) ...@@ -108,7 +108,7 @@ AllJoynAbout::ReadDeviceId(std::string&)
QStatus QStatus
AllJoynAbout::CreateAndSaveDeviceId(std::string& deviceId) AllJoynAbout::CreateAndSaveDeviceId(std::string& deviceId)
{ {
common::Guid guid = common::Guid::Create(); common::Guid guid = common::Guid::NewGuid();
deviceId = guid.ToString(); deviceId = guid.ToString();
// TODO: need to persist this configuration // TODO: need to persist this configuration
......
#include <Common/Guid.h>
#include <string.h>
common::Guid::Guid()
{
memset(m_uuid, 0, sizeof(uuid_t));
}
common::Guid::Guid(uuid_t id)
{
memcpy(m_uuid, id, sizeof(uuid_t));
}
common::Guid
common::Guid::NewGuid()
{
#ifdef __linux__
char id[17];
memset(id, 0, sizeof(id));
#else
uuid_string_t id;
#endif
uuid_t uuid;
uuid_generate_random(uuid);
return Guid(uuid);
}
common::Guid
common::Guid::Parse(char const* s)
{
if (s == NULL)
return Guid::Null();
uuid_t id;
if (uuid_parse(s, id) == 0)
return Guid(id);
else
return Guid::Null();
}
common::Guid const&
common::Guid::Null()
{
static Guid zeroGuid = Guid();
return zeroGuid;
}
std::string
common::Guid::ToString() const
{
char buff[64];
memset(buff, 0, sizeof(buff));
uuid_unparse_lower(m_uuid, buff);
return std::string(buff);
}
bool
common::Guid::operator < (Guid const& rhs) const
{
return uuid_compare(m_uuid, rhs.m_uuid) < 0;
}
bool
common::Guid::operator == (Guid const& rhs) const
{
return uuid_compare(m_uuid, rhs.m_uuid) == 0;
}
bool
common::Guid::operator != (Guid const& rhs) const
{
return uuid_compare(m_uuid, rhs.m_uuid) != 0;
}
#pragma once #pragma once
#include <string>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include <string>
namespace common namespace common
{ {
class Guid class Guid
{ {
public: public:
static Guid Create() static Guid const& Null();
{
uuid_t uuid;
uuid_generate_random(uuid);
#ifdef __linux__
char s[37];
#else
uuid_string_t s;
#endif
uuid_unparse(uuid, s); static Guid NewGuid();
static Guid Parse(char const* s);
return Guid(std::string(s)); std::string ToString() const;
}
static Guid FromString(char const* s) bool operator < (Guid const& rhs) const;
{ bool operator == (Guid const& rhs) const;
return Guid(s); bool operator != (Guid const& rhs) const;
}
std::string ToString() const
{ return m_uuid; }
private: private:
Guid(std::string const& uuid) : m_uuid(uuid) { } Guid();
Guid(uuid_t id);
private: private:
std::string m_uuid; uuid_t m_uuid;
}; };
} }
...@@ -12,6 +12,7 @@ SRCS=DeviceProviders/AllJoynProvider.cpp \ ...@@ -12,6 +12,7 @@ SRCS=DeviceProviders/AllJoynProvider.cpp \
Bridge/DeviceSignal.cpp \ Bridge/DeviceSignal.cpp \
Common/Log.cpp \ Common/Log.cpp \
Common/Variant.cpp \ Common/Variant.cpp \
Common/Guid.cpp \
Adapters/MockAdapter/MockAdapter.cpp \ Adapters/MockAdapter/MockAdapter.cpp \
Adapters/MockAdapter/MockDevices.cpp \ Adapters/MockAdapter/MockDevices.cpp \
Adapters/MockAdapter/MockAdapterDevice.cpp \ Adapters/MockAdapter/MockAdapterDevice.cpp \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment