| 212 | } |
| 213 | |
| 214 | uint64_t IdGenerator::getRandomDeviceSegment(int numBits) const { |
| 215 | uint64_t deviceSegment = 0; |
| 216 | Identifier::Data random_uuid{}; |
| 217 | for (int word = 0; word < 2; word++) { |
| 218 | #ifdef WIN32 |
| 219 | windowsUuidGenerateRandom(random_uuid); |
| 220 | #else |
| 221 | uuid temp_uuid; |
| 222 | temp_uuid.make(UUID_MAKE_V4); |
| 223 | void* uuid_bin = temp_uuid.binary(); |
| 224 | memcpy(random_uuid.data(), uuid_bin, 16); |
| 225 | free(uuid_bin); |
| 226 | #endif |
| 227 | for (int i = 0; i < 4; i++) { |
| 228 | deviceSegment += random_uuid[i]; |
| 229 | deviceSegment <<= 8; |
| 230 | } |
| 231 | } |
| 232 | deviceSegment >>= 64 - numBits; |
| 233 | logging::LOG_DEBUG(logger_) << "Using random defined device segment:" << deviceSegment; |
| 234 | deviceSegment <<= 64 - numBits; |
| 235 | return deviceSegment; |
| 236 | } |
| 237 | |
| 238 | void IdGenerator::initialize(const std::shared_ptr<Properties>& properties) { |
| 239 | std::string implementation_str; |
nothing calls this directly
no test coverage detected