|
ROOT
Reference Guide |
|
Go to the documentation of this file.
131 #include <Iphlpapi.h>
133 #define getpid() _getpid()
134 #define srandom(seed) srand(seed)
135 #define random() rand()
138 #include <sys/time.h>
139 #if defined(R__LINUX) && !defined(R__WINGCC)
140 #include <sys/sysinfo.h>
143 #include <netinet/in.h>
157 uuid_time_t *time_last_ptr = TTHREAD_TLS_PTR(time_last);
167 using namespace std::chrono;
168 system_clock::time_point today = system_clock::now();
169 seed = (
UInt_t)(system_clock::to_time_t ( today )) + ::getpid();
173 clockseq = 1+(
UShort_t)(65536*random()/(RAND_MAX+1.0));
183 if (
CmpTime(×tamp, time_last_ptr) == -1) {
184 clockseq = (clockseq + 1) & 0x3FFF;
185 if (clockseq == 0) clockseq++;
188 Format(clockseq, timestamp);
190 time_last = timestamp;
207 if (
t1->high < t2->
high)
return -1;
208 if (
t1->high > t2->
high)
return 1;
209 if (
t1->low < t2->
low)
return -1;
210 if (
t1->low > t2->
low)
return 1;
223 int timeHiAndVersion;
224 int clockSeqHiAndRes;
228 sscanf(uuid,
"%8lx-%4x-%4x-%2x%2x-%2x%2x%2x%2x%2x%2x",
234 &node[0], &node[1], &node[2], &node[3], &node[4], &node[5]);
266 Error(
"TUUID",
"null string not allowed");
276 Version_t version = TUUID::Class_Version();
277 tobuf(buffer, version);
283 for (
Int_t i = 0; i < 6; i++)
299 for (
Int_t i = 0; i < 6; i++)
315 for (
UInt_t i = 0; i < 6; i++) {
342 const UShort_t uuids_per_tick = 1024;
345 TTHREAD_TLS(
UShort_t) uuids_this_tick(0);
348 uuid_time_t *time_last_ptr = TTHREAD_TLS_PTR(time_last);
352 uuids_this_tick = uuids_per_tick;
362 if (
CmpTime(time_last_ptr, &time_now)) {
367 if (uuids_this_tick < uuids_per_tick) {
374 time_last = time_now;
376 if (uuids_this_tick != 0) {
377 if (time_now.
low & 0x80000000) {
378 time_now.
low += uuids_this_tick;
379 if (!(time_now.
low & 0x80000000))
382 time_now.
low += uuids_this_tick;
386 timestamp->
low = time_now.
low;
396 GetSystemTimeAsFileTime((FILETIME *)&time);
402 (
unsigned __int64) (1000*1000*10)
403 * (
unsigned __int64) (60 * 60 * 24)
404 * (
unsigned __int64) (17+30+31+365*18+5);
406 timestamp->
high = time.HighPart;
407 timestamp->
low = time.LowPart;
410 gettimeofday(&tp, 0);
415 0x01B21DD213814000LL;
417 timestamp->
low = (
UInt_t) (uuid_time & 0xFFFFFFFF);
434 struct ifaddrs *ifAddrStruct =
nullptr;
435 struct ifaddrs *ifa =
nullptr;
437 if (getifaddrs(&ifAddrStruct) != 0) {
440 for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
441 if (!ifa->ifa_addr) {
444 if (ifa->ifa_addr->sa_family != AF_INET) {
447 if (strncmp(ifa->ifa_name,
"lo",2) == 0) {
450 addr = ntohl(((
struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr);
455 if (ifAddrStruct !=
nullptr)
456 freeifaddrs(ifAddrStruct);
469 PIP_ADAPTER_INFO ainfo = (PIP_ADAPTER_INFO)
malloc(
sizeof(IP_ADAPTER_INFO));
470 ULONG buflen =
sizeof(IP_ADAPTER_INFO);
471 DWORD stat = GetAdaptersInfo(ainfo, &buflen);
472 if (stat == ERROR_BUFFER_OVERFLOW) {
474 ainfo = (PIP_ADAPTER_INFO)
malloc(buflen);
475 stat = GetAdaptersInfo(ainfo, &buflen);
477 if (stat != ERROR_SUCCESS)
481 PIP_ADAPTER_INFO adapter = ainfo;
483 sscanf(adapter->IpAddressList.IpAddress.String,
"%d.%d.%d.%d",
485 adr = (
a << 24) | (
b << 16) | (
c << 8) |
d;
491 memcpy(
fNode, &adr, 4);
520 char hostname[MAX_COMPUTERNAME_LENGTH + 1];
523 memset(&
r, 0,
sizeof(
r));
526 GlobalMemoryStatus(&
r.m);
530 GetSystemTimeAsFileTime(&
r.t);
532 QueryPerformanceCounter(&
r.pc);
534 r.tc = GetTickCount();
535 r.l = MAX_COMPUTERNAME_LENGTH + 1;
536 GetComputerName(
r.hostname, &
r.l);
539 #if defined(R__LINUX) && !defined(R__WINGCC)
546 memset(&
r, 0,
sizeof(
r));
548 #if defined(R__LINUX) && !defined(R__WINGCC)
551 gettimeofday(&
r.t, 0);
552 gethostname(
r.hostname, 256);
572 static char uuid[40];
574 snprintf(uuid,40,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
596 c0 += *
c++;
c1 += c0;
597 c0 += *
c++;
c1 += c0;
598 c0 += *
c++;
c1 += c0;
599 c0 += *
c++;
c1 += c0;
601 c0 += *
c++;
c1 += c0;
602 c0 += *
c++;
c1 += c0;
603 c0 += *
c++;
c1 += c0;
604 c0 += *
c++;
c1 += c0;
606 c0 += *
c++;
c1 += c0;
607 c0 += *
c++;
c1 += c0;
608 c0 += *
c++;
c1 += c0;
609 c0 += *
c++;
c1 += c0;
611 c0 += *
c++;
c1 += c0;
612 c0 += *
c++;
c1 += c0;
613 c0 += *
c++;
c1 += c0;
614 c0 += *
c++;
c1 += c0;
637 #define CHECK(f1, f2) if (f1 != f2) return f1 < f2 ? -1 : 1;
643 for (
int i = 0; i < 6; i++) {
660 memcpy(&addr,
fNode, 4);
683 uuid_time -= 0x01B21DD213814000LL;
684 uuid_time /= 10000000LL;
706 Error(
"SetUUID",
"null string not allowed");
718 const_cast<TUUID&
>(uuid).Streamer(buf);
void GetNodeIdentifier()
Get node identifier.
UShort_t Hash() const
Compute 16-bit hash value of the UUID.
UInt_t fTimeLow
index in the list of UUIDs in TProcessUUID
void FillBuffer(char *&buffer)
Stream UUID into output buffer.
virtual ~TUUID()
delete this TUUID
void GetCurrentTime(uuid_time_t *timestamp)
Get current time as 60 bit 100ns ticks since whenever.
void ReadBuffer(char *&buffer)
Stream UUID from input buffer.
void tobuf(char *&buf, Bool_t x)
void Final()
MD5 finalization, ends an MD5 message-digest operation, writing the the message digest and zeroizing ...
static constexpr double s
TBuffer & operator<<(TBuffer &buf, const TUUID &uuid)
Input operator. Delegate to Streamer.
Int_t CmpTime(uuid_time_t *t1, uuid_time_t *t2)
Compare two time values.
static constexpr double pc
void Update(const UChar_t *buf, UInt_t len)
Update TMD5 object to reflect the concatenation of another buffer full of bytes.
TDatime GetTime() const
Get time from UUID.
Buffer base class used for serializing objects.
void Set()
Set Date/Time to current time as reported by the system.
R__EXTERN TVirtualMutex * gROOTMutex
virtual int GetPid()
Get process id.
UShort_t fTimeHiAndVersion
#define R__LOCKGUARD(mutex)
virtual TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
This code implements the MD5 message-digest algorithm.
void StreamerV1(TBuffer &b)
Stream UUID from input buffer.
R__EXTERN TSystem * gSystem
unsigned long long ULong64_t
Int_t Compare(const TUUID &u) const
Compare two UUIDs "lexically" and return.
void SetUUID(const char *uuid_str)
Set this UUID to the value specified in uuid ((which must be in TUUID::AsString() format).
void Format(UShort_t clockseq, uuid_time_t ts)
Make a UUID from timestamp, clockseq and node id.
void frombuf(char *&buf, Bool_t *x)
TInetAddress GetHostAddress() const
Get address of host encoded in UUID.
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
void GetRandomInfo(UChar_t seed[16])
Get random info based on some machine parameters.
This class represents an Internet Protocol (IP) address.
UChar_t fClockSeqHiAndReserved
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 Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void GetUUID(UChar_t uuid[16]) const
Return uuid in specified buffer (16 byte = 128 bits).