SettingField.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/DataStore/SettingField.h>
00004 
00005 
00006 namespace fesa
00007 {
00008 
00009 SettingFieldString::SettingFieldString(const std::string& fieldName, bool multiplexed, bool multiMultiplexed,
00010                                        DataStore* pDataStore, bool isPersistent, bool shared, int32_t size, const DataIntegrity bufferType) :
00011     FieldString(fieldName, Setting, multiplexed, multiMultiplexed, isPersistent, bufferType, pDataStore, size)
00012 {
00013     // Set properly the attribute isShared
00014     this->isShared_ = shared;
00015 }
00016 
00017 SettingFieldString::~SettingFieldString() {
00018 
00019 }
00020 
00021 const char* SettingFieldString::get(MultiplexingContext* context) {
00022     // throw exception in case of NULL pointer
00023     if (context == NULL)
00024         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00025     // throw exception in case of NoneContext and multiplexed field.
00026     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00027         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00028                             this->name_.c_str());
00029     // Retrieve the right FieldValue according to the slot
00030     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00031         : this->multiplexingManager_->getSlot(*context);
00032     FieldValue<char[]>* pFV = this->getFieldValue(slot);
00033     // Return the value from the Active buffer
00034     if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00035     {
00036         // Value from the pending buffer
00037         return (const char*) pFV->pendingBuffer((char*) pFV);
00038     }
00039     else
00040     {
00041         // Value from the active buffer
00042         return (const char*) pFV->activeBuffer((char*) pFV);
00043     }
00044 }
00045 
00046 void SettingFieldString::set(const char* val, MultiplexingContext* context) {
00047     // throw exception in case of NULL pointer
00048     if (context == NULL)
00049         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00050     // throw exception in case of NoneContext and multiplexed field.
00051     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00052         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00053                             this->name_.c_str());
00054     // Check if the set is allowed
00055     if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00056         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00057                             this->name_.c_str());
00058     // Check against Max dimensions. Exception is thrown in case of out of bound
00059     uint32_t length = static_cast<uint32_t>(strlen(val));
00060     if (length > this->maxSize_) {
00061         throw FesaException(__FILE__, __LINE__,
00062                             FesaErrorFieldMaxDimensionOutOfBound.c_str(),
00063                             StringUtilities::toString(length).c_str(), this->name_.c_str(),
00064                             StringUtilities::toString(maxSize_).c_str());
00065     }
00066     // Retrieve the right FieldValue according to the slot
00067     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00068         : this->multiplexingManager_->requireSlot(*context);
00069     FieldValue<char[]>* pFV = this->getFieldValue(slot);
00070     // reset toBeSync flag of the field value
00071     this->resetToBeSync(slot);
00072     // Set the pending buffer including teh null character(length+1)
00073     std::memcpy(pFV->pendingBuffer((char*) pFV), val, (length+1) * sizeof(char));
00074     this->registerModifiedField(pFV, context);
00075 }
00076 
00077 /**************************** END CLASS SettingFieldString **********************/
00078 
00079 SettingFieldStringArray::SettingFieldStringArray(const std::string& fieldName,
00080                                                  bool multiplexed, bool multiMultiplexed, DataStore* pDataStore,
00081                                                  bool isPersistent, bool shared, int32_t size1, int32_t size2,
00082                                                  const DataIntegrity bufferType) :
00083     FieldStringArray(fieldName, Setting, multiplexed, multiMultiplexed,
00084                      isPersistent, bufferType, pDataStore, size1, size2) {
00085     // Set properly the attribute isShared
00086     this->isShared_ = shared;
00087 }
00088 
00089 SettingFieldStringArray::~SettingFieldStringArray() {
00090 
00091 }
00092 
00093 const char** SettingFieldStringArray::get(uint32_t& size1,
00094                                           MultiplexingContext* context) {
00095     // throw exception in case of NULL pointer
00096     if (context == NULL)
00097         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00098     // throw exception in case of NoneContext and multiplexed field.
00099     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00100         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00101                             this->name_.c_str());
00102     // Retrieve the right FieldValue according to the slot
00103     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00104         : this->multiplexingManager_->getSlot(*context);
00105     FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00106     // Return the current size get from the Active buffer
00107     size1 = pFV->getActiveCurrentSize();
00108     if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00109     {
00110         // Value from the pending buffer
00111         return (const char**) pointers_[slot][pFV->pendingBuffer()];
00112     }
00113     else
00114     {
00115         // Value from the active buffer
00116         return (const char**) pointers_[slot][pFV->activeBuffer()];
00117     }
00118 }
00119 
00120 const char* SettingFieldStringArray::getString(uint32_t index,
00121                                                MultiplexingContext* context) {
00122     // throw exception in case of NULL pointer
00123     if (context == NULL)
00124         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00125     // throw exception in case of NoneContext and multiplexed field.
00126     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00127         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00128                             this->name_.c_str());
00129     // Retrieve the right FieldValue according to the slot
00130     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00131         : this->multiplexingManager_->getSlot(*context);
00132     FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00133     // Check against dynamic dimensions. Exception is thrown in case of out of bound
00134     uint32_t size = pFV->getActiveCurrentSize();
00135     if ((index+1) > size) {
00136         throw FesaException(__FILE__, __LINE__,
00137                             FesaErrorFieldCurrentDimensionOutOfBound.c_str(),
00138                             StringUtilities::toString(index).c_str(), this->name_.c_str(),
00139                             StringUtilities::toString(size).c_str());
00140     }
00141     if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00142     {
00143         // Value from the pending buffer
00144         return (const char*) pointers_[slot][pFV->pendingBuffer()][index];
00145     }
00146     else
00147     {
00148         // Value from the active buffer
00149         return (const char*) pointers_[slot][pFV->activeBuffer()][index];
00150     }
00151 }
00152 
00153 void SettingFieldStringArray::set(const char ** val, uint32_t size1,
00154                                   MultiplexingContext* context) {
00155     // throw exception in case of NULL pointer
00156     if (context == NULL)
00157         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00158     // throw exception in case of NoneContext and multiplexed field.
00159     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00160         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00161                             this->name_.c_str());
00162     // Check if the set is allowed
00163     if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00164         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00165                             this->name_.c_str());
00166     // Check against Max dimensions. Exception is thrown in case of out of bound
00167     uint32_t maxLength = 0;
00168     for (uint32_t i = 0; i < size1; i++) {
00169         maxLength = (strlen(val[i])>maxLength) ? static_cast<uint32_t>(strlen(val[i])) : maxLength;
00170     }
00171     if ((size1) > maxSize1_ || maxLength > maxSize2_) {
00172         throw FesaException(__FILE__, __LINE__,
00173                             FesaErrorFieldMaxDimensionsOutOfBound.c_str(),
00174                             StringUtilities::toString(size1).c_str(),
00175                             StringUtilities::toString(maxLength).c_str(),
00176                             this->name_.c_str(),
00177                             StringUtilities::toString(maxSize1_).c_str(),
00178                             StringUtilities::toString(maxSize2_).c_str());
00179     }
00180     // Retrieve the right FieldValue according to the slot
00181     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00182         : this->multiplexingManager_->requireSlot(*context);
00183     FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00184     // reset toBeSync flag of the field value
00185     this->resetToBeSync(slot);
00186     // Set the pending buffer and pending dynamic size.
00187     // Register the field to be committed or rolled-back.
00188     pFV->setPendingCurrentSize(size1);
00189     for (uint32_t i = 0; i < size1; i++) {
00190         uint32_t length = static_cast<uint32_t>(strlen(val[i]));
00191         // copy the string including the null character(length+1)
00192         std::memcpy(pointers_[slot][pFV->pendingBuffer()][i], val[i],
00193                (length+1) * sizeof(char));
00194     }
00195     this->registerModifiedField(pFV, context);
00196 }
00197 
00198 void SettingFieldStringArray::setString(const char* val, uint32_t index,
00199                                         MultiplexingContext* context) {
00200     // throw exception in case of NULL pointer
00201     if (context == NULL)
00202         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00203     // throw exception in case of NoneContext and multiplexed field.
00204     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00205         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00206                             this->name_.c_str());
00207     // Check if the set is allowed
00208     if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00209         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00210                             this->name_.c_str());
00211     // Check against Max dimensions. Exception is thrown in case of out of bound
00212     uint32_t length = static_cast<uint32_t>(strlen(val));
00213     if ((index+1) > maxSize1_ || length > maxSize2_) {
00214         throw FesaException(__FILE__, __LINE__,
00215                             FesaErrorFieldMaxDimensionsOutOfBound.c_str(),
00216                             StringUtilities::toString(index+1).c_str(),
00217                             StringUtilities::toString(length).c_str(),
00218                             this->name_.c_str(),
00219                             StringUtilities::toString(maxSize1_).c_str(),
00220                             StringUtilities::toString(maxSize2_).c_str());
00221     }
00222     // Retrieve the right FieldValue according to the slot
00223     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00224         : this->multiplexingManager_->requireSlot(*context);
00225     FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00226     // reset toBeSync flag of the field value
00227     this->resetToBeSync(slot);
00228     // Partial setting method. First set, synchronize pending with active
00229     if (!pFV->hasPendingChanged()) {
00230         uint32_t size = pFV->getActiveCurrentSize();
00231         pFV->setPendingCurrentSize(size);
00232         std::memcpy(pointers_[slot][pFV->pendingBuffer()][0],
00233                pointers_[slot][pFV->activeBuffer()][0],
00234                this->maxSize1_ * (this->maxSize2_ + 1) * sizeof(char));
00235     }
00236     // Adjust the dynamic dimension if it's required
00237     uint32_t size = pFV->getPendingCurrentSize();
00238     if ((index + 1) > size)
00239         pFV->setPendingCurrentSize(index+1);
00240     std::memcpy(pointers_[slot][pFV->pendingBuffer()][index], val, (length+1)
00241            * sizeof(char));
00242     this->registerModifiedField(pFV, context);
00243 }
00244 
00245 /**************************** END CLASS FieldStringArray **********************/
00246 
00247 } // fesa
00248 

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1