Fixed issue of invalid value gets update even if attribute has allowed values property.
authorHarish Kumara Marappa <h.marappa@samsung.com>
Mon, 16 Nov 2015 15:48:55 +0000 (21:18 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 17 Nov 2015 10:34:45 +0000 (10:34 +0000)
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 <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4231
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/simulator/java/jni/simulator_single_resource_jni.cpp
service/simulator/src/common/simulator_resource_model.cpp
service/simulator/src/server/resource_update_automation.cpp
service/simulator/src/server/simulator_collection_resource_impl.cpp
service/simulator/src/server/simulator_resource_factory.cpp
service/simulator/src/server/simulator_resource_factory.h
service/simulator/src/server/simulator_single_resource_impl.cpp
service/simulator/src/server/simulator_single_resource_impl.h

index 638f816..81b113c 100644 (file)
@@ -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)
index f309ec4..bb44646 100644 (file)
@@ -385,7 +385,8 @@ class SimulatorResourceModelBuilder
                 std::vector<std::vector<std::vector<OC::OCRepresentation>>> ocSubRepArray =
                     ocAttribute.getValue<std::vector<std::vector<std::vector<OC::OCRepresentation>>>>();
 
-                std::vector<std::vector<std::vector<SimulatorResourceModel>>> subResModelArray(ocSubRepArray.size());
+                std::vector<std::vector<std::vector<SimulatorResourceModel>>> subResModelArray(
+                    ocSubRepArray.size());
                 for  (size_t i = 0; i < ocSubRepArray.size(); i++)
                 {
                     std::vector<std::vector<SimulatorResourceModel>> 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> SimulatorResourceModel::AttributeProperty::getChildProperty()
+std::shared_ptr<SimulatorResourceModel::AttributeProperty>
+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;
         }
     }
 
index 766d42f..6c6f863 100644 (file)
@@ -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);
index ef74e41..ff673fd 100755 (executable)
@@ -523,7 +523,8 @@ void SimulatorCollectionResourceImpl::addLink(SimulatorResourceSP &resource)
 
     // Add OIC Link if it is not present
     bool found = false;
-    std::vector<SimulatorResourceModel> links = m_resModel.get<std::vector<SimulatorResourceModel>>("links");
+    std::vector<SimulatorResourceModel> links =
+        m_resModel.get<std::vector<SimulatorResourceModel>>("links");
     for (auto &link : links)
     {
         std::string linkURI = link.get<std::string>("href");
@@ -548,13 +549,14 @@ void SimulatorCollectionResourceImpl::removeLink(std::string uri)
         return;
 
     // Add OIC Link if it is not present
-    std::vector<SimulatorResourceModel> links = m_resModel.get<std::vector<SimulatorResourceModel>>("links");
+    std::vector<SimulatorResourceModel> links =
+        m_resModel.get<std::vector<SimulatorResourceModel>>("links");
     for (size_t i = 0; i < links.size(); i++)
     {
         std::string linkURI = links[i].get<std::string>("href");
         if (linkURI == uri)
         {
-            links.erase(links.begin()+i);
+            links.erase(links.begin() + i);
             m_resModel.updateValue("links", links);
             break;
         }
index 4a20e3d..2c862ed 100644 (file)
@@ -239,7 +239,8 @@ RAML::RequestResponseBodyPtr SimulatorResourceFactory::getRAMLResponseBody(
 }\r
 \r
 SimulatorResourceModel SimulatorResourceFactory::buildModelFromResponseBody(\r
-    RAML::RequestResponseBodyPtr responseBody, std::string &resourceType, std::vector<std::string> &interfaceType)\r
+    RAML::RequestResponseBodyPtr responseBody, std::string &resourceType,\r
+    std::vector<std::string> &interfaceType)\r
 {\r
     SimulatorResourceModel resModel;\r
 \r
@@ -332,18 +333,18 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
     uri = ramlResource->getResourceUri();\r
 \r
     RAML::RequestResponseBodyPtr successResponseBody = getRAMLResponseBody(\r
-        ramlResource, RAML::ActionType::GET, "200");\r
+                ramlResource, RAML::ActionType::GET, "200");\r
     RAML::RequestResponseBodyPtr putErrorResponseBody = getRAMLResponseBody(\r
-        ramlResource, RAML::ActionType::PUT, "403");\r
+                ramlResource, RAML::ActionType::PUT, "403");\r
     RAML::RequestResponseBodyPtr postErrorResponseBody = getRAMLResponseBody(\r
-        ramlResource, RAML::ActionType::POST, "403");\r
+                ramlResource, RAML::ActionType::POST, "403");\r
 \r
     SimulatorResourceModel successResponseModel = buildModelFromResponseBody(\r
-        successResponseBody, resourceType, interfaceType);\r
+                successResponseBody, resourceType, interfaceType);\r
     SimulatorResourceModel putErrorResponseModel = buildModelFromResponseBody(\r
-        putErrorResponseBody, rt, ifType);\r
+                putErrorResponseBody, rt, ifType);\r
     SimulatorResourceModel postErrorResponseModel = buildModelFromResponseBody(\r
-        postErrorResponseBody, rt, ifType);\r
+                postErrorResponseBody, rt, ifType);\r
 \r
     // Create simple/collection resource\r
     std::shared_ptr<SimulatorResource> simResource;\r
index 242385e..84ff428 100755 (executable)
@@ -91,7 +91,8 @@ class SimulatorResourceFactory
             std::shared_ptr<RAML::Properties> propertyElement);
         SimulatorResourceModel buildResourceModel(std::shared_ptr<RAML::Items> item);
         SimulatorResourceModel buildModelFromResponseBody(
-            RAML::RequestResponseBodyPtr responseBody, std::string &resourceType, std::vector<std::string> &interfaceType);
+            RAML::RequestResponseBodyPtr responseBody, std::string &resourceType,
+            std::vector<std::string> &interfaceType);
         RAML::RequestResponseBodyPtr getRAMLResponseBody(
             std::shared_ptr<RAML::RamlResource> ramlResource, RAML::ActionType type, std::string responseCode);
         std::shared_ptr<SimulatorResource> buildResource(
index 5d5df1d..16d6a65 100755 (executable)
@@ -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<UnregisterResource>(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<OC::OCResourceResponse> 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<ObserverInfo> 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
index 6aa6a4a..d25c4b5 100755 (executable)
@@ -84,6 +84,9 @@ class SimulatorSingleResourceImpl : public SimulatorSingleResource
             std::shared_ptr<OC::OCResourceRequest> 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;