X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fsimulator%2Fsrc%2Fsimulator_resource_model.cpp;h=ce20a9d1a3d912cdb72cfa05b3647feb230dc264;hb=0749b9bdfb5f2bfbbbd7d5b122eaf3941ed64af0;hp=a059226d657ba3680e604e2f096a6ed02e9b438b;hpb=f0c4c484ab464a63590ce3abcf7aac89dd257987;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/simulator/src/simulator_resource_model.cpp b/service/simulator/src/simulator_resource_model.cpp index a059226..ce20a9d 100644 --- a/service/simulator/src/simulator_resource_model.cpp +++ b/service/simulator/src/simulator_resource_model.cpp @@ -100,28 +100,6 @@ class range_validation : public boost::static_visitor SimulatorResourceModel::Attribute &m_attrItem; }; -class Converter -{ - public: - void convert(const OC::OCRepresentation::AttributeItem &attrItem) - { - if (attrItem.type() == OC::AttributeType::Integer) - m_attribute.setValue(attrItem.getValue()); - if (attrItem.type() == OC::AttributeType::Double) - m_attribute.setValue(attrItem.getValue()); - if (attrItem.type() == OC::AttributeType::String) - m_attribute.setValue(attrItem.getValue()); - } - - SimulatorResourceModel::Attribute &&get() - { - return std::move(m_attribute); - } - - private: - SimulatorResourceModel::Attribute m_attribute; -}; - SimulatorResourceModel::Attribute::ValueVariant &SimulatorResourceModel::Attribute::AllowedValues::at(int index) { @@ -213,7 +191,7 @@ std::vector SimulatorResourceModel::Attribute::allowedValuesToVecto } void SimulatorResourceModel::Attribute::addValuetoRepresentation(OC::OCRepresentation &rep, - const std::string &key) + const std::string &key) const { add_to_representation visitor(rep, key); boost::apply_visitor(visitor, m_value); @@ -281,7 +259,7 @@ void SimulatorResourceModel::removeAttribute(const std::string &attrName) return; } -OC::OCRepresentation SimulatorResourceModel::getOCRepresentation() +OC::OCRepresentation SimulatorResourceModel::getOCRepresentation() const { OC::OCRepresentation rep; for (auto & attribute : m_attributes) @@ -292,70 +270,57 @@ OC::OCRepresentation SimulatorResourceModel::getOCRepresentation() return rep; } -bool SimulatorResourceModel::update(OC::OCRepresentation &ocRep, UpdateType type) +bool SimulatorResourceModel::update(OC::OCRepresentation &ocRep) { if (0 == ocRep.size()) return true; // Convert OCRepresentation to SimulatorResourceModel - SimulatorResourceModel resModel; - for (auto & attributeItem : ocRep) - { - Converter converter; - converter.convert(attributeItem); - SimulatorResourceModel::Attribute attribute = converter.get(); - attribute.setName(attributeItem.attrname()); - resModel.m_attributes[attributeItem.attrname()] = attribute; - } + SimulatorResourceModel resModel = create(ocRep); - return update(resModel, type); + return update(resModel); } -bool SimulatorResourceModel::update(SimulatorResourceModel &repModel, UpdateType type) +bool SimulatorResourceModel::update(SimulatorResourceModel &repModel) { std::map attributes = repModel.getAttributes(); for (auto & attributeItem : attributes) { // Check the attribute presence SimulatorResourceModel::Attribute attribute; - if (type == PUT) - { - if (false == getAttribute((attributeItem.second).getName(), attribute)) - { - return false; - } - - // Check the validity of the value to be set - if (false == attribute.compare(attributeItem.second)) - { - return false; - } - m_attributes[(attributeItem.second).getName()].setValue((attributeItem.second).getValue()); - } - else if (type == POST) + if (false == getAttribute((attributeItem.second).getName(), attribute)) { - if (false == getAttribute((attributeItem.second).getName(), attribute)) - { - addAttribute(((attributeItem.second).getName()) , ((attributeItem.second).getValue())); - continue; - } - else - { - // Check the validity of the value to be set - if (false == attribute.compare(attributeItem.second)) - { - return false; - } - m_attributes[(attributeItem.second).getName()].setValue((attributeItem.second).getValue()); - } + return false; } - else if (type == DELETE ) + + // Check the validity of the value to be set + if (false == attribute.compare(attributeItem.second)) { - if (true == getAttribute((attributeItem.second).getName(), attribute)) - { - removeAttribute((attributeItem.second).getName()); - } + return false; } + m_attributes[(attributeItem.second).getName()].setValue((attributeItem.second).getValue()); } + return true; -} \ No newline at end of file +} + +SimulatorResourceModel SimulatorResourceModel::create(const OC::OCRepresentation &ocRep) +{ + SimulatorResourceModel resModel; + for (auto & attributeItem : ocRep) + { + SimulatorResourceModel::Attribute attribute; + if (attributeItem.type() == OC::AttributeType::Integer) + attribute.setValue(attributeItem.getValue()); + if (attributeItem.type() == OC::AttributeType::Double) + attribute.setValue(attributeItem.getValue()); + if (attributeItem.type() == OC::AttributeType::String) + attribute.setValue(attributeItem.getValue()); + + attribute.setName(attributeItem.attrname()); + resModel.m_attributes[attributeItem.attrname()] = attribute; + } + + return resModel; +} +