FaultField.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef FAULT_FIELD_H_
00004 #define FAULT_FIELD_H_
00005 
00006 #include <fesa-core/DataStore/GenericField.h>
00007 #include <fesa-core/DataStore/AbstractFaultField.h>
00008 #include <fesa-core/DataStore/TypeDefinition.h>
00009 
00010 #include <string>
00011 #include <sys/time.h>
00012 
00013 namespace fesa
00014 {
00015 
00023 template<typename DataType>
00024 class FaultField  : protected GenericFieldStruct<DataType>, virtual AbstractFaultField
00025 {
00026   public:
00031     FaultField(const std::string& name, bool multiplexed, DataStore* pDataStore,
00032                const std::string& description, FaultSeverity severity);
00033 
00037     ~FaultField();
00038 
00050     void raise(int64_t time, MultiplexingContext* pCtx, int32_t errorCode = 0);
00051 
00062     void raise(MultiplexingContext* pCtx, int32_t errorCode = 0);
00063 
00069     virtual void lower(int64_t time, MultiplexingContext* pCtx);
00070 
00076     virtual void lower(MultiplexingContext* pCtx);
00077 
00083     bool isRaised(MultiplexingContext* pCtxt);
00084 
00089     FaultSeverity getSeverity();
00090 
00096     int64_t getTimestamp(MultiplexingContext* pCtxt);
00097 
00098     std::string getDescription();
00099 
00100   private:
00101 
00102     int64_t getActualTime();
00103 
00107     std::string description_;
00108 
00112     FaultSeverity severity_;
00113 
00114 };
00115 
00116 template<typename DataType>
00117 FaultField<DataType>::FaultField(const std::string& name, bool multiplexed, DataStore* pDataStore,
00118                                  const std::string& description, FaultSeverity severity) :
00119     GenericFieldStruct<DataType> (name, multiplexed,pDataStore,false,SingleBuffered), description_(description),
00120     severity_(severity)
00121    // AbstractFaultField(name, multiplexed, pDataStore, description, severity)
00122 {
00123 
00124 }
00125 
00126 template<typename DataType>
00127 FaultField<DataType>::~FaultField()
00128 {
00129 
00130 }
00131 
00132 template<typename DataType>
00133 void FaultField<DataType>::raise(int64_t time, MultiplexingContext* pCtx, int32_t errorCode)
00134 {
00135     if (!isRaised(pCtx))
00136     {
00137         uint32_t slot = (this->multiplexingManager_ == NULL) ? 0 : this->multiplexingManager_->requireSlot(*pCtx);
00138 
00139         char* address = (char*)this->getFieldValue(slot);
00140 
00141         FaultField_DataType* pActiveBuffer = &(this->getFieldValue(slot)->activeBuffer(address));
00142         pActiveBuffer->state_ = true;
00143         pActiveBuffer->timestamp_ = time;
00144         pActiveBuffer->errorCode_ = errorCode;
00145 
00146         this->commit(slot);
00147     }
00148 }
00149 
00150 template<typename DataType>
00151 void FaultField<DataType>::raise(MultiplexingContext* pCtx, int32_t errorCode)
00152 {
00153     if (!isRaised(pCtx))
00154     {
00155         int64_t time = getActualTime();
00156         raise(time, pCtx);
00157     }
00158 }
00159 
00160 template<typename DataType>
00161 void FaultField<DataType>::lower(int64_t time, MultiplexingContext* pCtx)
00162 {
00163     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0 : this->multiplexingManager_->requireSlot(*pCtx);
00164     char* address = (char*)this->getFieldValue(slot);
00165     FaultField_DataType* pActiveBuffer = &(this->getFieldValue(slot)->activeBuffer(address));
00166     pActiveBuffer->state_ = false;
00167     pActiveBuffer->timestamp_ = time;
00168 
00169     this->commit(slot);
00170 }
00171 
00172 template<typename DataType>
00173 void FaultField<DataType>::lower(MultiplexingContext* pCtx)
00174 {
00175     int64_t time = getActualTime();
00176     lower(time, pCtx);
00177 }
00178 
00179 template<typename DataType>
00180 bool FaultField<DataType>::isRaised(MultiplexingContext* pCtx)
00181 {
00182     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0 : this->multiplexingManager_->requireSlot(*pCtx);
00183     char* addr = (char*)this->getFieldValue(slot);
00184     return (this->getFieldValue(slot)->activeBuffer(addr).state_);
00185 }
00186 
00187 template<typename DataType>
00188 FaultSeverity FaultField<DataType>::getSeverity()
00189 {
00190     return severity_;
00191 }
00192 
00193 template<typename DataType>
00194 int64_t FaultField<DataType>::getTimestamp(MultiplexingContext* pCtx)
00195 {
00196     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0 : this->multiplexingManager_->requireSlot(*pCtx);
00197     char* addr = (char*)this->getFieldValue(slot);
00198     return (this->getFieldValue(slot)->activeBuffer(addr).timestamp_);
00199 }
00200 
00201 template<typename DataType>
00202 int64_t FaultField<DataType>::getActualTime()
00203 {
00204     struct timeval now;
00205     gettimeofday(&now, 0);
00206     return (now.tv_sec * (int64_t) 1000000000 + now.tv_usec * (int64_t) 1000);
00207 }
00208 
00209 template<typename DataType>
00210 std::string FaultField<DataType>::getDescription()
00211 {
00212     return description_;
00213 }
00214 
00215 } // fesa
00216 
00217 #endif // FAULT_FIELD_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1