/********************************************************************\ SlowData.cc Class handling the writing of slow data. Strings to be written in the slow data file are checked that they do not contain control characters. 1. Call constructor with desired identification and directory for slow data file. The public ErrorCode variable will be zero if successful, otherwise contain the relevant errno. 2. Use NewEntry() to start a new entry with given variable name. A text as second argument is optional. 3. If text should be added to an open entry, use AddToEntry(). It can process printf()-style formatting. 4. The slow data file will be closed upon destruction of the instance. Oliver Grimm \********************************************************************/ #include "SlowData.h" // // Constructor: Open slow data file (filename generate using current date) // SlowData::SlowData(const char* IssuerName, const char* Direcory) { time_t rawtime; struct tm *timeinfo; char Filename[MAX_PATH]; Issuer = IssuerName; NewEntryCalled = false; InternalCall = false; time(&rawtime); timeinfo = gmtime(&rawtime); if(timeinfo->tm_hour>=13) rawtime += 12*60*60; timeinfo = gmtime(&rawtime); snprintf(Filename, sizeof(Filename), "%s/%s_%d%02d%02d.slow", Direcory, Issuer, timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday); if ((SlowdataFile = fopen(Filename, "a")) == NULL) ErrorCode = errno; else ErrorCode = 0; } // // Destructor // SlowData::~SlowData() { if(SlowdataFile!=NULL) fclose(SlowdataFile); } // // Add a new entry to slow data file // bool SlowData::NewEntry(const char *Variable, const char *Text) { time_t RawTime; struct tm *TM; struct timeval Time; time(&RawTime); TM = localtime(&RawTime); gettimeofday(&Time, NULL); InternalCall = true; NewEntryCalled = AddToEntry("\n%s %s %d %d %d %d %d %d %d %lu ", Issuer, Variable, TM->tm_year+1900,TM->tm_mon+1,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec, Time.tv_usec/1000, Time.tv_sec); InternalCall = false; if(Text != NULL && NewEntryCalled == true) NewEntryCalled = AddToEntry("%s", Text); return NewEntryCalled; } // // Add data to an open entry // bool SlowData::AddToEntry(const char *Format, ...) { char Textbuffer[MAX_ENTRY_SIZE]; va_list ArgumentPointer; if(SlowdataFile==NULL || (!NewEntryCalled && !InternalCall)) return false; va_start(ArgumentPointer, Format); vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer); va_end(ArgumentPointer); if(!InternalCall) for(unsigned int i=0; i