00001
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
00014 this->isShared_ = shared;
00015 }
00016
00017 SettingFieldString::~SettingFieldString() {
00018
00019 }
00020
00021 const char* SettingFieldString::get(MultiplexingContext* context) {
00022
00023 if (context == NULL)
00024 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00025
00026 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00027 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00028 this->name_.c_str());
00029
00030 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00031 : this->multiplexingManager_->getSlot(*context);
00032 FieldValue<char[]>* pFV = this->getFieldValue(slot);
00033
00034 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00035 {
00036
00037 return (const char*) pFV->pendingBuffer((char*) pFV);
00038 }
00039 else
00040 {
00041
00042 return (const char*) pFV->activeBuffer((char*) pFV);
00043 }
00044 }
00045
00046 void SettingFieldString::set(const char* val, MultiplexingContext* context) {
00047
00048 if (context == NULL)
00049 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00050
00051 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00052 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00053 this->name_.c_str());
00054
00055 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00056 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00057 this->name_.c_str());
00058
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
00067 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00068 : this->multiplexingManager_->requireSlot(*context);
00069 FieldValue<char[]>* pFV = this->getFieldValue(slot);
00070
00071 this->resetToBeSync(slot);
00072
00073 std::memcpy(pFV->pendingBuffer((char*) pFV), val, (length+1) * sizeof(char));
00074 this->registerModifiedField(pFV, context);
00075 }
00076
00077
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
00086 this->isShared_ = shared;
00087 }
00088
00089 SettingFieldStringArray::~SettingFieldStringArray() {
00090
00091 }
00092
00093 const char** SettingFieldStringArray::get(uint32_t& size1,
00094 MultiplexingContext* context) {
00095
00096 if (context == NULL)
00097 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00098
00099 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00100 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00101 this->name_.c_str());
00102
00103 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00104 : this->multiplexingManager_->getSlot(*context);
00105 FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00106
00107 size1 = pFV->getActiveCurrentSize();
00108 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00109 {
00110
00111 return (const char**) pointers_[slot][pFV->pendingBuffer()];
00112 }
00113 else
00114 {
00115
00116 return (const char**) pointers_[slot][pFV->activeBuffer()];
00117 }
00118 }
00119
00120 const char* SettingFieldStringArray::getString(uint32_t index,
00121 MultiplexingContext* context) {
00122
00123 if (context == NULL)
00124 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00125
00126 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00127 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00128 this->name_.c_str());
00129
00130 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00131 : this->multiplexingManager_->getSlot(*context);
00132 FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00133
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
00144 return (const char*) pointers_[slot][pFV->pendingBuffer()][index];
00145 }
00146 else
00147 {
00148
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
00156 if (context == NULL)
00157 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00158
00159 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00160 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00161 this->name_.c_str());
00162
00163 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00164 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00165 this->name_.c_str());
00166
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
00181 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00182 : this->multiplexingManager_->requireSlot(*context);
00183 FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00184
00185 this->resetToBeSync(slot);
00186
00187
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
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
00201 if (context == NULL)
00202 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00203
00204 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00205 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00206 this->name_.c_str());
00207
00208 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00209 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00210 this->name_.c_str());
00211
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
00223 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00224 : this->multiplexingManager_->requireSlot(*context);
00225 FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00226
00227 this->resetToBeSync(slot);
00228
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
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
00246
00247 }
00248