You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectPathfinderBinaryLog.h"
  2. #define LOG( X ) m_pLog->Log( "BILO", this, X )
  3. #define LOG_ERROR( X ) m_pLog->Log( "BILO", this, _LOG_ERROR, X )
  4. #define PACKAGE_NAME "PATHFINDER_BIN_LOG"
  5. objectPathfinderBinaryLog *objectPathfinderBinaryLog::_instance = NULL;
  6. objectPathfinderBinaryLog *objectPathfinderBinaryLog::getInstance(){
  7. if( _instance == NULL ){
  8. _instance = new objectPathfinderBinaryLog();
  9. };
  10. return _instance;
  11. };
  12. objectPathfinderBinaryLog::objectPathfinderBinaryLog(){
  13. m_pLog = basicLogCollection::getInstance();
  14. m_pFID = NULL;
  15. uuidgen();
  16. };
  17. objectPathfinderBinaryLog::~objectPathfinderBinaryLog(){
  18. if( m_pFID!= NULL ) fclose( m_pFID );
  19. };
  20. void objectPathfinderBinaryLog::uuidgen(void){
  21. FILE * fp;
  22. char buf[CTEXT];
  23. #ifdef DEBUG
  24. char tBuf[CTEXT];
  25. #endif
  26. const char * file = _PATH_VARDB PACKAGE_NAME ".cache";
  27. fp = fopen(file, "r");
  28. if (!fp) {
  29. fp = fopen(file, "w");
  30. if (!fp){
  31. sprintf( buf, "Cannot create UUID cache, %s: %s", file, strerror(errno));
  32. LOG_ERROR( buf );
  33. };
  34. generate:
  35. srand(time(NULL));
  36. snprintf( buf, 42, "%8.8x-%4.4x-%4.4x-%4.4x-%6.6x%6.6x",
  37. rand() & 0xFFFFFFFF,
  38. rand() & 0xFFFF,
  39. (rand() & 0x0FFF) | 0x4000, /* M 4 MSB version => version 4 */
  40. (rand() & 0x1FFF) | 0x8000, /* N: 3 MSB variant => variant 1 */
  41. rand() & 0xFFFFFF, rand() & 0xFFFFFF
  42. );
  43. if (fp) {
  44. #ifdef DEBUG
  45. sprintf( tBuf, "Creating new UUID cache file, %s", file);
  46. LOG( tBuf );
  47. #endif
  48. fprintf(fp, "%s\n", buf);
  49. fclose(fp);
  50. };
  51. } else {
  52. #ifdef DEBUG
  53. sprintf( tBuf, "Cache file [%s] is Ok", file);
  54. LOG( tBuf );
  55. #endif
  56. if (!fgets(buf, sizeof(buf), fp)) {
  57. fclose(fp);
  58. goto generate;
  59. }
  60. buf[strlen(buf) - 1] = 0;
  61. fclose(fp);
  62. };
  63. strcpy( m_sUUID, buf );
  64. #ifdef DEBUG
  65. sprintf( tBuf, "URN: %s", m_sUUID );
  66. LOG( tBuf );
  67. #endif
  68. };
  69. #undef LOG
  70. #undef LOG_ERROR