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

#include "objectPathfinderBinaryLog.h"
#define LOG( X ) m_pLog->Log( "BILO", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "BILO", this, _LOG_ERROR, X )
#define PACKAGE_NAME "PATHFINDER_BIN_LOG"
objectPathfinderBinaryLog *objectPathfinderBinaryLog::_instance = NULL;
objectPathfinderBinaryLog *objectPathfinderBinaryLog::getInstance(){
if( _instance == NULL ){
_instance = new objectPathfinderBinaryLog();
};
return _instance;
};
objectPathfinderBinaryLog::objectPathfinderBinaryLog(){
m_pLog = basicLogCollection::getInstance();
m_pFID = NULL;
uuidgen();
};
objectPathfinderBinaryLog::~objectPathfinderBinaryLog(){
if( m_pFID!= NULL ) fclose( m_pFID );
};
void objectPathfinderBinaryLog::uuidgen(void){
FILE * fp;
char buf[CTEXT];
#ifdef DEBUG
char tBuf[CTEXT];
#endif
const char * file = _PATH_VARDB PACKAGE_NAME ".cache";
fp = fopen(file, "r");
if (!fp) {
fp = fopen(file, "w");
if (!fp){
sprintf( buf, "Cannot create UUID cache, %s: %s", file, strerror(errno));
LOG_ERROR( buf );
};
generate:
srand(time(NULL));
snprintf( buf, 42, "%8.8x-%4.4x-%4.4x-%4.4x-%6.6x%6.6x",
rand() & 0xFFFFFFFF,
rand() & 0xFFFF,
(rand() & 0x0FFF) | 0x4000, /* M 4 MSB version => version 4 */
(rand() & 0x1FFF) | 0x8000, /* N: 3 MSB variant => variant 1 */
rand() & 0xFFFFFF, rand() & 0xFFFFFF
);
if (fp) {
#ifdef DEBUG
sprintf( tBuf, "Creating new UUID cache file, %s", file);
LOG( tBuf );
#endif
fprintf(fp, "%s\n", buf);
fclose(fp);
};
} else {
#ifdef DEBUG
sprintf( tBuf, "Cache file [%s] is Ok", file);
LOG( tBuf );
#endif
if (!fgets(buf, sizeof(buf), fp)) {
fclose(fp);
goto generate;
}
buf[strlen(buf) - 1] = 0;
fclose(fp);
};
strcpy( m_sUUID, buf );
#ifdef DEBUG
sprintf( tBuf, "URN: %s", m_sUUID );
LOG( tBuf );
#endif
};
#undef LOG
#undef LOG_ERROR