Uuid.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # ifdef FC_OS_WIN32
00028 # include <Rpc.h>
00029 # endif
00030 #endif
00031
00033 #include "Uuid.h"
00034 #include "Exception.h"
00035 #include "Interpreter.h"
00036 #include <CXX/Objects.hxx>
00037
00038
00039 using namespace Base;
00040
00041
00042
00043
00044
00049 Uuid::Uuid()
00050 {
00051 UuidStr = CreateUuid();
00052 }
00053
00058 Uuid::~Uuid()
00059 {
00060 }
00061
00062
00063
00064
00065
00066
00067 std::string Uuid::CreateUuid(void)
00068 {
00069 #ifdef FC_OS_WIN32
00070 RPC_STATUS rstat;
00071 UUID uuid;
00072 unsigned char *uuidStr;
00073
00074 rstat = UuidCreate(&uuid);
00075 if (rstat != RPC_S_OK) throw Base::Exception("Cannot convert a unique Windows UUID to a string");
00076
00077 rstat = UuidToString(&uuid, &uuidStr);
00078 if (rstat != RPC_S_OK) throw Base::Exception("Cannot convert a unique Windows UUID to a string");
00079
00080 std::string Uuid((char *)uuidStr);
00081
00082
00083
00084 RpcStringFree(&uuidStr);
00085 #else
00086
00087 std::string Uuid;
00088 PyGILStateLocker lock;
00089 try {
00090 Py::Module module(PyImport_ImportModule("uuid"),true);
00091 Py::Callable method(module.getAttr("uuid4"));
00092 Py::Tuple arg;
00093 Py::Object guid = method.apply(arg);
00094 Uuid = guid.as_string();
00095 }
00096 catch (Py::Exception& e) {
00097 e.clear();
00098 throw Base::Exception("Creation of UUID failed");
00099 }
00100 #endif
00101 return Uuid;
00102 }