SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Static Public Member Functions | Static Private Member Functions | List of all members
UidCalculator Class Reference

#include <uid.h>

Static Public Member Functions

static uint64_t getNewObjectId ()
 
static uint32_t getNewInstanceId ()
 

Static Private Member Functions

static uint64_t getCurrentMiroseconds ()
 

Detailed Description

Definition at line 27 of file uid.h.

Member Function Documentation

◆ getCurrentMiroseconds()

uint64_t UidCalculator::getCurrentMiroseconds ( )
staticprivate

Definition at line 69 of file uid.cpp.

Referenced by getNewObjectId().

70 {
71 #if (defined _WIN32_) || (defined _MSC_VER)
72  LARGE_INTEGER tickPerSecond;
73  LARGE_INTEGER tick; // a point in time
74 
75  // get the high resolution counter's accuracy
76  QueryPerformanceFrequency(&tickPerSecond);
77 
78  // what time is it ?
79  QueryPerformanceCounter(&tick);
80 
81  // and here we get the current microsecond! \o/
82  return (tick.QuadPart % tickPerSecond.QuadPart);
83 #else
84  struct timeval tv;
85  gettimeofday(&tv, 0);
86  return tv.tv_usec;
87 #endif
88 }
+ Here is the caller graph for this function:

◆ getNewInstanceId()

uint32_t UidCalculator::getNewInstanceId ( )
static

Get a new instance unique Id. It is made of from LSB to MSB:

  • 2 byte process id
  • 2 byte hashed host name

Definition at line 50 of file uid.cpp.

References i.

51 {
52  uint32_t uid = (QCoreApplication::applicationPid() % (1<<16));
53 
54  QString hostname = QHostInfo::localHostName();
55  QByteArray hashKey = QCryptographicHash::hash(hostname.toUtf8(), QCryptographicHash::Sha1);
56  uint32_t hashHost = 0;
57 
58  for (int i = 0; i < hashKey.size(); i++) {
59  char c = hashKey.at(i);
60  hashHost += (uint32_t) c;
61  }
62 
63  hashHost %= (1<<16);
64  uid += (hashHost<<16);
65 
66  return uid;
67 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
int32_t i
Definition: decimators.h:244

◆ getNewObjectId()

uint64_t UidCalculator::getNewObjectId ( )
static

Get a new object unique Id. It is the addition of:

  • 6 digit microseconds in current second
  • 4 byte Unix epoch multiplied by 1000000

Definition at line 35 of file uid.cpp.

References getCurrentMiroseconds().

36 {
37  QDateTime currentDateTime = QDateTime::currentDateTime();
38  uint64_t uid = currentDateTime.toTime_t();
39  uid *= 1000000UL; // make room for microseconds
40 
41 // Fallback to milliseconds:
42 // QTime timeNow = QTime::currentTime();
43 // uint64_t usecs = timeNow.msec() * 1000UL;
44 // uid += usecs;
45  uid += getCurrentMiroseconds();
46 
47  return uid;
48 }
static uint64_t getCurrentMiroseconds()
Definition: uid.cpp:69
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48
+ Here is the call graph for this function:

The documentation for this class was generated from the following files: