From: Harish Kumara Marappa Date: Mon, 16 Nov 2015 15:48:55 +0000 (+0530) Subject: Fixed issue of invalid value gets update even if attribute has allowed values property. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04639fe70654bc2e20760015abc90727557a512f;p=contrib%2Fiotivity.git Fixed issue of invalid value gets update even if attribute has allowed values property. Other issues fixed: 1. Crash while editing resource properties when attribute's update automation is going on. 2. Update automation starts from previous state when resource is deleted and created with same properties as deleted one. Change-Id: I0ab53a1ebc4b03fd4e7d281fed612ba1c1709268 Signed-off-by: Harish Kumara Marappa Reviewed-on: https://gerrit.iotivity.org/gerrit/4231 Tested-by: jenkins-iotivity Reviewed-by: RadhaBhavani Reviewed-by: Madan Lanka --- diff --git a/service/simulator/java/jni/simulator_single_resource_jni.cpp b/service/simulator/java/jni/simulator_single_resource_jni.cpp index 638f816..81b113c 100644 --- a/service/simulator/java/jni/simulator_single_resource_jni.cpp +++ b/service/simulator/java/jni/simulator_single_resource_jni.cpp @@ -156,7 +156,7 @@ Java_org_oic_simulator_server_SimulatorSingleResource_removeAttribute JNIEXPORT jint JNICALL Java_org_oic_simulator_server_SimulatorSingleResource_startResourceUpdation -(JNIEnv *env, jobject object, jint type, jint interval, jobject listener) +(JNIEnv *env, jobject object, jobject type, jint interval, jobject listener) { VALIDATE_CALLBACK_RET(env, listener, -1) @@ -171,8 +171,8 @@ Java_org_oic_simulator_server_SimulatorSingleResource_startResourceUpdation try { - int id = singleResource->startResourceUpdation((1 == type) ? AutomationType::RECURRENT : - AutomationType::NORMAL, interval, callback); + AutomationType automationType = AutomationTypeToCpp(env, type); + int id = singleResource->startResourceUpdation(automationType, interval, callback); return id; } catch (InvalidArgsException &e) diff --git a/service/simulator/src/common/simulator_resource_model.cpp b/service/simulator/src/common/simulator_resource_model.cpp index f309ec4..bb44646 100644 --- a/service/simulator/src/common/simulator_resource_model.cpp +++ b/service/simulator/src/common/simulator_resource_model.cpp @@ -385,7 +385,8 @@ class SimulatorResourceModelBuilder std::vector>> ocSubRepArray = ocAttribute.getValue>>>(); - std::vector>> subResModelArray(ocSubRepArray.size()); + std::vector>> subResModelArray( + ocSubRepArray.size()); for (size_t i = 0; i < ocSubRepArray.size(); i++) { std::vector> innerArray1(ocSubRepArray[i].size()); @@ -785,7 +786,8 @@ void SimulatorResourceModel::AttributeProperty::setChildProperty(AttributeProper m_childProperty.reset(new SimulatorResourceModel::AttributeProperty(childProperty)); } -std::shared_ptr SimulatorResourceModel::AttributeProperty::getChildProperty() +std::shared_ptr +SimulatorResourceModel::AttributeProperty::getChildProperty() { return m_childProperty; } @@ -1092,7 +1094,8 @@ bool SimulatorResourceModel::match(const SimulatorResourceModel &resModel, bool && SimulatorResourceModel::AttributeProperty::Type::UNKNOWN != prop.type()) { RangeValidator rangeValidator(prop); - return boost::apply_visitor(rangeValidator, element.second); + if (false == boost::apply_visitor(rangeValidator, element.second)) + return false; } } diff --git a/service/simulator/src/server/resource_update_automation.cpp b/service/simulator/src/server/resource_update_automation.cpp index 766d42f..6c6f863 100644 --- a/service/simulator/src/server/resource_update_automation.cpp +++ b/service/simulator/src/server/resource_update_automation.cpp @@ -171,6 +171,11 @@ void ResourceUpdateAutomation::updateAttributes( } while (!m_stopRequested && AutomationType::RECURRENT == m_type); + if (!m_stopRequested) + { + SIM_LOG(ILogger::INFO, "Resource update automation complete [id: " << m_id << "]"); + } + // Notify application if (m_callback) m_callback(m_resource->getURI(), m_id); diff --git a/service/simulator/src/server/simulator_collection_resource_impl.cpp b/service/simulator/src/server/simulator_collection_resource_impl.cpp index ef74e41..ff673fd 100755 --- a/service/simulator/src/server/simulator_collection_resource_impl.cpp +++ b/service/simulator/src/server/simulator_collection_resource_impl.cpp @@ -523,7 +523,8 @@ void SimulatorCollectionResourceImpl::addLink(SimulatorResourceSP &resource) // Add OIC Link if it is not present bool found = false; - std::vector links = m_resModel.get>("links"); + std::vector links = + m_resModel.get>("links"); for (auto &link : links) { std::string linkURI = link.get("href"); @@ -548,13 +549,14 @@ void SimulatorCollectionResourceImpl::removeLink(std::string uri) return; // Add OIC Link if it is not present - std::vector links = m_resModel.get>("links"); + std::vector links = + m_resModel.get>("links"); for (size_t i = 0; i < links.size(); i++) { std::string linkURI = links[i].get("href"); if (linkURI == uri) { - links.erase(links.begin()+i); + links.erase(links.begin() + i); m_resModel.updateValue("links", links); break; } diff --git a/service/simulator/src/server/simulator_resource_factory.cpp b/service/simulator/src/server/simulator_resource_factory.cpp index 4a20e3d..2c862ed 100644 --- a/service/simulator/src/server/simulator_resource_factory.cpp +++ b/service/simulator/src/server/simulator_resource_factory.cpp @@ -239,7 +239,8 @@ RAML::RequestResponseBodyPtr SimulatorResourceFactory::getRAMLResponseBody( } SimulatorResourceModel SimulatorResourceFactory::buildModelFromResponseBody( - RAML::RequestResponseBodyPtr responseBody, std::string &resourceType, std::vector &interfaceType) + RAML::RequestResponseBodyPtr responseBody, std::string &resourceType, + std::vector &interfaceType) { SimulatorResourceModel resModel; @@ -332,18 +333,18 @@ std::shared_ptr SimulatorResourceFactory::buildResource( uri = ramlResource->getResourceUri(); RAML::RequestResponseBodyPtr successResponseBody = getRAMLResponseBody( - ramlResource, RAML::ActionType::GET, "200"); + ramlResource, RAML::ActionType::GET, "200"); RAML::RequestResponseBodyPtr putErrorResponseBody = getRAMLResponseBody( - ramlResource, RAML::ActionType::PUT, "403"); + ramlResource, RAML::ActionType::PUT, "403"); RAML::RequestResponseBodyPtr postErrorResponseBody = getRAMLResponseBody( - ramlResource, RAML::ActionType::POST, "403"); + ramlResource, RAML::ActionType::POST, "403"); SimulatorResourceModel successResponseModel = buildModelFromResponseBody( - successResponseBody, resourceType, interfaceType); + successResponseBody, resourceType, interfaceType); SimulatorResourceModel putErrorResponseModel = buildModelFromResponseBody( - putErrorResponseBody, rt, ifType); + putErrorResponseBody, rt, ifType); SimulatorResourceModel postErrorResponseModel = buildModelFromResponseBody( - postErrorResponseBody, rt, ifType); + postErrorResponseBody, rt, ifType); // Create simple/collection resource std::shared_ptr simResource; diff --git a/service/simulator/src/server/simulator_resource_factory.h b/service/simulator/src/server/simulator_resource_factory.h index 242385e..84ff428 100755 --- a/service/simulator/src/server/simulator_resource_factory.h +++ b/service/simulator/src/server/simulator_resource_factory.h @@ -91,7 +91,8 @@ class SimulatorResourceFactory std::shared_ptr propertyElement); SimulatorResourceModel buildResourceModel(std::shared_ptr item); SimulatorResourceModel buildModelFromResponseBody( - RAML::RequestResponseBodyPtr responseBody, std::string &resourceType, std::vector &interfaceType); + RAML::RequestResponseBodyPtr responseBody, std::string &resourceType, + std::vector &interfaceType); RAML::RequestResponseBodyPtr getRAMLResponseBody( std::shared_ptr ramlResource, RAML::ActionType type, std::string responseCode); std::shared_ptr buildResource( diff --git a/service/simulator/src/server/simulator_single_resource_impl.cpp b/service/simulator/src/server/simulator_single_resource_impl.cpp index 5d5df1d..16d6a65 100755 --- a/service/simulator/src/server/simulator_single_resource_impl.cpp +++ b/service/simulator/src/server/simulator_single_resource_impl.cpp @@ -205,6 +205,13 @@ void SimulatorSingleResourceImpl::stop() if (!m_resourceHandle) return; + // Stop all the update automation of this resource + m_updateAutomationMgr.stopAll(); + + // Clear all the observers + removeAllObservers(); + + // Unregister the resource from stack typedef OCStackResult (*UnregisterResource)(const OCResourceHandle &); invokeocplatform(static_cast(OC::OCPlatform::unregisterResource), @@ -498,29 +505,12 @@ OCEntityHandlerResult SimulatorSingleResourceImpl::handleRequests( if (OC::ObserveAction::ObserveRegister == observationInfo.action) { SIM_LOG(ILogger::INFO, "[" << m_uri << "] OBSERVE REGISTER request received"); - - ObserverInfo info {observationInfo.obsId, observationInfo.address, observationInfo.port}; - m_observersList.push_back(info); - - if (m_observeCallback) - m_observeCallback(m_uri, ObservationStatus::REGISTER, info); + addObserver(observationInfo); } else if (OC::ObserveAction::ObserveUnregister == observationInfo.action) { SIM_LOG(ILogger::INFO, "[" << m_uri << "] OBSERVE UNREGISTER request received"); - - ObserverInfo info; - for (auto iter = m_observersList.begin(); iter != m_observersList.end(); iter++) - { - if ((info = *iter), info.id == observationInfo.obsId) - { - m_observersList.erase(iter); - break; - } - } - - if (m_observeCallback) - m_observeCallback(m_uri, ObservationStatus::UNREGISTER, info); + removeObserver(observationInfo); } errCode = OC_EH_OK; } @@ -596,3 +586,39 @@ std::shared_ptr SimulatorSingleResourceImpl::requestOnBa return response; } + +void SimulatorSingleResourceImpl::addObserver(OC::ObservationInfo ocObserverInfo) +{ + ObserverInfo info {ocObserverInfo.obsId, ocObserverInfo.address, ocObserverInfo.port}; + m_observersList.push_back(info); + + if (m_observeCallback) + m_observeCallback(m_uri, ObservationStatus::REGISTER, info); +} + +void SimulatorSingleResourceImpl::removeObserver(OC::ObservationInfo ocObserverInfo) +{ + ObserverInfo info; + for (auto iter = m_observersList.begin(); iter != m_observersList.end(); iter++) + { + if ((info = *iter), info.id == ocObserverInfo.obsId) + { + m_observersList.erase(iter); + break; + } + } + + if (m_observeCallback) + m_observeCallback(m_uri, ObservationStatus::UNREGISTER, info); +} + +void SimulatorSingleResourceImpl::removeAllObservers() +{ + std::vector observerList = m_observersList; + m_observersList.clear(); + for (int index = 0; index < observerList.size(); index++) + { + if (m_observeCallback) + m_observeCallback(m_uri, ObservationStatus::UNREGISTER, observerList[index]); + } +} \ No newline at end of file diff --git a/service/simulator/src/server/simulator_single_resource_impl.h b/service/simulator/src/server/simulator_single_resource_impl.h index 6aa6a4a..d25c4b5 100755 --- a/service/simulator/src/server/simulator_single_resource_impl.h +++ b/service/simulator/src/server/simulator_single_resource_impl.h @@ -84,6 +84,9 @@ class SimulatorSingleResourceImpl : public SimulatorSingleResource std::shared_ptr request); void resourceModified(); bool updateResourceModel(OC::OCRepresentation &ocRep, SimulatorResourceModel &resModel); + void addObserver(OC::ObservationInfo ocObserverInfo); + void removeObserver(OC::ObservationInfo ocObserverInfo); + void removeAllObservers(); SimulatorResource::Type m_type; std::string m_name;