00001
00002 #ifndef ALARM_FIELD_H_
00003 #define ALARM_FIELD_H_
00004
00005 #include <fesa-core/DataStore/FaultField.h>
00006 #include <fesa-core-gsi/DataStore/TypeDefinition.h>
00007 #include <fesa-core/Exception/FesaException.h>
00008 #include <fesa-core-gsi/Exception/GSIException.h>
00009 #include <fesa-core-gsi/DataStore/ConverterAlarmField.h>
00010
00011 namespace fesaGSI
00012 {
00013
00019 template<typename AlarmDataType, unsigned int userKeyNb>
00020 class AlarmField: public fesa::FaultField<AlarmDataType>
00021 {
00022 public:
00023
00028 AlarmField(const std::string& name, bool multiplexed, fesa::DataStore* pDataStore,
00029 const std::string& description, fesa::FaultSeverity severity,
00030 const char** userKeyNames = 0);
00031
00035 ~AlarmField();
00036
00045 const char** getUserKeyNames(unsigned int& size, fesa::MultiplexingContext* pCtx);
00046
00056 const char** getUserKeyValues(unsigned int& size, fesa::MultiplexingContext* pCtx);
00057
00065 const char* getUserKeyValue(const char* userKeyName, fesa::MultiplexingContext* pCtx);
00066
00075 void setUserKeyValue(const char* userKeyName, const char* userKeyValue, fesa::MultiplexingContext* pCtx);
00076
00082 void lower(long long time, fesa::MultiplexingContext* pCtx);
00083
00089 void lower(fesa::MultiplexingContext* pCtx);
00090
00091 protected:
00092 char userKeyNameCol_[userKeyNb][KEY_VALUE_MAXSIZE];
00093 char** pUserKeyNameCol_;
00094 char* pUserKeyName_[userKeyNb];
00095
00096 void cleanAlarmMessages(fesa::MultiplexingContext* pCtx);
00097
00098 };
00099
00100 template<typename AlarmDataType, unsigned int userKeyNb>
00101 AlarmField<AlarmDataType, userKeyNb>::AlarmField(const std::string& name, bool multiplexed,
00102 fesa::DataStore* pDataStore, const std::string& description, fesa::FaultSeverity severity,
00103 const char** userKeyNames) :
00104 fesa::FaultField<AlarmDataType>(name, multiplexed, pDataStore, description, severity)
00105 {
00106 memset(userKeyNameCol_, '\0', (userKeyNb*KEY_VALUE_MAXSIZE));
00107 pUserKeyNameCol_ = &pUserKeyName_[0];
00108 for (unsigned int i = 0; i < userKeyNb; i++)
00109 {
00110 pUserKeyName_[i] = userKeyNameCol_[i];
00111 strcpy(userKeyNameCol_[i],userKeyNames[i]);
00112 }
00113 }
00114
00115 template<typename AlarmDataType, unsigned int userKeyNb>
00116 AlarmField<AlarmDataType, userKeyNb>::~AlarmField()
00117 {
00118
00119 }
00120
00121 template<typename AlarmDataType, unsigned int userKeyNb>
00122 const char** AlarmField<AlarmDataType, userKeyNb>::getUserKeyNames(unsigned int& size,
00123 fesa::MultiplexingContext* pCtx)
00124 {
00125 size = userKeyNb;
00126 return (const char**) pUserKeyNameCol_;
00127 }
00128
00129 template<typename AlarmDataType, unsigned int userKeyNb>
00130 const char** AlarmField<AlarmDataType, userKeyNb>::getUserKeyValues(unsigned int& size,
00131 fesa::MultiplexingContext* pCtx)
00132 {
00133 if (userKeyNb == 0)
00134 {
00135 throw GSIException(__FILE__, __LINE__,FesaGSIErrorAlarmFieldEmptyKeyValues.c_str());
00136 }
00137 size = userKeyNb;
00138 unsigned int slot = (this->multiplexingManager_ == NULL) ? 0 : this->multiplexingManager_->requireSlot(*pCtx);
00139 return ((const char**) this->getFieldValue(slot)->activeBuffer().pUserKeyValueCol_);
00140 }
00141
00142 template<typename AlarmDataType, unsigned int userKeyNb>
00143 const char* AlarmField<AlarmDataType, userKeyNb>::getUserKeyValue(const char* userKeyName,
00144 fesa::MultiplexingContext* pCtx)
00145 {
00146 if (userKeyNb == 0)
00147 {
00148 throw GSIException(__FILE__, __LINE__,FesaGSIErrorAlarmFieldEmptyKeyValues.c_str());
00149 }
00150 unsigned int i;
00151 for (i = 0; i < userKeyNb; i++)
00152 {
00153 if(!strcmp(userKeyNameCol_[i], userKeyName))
00154 {
00155 break;
00156 }
00157 }
00158 if (i == userKeyNb)
00159 {
00160 throw GSIException(__FILE__, __LINE__,FesaGSIErrorAlarmFieldKeyNameNotFound.c_str());
00161 }
00162 unsigned int slot = (this->multiplexingManager_ == NULL) ? 0 : this->multiplexingManager_->requireSlot(*pCtx);
00163 return ((const char*) this->getFieldValue(slot)->activeBuffer().userKeyValueCol_[i]);
00164 }
00165
00166 template<typename AlarmDataType, unsigned int userKeyNb>
00167 void AlarmField<AlarmDataType, userKeyNb>::setUserKeyValue(const char* userKeyName, const char* userKeyValue,
00168 fesa::MultiplexingContext* pCtx)
00169 {
00170 if (strlen(userKeyName) > KEY_VALUE_MAXSIZE)
00171 {
00172 throw GSIException(__FILE__, __LINE__,FesaGSIErrorAlarmFieldKeyNameExceedsMaxSize.c_str());
00173 }
00174 unsigned int i;
00175 for (i = 0; i < userKeyNb; i++)
00176 {
00177 if(!strcmp(userKeyNameCol_[i], userKeyName))
00178 {
00179 break;
00180 }
00181 }
00182 if (i == userKeyNb)
00183 {
00184 throw GSIException(__FILE__, __LINE__,FesaGSIErrorAlarmFieldKeyNameNotFound.c_str());
00185 }
00186 unsigned int slot = (this->multiplexingManager_ == NULL) ? 0 : this->multiplexingManager_->requireSlot(*pCtx);
00187 AlarmField_DataType<userKeyNb>* pActiveBuffer = &(this->getFieldValue(slot)->activeBuffer());
00188 strcpy(pActiveBuffer->userKeyValueCol_[i], userKeyValue);
00189 }
00190
00191 template<typename AlarmDataType, unsigned int userKeyNb>
00192 void AlarmField<AlarmDataType, userKeyNb>::lower(long long time, fesa::MultiplexingContext* pCtx)
00193 {
00194 cleanAlarmMessages(pCtx);
00195 fesa::FaultField<AlarmDataType>::lower(time, pCtx);
00196 }
00197
00198 template<typename AlarmDataType, unsigned int userKeyNb>
00199 void AlarmField<AlarmDataType, userKeyNb>::lower(fesa::MultiplexingContext* pCtx)
00200 {
00201 cleanAlarmMessages(pCtx);
00202 fesa::FaultField<AlarmDataType>::lower(pCtx);
00203 }
00204
00205 template<typename AlarmDataType, unsigned int userKeyNb>
00206 void AlarmField<AlarmDataType, userKeyNb>::cleanAlarmMessages(fesa::MultiplexingContext* pCtx)
00207 {
00208 unsigned int slot = (this->multiplexingManager_ == NULL) ? 0 : this->multiplexingManager_->requireSlot(*pCtx);
00209
00210 char* addr = (char*)this->getFieldValue(slot);
00211
00212 AlarmField_DataType<userKeyNb>* pActiveBuffer = &(this->getFieldValue(slot)->activeBuffer(addr));
00213 for (unsigned int i = 0; i < userKeyNb; i++)
00214 {
00215 pActiveBuffer->userKeyValueCol_[i][0] = '\0';
00216 }
00217 }
00218
00219 }
00220
00221
00222 #endif