diff Core/SystemToolbox.cpp @ 2172:84d1d392a9ab

GenerateUuid() not available in sandboxed environments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Nov 2016 12:06:00 +0100
parents fd5875662670
children 1c42860097fc
line wrap: on
line diff
--- a/Core/SystemToolbox.cpp	Wed Nov 23 11:46:42 2016 +0100
+++ b/Core/SystemToolbox.cpp	Wed Nov 23 12:06:00 2016 +0100
@@ -59,6 +59,19 @@
 #endif
 
 
+// Inclusions for UUID
+// http://stackoverflow.com/a/1626302
+
+extern "C"
+{
+#ifdef WIN32
+#  include <rpc.h>
+#else
+#  include <uuid/uuid.h>
+#endif
+}
+
+
 #include "Logging.h"
 #include "OrthancException.h"
 #include "Toolbox.h"
@@ -477,6 +490,28 @@
   }
 
 
+  std::string SystemToolbox::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;
+  }
+
+
 #if BOOST_HAS_DATE_TIME == 1
   std::string SystemToolbox::GetNowIsoString()
   {