posix/coil/UUID.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 #include <coil/UUID.h>
21 #include <iostream>
22 #include <string.h>
23 
24 #ifdef COIL_OS_FREEBSD
25 void error_code(uint32_t status)
26 {
27  if (status == uuid_s_ok)
28  std::cout << "uuid_s_ok" << std::endl;
29  else if (status == uuid_s_bad_version)
30  std::cout << "uuid_s_bad_version" << std::endl;
31  else if (status == uuid_s_invalid_string_uuid)
32  std::cout << "uuid_s_invalid_string_uuid" << std::endl;
33  else if (status == uuid_s_no_memory)
34  std::cout << "uuid_s_no_memory" << std::endl;
35  else
36  std::cout << "other error" << std::endl;
37 }
38 
39 void uuid_clear(uuid_t& uu)
40 {
41  uint32_t status;
42  uuid_create_nil(&uu, &status);
43 }
44 void uuid_unparse(uuid_t& uu, char*& uuidstr)
45 {
46  uint32_t status;
47  uuid_to_string(&uu, &uuidstr, &status);
48 }
49 void uuid_generate(uuid_t& out)
50 {
51  uint32_t status;
52  uuid_create(&out, &status);
53 }
54 #endif
55 
56 namespace coil
57 {
58 
59 #ifdef COIL_OS_FREEBSD
60  UUID::UUID()
61  : m_uuidstr(0)
62  {
63  ::uuid_clear(m_uuid);
64  }
65  UUID::UUID(const uuid_t& uuid)
66  : m_uuid(uuid), m_uuidstr(0)
67  {
68  }
69 
70  UUID::~UUID()
71  {
72  free(m_uuidstr);
73  }
74 
75  const char* UUID::to_string()
76  {
77  uuid_unparse(m_uuid, m_uuidstr);
78  return m_uuidstr;
79  }
80 
81 
82  UUID_Generator::UUID_Generator()
83  {
84  }
85 
86  UUID_Generator::~UUID_Generator()
87  {
88  }
89 
90  void UUID_Generator::init()
91  {
92  }
93 
94  UUID* UUID_Generator::generateUUID(int n, int h)
95  {
96  uuid_t uuid;
97  uuid_generate(uuid);
98  return new UUID(uuid);
99  }
100 #endif
101 
102 #if defined(COIL_OS_LINUX) || defined(COIL_OS_DARWIN) || defined(COIL_OS_CYGWIN)
103 
104  UUID_Generator::UUID_Generator(){}
105 
106  void UUID_Generator::init(){}
107  UUID* UUID_Generator::generateUUID(int varsion, int variant){
108  uuid_t uuid;
109 
110  uuid_generate(uuid);
111  return new UUID(&uuid);
112  }
113 
114  UUID::UUID(){
115  uuid_clear(this->_uuid);
116  }
117 
118  UUID::UUID(uuid_t *uuid){
119  strncpy((char *)this->_uuid, (char *)(*uuid), sizeof(this->_uuid));
120  }
121 
122  const char* UUID::to_string(){
123  uuid_unparse(this->_uuid, buf);
124  return buf;
125  }
126 
127 #endif
128 };
UUID()
UUID class constructor.
ACE_Utils::UUID UUID
Definition: ace/coil/UUID.h:36
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:56