GSIErrorCollectionField.cpp

Go to the documentation of this file.
00001 //Copyright GSI 2012
00002 #include <fesa-core-gsi/DataStore/GSIErrorCollectionField.h>
00003 #include <fesa-core/Utilities/Lock.h>
00004 
00005 #include <cmw-log/Logger.h>
00006 
00007 #include <sstream>//to convert the error code to string
00008 #include <sys/time.h>
00009 
00010 namespace
00011 {
00012 
00013 CMW::Log::Logger& logger = CMW::Log::LoggerFactory::getLogger("FESA.FWK.fesa-core-gsi.DataStore.GSIErrorCollectionField");
00014 
00015 } // namespace
00016 
00017 namespace fesaGSI
00018 {
00019         GSIErrorCollectionField::GSIErrorCollectionField(const std::string& fieldName, bool multiplexed, fesa::DataStore* pDataStore, bool persistent, int size)
00020         : fesa::AcqFieldStructArray<GSI_ERROR> (fieldName, multiplexed, pDataStore, persistent, size, fesa::SingleBuffered)
00021         {
00022                 index_ = 0;
00023         }
00024 
00025         GSIErrorCollectionField::~GSIErrorCollectionField()
00026         {
00027         }
00028 
00029         void GSIErrorCollectionField::addError(long error_code, std::string& ErrorMessage, fesa::MultiplexingContext* context, fesa::AbstractDevice* pDev)
00030         {
00031                 unsigned int index;
00032                 {//usage of fesa::lock to automatically release lock after this block
00033                         fesa::Lock lock(mutexIndex_);
00034 
00035                         //we use this field-array as rolling buffer
00036                         index_= index_ % maxSize_;
00037                         index = index_;
00038                 }
00039 
00040                 //The cell we want to overwrite
00041                 GSI_ERROR* temp = const_cast<GSI_ERROR*>(getCell(index,context));
00042 
00043                 for(unsigned int x=0;x<MAX_ERROR_MESSAGE_LENGTH && x< ErrorMessage.size();x++)
00044                         temp->error_string[x]= ErrorMessage[x];
00045 
00046                 std::string cycleName= context->getCycleName();
00047                 for(unsigned int x=0;x<MAX_CYCLE_NAME_LENGTH && x< cycleName.size();x++)
00048                         temp->error_cycle_name[x]= cycleName[x];
00049 
00050                 temp->error_code = error_code;
00051 
00052                 //for logging we as well need the error-code as string
00053                 std::string error_code_as_string;
00054                 std::stringstream tempStream;
00055                 tempStream << error_code;
00056                 tempStream >> error_code_as_string;
00057 
00058                 //get timestamp as char-array (only for fesa, syslog automatically adds stamps)
00059         time_t ltime;
00060         struct tm *Tm;
00061 
00062         ltime=time(NULL);
00063         Tm=localtime(&ltime);
00064 
00065         char temp_stamp[MAX_TIMESTAMP_LENGTH];
00066         sprintf(temp_stamp,"[%d] %d %d %d, %d:%d:%d",
00067                 Tm->tm_wday, /* Mon - Sun */
00068                 Tm->tm_mday,
00069                 Tm->tm_mon+1,
00070                 Tm->tm_year+1900,
00071                 Tm->tm_hour,
00072                 Tm->tm_min,
00073                 Tm->tm_sec);
00074 
00075                 for(unsigned int x=0;x<MAX_TIMESTAMP_LENGTH;x++)
00076                         temp->error_timestamp[x]= temp_stamp[x];
00077 
00078         //log the error
00079         std::ostringstream message;
00080         message << "Error at: [Device]: " << pDev->getName() << " [Cycle:]" << context->getCycleName()
00081                         << " [Error Code:] " << error_code_as_string << " [Error Message:] " << ErrorMessage;
00082                 LOG_ERROR_IF(logger, message.str());
00083 
00084                 setCell(temp, index, context);
00085                 index_++;
00086         }
00087 
00088 } // namespace end
00089 
00090 

Generated on 25 Jan 2013 for fesa-core-gsi by  doxygen 1.6.1