lnuid.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include <ctime>
  14. #include <string>
  15. using namespace std;
  16. /**
  17. * This is an implementation of Globally Unique Transaction ID’s.
  18. * Note: This class currently generates unique id on OS's that supports device /dev/urandom.
  19. * @author - Amol Patwardhan
  20. * Version: 1.0
  21. */
  22. namespace ln_uid {
  23. //Random byte count
  24. const unsigned int uid_size = 16;
  25. typedef unsigned char ln_uid_t[uid_size];
  26. ln_uid_t &createUniqueId(ln_uid_t &out);
  27. string createUniqueIdString();
  28. std::string uniqueIdToString(const ln_uid_t &uid);
  29. ln_uid_t &uniqueIdFromString(const char* uid, ln_uid_t &out);
  30. time_t timeFromUniqueId(const char* uid);
  31. time_t timeFromUniqueId(const ln_uid_t &uid);
  32. void getUniqueIdRange(time_t start, time_t end, ln_uid_t &uid_start, ln_uid_t &uid_end);
  33. void getUniqueIdDateRange(const char *start, const char *end, ln_uid_t &uid_start, ln_uid_t &uid_end);
  34. bool sameUniqueId(const ln_uid_t &uid1, const ln_uid_t &uid2);
  35. void copyUniqueId(ln_uid_t &to, const ln_uid_t &from);
  36. int get_utc_offset();
  37. };