From 278ee37c56915b2ccaa4c2ac9f3d717dee33c82c Mon Sep 17 00:00:00 2001 From: Harish Kumara Marappa Date: Thu, 21 Apr 2016 22:16:39 +0530 Subject: [PATCH] Fix for jira issue IOT-1087. Resource was creating with oic.if.def which is not defined in OIC spec. Modified the code such that all simulated resource will be having at least oic.if.baseline interface at any point of time as per 1.0.0 core spec. Change-Id: I07c6e4513546d1d4be9c0584408801552c5f4ce4 Signed-off-by: Harish Kumara Marappa Reviewed-on: https://gerrit.iotivity.org/gerrit/7877 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka Reviewed-by: Uze Choi Tested-by: Uze Choi (cherry picked from commit 3cd3700407657c96d02534f6e6be6c2398b97c68) Reviewed-on: https://gerrit.iotivity.org/gerrit/8047 --- .../manager/ResourceManager.java | 15 ++++++++--- .../serviceprovider/utils/Utility.java | 1 - .../view/MetaPropertiesView.java | 10 +++++++- .../UpdateResourceInterfaceDialog.java | 25 ++++++------------- .../src/server/oc_interface_details.cpp | 2 +- .../server/simulator_single_resource_impl.cpp | 20 +++++++++++++-- 6 files changed, 47 insertions(+), 26 deletions(-) diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java index dc1165431..44fc3eedc 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java @@ -590,12 +590,21 @@ public class ResourceManager { } // Set the resource interfaces. - jSimulatorSingleResource - .setInterface(Utility.convertSetToVectorString(resource - .getResourceInterfaces())); + Set interfaces = resource.getResourceInterfaces(); + if (null != interfaces && !interfaces.isEmpty()) { + jSimulatorSingleResource.setInterface(Utility + .convertSetToVectorString(resource + .getResourceInterfaces())); + } // Register the resource with the platform. jSimulatorSingleResource.start(); + + // Read the interfaces from the native layer and set it to the + // interface list. + resource.setResourceInterfaces(Utility + .convertVectorToSet(jSimulatorSingleResource.getInterface())); + resource.setStarted(true); } catch (SimulatorException e) { Activator diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java index a6628745c..dcf10e418 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java @@ -577,7 +577,6 @@ public class Utility { Map ifTypes = null; if (resourceClass == SingleResource.class) { ifTypes = new HashMap(); - ifTypes.put(Constants.BASELINE_INTERFACE, "Baseline"); ifTypes.put(Constants.READ_ONLY_INTERFACE, "Read-Only"); ifTypes.put(Constants.READ_WRITE_INTERFACE, "Read-Write"); ifTypes.put(Constants.ACTUATOR_INTERFACE, "Actuator"); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java index d5fd2d67a..b362e2e0b 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java @@ -223,6 +223,8 @@ public class MetaPropertiesView extends ViewPart { // interface set. Set curIfSet = resourceInSelection .getResourceInterfaces(); + // Adding default interface to local set if removed. + updatedIfSet.add(Constants.BASELINE_INTERFACE); if (null != curIfSet && null != updatedIfSet) { if (curIfSet.size() != updatedIfSet.size()) { update = true; @@ -506,7 +508,13 @@ public class MetaPropertiesView extends ViewPart { } // Update the model MetaProperty prop = (MetaProperty) element; - prop.setPropValue(newPropValue.toString()); + StringBuilder value = new StringBuilder(); + value.append(Constants.BASELINE_INTERFACE); + if (newPropValue.length() > 0) { + value.append(", " + newPropValue.toString()); + } + prop.setPropValue(value.toString()); + // Update the viewer in a separate UI thread. Display.getDefault().asyncExec(new Runnable() { @Override diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java index 4fe07b558..09a40073a 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java @@ -17,7 +17,6 @@ package oic.simulator.serviceprovider.view.dialogs; import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TrayDialog; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; @@ -36,8 +35,6 @@ import org.eclipse.swt.widgets.Shell; import java.util.ArrayList; import java.util.Map; -import oic.simulator.serviceprovider.utils.Constants; - /** * Dialog for starting and stopping the automatic verifications. */ @@ -197,23 +194,15 @@ public class UpdateResourceInterfaceDialog extends TrayDialog { @Override protected void okPressed() { - String[] items = ifTypesList.getItems(); - if (null == items || items.length == 0) { - MessageDialog - .openInformation( - getShell(), - "Default Interface Type Selection", - "As no interface types are added, the resource will be " - + "configured with the default interface type(oic.if.baseline)."); - ifTypesList.add("Baseline" + " (" - + Constants.DEFAULT_SINGLE_RESOURCE_INTERFACE + ")"); - } - // Clearing the map to freshly add selected items. updatedResInterfaces.clear(); - for (String item : ifTypesList.getItems()) { - String value = supportedResInterfaces.get(item); - updatedResInterfaces.put(item, value); + + String[] items = ifTypesList.getItems(); + if (null != items && items.length > 0) { + for (String item : items) { + String value = supportedResInterfaces.get(item); + updatedResInterfaces.put(item, value); + } } close(); } diff --git a/service/simulator/src/server/oc_interface_details.cpp b/service/simulator/src/server/oc_interface_details.cpp index b32f1f69d..96f1599fc 100644 --- a/service/simulator/src/server/oc_interface_details.cpp +++ b/service/simulator/src/server/oc_interface_details.cpp @@ -39,7 +39,7 @@ bool OCInterfaceDetails::isInterface(const std::string &interfaceType) { if (m_interfaces.end() != m_interfaces.find(interfaceType)) return true; - return true; + return false; } bool OCInterfaceDetails::isRequestSupported(const std::string &interfaceType, diff --git a/service/simulator/src/server/simulator_single_resource_impl.cpp b/service/simulator/src/server/simulator_single_resource_impl.cpp index 5cc5c87f7..2539d2289 100755 --- a/service/simulator/src/server/simulator_single_resource_impl.cpp +++ b/service/simulator/src/server/simulator_single_resource_impl.cpp @@ -79,6 +79,12 @@ void SimulatorSingleResourceImpl::setInterface(const std::string &interfaceType) { VALIDATE_INPUT(interfaceType.empty(), "Interface type list is empty!") + if (false == OCInterfaceDetails::getInstance()->isInterface(interfaceType)) + { + OIC_LOG(ERROR, TAG, "Request is not OIC spec defined!"); + return; + } + std::lock_guard lock(m_objectLock); if (m_resourceHandle) { @@ -86,7 +92,8 @@ void SimulatorSingleResourceImpl::setInterface(const std::string &interfaceType) "Resource interface can not be reset when resource is started!"); } - m_interfaces = {interfaceType}; + if (interfaceType != OC::DEFAULT_INTERFACE) + m_interfaces = {OC::DEFAULT_INTERFACE, interfaceType}; } void SimulatorSingleResourceImpl::setInterface(const std::vector &interfaceTypes) @@ -100,9 +107,12 @@ void SimulatorSingleResourceImpl::setInterface(const std::vector &i "Resource interface can not be reset when resource is started!"); } - m_interfaces.clear(); + m_interfaces = {OC::DEFAULT_INTERFACE}; for (auto &interfaceType : interfaceTypes) { + if (false == OCInterfaceDetails::getInstance()->isInterface(interfaceType)) + continue; + if (m_interfaces.end() == std::find(m_interfaces.begin(), m_interfaces.end(), interfaceType)) { @@ -115,6 +125,12 @@ void SimulatorSingleResourceImpl::addInterface(const std::string &interfaceType) { VALIDATE_INPUT(interfaceType.empty(), "Interface type is empty!") + if (false == OCInterfaceDetails::getInstance()->isInterface(interfaceType)) + { + OIC_LOG(ERROR, TAG, "Request is not OIC spec defined!"); + return; + } + if (m_interfaces.end() != std::find(m_interfaces.begin(), m_interfaces.end(), interfaceType)) { SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " -- 2.34.1