diff Core/Toolbox.cpp @ 2512:4dcafa8d6633

SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Mar 2018 15:20:50 +0200
parents 878b59270859
children 97a74f0eac7a
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Wed Mar 28 14:18:02 2018 +0200
+++ b/Core/Toolbox.cpp	Wed Mar 28 15:20:50 2018 +0200
@@ -87,6 +87,20 @@
 #endif
 
 
+// Inclusions for UUID
+// http://stackoverflow.com/a/1626302
+
+extern "C"
+{
+#if defined(_WIN32)
+#  include <rpc.h>
+#else
+#  include <uuid/uuid.h>
+#endif
+}
+
+
+
 namespace Orthanc
 {
   void Toolbox::ToUpperCase(std::string& s)
@@ -1376,4 +1390,26 @@
     return boost::locale::conv::utf_to_utf<char>(w);
   }
 #endif
+
+
+  std::string Toolbox::GenerateUuid()
+  {
+#ifdef WIN32
+    UUID uuid;
+    UuidCreate ( &uuid );
+
+    unsigned char * str;
+    UuidToStringA ( &uuid, &str );
+
+    std::string s( ( char* ) str );
+
+    RpcStringFreeA ( &str );
+#else
+    uuid_t uuid;
+    uuid_generate_random ( uuid );
+    char s[37];
+    uuid_unparse ( uuid, s );
+#endif
+    return s;
+  }
 }