121 #include <Iphlpapi.h> 124 #include <sys/time.h> 125 #if defined(R__LINUX) && !defined(R__WINGCC) 126 #include <sys/sysinfo.h> 141 uuid_time_t *time_last_ptr = TTHREAD_TLS_PTR(time_last);
151 using namespace std::chrono;
152 system_clock::time_point today = system_clock::now();
153 seed = (
UInt_t)(system_clock::to_time_t ( today )) + ::getpid();
160 GetCurrentTime(time_last_ptr);
162 clockseq = 1+(
UShort_t)(65536*rand()/(RAND_MAX+1.0));
164 clockseq = 1+(
UShort_t)(65536*random()/(RAND_MAX+1.0));
172 GetCurrentTime(×tamp);
175 if (CmpTime(×tamp, time_last_ptr) == -1) {
176 clockseq = (clockseq + 1) & 0x3FFF;
177 if (clockseq == 0) clockseq++;
180 Format(clockseq, timestamp);
182 time_last = timestamp;
201 if (t1->
low < t2->
low)
return -1;
202 if (t1->
low > t2->
low)
return 1;
215 int timeHiAndVersion;
216 int clockSeqHiAndRes;
220 sscanf(uuid,
"%8lx-%4x-%4x-%2x%2x-%2x%2x%2x%2x%2x%2x",
226 &node[0], &node[1], &node[2], &node[3], &node[4], &node[5]);
230 fTimeLow = (
UInt_t) timeLo;
232 fTimeHiAndVersion = (
UShort_t) timeHiAndVersion;
233 fClockSeqHiAndReserved = (
UChar_t) clockSeqHiAndRes;
234 fClockSeqLow = (
UChar_t) clockSeqLo;
251 fTimeHiAndVersion = 0;
252 fClockSeqHiAndReserved = 0;
258 Error(
"TUUID",
"null string not allowed");
268 Version_t version = TUUID::Class_Version();
269 tobuf(buffer, version);
270 tobuf(buffer, fTimeLow);
271 tobuf(buffer, fTimeMid);
272 tobuf(buffer, fTimeHiAndVersion);
273 tobuf(buffer, fClockSeqHiAndReserved);
274 tobuf(buffer, fClockSeqLow);
275 for (
Int_t i = 0; i < 6; i++)
276 tobuf(buffer, fNode[i]);
288 frombuf(buffer, &fTimeHiAndVersion);
289 frombuf(buffer, &fClockSeqHiAndReserved);
290 frombuf(buffer, &fClockSeqLow);
291 for (
Int_t i = 0; i < 6; i++)
304 b >> fTimeHiAndVersion;
305 b >> fClockSeqHiAndReserved;
307 for (
UInt_t i = 0; i < 6; i++) {
319 fTimeHiAndVersion = (
UShort_t)((ts.
high >> 16) & 0x0FFF);
320 fTimeHiAndVersion |= (1 << 12);
321 fClockSeqLow = clockseq & 0xFF;
322 fClockSeqHiAndReserved = (clockseq & 0x3F00) >> 8;
323 fClockSeqHiAndReserved |= 0x80;
334 const UShort_t uuids_per_tick = 1024;
337 TTHREAD_TLS(
UShort_t) uuids_this_tick(0);
340 uuid_time_t *time_last_ptr = TTHREAD_TLS_PTR(time_last);
343 GetSystemTime(time_last_ptr);
344 uuids_this_tick = uuids_per_tick;
351 GetSystemTime(&time_now);
354 if (CmpTime(time_last_ptr, &time_now)) {
359 if (uuids_this_tick < uuids_per_tick) {
366 time_last = time_now;
368 if (uuids_this_tick != 0) {
369 if (time_now.
low & 0x80000000) {
370 time_now.
low += uuids_this_tick;
371 if (!(time_now.
low & 0x80000000))
374 time_now.
low += uuids_this_tick;
378 timestamp->
low = time_now.
low;
388 GetSystemTimeAsFileTime((FILETIME *)&time);
394 (
unsigned __int64) (1000*1000*10)
395 * (
unsigned __int64) (60 * 60 * 24)
396 * (
unsigned __int64) (17+30+31+365*18+5);
398 timestamp->
high = time.HighPart;
399 timestamp->
low = time.LowPart;
402 gettimeofday(&tp, 0);
407 0x01B21DD213814000LL;
409 timestamp->
low = (
UInt_t) (uuid_time & 0xFFFFFFFF);
436 PIP_ADAPTER_INFO ainfo = (PIP_ADAPTER_INFO)
malloc(
sizeof(IP_ADAPTER_INFO));
437 ULONG buflen =
sizeof(IP_ADAPTER_INFO);
438 DWORD stat = GetAdaptersInfo(ainfo, &buflen);
439 if (stat == ERROR_BUFFER_OVERFLOW) {
441 ainfo = (PIP_ADAPTER_INFO)
malloc(buflen);
442 stat = GetAdaptersInfo(ainfo, &buflen);
444 if (stat != ERROR_SUCCESS)
448 PIP_ADAPTER_INFO adapter = ainfo;
450 sscanf(adapter->IpAddressList.IpAddress.String,
"%d.%d.%d.%d",
452 adr = (a << 24) | (b << 16) | (c << 8) | d;
458 memcpy(fNode, &adr, 4);
470 memcpy(fNode, seed,
sizeof(fNode));
471 fTimeHiAndVersion |= (3 << 12);
487 char hostname[MAX_COMPUTERNAME_LENGTH + 1];
490 memset(&r, 0,
sizeof(r));
493 GlobalMemoryStatus(&r.m);
497 GetSystemTimeAsFileTime(&r.t);
499 QueryPerformanceCounter(&r.pc);
501 r.tc = GetTickCount();
502 r.l = MAX_COMPUTERNAME_LENGTH + 1;
503 GetComputerName(r.hostname, &r.l);
506 #if defined(R__LINUX) && !defined(R__WINGCC) 513 memset(&r, 0,
sizeof(r));
515 #if defined(R__LINUX) && !defined(R__WINGCC) 518 gettimeofday(&r.t, 0);
519 gethostname(r.hostname, 256);
531 printf(
"%s\n", AsString());
539 static char uuid[40];
541 snprintf(uuid,40,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
542 fTimeLow, fTimeMid, fTimeHiAndVersion, fClockSeqHiAndReserved,
543 fClockSeqLow, fNode[0], fNode[1], fNode[2], fNode[3], fNode[4],
555 char *
c = (
char *) &fTimeLow;
563 c0 += *c++;
c1 += c0;
564 c0 += *c++;
c1 += c0;
565 c0 += *c++;
c1 += c0;
566 c0 += *c++;
c1 += c0;
568 c0 += *c++;
c1 += c0;
569 c0 += *c++;
c1 += c0;
570 c0 += *c++;
c1 += c0;
571 c0 += *c++;
c1 += c0;
573 c0 += *c++;
c1 += c0;
574 c0 += *c++;
c1 += c0;
575 c0 += *c++;
c1 += c0;
576 c0 += *c++;
c1 += c0;
578 c0 += *c++;
c1 += c0;
579 c0 += *c++;
c1 += c0;
580 c0 += *c++;
c1 += c0;
581 c0 += *c++;
c1 += c0;
604 #define CHECK(f1, f2) if (f1 != f2) return f1 < f2 ? -1 : 1; 610 for (
int i = 0; i < 6; i++) {
611 if (fNode[i] < u.
fNode[i])
613 if (fNode[i] > u.
fNode[i])
625 if ((fTimeHiAndVersion >> 12) == 1) {
627 memcpy(&addr, fNode, 4);
643 ts.
high |= (
UInt_t)((fTimeHiAndVersion & 0x0FFF) << 16);
650 uuid_time -= 0x01B21DD213814000LL;
651 uuid_time /= 10000000LL;
663 memcpy(uuid, &fTimeLow, 16);
673 Error(
"SetUUID",
"null string not allowed");
685 const_cast<TUUID&
>(uuid).Streamer(buf);
virtual ~TUUID()
delete this TUUID
void frombuf(char *&buf, Bool_t *x)
virtual int GetPid()
Get process id.
void Set()
Set Date/Time to current time as reported by the system.
void Final()
MD5 finalization, ends an MD5 message-digest operation, writing the the message digest and zeroizing ...
This class represents an Internet Protocol (IP) address.
void ReadBuffer(char *&buffer)
Stream UUID from input buffer.
UInt_t fTimeLow
index in the list of UUIDs in TProcessUUID
Buffer base class used for serializing objects.
R__EXTERN TVirtualMutex * gROOTMutex
Int_t CmpTime(uuid_time_t *t1, uuid_time_t *t2)
Compare two time values.
TBuffer & operator<<(TBuffer &buf, const TUUID &uuid)
Input operator. Delegate to Streamer.
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
TDatime GetTime() const
Get time from UUID.
This code implements the MD5 message-digest algorithm.
UShort_t fTimeHiAndVersion
void tobuf(char *&buf, Bool_t x)
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
void Error(const char *location, const char *msgfmt,...)
virtual TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
void Update(const UChar_t *buf, UInt_t len)
Update TMD5 object to reflect the concatenation of another buffer full of bytes.
R__EXTERN TSystem * gSystem
UInt_t GetAddress() const
#define R__LOCKGUARD2(mutex)
void Format(UShort_t clockseq, uuid_time_t ts)
Make a UUID from timestamp, clockseq and node id.
virtual const char * HostName()
Return the system's host name.
void StreamerV1(TBuffer &b)
Stream UUID from input buffer.
unsigned long long ULong64_t
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
void SetUUID(const char *uuid_str)
Set this UUID to the value specified in uuid ((which must be in TUUID::AsString() format)...
UChar_t fClockSeqHiAndReserved
void GetRandomInfo(UChar_t seed[16])
Get random info based on some machine parameters.
void GetNodeIdentifier()
Get node identifier.
UShort_t Hash() const
Compute 16-bit hash value of the UUID.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
void FillBuffer(char *&buffer)
Stream UUID into output buffer.
Int_t Compare(const TUUID &u) const
Compare two UUIDs "lexically" and return.
void Print() const
Print UUID.
void GetSystemTime(uuid_time_t *timestamp)
Get system time with 100ns precision. Time is since Oct 15, 1582.
void SetFromString(const char *uuid_str)
Set this UUID to the value specified in uuid ((which must be in TUUID::AsString() format)...
void GetUUID(UChar_t uuid[16]) const
Return uuid in specified buffer (16 byte = 128 bits).
TInetAddress GetHostAddress() const
Get address of host encoded in UUID.
void GetCurrentTime(uuid_time_t *timestamp)
Get current time as 60 bit 100ns ticks since whenever.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
static char * Format(const char *format, va_list ap)
Format a string in a circular formatting buffer (using a printf style format descriptor).