1. Resolved minor issues in resource creation, invalid URIs and editing attribute values.
2. Updated the APIs to get the device and platform information by address.
3. Showing all properties of device in service provider plug-in.
Change-Id: I810f3110c0587a34042361c4d0be109ba9f7f646
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4313
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
try
{
- SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(), std::bind([](DeviceInfo & deviceInfo)
+ SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(),
+ std::bind([](const std::string & host, DeviceInfo & deviceInfo)
{
std::cout << "###Device Information received...." << std::endl;
std::ostringstream out;
+ out << "Host URI: " << host << std::endl;
out << "Device name: " << deviceInfo.getName() << std::endl;
out << "Device ID: " << deviceInfo.getID() << std::endl;
out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl;
out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl;
std::cout << out.str() << std::endl;
- }, std::placeholders::_1));
+ }, std::placeholders::_1, std::placeholders::_2));
}
catch (InvalidArgsException &e)
{
try
{
- SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(), std::bind([](PlatformInfo & platformInfo)
+ SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(),
+ std::bind([](const std::string & host, PlatformInfo & platformInfo)
{
std::cout << "###Platform Information received...." << std::endl;
std::ostringstream out;
+ out << "Host URI: " << host << std::endl;
out << "Platform ID: " << platformInfo.getPlatformID() << std::endl;
out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl;
out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl;
out << "System time: " << platformInfo.getSystemTime() << std::endl;
std::cout << out.str() << std::endl;
- }, std::placeholders::_1));
+ }, std::placeholders::_1, std::placeholders::_2));
}
catch (InvalidArgsException &e)
{
#include "simulator_exceptions.h"
#include "simulator_logger.h"
-typedef std::function<void(DeviceInfo &deviceInfo)> DeviceInfoCallback;
-typedef std::function<void(PlatformInfo &platformInfo)> PlatformInfoCallback;
+typedef std::function<void(const std::string &hostUri, DeviceInfo &deviceInfo)> DeviceInfoCallback;
+typedef std::function<void(const std::string &hostUri, PlatformInfo &platformInfo)> PlatformInfoCallback;
/**
* @class SimulatorManager
import oic.simulator.clientcontroller.listener.IPutUIListener;
import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
import oic.simulator.clientcontroller.listener.IVerificationUIListener;
+import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo;
import oic.simulator.clientcontroller.remoteresource.MetaProperty;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
import oic.simulator.clientcontroller.utils.Constants;
// Maintaining a list of observed resource URIs.
private List<String> observedResourceURIList;
- private DeviceInfo devInfo;
- private PlatformInfo platInfo;
+ private Map<String, DeviceAndPlatformInfo> hostDeviceAndPlatformMap;
public ResourceManager() {
resourceMap = new HashMap<String, RemoteResource>();
favoriteResources = new ArrayList<RemoteResource>();
favoriteURIList = new ArrayList<String>();
observedResourceURIList = new ArrayList<String>();
+ hostDeviceAndPlatformMap = new HashMap<String, DeviceAndPlatformInfo>();
+
findResourceUIListeners = new ArrayList<IFindResourceUIListener>();
resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
getUIListeners = new ArrayList<IGetUIListener>();
null));
}
- // Get the device and platform information
- try {
- SimulatorManager.findDevices(resource
- .getRemoteResourceRef().getHost(),
- deviceListener);
- SimulatorManager.getPlatformInformation(resource
- .getRemoteResourceRef().getHost(),
- platformListener);
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- Utility.getSimulatorErrorString(e,
- null));
+ // Get the device information
+ if (!isDeviceInfoExist(resourceN.getHost())) {
+ try {
+ SimulatorManager.findDevices(resource
+ .getRemoteResourceRef().getHost(),
+ deviceListener);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ Utility.getSimulatorErrorString(
+ e, null));
+ }
+ }
+
+ // Get the platform information
+ if (!isPlatformInfoExist(resourceN.getHost())) {
+ try {
+ SimulatorManager.getPlatformInformation(
+ resource.getRemoteResourceRef()
+ .getHost(), platformListener);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ Utility.getSimulatorErrorString(
+ e, null));
+ }
}
}
});
deviceListener = new DeviceListener() {
@Override
- public void onDeviceFound(final DeviceInfo deviceInfo) {
- if (null == deviceInfo) {
+ public void onDeviceFound(final String host,
+ final DeviceInfo deviceInfo) {
+ if (null == deviceInfo || null == host) {
return;
}
synchronizerThread.addToQueue(new Runnable() {
@Override
public void run() {
- setDeviceInfo(deviceInfo);
+ synchronized (hostDeviceAndPlatformMap) {
+ DeviceAndPlatformInfo info = hostDeviceAndPlatformMap
+ .get(host);
+ if (null == info) {
+ info = new DeviceAndPlatformInfo();
+ info.setHost(host);
+ hostDeviceAndPlatformMap.put(host, info);
+ }
+ info.setDeviceInfo(deviceInfo);
+ }
// Notify UI listeners
deviceInfoReceivedNotification();
platformListener = new PlatformListener() {
@Override
- public void onPlatformFound(final PlatformInfo platformInfo) {
- if (null == platformInfo) {
+ public void onPlatformFound(final String host,
+ final PlatformInfo platformInfo) {
+ if (null == platformInfo || null == host) {
return;
}
synchronizerThread.addToQueue(new Runnable() {
@Override
public void run() {
- setPlatformInfo(platformInfo);
+ synchronized (hostDeviceAndPlatformMap) {
+ DeviceAndPlatformInfo info = hostDeviceAndPlatformMap
+ .get(host);
+ if (null == info) {
+ info = new DeviceAndPlatformInfo();
+ info.setHost(host);
+ hostDeviceAndPlatformMap.put(host, info);
+ }
+ info.setPlatformInfo(platformInfo);
+ }
// Notify UI listeners
platformInfoReceivedNotification();
return resource;
}
- public synchronized DeviceInfo getDeviceInfo() {
- return devInfo;
- }
-
- public synchronized void setDeviceInfo(DeviceInfo devInfo) {
- this.devInfo = devInfo;
- }
-
- public synchronized PlatformInfo getPlatformInfo() {
- return platInfo;
+ public synchronized boolean isDeviceInfoExist(String host) {
+ DeviceAndPlatformInfo info = hostDeviceAndPlatformMap.get(host);
+ if (null == info) {
+ return false;
+ }
+ if (null == info.getDeviceInfo()) {
+ return false;
+ }
+ return true;
}
- public synchronized void setPlatformInfo(PlatformInfo platInfo) {
- this.platInfo = platInfo;
+ public synchronized boolean isPlatformInfoExist(String host) {
+ DeviceAndPlatformInfo info = hostDeviceAndPlatformMap.get(host);
+ if (null == info) {
+ return false;
+ }
+ if (null == info.getPlatformInfo()) {
+ return false;
+ }
+ return true;
}
private static class ResponseSynchronizerThread implements Runnable {
// Delete all cached details of resources
resourceMap.clear();
favoriteResources.clear();
+
+ // Clearing the device and platform information
+ hostDeviceAndPlatformMap.clear();
}
// Change the current resource in selection
setCurrentResourceInSelection(null);
removeResourceFromFavorites(resource);
// Remove the resource
keyItr.remove();
+ // Remove the device and platform information
+ synchronized (hostDeviceAndPlatformMap) {
+ hostDeviceAndPlatformMap.remove(resource
+ .getRemoteResourceRef().getHost());
+ }
}
}
}
}
public List<MetaProperty> getDeviceProperties() {
- if (null == devInfo) {
+ if (null == currentResourceInSelection) {
return null;
}
- List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+ SimulatorRemoteResource remoteResource = currentResourceInSelection
+ .getRemoteResourceRef();
+ if (null == remoteResource) {
+ return null;
+ }
+
+ String host = remoteResource.getHost();
+ if (null == host) {
+ return null;
+ }
+
+ if (!isDeviceInfoExist(host)) {
+ // Device Information
+ try {
+ SimulatorManager.findDevices(host, deviceListener);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
+ }
+ return null;
+ }
- metaProperties.add(new MetaProperty(Constants.DEVICE_ID, devInfo
- .getID()));
- metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, devInfo
- .getName()));
- metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
- devInfo.getSpecVersion()));
- metaProperties.add(new MetaProperty(Constants.DEVICE_DMV_VERSION,
- devInfo.getDataModelVersion()));
+ List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+ synchronized (hostDeviceAndPlatformMap) {
+ DeviceInfo devInfo = hostDeviceAndPlatformMap.get(host)
+ .getDeviceInfo();
+ metaProperties.add(new MetaProperty(Constants.DEVICE_ID, devInfo
+ .getID()));
+ metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, devInfo
+ .getName()));
+ metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
+ devInfo.getSpecVersion()));
+ metaProperties.add(new MetaProperty(Constants.DEVICE_DMV_VERSION,
+ devInfo.getDataModelVersion()));
+ }
/*
* metaProperties.add(new MetaProperty(Constants.DEVICE_ID, ""));
}
public List<MetaProperty> getPlatformProperties() {
- if (null == platInfo) {
+ if (null == currentResourceInSelection) {
return null;
}
- List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+ SimulatorRemoteResource remoteResource = currentResourceInSelection
+ .getRemoteResourceRef();
+ if (null == remoteResource) {
+ return null;
+ }
- metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platInfo
- .getPlatformID()));
- metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
- platInfo.getManufacturerName()));
- metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_URL,
- platInfo.getManufacturerUrl()));
- metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
- platInfo.getModelNumber()));
- metaProperties.add(new MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC,
- platInfo.getDateOfManufacture()));
- metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION,
- platInfo.getPlatformVersion()));
- metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
- platInfo.getOperationSystemVersion()));
- metaProperties.add(new MetaProperty(
- Constants.PLATFORM_HARDWARE_VERSION, platInfo
- .getHardwareVersion()));
- metaProperties.add(new MetaProperty(
- Constants.PLATFORM_FIRMWARE_VERSION, platInfo
- .getFirmwareVersion()));
- metaProperties.add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
- platInfo.getSupportUrl()));
- metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
- platInfo.getSystemTime()));
+ String host = remoteResource.getHost();
+ if (null == host) {
+ return null;
+ }
+ if (!isPlatformInfoExist(host)) {
+ // Platform Information
+ try {
+ SimulatorManager.getPlatformInformation(host, platformListener);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
+ }
+ return null;
+ }
+
+ List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+ synchronized (hostDeviceAndPlatformMap) {
+ PlatformInfo platInfo = hostDeviceAndPlatformMap.get(host)
+ .getPlatformInfo();
+ metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platInfo
+ .getPlatformID()));
+ metaProperties.add(new MetaProperty(
+ Constants.PLATFORM_MANUFAC_NAME, platInfo
+ .getManufacturerName()));
+ metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_URL,
+ platInfo.getManufacturerUrl()));
+ metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
+ platInfo.getModelNumber()));
+ metaProperties.add(new MetaProperty(
+ Constants.PLATFORM_DATE_OF_MANUFAC, platInfo
+ .getDateOfManufacture()));
+ metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION,
+ platInfo.getPlatformVersion()));
+ metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
+ platInfo.getOperationSystemVersion()));
+ metaProperties.add(new MetaProperty(
+ Constants.PLATFORM_HARDWARE_VERSION, platInfo
+ .getHardwareVersion()));
+ metaProperties.add(new MetaProperty(
+ Constants.PLATFORM_FIRMWARE_VERSION, platInfo
+ .getFirmwareVersion()));
+ metaProperties.add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
+ platInfo.getSupportUrl()));
+ metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
+ platInfo.getSystemTime()));
+ }
/*
* metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, ""));
* metaProperties .add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
--- /dev/null
+package oic.simulator.clientcontroller.remoteresource;
+
+import org.oic.simulator.DeviceInfo;
+import org.oic.simulator.PlatformInfo;
+
+public class DeviceAndPlatformInfo {
+ private String host;
+ private DeviceInfo deviceInfo;
+ private PlatformInfo platformInfo;
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public DeviceInfo getDeviceInfo() {
+ return deviceInfo;
+ }
+
+ public void setDeviceInfo(DeviceInfo deviceInfo) {
+ this.deviceInfo = deviceInfo;
+ }
+
+ public PlatformInfo getPlatformInfo() {
+ return platformInfo;
+ }
+
+ public void setPlatformInfo(PlatformInfo platformInfo) {
+ this.platformInfo = platformInfo;
+ }
+}
if (0 != findDepth(valueString))
return null;
- if (valueType == AttributeValue.ValueType.INTEGER)
- return new AttributeValue(Integer.parseInt(valueString));
- else if (valueType == AttributeValue.ValueType.DOUBLE)
- return new AttributeValue(Double.parseDouble(valueString));
- else if (valueType == AttributeValue.ValueType.BOOLEAN)
- return new AttributeValue(Boolean.parseBoolean(valueString));
- else if (valueType == AttributeValue.ValueType.STRING)
- return new AttributeValue(valueString);
+ try {
+ if (valueType == AttributeValue.ValueType.INTEGER)
+ return new AttributeValue(Integer.parseInt(valueString));
+ else if (valueType == AttributeValue.ValueType.DOUBLE) {
+ Double value = Double.parseDouble(valueString);
+ if (!value.isInfinite()) {
+ return new AttributeValue(value);
+ }
+ } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+ if (valueString.equalsIgnoreCase("true")
+ || valueString.equalsIgnoreCase("false"))
+ return new AttributeValue(Boolean.parseBoolean(valueString));
+ } else if (valueType == AttributeValue.ValueType.STRING)
+ return new AttributeValue(valueString);
+ } catch (Exception e) {
+ return null;
+ }
return null;
}
@Override
public void modifyText(ModifyEvent event) {
-
String newValue = comboBox.getText();
if (null != newValue && !newValue.isEmpty()) {
attributeElement.setPostState(false);
}
- /*
- * if (type.mType == ValueType.ARRAY) { return; }
- */
- /*
- * String oldValue = String.valueOf(Utility
- * .getAttributeValueAsString(val)); String newValue =
- * comboBox.getText();
- *
- * if (null != newValue && !newValue.isEmpty()) {
- * attributeElement.setPostState(true); } else {
- * attributeElement.setPostState(false); }
- *
- * if (!oldValue.equals(newValue)) { // Get the
- * AttriuteValue from the string AttributeValue value =
- * AttributeValueBuilder.build( newValue, type.mBaseType);
- * TypeInfo resTypeInfo = value.typeInfo(); if (null ==
- * value || type.mDepth != resTypeInfo.mDepth || type.mType
- * != resTypeInfo.mType || type.mBaseType !=
- * resTypeInfo.mBaseType) { MessageBox dialog = new
- * MessageBox(viewer.getTree() .getShell(), SWT.ICON_ERROR |
- * SWT.OK); dialog.setText("Invalid Value");
- * dialog.setMessage("Given value is invalid");
- * dialog.open(); } else { updateAttributeValue(attribute,
- * value); } }
- */
if (dialog instanceof PostRequestDialog) {
viewer.update(attributeElement, null);
// comboBox.setVisible(false);
}
TypeInfo type = val.typeInfo();
- /*
- * if (type.mType == ValueType.ARRAY) { int index; try { index =
- * Integer.parseInt(String.valueOf(value)); } catch
- * (NumberFormatException nfe) { index = -1; } if (index == -1) {
- * String oldValue = String.valueOf(Utility
- * .getAttributeValueAsString(val)); String newValue =
- * comboBox.getText(); if (!oldValue.equals(newValue)) { // Get the
- * AttriuteValue from the string AttributeValue attValue =
- * AttributeValueBuilder.build( newValue, type.mBaseType); TypeInfo
- * resTypeInfo = attValue.typeInfo(); if (null == attValue ||
- * type.mDepth != resTypeInfo.mDepth || type.mType !=
- * resTypeInfo.mType || type.mBaseType != resTypeInfo.mBaseType) {
- * MessageBox dialog = new MessageBox(viewer.getTree() .getShell(),
- * SWT.ICON_ERROR | SWT.OK); dialog.setText("Invalid Value");
- * dialog.setMessage("Given value is invalid"); dialog.open(); }
- * else { updateAttributeValue(att, attValue); } } } }
- */
String oldValue = String.valueOf(Utility
.getAttributeValueAsString(val));
// Get the AttriuteValue from the string
AttributeValue attValue = AttributeValueBuilder.build(newValue,
type.mBaseType);
- TypeInfo resTypeInfo = attValue.typeInfo();
- if (null == attValue || type.mDepth != resTypeInfo.mDepth
- || type.mType != resTypeInfo.mType
- || type.mBaseType != resTypeInfo.mBaseType) {
+ boolean invalid = false;
+ if (null == attValue) {
+ invalid = true;
+ } else {
+ TypeInfo resTypeInfo = attValue.typeInfo();
+ if (type.mDepth != resTypeInfo.mDepth
+ || type.mType != resTypeInfo.mType
+ || type.mBaseType != resTypeInfo.mBaseType) {
+ invalid = true;
+ }
+ }
+ if (invalid) {
MessageBox dialog = new MessageBox(viewer.getTree()
.getShell(), SWT.ICON_ERROR | SWT.OK);
dialog.setText("Invalid Value");
Tree tree = attViewer.getTree();
if (null != resource) {
attViewer.setInput(resource.getResourceRepresentation());
+ attViewer.expandAll();
if (!tree.isDisposed()) {
tree.setLinesVisible(true);
}
PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
@Override
public void run() {
- if (resourceInSelection.isPutAutomtnInProgress()) {
- MessageDialog
- .openInformation(Display.getDefault()
- .getActiveShell(), "PUT Request",
- "PUT Automation is in progress. Please wait or stop the automation.");
- return;
+ boolean attributesExist = false;
+ ResourceRepresentation rep = resourceInSelection
+ .getResourceRepresentation();
+ if (null != rep) {
+ Map<String, AttributeElement> attributes = rep
+ .getAttributes();
+ if (null != attributes && !attributes.isEmpty()) {
+ attributesExist = true;
+ }
}
- if (resourceInSelection.getResourceRepresentation()
- .getAttributes().size() < 1) {
+ if (!attributesExist) {
MessageDialog
.openInformation(Display.getDefault()
.getActiveShell(), "PUT Request",
PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
@Override
public void run() {
- if (resourceInSelection.isPostAutomtnInProgress()) {
- MessageDialog
- .openInformation(Display.getDefault()
- .getActiveShell(), "POST Request",
- "POST Automation is in progress. Please wait or stop the automation.");
- return;
+ boolean attributesExist = false;
+ ResourceRepresentation rep = resourceInSelection
+ .getResourceRepresentation();
+ if (null != rep) {
+ Map<String, AttributeElement> attributes = rep
+ .getAttributes();
+ if (null != attributes && !attributes.isEmpty()) {
+ attributesExist = true;
+ }
}
- if (resourceInSelection.getResourceRepresentation()
- .getAttributes().size() < 1) {
+ if (!attributesExist) {
MessageDialog
.openInformation(Display.getDefault()
.getActiveShell(), "POST Request",
@Override
public void run() {
- if (null != deviceTblViewer) {
- updateViewer(deviceTblViewer, getDevicePropData());
+ if (null != platformTblViewer) {
+ updateViewer(platformTblViewer,
+ getPlatformPropData());
}
}
});
@Override
public void run() {
- if (null != platformTblViewer) {
- updateViewer(platformTblViewer,
- getPlatformPropData());
+ if (null != deviceTblViewer) {
+ updateViewer(deviceTblViewer, getDevicePropData());
}
}
});
attViewer.setInput(updatedRepresentation);
+ attViewer.expandAll();
+
return compLayout;
}
attViewer.setInput(updatedRepresentation);
+ attViewer.expandAll();
+
return compLayout;
}
--- /dev/null
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.listener;
+
+public interface IDeviceInfoUIListener {
+ public void onDeviceInfoFound();
+}
import java.util.Set;
import java.util.Vector;
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.AttributeElement;
+import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
+import oic.simulator.serviceprovider.model.LocalResourceAttribute;
+import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.ResourceType;
+import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+
import org.eclipse.swt.widgets.Display;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeProperty.Type;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.DeviceInfo;
+import org.oic.simulator.DeviceListener;
import org.oic.simulator.ILogger.Level;
import org.oic.simulator.PlatformInfo;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.server.SimulatorResource.ResourceModelChangeListener;
import org.oic.simulator.server.SimulatorSingleResource;
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.AttributeElement;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
-import oic.simulator.serviceprovider.model.MetaProperty;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.ResourceType;
-import oic.simulator.serviceprovider.model.SRMItem;
-import oic.simulator.serviceprovider.model.SingleResource;
-import oic.simulator.serviceprovider.utils.Constants;
-import oic.simulator.serviceprovider.utils.Utility;
-
/**
* This class acts as an interface between the simulator java SDK and the
* various UI modules. It maintains all the details of resources and provides
private ObserverListener observer;
+ private DeviceListener deviceListener;
+
private NotificationSynchronizerThread synchronizerThread;
private Thread threadHandle;
- private String deviceName;
+ private DeviceInfo deviceInfo;
private PlatformInfo platformInfo;
+ private String deviceName;
+
public ResourceManager() {
data = new Data();
+ Utility.getSimulatorErrorString(e, null));
}
+ deviceListener = new DeviceListener() {
+
+ @Override
+ public void onDeviceFound(final String host,
+ final DeviceInfo deviceInfo) {
+ if (null != ResourceManager.this.deviceInfo
+ || null == deviceInfo || null == host) {
+ return;
+ }
+ synchronizerThread.addToQueue(new Runnable() {
+ @Override
+ public void run() {
+ String rcvdDeviceName = deviceInfo.getName();
+ if (null == rcvdDeviceName) {
+ return;
+ }
+ if (deviceName.equalsIgnoreCase(rcvdDeviceName)) {
+ ResourceManager.this.deviceInfo = deviceInfo;
+
+ // Notify the UI Listeners
+ UiListenerHandler.getInstance()
+ .deviceInfoReceivedNotification();
+ }
+ }
+ });
+ }
+ };
+
+ // Get the device information to show other details of the device in UI.
+ try {
+ SimulatorManager.findDevices("", deviceListener);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "Failed to get the local device information.\n"
+ + Utility.getSimulatorErrorString(e, null));
+ }
+
resourceModelChangeListener = new ResourceModelChangeListener() {
@Override
}
}
- public String getDeviceName() {
- return deviceName;
- }
+ public void setDeviceInfo(List<MetaProperty> metaProperties) {
+ if (null == metaProperties || metaProperties.size() < 1) {
+ return;
+ }
+ Iterator<MetaProperty> itr = metaProperties.iterator();
+ MetaProperty prop;
+ String propName;
+ String propValue;
+ boolean found = false;
+ while (itr.hasNext()) {
+ prop = itr.next();
+ propName = prop.getPropName();
+ propValue = prop.getPropValue();
+ if (propName.equals(Constants.DEVICE_NAME)) {
+ this.deviceName = propValue;
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ return;
+ }
- public void setDeviceName(String deviceName) {
- this.deviceName = deviceName;
try {
SimulatorManager.setDeviceInfo(deviceName);
} catch (SimulatorException e) {
}
}
+ public boolean isDeviceInfoValid(List<MetaProperty> metaProperties) {
+ if (null == metaProperties || metaProperties.size() < 1) {
+ return false;
+ }
+
+ Iterator<MetaProperty> itr = metaProperties.iterator();
+ MetaProperty prop;
+ String propName;
+ String propValue;
+ while (itr.hasNext()) {
+ prop = itr.next();
+ propName = prop.getPropName();
+ propValue = prop.getPropValue();
+ if (propName.equals(Constants.DEVICE_NAME)) {
+ if (null == propValue || propValue.length() < 1) {
+ return false;
+ }
+ break;
+ }
+ }
+ return true;
+ }
+
+ public List<MetaProperty> getDeviceInfo() {
+ List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+ metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, deviceName));
+ if (null != deviceInfo) {
+ metaProperties.add(new MetaProperty(Constants.DEVICE_ID, deviceInfo
+ .getID()));
+ metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
+ deviceInfo.getSpecVersion()));
+ metaProperties.add(new MetaProperty(Constants.DEVICE_DMV,
+ deviceInfo.getDataModelVersion()));
+ }
+ return metaProperties;
+ }
+
public List<MetaProperty> getPlatformInfo() {
List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platformInfo
}
}
+ public boolean isPlatformInfoValid(List<MetaProperty> metaProperties) {
+ if (null == metaProperties || metaProperties.size() < 1) {
+ return false;
+ }
+ Iterator<MetaProperty> itr = metaProperties.iterator();
+ MetaProperty prop;
+ String propValue;
+ while (itr.hasNext()) {
+ prop = itr.next();
+ propValue = prop.getPropValue();
+ if (null == propValue || propValue.length() < 1) {
+ return false;
+ }
+ }
+ return true;
+ }
+
public synchronized Resource getCurrentResourceInSelection() {
return currentResourceInSelection;
}
return createCount;
}
- public void createDevice(String deviceName, Set<Resource> childs) {
+ public Device createDevice(String deviceName, Set<Resource> childs) {
// 1. Create device
Device dev = new Device();
dev.setDeviceName(deviceName);
// 3. Update ui listeners
UiListenerHandler.getInstance().resourceListUpdateUINotification(
ResourceType.DEVICE);
+ return dev;
}
private Map<String, LocalResourceAttribute> fetchResourceAttributesFromModel(
}
- // This method gives all known possible values of the attribute in string
- // format. It takes allowed values or range of values whichever is available
- private List<String> getValueList(SimulatorResourceAttribute attributeN) {
- AttributeProperty attProp = attributeN.property();
- if (null == attProp) {
- return null;
- }
- List<String> valueList = new ArrayList<String>();
- Type valuesType = attProp.type();
- if (valuesType == Type.VALUESET) {
- Object[] allowedValues = attProp.valueSet();
- if (null != allowedValues && allowedValues.length > 0) {
- for (Object value : allowedValues) {
- if (null != value) {
- valueList.add(String.valueOf(((AttributeValue) value)
- .get()));
- }
- }
- }
- } else if (valuesType == Type.RANGE) {
- double minD = attProp.min();
- double maxD = attProp.max();
- for (double value = minD; value <= maxD; value++) {
- valueList.add(String.valueOf(value));
- }
- }
- Object attValue = attributeN.value().get();
- if (valueList.size() < 1 && null != attValue) {
- valueList.add(String.valueOf(attValue));
- }
- return valueList;
- }
-
public List<Resource> getResourceList() {
List<Resource> resourceList = data.getResources();
if (null == resourceList) {
}
String curURI = resource.getResourceURI();
+ setResourceURI(resource, newURI);
+
+ try {
+ if (!startResource(resource)) {
+ return false;
+ }
+ } catch (SimulatorException e) {
+ setResourceURI(resource, curURI);
+ }
+
+ return true;
+ }
+
+ public void setResourceURI(Resource resource, String newURI)
+ throws SimulatorException {
+ String curURI = resource.getResourceURI();
SimulatorResource server = resource.getSimulatorResource();
try {
server.setURI(newURI);
+ Utility.getSimulatorErrorString(e, null));
throw e;
}
-
- if (!startResource(resource)) {
- return false;
- }
- return true;
}
public boolean updateResourceProperties(Resource resource,
prop = itr.next();
if (prop.getPropName().equals(propName)) {
String value = prop.getPropValue();
- if (null == value || value.trim().isEmpty()) {
- invalid = true;
+ if (propName.equals(Constants.RESOURCE_URI)) {
+ if (!Utility.isUriValid(value)) {
+ invalid = true;
+ }
+ } else {
+ if (null == value || value.trim().isEmpty()) {
+ invalid = true;
+ }
}
}
}
import java.util.List;
import oic.simulator.serviceprovider.listener.IAutomationUIListener;
+import oic.simulator.serviceprovider.listener.IDeviceInfoUIListener;
import oic.simulator.serviceprovider.listener.IObserverListChangedUIListener;
import oic.simulator.serviceprovider.listener.IPropertiesChangedUIListener;
import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
private List<IPropertiesChangedUIListener> propertiesChangedUIListeners;
+ private List<IDeviceInfoUIListener> deviceInfoUIListeners;
+
private UiListenerHandler() {
resourceListChangedUIListeners = new ArrayList<IResourceListChangedUIListener>();
selectionChangedUIListeners = new ArrayList<ISelectionChangedUIListener>();
automationUIListeners = new ArrayList<IAutomationUIListener>();
observerUIListeners = new ArrayList<IObserverListChangedUIListener>();
propertiesChangedUIListeners = new ArrayList<IPropertiesChangedUIListener>();
+ deviceInfoUIListeners = new ArrayList<IDeviceInfoUIListener>();
}
public static UiListenerHandler getInstance() {
}
}
+ public void addDeviceInfoUIListener(IDeviceInfoUIListener deviceUIListener) {
+ synchronized (deviceInfoUIListeners) {
+ deviceInfoUIListeners.add(deviceUIListener);
+ }
+ }
+
+ public void removeDeviceInfoUIListener(
+ IDeviceInfoUIListener platformUIListener) {
+ synchronized (deviceInfoUIListeners) {
+ deviceInfoUIListeners.remove(platformUIListener);
+ }
+ }
+
public void resourceCreatedUINotification(ResourceType type) {
synchronized (resourceListChangedUIListeners) {
if (resourceListChangedUIListeners.size() > 0) {
}
}
- public void propertiesChangedUINotification(Class targetClass) {
+ public void propertiesChangedUINotification(Class<?> targetClass) {
synchronized (propertiesChangedUIListeners) {
if (propertiesChangedUIListeners.size() > 0) {
IPropertiesChangedUIListener listener;
}
}
}
+
+ public void deviceInfoReceivedNotification() {
+ synchronized (deviceInfoUIListeners) {
+ if (deviceInfoUIListeners.size() > 0) {
+ IDeviceInfoUIListener listener;
+ Iterator<IDeviceInfoUIListener> listenerItr = deviceInfoUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onDeviceInfoFound();
+ }
+ }
+ }
+ }
+ }
}
package oic.simulator.serviceprovider.model;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import oic.simulator.serviceprovider.utils.Constants;
min = Double.parseDouble(this.min);
max = Double.parseDouble(this.max);
dflValue = Double.parseDouble(value);
- if (dflValue < min || dflValue > max) {
+ boolean found = false;
+ for (double val = min; val <= max; val += 1.0) {
+ if (dflValue == val) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
result = false;
}
} catch (Exception e) {
}
} else if (validValuesType == Type.VALUESET
&& null != allowedValues && !allowedValues.isEmpty()) {
- result = allowedValues.contains(value);
+ boolean found = false;
+ if (attributeType.equals(Constants.INT)) {
+ Iterator<String> itr = allowedValues.iterator();
+ while (itr.hasNext()) {
+ String val = itr.next();
+ int v1 = Integer.parseInt(val);
+ int v2 = Integer.parseInt(value);
+ if (v1 == v2) {
+ found = true;
+ break;
+ }
+ }
+ } else {
+ Iterator<String> itr = allowedValues.iterator();
+ while (itr.hasNext()) {
+ String val = itr.next();
+ double v1 = Double.parseDouble(val);
+ double v2 = Double.parseDouble(value);
+ if (v1 == v2) {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found) {
+ result = false;
+ }
}
}
return result;
} else {
attProperty = null;
}
+ break;
case DOUBLE:
attValue = new AttributeValue(
Double.parseDouble(attributeDflValue));
if (0 != findDepth(valueString))
return null;
- if (valueType == AttributeValue.ValueType.INTEGER)
- return new AttributeValue(Integer.parseInt(valueString));
- else if (valueType == AttributeValue.ValueType.DOUBLE)
- return new AttributeValue(Double.parseDouble(valueString));
- else if (valueType == AttributeValue.ValueType.BOOLEAN)
- return new AttributeValue(Boolean.parseBoolean(valueString));
- else if (valueType == AttributeValue.ValueType.STRING)
- return new AttributeValue(valueString);
+ try {
+ if (valueType == AttributeValue.ValueType.INTEGER)
+ return new AttributeValue(Integer.parseInt(valueString));
+ else if (valueType == AttributeValue.ValueType.DOUBLE) {
+ Double value = Double.parseDouble(valueString);
+ if (!value.isInfinite()) {
+ return new AttributeValue(value);
+ }
+ } else if (valueType == AttributeValue.ValueType.BOOLEAN) {
+ if (valueString.equalsIgnoreCase("true")
+ || valueString.equalsIgnoreCase("false"))
+ return new AttributeValue(Boolean.parseBoolean(valueString));
+ } else if (valueType == AttributeValue.ValueType.STRING)
+ return new AttributeValue(valueString);
+ } catch (Exception e) {
+ return null;
+ }
return null;
}
public static final String INT = "Int";
public static final String DOUBLE = "Double";
- public static final String BOOL = "Bool";
+ public static final String BOOL = "Boolean";
public static final String STRING = "String";
public static final String UNKNOWN = "Unknown";
public static final String RESOURCE_TYPE = "Resource Type";
public static final String RESOURCE_TYPES = "Resource Types";
public static final String RESOURCE_NAME = "Resource Name";
- public static final String DEVICE_NAME = "Device Name";
public static final String RESOURCE_UID = "Resource ID";
public static final String CONNECTIVITY_TYPE = "Connectivity Type";
public static final String PLATFORM_SUPPORT_URL = "Support URL";
public static final String PLATFORM_SYSTEM_TIME = "System Time";
+ // Device information
+ public static final String DEVICE_NAME = "Device Name";
+ public static final String DEVICE_ID = "Device ID";
+ public static final String DEVICE_SPEC_VERSION = "Spec Version";
+ public static final String DEVICE_DMV = "Data Model Version";
+
public static final String SAMPLE_LIGHT = "sample.light";
public static final String UPDATE_PROP_PAGE_TITLE = "Update Properties";
public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 3 of 3)";
public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_MESSAGE = "Fill other details of the resource";
- public static final String COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE1 = "Create Collection Resource";
- public static final String COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE2 = "Create Collection Resource(Step 1 of 2)";
+ public static final String COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE = "Create Collection Resource";
public static final String COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE = "Fill basic details of the resource";
- public static final String COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE = "Create Collection Resource(Step 2 of 2)";
+ public static final String COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE = "Create Collection Resource";
public static final String COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_MESSAGE = "Add other resources to this collection resource";
public static final String CREATE_DEVICE_PAGE_TITLE = "Create Device";
public static final String DEVICE = "Create Device";
public static final String SINGLE_RESOURCE = "Single Resource";
public static final String COLLECTION_RESOURCE = "Collection Resource";
+ public static final String INVALID_URI_MESSAGE = "Resource URI should start with a '/' followed by atleast one character and it should not contain either # or ? or % or consecutive '/'.";
+ public static final int TREE_EXPANSION_LEVEL = 10;
}
\ No newline at end of file
return localAtt;
}
+ public static boolean isUriValid(String resURI) {
+ if (null == resURI || resURI.length() < 2 || !resURI.startsWith("/")
+ || resURI.contains("//") || resURI.contains("?")
+ || resURI.contains("#") || resURI.contains("%")) {
+ return false;
+ }
+ return true;
+ }
+
}
\ No newline at end of file
// Get the AttriuteValue from the string
AttributeValue value = AttributeValueBuilder.build(
newValue, type.mBaseType);
- TypeInfo resTypeInfo = value.typeInfo();
- if (null == value || type.mDepth != resTypeInfo.mDepth
- || type.mType != resTypeInfo.mType
- || type.mBaseType != resTypeInfo.mBaseType) {
+ boolean invalid = false;
+ if (null == value) {
+ invalid = true;
+ } else {
+ TypeInfo resTypeInfo = value.typeInfo();
+ if (type.mDepth != resTypeInfo.mDepth
+ || type.mType != resTypeInfo.mType
+ || type.mBaseType != resTypeInfo.mBaseType) {
+ invalid = true;
+ }
+ }
+ if (invalid) {
MessageBox dialog = new MessageBox(viewer.getTree()
.getShell(), SWT.ICON_ERROR | SWT.OK);
dialog.setText("Invalid Value");
// Get the AttriuteValue from the string
AttributeValue attValue = AttributeValueBuilder.build(
newValue, type.mBaseType);
- TypeInfo resTypeInfo = attValue.typeInfo();
- if (null == attValue
- || type.mDepth != resTypeInfo.mDepth
- || type.mType != resTypeInfo.mType
- || type.mBaseType != resTypeInfo.mBaseType) {
+ boolean invalid = false;
+ if (null == attValue) {
+ invalid = true;
+ } else {
+ TypeInfo resTypeInfo = attValue.typeInfo();
+ if (type.mDepth != resTypeInfo.mDepth
+ || type.mType != resTypeInfo.mType
+ || type.mBaseType != resTypeInfo.mBaseType) {
+ invalid = true;
+ }
+ }
+ if (invalid) {
MessageBox dialog = new MessageBox(viewer.getTree()
.getShell(), SWT.ICON_ERROR | SWT.OK);
dialog.setText("Invalid Value");
public SimulatorResourceAttribute getResultantValue(
AttributeValue newValue) {
- AttributeValue val = null;
IStructuredSelection selection = (IStructuredSelection) viewer
.getSelection();
if (null == selection) {
return null;
}
+ if (((AttributeElement) element).isReadOnly()) {
+ return null;
+ }
+
return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
}
@Override
public void run() {
if (null != attViewer) {
+ Tree tree = attViewer.getTree();
+ if (null == tree || tree.isDisposed()) {
+ return;
+ }
if (null != resource
&& null != resource
- .getResourceRepresentation())
+ .getResourceRepresentation()) {
attViewer.setInput(resource
.getResourceRepresentation());
- /*
- * updateViewer(getData(resource)); Tree tree =
- * attViewer.getTree(); if (!tree.isDisposed()) { if
- * (null != resource && (resource instanceof
- * SingleResource && ((SingleResource) resource)
- * .isResourceAutomationInProgress())) {
- * tree.setEnabled(false); } else {
- * tree.setEnabled(true); } }
- */
+ attViewer.expandAll();
+ if (null != tree) {
+ tree.setLinesVisible(true);
+ }
+ } else {
+ attViewer.setInput(null);
+ if (null != tree) {
+ tree.setLinesVisible(false);
+ }
+ }
}
}
});
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- updateViewer(null);
+ if (null != attViewer) {
+ Tree tree = attViewer.getTree();
+ if (null != tree && !tree.isDisposed()) {
+ // tbl.deselectAll();
+ tree.removeAll();
+ tree.setLinesVisible(false);
+ }
+ }
}
});
}
if (null == resourceInSelection) {
return;
}
- /*
- * if (resource != resourceInSelection) { // This
- * notification is for a different resource // whose
- * attributes are not // currently not being shown in
- * UI. So ignoring this // notification. return; } //
- * Refresh the table viewers which will display // the
- * updated values if (null != attViewer) { if (resource
- * instanceof CollectionResource) {
- * updateViewer(getData(resource)); } else {
- * updateViewer(getData(resource)); } }
- */
}
});
}
automationUIListener);
}
- private List<LocalResourceAttribute> getData(Resource resource) {
- if (null != resource) {
- List<LocalResourceAttribute> attList = resourceManager
- .getAttributes((Resource) resource);
- // List<LocalResourceAttribute> attList =
- // Utility.getDummyAttributes();
- return attList;
- } else {
- return null;
- }
- }
-
- private void updateViewer(List<LocalResourceAttribute> attList) {
- Tree tree = attViewer.getTree();;
- if (null != attList) {
- if (null != tree && !tree.isDisposed()) {
- tree.setLinesVisible(true);
- attViewer.setInput(attList.toArray());
- }
- } else {
- // Clear the attributes table viewer
- if (null != attViewer) {
- if (null != tree && !tree.isDisposed()) {
- // tbl.deselectAll();
- tree.removeAll();
- tree.setLinesVisible(false);
- }
- }
- }
- }
-
class AttributeContentProvider implements ITreeContentProvider,
DataChangeListener {
@Override
public void run() {
mTreeViewer.refresh(attribute.getParent());
+ mTreeViewer.expandAll();
}
});
}
@Override
public void run() {
mTreeViewer.refresh(attribute.getParent());
+ mTreeViewer.expandAll();
}
});
}
@Override
public void run() {
mTreeViewer.update(attribute, null);
+ mTreeViewer.expandAll();
}
});
}
import java.util.List;
import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.IDeviceInfoUIListener;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.utils.Constants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
/**
private final Integer[] columnWidth = { 150, 150 };
- private List<MetaProperty> metaProperties;
+ enum PropertiesType {
+ DEVICE, PLATFORM
+ }
+
+ private List<MetaProperty> deviceProperties;
+ private List<MetaProperty> platformProperties;
+
+ private boolean enableDeviceEdit;
+ private boolean enablePlatformEdit;
- private boolean enable_edit;
+ private Button devEditBtn;
+ private Button devCancelBtn;
+ private Button platEditBtn;
+ private Button platCancelBtn;
- private Text deviceNameTxt;
- private Button devEditBtn;
- private Button devCancelBtn;
- private Button platEditBtn;
- private Button platCancelBtn;
+ private TableViewer platformTblViewer;
+ private TableViewer deviceTblViewer;
- private TableViewer platformTblViewer;
+ private CTabFolder folder;
+ private CTabItem devicePropTab;
+ private CTabItem platformPropTab;
- private CTabFolder folder;
- private CTabItem devicePropTab;
- private CTabItem platformPropTab;
+ private IDeviceInfoUIListener deviceInfoUIListener;
+
+ public DevicePlatformInfoView() {
+ deviceInfoUIListener = new IDeviceInfoUIListener() {
+
+ @Override
+ public void onDeviceInfoFound() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ if (null != deviceTblViewer) {
+ updateViewer(deviceTblViewer, getDevicePropData());
+ }
+ }
+ });
+ }
+ };
+
+ addManagerListeners();
+ }
@Override
public void createPartControl(Composite parent) {
folder.setSelection(devicePropTab);
- metaProperties = getPlatformPropData();
+ platformProperties = getPlatformPropData();
+
+ updateViewer(platformTblViewer, platformProperties);
- updateViewer(metaProperties);
+ deviceProperties = getDevicePropData();
+
+ updateViewer(deviceTblViewer, deviceProperties);
+ }
+
+ private void addManagerListeners() {
+ UiListenerHandler.getInstance().addDeviceInfoUIListener(
+ deviceInfoUIListener);
}
private void createDevicePropertiesTab() {
propGroup.setLayout(new GridLayout(2, false));
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- gd.horizontalIndent = 5;
- gd.verticalIndent = 5;
propGroup.setLayoutData(gd);
- Label devNameLbl = new Label(propGroup, SWT.NULL);
- devNameLbl.setText("Device Name");
- gd = new GridData();
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalSpan = 2;
- devNameLbl.setLayoutData(gd);
+ deviceTblViewer = new TableViewer(propGroup, SWT.SINGLE | SWT.H_SCROLL
+ | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
- deviceNameTxt = new Text(propGroup, SWT.BORDER);
- deviceNameTxt.setText(Activator.getDefault().getResourceManager()
- .getDeviceName());
- gd = new GridData();
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
+ createColumns(deviceTblViewer, PropertiesType.DEVICE);
+
+ // Make lines and header visible
+ final Table table = deviceTblViewer.getTable();
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.horizontalSpan = 2;
- deviceNameTxt.setLayoutData(gd);
- deviceNameTxt.setEnabled(false);
+ table.setLayoutData(gd);
+
+ deviceTblViewer.setContentProvider(new PropertycontentProvider());
devEditBtn = new Button(propGroup, SWT.PUSH);
devEditBtn.setText("Edit");
@Override
public void widgetSelected(SelectionEvent e) {
if (devEditBtn.getText().equals("Edit")) {
- deviceNameTxt.setEnabled(true);
devCancelBtn.setEnabled(true);
-
- deviceNameTxt.selectAll();
- deviceNameTxt.setFocus();
devEditBtn.setText("Save");
+ enableDeviceEdit = true;
} else {
- String devName = deviceNameTxt.getText();
- if (null == devName || devName.trim().length() < 1) {
+ if (Activator.getDefault().getResourceManager()
+ .isDeviceInfoValid(deviceProperties)) {
+ Activator.getDefault().getResourceManager()
+ .setDeviceInfo(deviceProperties);
+ devCancelBtn.setEnabled(false);
+ devEditBtn.setText("Edit");
+ enableDeviceEdit = false;
+ } else {
MessageDialog.openError(Display.getDefault()
- .getActiveShell(), "Invalid Device Name",
- "Device name is Invalid!!");
- deviceNameTxt.setFocus();
- return;
+ .getActiveShell(), "Invalid value",
+ "Property value cannot be empty.");
}
- Activator.getDefault().getResourceManager()
- .setDeviceName(devName);
- deviceNameTxt.setEnabled(false);
- devCancelBtn.setEnabled(false);
- devEditBtn.setText("Edit");
}
}
});
devCancelBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- deviceNameTxt.setText(Activator.getDefault()
- .getResourceManager().getDeviceName());
- deviceNameTxt.setEnabled(false);
+ deviceProperties = getDevicePropData();
+ updateViewer(deviceTblViewer, deviceProperties);
+
devCancelBtn.setEnabled(false);
devEditBtn.setText("Edit");
+ enableDeviceEdit = false;
}
});
platformTblViewer = new TableViewer(propGroup, SWT.SINGLE
| SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
- createColumns(platformTblViewer);
+ createColumns(platformTblViewer, PropertiesType.PLATFORM);
// Make lines and header visible
final Table table = platformTblViewer.getTable();
if (platEditBtn.getText().equals("Edit")) {
platCancelBtn.setEnabled(true);
platEditBtn.setText("Save");
- enable_edit = true;
+ enablePlatformEdit = true;
} else {
- Activator.getDefault().getResourceManager()
- .setPlatformInfo(metaProperties);
- platCancelBtn.setEnabled(false);
- platEditBtn.setText("Edit");
- enable_edit = false;
+ if (Activator.getDefault().getResourceManager()
+ .isPlatformInfoValid(platformProperties)) {
+ Activator.getDefault().getResourceManager()
+ .setPlatformInfo(platformProperties);
+ platCancelBtn.setEnabled(false);
+ platEditBtn.setText("Edit");
+ enablePlatformEdit = false;
+ } else {
+ MessageDialog.openError(Display.getDefault()
+ .getActiveShell(), "Invalid value",
+ "Property value cannot be empty.");
+ }
}
}
});
platCancelBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- metaProperties = getPlatformPropData();
- updateViewer(metaProperties);
+ platformProperties = getPlatformPropData();
+ updateViewer(platformTblViewer, platformProperties);
platCancelBtn.setEnabled(false);
platEditBtn.setText("Edit");
- enable_edit = false;
+ enablePlatformEdit = false;
}
});
platformPropTab.setControl(propGroup);
}
- public void createColumns(TableViewer tableViewer) {
+ public void createColumns(TableViewer tableViewer, PropertiesType propType) {
TableViewerColumn propName = new TableViewerColumn(tableViewer,
SWT.NONE);
propName.getColumn().setWidth(columnWidth[0]);
}
}
});
- propValue.setEditingSupport(new PropValueEditor(platformTblViewer));
+ if (propType == PropertiesType.DEVICE) {
+ propValue.setEditingSupport(new PropValueEditor(deviceTblViewer,
+ propType));
+ } else {
+ propValue.setEditingSupport(new PropValueEditor(platformTblViewer,
+ propType));
+ }
}
class PropertycontentProvider implements IStructuredContentProvider {
return metaPropertyList;
}
- private void updateViewer(List<MetaProperty> metaPropertyList) {
- if (null != platformTblViewer) {
- Table tbl = platformTblViewer.getTable();
+ private List<MetaProperty> getDevicePropData() {
+ List<MetaProperty> metaPropertyList = Activator.getDefault()
+ .getResourceManager().getDeviceInfo();
+ return metaPropertyList;
+ }
+
+ private void updateViewer(TableViewer tableViewer,
+ List<MetaProperty> metaPropertyList) {
+ if (null != tableViewer) {
+ Table tbl = tableViewer.getTable();
if (null != metaPropertyList) {
- platformTblViewer.setInput(metaPropertyList.toArray());
+ tableViewer.setInput(metaPropertyList.toArray());
if (!tbl.isDisposed()) {
tbl.setLinesVisible(true);
}
class PropValueEditor extends EditingSupport {
- private final TableViewer viewer;
+ private final TableViewer viewer;
- public PropValueEditor(TableViewer viewer) {
+ private final PropertiesType propType;
+
+ public PropValueEditor(TableViewer viewer, PropertiesType propType) {
super(viewer);
this.viewer = viewer;
+ this.propType = propType;
}
@Override
@Override
protected CellEditor getCellEditor(Object element) {
- if (!enable_edit) {
+ String propName = ((MetaProperty) element).getPropName();
+ if (null == propName) {
return null;
}
+
+ if (propType == PropertiesType.DEVICE) {
+ if (!enableDeviceEdit)
+ return null;
+ // Only device name property is editable
+ if (!propName.equals(Constants.DEVICE_NAME)) {
+ return null;
+ }
+ } else {
+ if (!enablePlatformEdit) {
+ return null;
+ }
+ }
+
CellEditor editor = new TextCellEditor(viewer.getTable());
return editor;
}
Constants.RESOURCE_URI);
if (result) {
MessageDialog.openError(parent.getShell(),
- "Invalid Input", "Resource URI is invalid.");
+ "Invalid Resource URI.",
+ Constants.INVALID_URI_MESSAGE);
return;
}
import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog;
import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard;
import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromCollections;
import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromDevices;
import oic.simulator.serviceprovider.view.dialogs.RemoveResources;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
collectionResTreeViewer.refresh();
// if(refreshDeviceTree)
deviceTreeViewer.refresh();
+
+ resourceManager
+ .resourceSelectionChanged(null);
+
MessageDialog.openInformation(
Display.getDefault()
.getActiveShell(),
.refresh();
deviceTreeViewer.refresh();
+ resourceManager
+ .resourceSelectionChanged(null);
+
status = "Resource removed from its parent";
} catch (SimulatorException e1) {
status = "Failed to remove the resource from its parent";
collectionResTreeViewer.refresh();
// if(refreshDeviceTree)
deviceTreeViewer.refresh();
+
+ resourceManager.resourceSelectionChanged(null);
+
MessageDialog.openInformation(Display.getDefault()
.getActiveShell(), "Deleted", "Resource deleted.");
} catch (SimulatorException e1) {
int open = wizardDialog.open();
if (open == WizardDialog.OK
|| createWizard.isDlgForceClosed()) {
+
+ Option option = createWizard.getMainPage()
+ .getOption();
+ if (option == Option.DEVICE) {
+ Device dev = createWizard.getCreatedDevice();
+ folder.setSelection(deviceTab);
+ deviceTreeViewer.setSelection(
+ new StructuredSelection(dev), true);
+ resourceManager.deviceSelectionChanged(dev);
+ deviceTreeViewer.expandToLevel(dev,
+ Constants.TREE_EXPANSION_LEVEL);
+ } else if (option == Option.SIMPLE_FROM_RAML
+ || option == Option.SIMPLE) {
+ SingleResource res = (SingleResource) createWizard
+ .getCreatedResource();
+ folder.setSelection(singleResTab);
+ boolean canSelect = true;
+ if (option == Option.SIMPLE_FROM_RAML
+ && createWizard.getResourceCount() > 1) {
+ canSelect = false;
+ }
+ if (canSelect) {
+ singleResTreeViewer.setSelection(
+ new StructuredSelection(res), true);
+ resourceManager
+ .resourceSelectionChanged(res);
+ }
+ } else if (option == Option.COLLECTION_FROM_RAML
+ || option == Option.COLLECTION) {
+ CollectionResource res = (CollectionResource) createWizard
+ .getCreatedResource();
+ folder.setSelection(collectionResTab);
+ collectionResTreeViewer.setSelection(
+ new StructuredSelection(res), true);
+ resourceManager.resourceSelectionChanged(res);
+ collectionResTreeViewer.expandToLevel(res,
+ Constants.TREE_EXPANSION_LEVEL);
+ }
+
MessageDialog.openInformation(Display.getDefault()
.getActiveShell(),
"Resource Creation Status", createWizard
}
private void setUiListeners() {
-
- /*
- * attNameTxt.addModifyListener(new ModifyListener() {
- *
- * @Override public void modifyText(ModifyEvent e) { String value =
- * attNameTxt.getText(); if(null != value) { value = value.trim(); }
- * attHelper.setAttributeName(value); } });
- *
- * dflValueTxt.addModifyListener(new ModifyListener() {
- *
- * @Override public void modifyText(ModifyEvent arg0) { String value =
- * dflValueTxt.getText(); if(null != value) { value = value.trim(); }
- * attHelper.setAttributeDflValue(value); } });
- */
rangeBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
char[] chars = new char[string.length()];
string.getChars(0, chars.length, chars, 0);
for (int i = 0; i < chars.length; i++) {
- if (!('0' <= chars[i] && chars[i] <= '9')) {
+ if (!(('0' <= chars[i] && chars[i] <= '9')
+ || chars[i] == '-' || chars[i] == '+')) {
if (attTypeCmb.getText().equals(Constants.INT)) {
e.doit = false;
return;
char[] chars = new char[string.length()];
string.getChars(0, chars.length, chars, 0);
for (int i = 0; i < chars.length; i++) {
- if (!('0' <= chars[i] && chars[i] <= '9')) {
+ if (!(('0' <= chars[i] && chars[i] <= '9')
+ || chars[i] == '-' || chars[i] == '+')) {
if (attTypeCmb.getText().equals(Constants.INT)) {
e.doit = false;
return;
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
@Override
public void createControl(Composite parent) {
setPageComplete(false);
- if (anyResourceExist)
- setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE2);
- else
- setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE1);
+ setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE);
setMessage(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE);
Composite container = new Composite(parent, SWT.NONE);
if (null == resURI) {
return;
}
+
if (anyResourceExist)
getWizard().getContainer().updateButtons();
else
// itself.
return null;
}
+
+ if (!Utility.isUriValid(resURI)) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+ return null;
+ }
+
if (anyResourceExist) {
return ((CreateResourceWizard) getWizard())
.getAddResourcesToCollectionPage();
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.AttributeHelper;
import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.LocalResourceAttribute;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceType;
import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
-import oic.simulator.serviceprovider.view.dialogs.MainPage.ResourceOption;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
import org.oic.simulator.ILogger.Level;
import org.oic.simulator.SimulatorException;
private WizardDialog wizDialog;
private boolean dlgForceClosed;
+ private Resource createdResource;
+ private Device createdDevice;
+
public CreateResourceWizard() {
setWindowTitle("Create resources");
IPath path = new Path("/icons/oic_logo_64x64.png");
return loadRamlPage.getResourceCount();
}
+ public Resource getCreatedResource() {
+ return createdResource;
+ }
+
+ public Device getCreatedDevice() {
+ return createdDevice;
+ }
+
@Override
public boolean canFinish() {
System.out.println("canFinish()");
IWizardPage curPage = this.getContainer().getCurrentPage();
System.out.println(curPage.getName());
- if ((curPage == updatePropPage && ((mainPage.getResourceOption() == ResourceOption.SIMPLE_FROM_RAML) || !Activator
+ if ((curPage == updatePropPage && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
.getDefault().getResourceManager().isAnyResourceExist()))
|| (curPage == collectionResourceBasicDetailsPage
&& !Activator.getDefault().getResourceManager()
monitor.beginTask(
"Single Resource Creation Without RAML", 2);
monitor.worked(1);
- createSingleResourceWithoutRAML();
- monitor.worked(1);
+ createdResource = createSingleResourceWithoutRAML();
} finally {
monitor.done();
}
e.printStackTrace();
}
} else if (curPage == updatePropPage) { // Handling the single instance
+ String resName = updatePropPage.getResName();
+ String resURI = updatePropPage.getResURI();
+ if (null == resName || resName.trim().length() < 1) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource Name.", "Resource name is invalid");
+ return false;
+ }
+ if (!Utility.isUriValid(resURI)) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+ return false;
+ }
// creation of simple resource
// with RAML
// String resURI = updatePropPage.getResURI();
e.printStackTrace();
}
} else if (curPage == collectionResourceBasicDetailsPage
- || curPage == addResourcesToCollectionPage) { // Handling
- // Collection
- // Resource
- // Creation
- // without RAML
- if (mainPage.getResourceOption() == ResourceOption.COLLECTION_FROM_RAML) {
- Resource res = loadRamlPage.getResource();
- if (null != res && res instanceof CollectionResource) {
- Set<Resource> selectedResources = addResourcesToCollectionPage
- .getSelectedResourceList();
- if (!selectedResources.isEmpty()) {
- int addedCount = Activator
- .getDefault()
- .getResourceManager()
- .addResourceToCollection(
- (CollectionResource) res,
- selectedResources);
- if (addedCount > 0) {
-
- status = "[" + addedCount + "/"
- + selectedResources.size()
- + "] resources added to the collection";
+ || (curPage == addResourcesToCollectionPage && mainPage
+ .getOption() == Option.COLLECTION)) {
+ // Checking whether the uri is used by any other resource.
+ if (Activator
+ .getDefault()
+ .getResourceManager()
+ .isResourceExist(
+ collectionResourceBasicDetailsPage.getResURI())) {
+ MessageDialog
+ .openError(getShell(), "Resource URI in use",
+ "Entered resource URI is in use. Please try a different one.");
+ // TODO: Instead of MessageDialog, errors may be shown on
+ // wizard
+ // itself.
+ return false;
+ }
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
- UiListenerHandler.getInstance()
- .resourceListUpdateUINotification(
- ResourceType.COLLECTION);
- } else {
- status = "Failed to add resources to the collection";
+ @Override
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException,
+ InterruptedException {
+ try {
+ monitor.beginTask(
+ "Collection Resource Creation Without RAML",
+ 3);
+ monitor.worked(1);
+ createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true
+ : false);
+ monitor.worked(1);
+ if (curPage == addResourcesToCollectionPage) {
+ UiListenerHandler.getInstance()
+ .resourceListUpdateUINotification(
+ ResourceType.COLLECTION);
+ }
+ monitor.worked(1);
+ } finally {
+ monitor.done();
}
}
- }
- } else {
- // Checking whether the uri is used by any other resource.
- if (Activator
- .getDefault()
- .getResourceManager()
- .isResourceExist(
- collectionResourceBasicDetailsPage.getResURI())) {
- MessageDialog
- .openError(getShell(), "Resource URI in use",
- "Entered resource URI is in use. Please try a different one.");
- // TODO: Instead of MessageDialog, errors may be shown on
- // wizard
- // itself.
- return false;
- }
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
- try {
- monitor.beginTask(
- "Collection Resource Creation Without RAML",
- 3);
- monitor.worked(1);
- createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true
- : false);
- monitor.worked(1);
- if (curPage == addResourcesToCollectionPage) {
- UiListenerHandler.getInstance()
- .resourceListUpdateUINotification(
- ResourceType.COLLECTION);
+ });
+ } catch (InvocationTargetException e) {
+ Activator.getDefault().getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ Activator.getDefault().getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+ e.printStackTrace();
+ }
+ } else if (curPage == addResourcesToCollectionPage) {
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
+
+ @Override
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException,
+ InterruptedException {
+ try {
+ monitor.beginTask(
+ "Completing Collection Resource Creation With RAML",
+ 3);
+ monitor.worked(1);
+ completeResourceCreationWithRAML();
+ monitor.worked(1);
+
+ if (mainPage.getOption() == Option.COLLECTION_FROM_RAML) {
+ Resource res = loadRamlPage.getResource();
+ if (null != res
+ && res instanceof CollectionResource) {
+ Set<Resource> selectedResources = addResourcesToCollectionPage
+ .getSelectedResourceList();
+ if (!selectedResources.isEmpty()) {
+ int addedCount = Activator
+ .getDefault()
+ .getResourceManager()
+ .addResourceToCollection(
+ (CollectionResource) res,
+ selectedResources);
+ if (addedCount > 0) {
+
+ status += " and ["
+ + addedCount
+ + "/"
+ + selectedResources.size()
+ + "] resources added to the collection";
+
+ UiListenerHandler
+ .getInstance()
+ .resourceListUpdateUINotification(
+ ResourceType.COLLECTION);
+ } else {
+ status += " but failed to add resources to the collection";
+ }
+ }
}
- monitor.worked(1);
- } finally {
- monitor.done();
}
+ monitor.worked(1);
+ } finally {
+ monitor.done();
}
- });
- } catch (InvocationTargetException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- e.getMessage());
- e.printStackTrace();
- } catch (InterruptedException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- e.getMessage());
- e.printStackTrace();
- }
+ }
+ });
+ } catch (InvocationTargetException e) {
+ Activator.getDefault().getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ Activator.getDefault().getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
+ e.printStackTrace();
}
} else if (curPage == devicePage) {
final String devName = devicePage.getDeviceName();
try {
monitor.beginTask("Device Creation", 3);
monitor.worked(1);
- createDevice(devName, resourceList);
+ createdDevice = createDevice(devName, resourceList);
monitor.worked(1);
UiListenerHandler.getInstance()
.resourceListUpdateUINotification(
* public SingleResource getCreatedResource() { return simResource; }
*/
- private void createSingleResourceWithoutRAML() {
+ private SingleResource createSingleResourceWithoutRAML() {
SingleResource resource = new SingleResource();
// Basic resource details
resource.setResourceURI(simpleResourceBasicDetailsPage.getResURI());
status = "Resource created.";
} else {
status = "Failed to create resource.";
+ resource = null;
}
} catch (SimulatorException e) {
status = "Failed to create resource.\n"
+ Utility.getSimulatorErrorString(e, null);
+ resource = null;
}
+ return resource;
}
private void completeResourceCreationWithRAML() {
if (result) {
status = "Resource created.";
+ createdResource = res;
} else {
status = "Failed to create resource.";
+ createdResource = null;
}
} catch (SimulatorException e) {
status = "Failed to create resource.\n"
+ Utility.getSimulatorErrorString(e, null);
+ createdResource = null;
}
}
boolean result = Activator.getDefault().getResourceManager()
.createCollectionResource(resource);
if (result) {
- status = "Resource created.";
+ status = "Resource created";
// Adding child resources.
if (childResExist) {
Set<Resource> selectedResources = addResourcesToCollectionPage
.addResourceToCollection(resource,
selectedResources);
if (addedCount > 0) {
- status = "[" + addedCount + "/"
+ status += " and [" + addedCount + "/"
+ selectedResources.size()
+ "] resources added to the collection";
} else {
- status = "Failed to add resources to the collection.";
+ status += " but failed to add resources to the collection.";
}
}
}
+ createdResource = resource;
} else {
status = "Failed to create resource.";
+ createdResource = null;
}
} catch (SimulatorException e) {
status = "Failed to create resource.\n"
+ Utility.getSimulatorErrorString(e, null);
+ createdResource = null;
}
}
- private void createDevice(String deviceName, Set<Resource> childs) {
- Activator.getDefault().getResourceManager()
+ private Device createDevice(String deviceName, Set<Resource> childs) {
+ return Activator.getDefault().getResourceManager()
.createDevice(deviceName, childs);
}
import java.util.Set;
import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.SingleResource;
import org.eclipse.core.runtime.FileLocator;
@Override
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
+ ResourceManager resourceManager = Activator.getDefault()
+ .getResourceManager();
try {
monitor.beginTask("Resource Deletion", 2);
Set<CollectionResource> collectionResources = page
.getResourceManager()
.removeCollectionResources(
collectionResources);
+
+ Resource res = resourceManager
+ .getCurrentResourceInSelection();
+ if (null != res
+ && res instanceof CollectionResource) {
+ if (collectionResources
+ .contains((CollectionResource) res)) {
+ resourceManager
+ .resourceSelectionChanged(null);
+ }
+ }
}
monitor.worked(1);
Set<SingleResource> singleResources = page
&& singleResources.size() > 0) {
Activator.getDefault().getResourceManager()
.removeSingleResources(singleResources);
+
+ Resource res = resourceManager
+ .getCurrentResourceInSelection();
+ if (null != res && res instanceof SingleResource) {
+ if (singleResources
+ .contains((SingleResource) res)) {
+ resourceManager
+ .resourceSelectionChanged(null);
+ }
+ }
}
monitor.worked(1);
status = "Resources deleted.";
import java.util.Date;
import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.CollectionResource;
import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SingleResource;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
wizard.setStatus("Failed to create Resource.");
wizard.getWizardDialog().close();
return null;
+ } else {
+ // Checking whether the resource is single or collection.
+ Option intendedResource = wizard.getMainPage().getOption();
+ if ((intendedResource == Option.SIMPLE_FROM_RAML && resource instanceof CollectionResource)) {
+ MessageDialog
+ .openError(
+ getShell(),
+ "Invalid RAML",
+ "Uploaded RAML is of type collection. "
+ + "Please upload the proper RAML of simple type.");
+ return null;
+ } else if (intendedResource == Option.COLLECTION_FROM_RAML
+ && resource instanceof SingleResource) {
+ MessageDialog
+ .openError(
+ getShell(),
+ "Invalid RAML",
+ "Uploaded RAML is of type simple. "
+ + "Please upload the proper RAML of collection type.");
+ return null;
+ }
}
UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage();
updatePageRef.setResName(resource.getResourceName());
private Button deviceBtn;
private Text description;
- public enum ResourceOption {
+ public enum Option {
SIMPLE, SIMPLE_FROM_RAML, COLLECTION, COLLECTION_FROM_RAML, DEVICE, NONE
}
- private ResourceOption resOption;
+ private Option option;
protected MainPage() {
super("Main Page");
+ "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
+ "\t2. Options such as Observable, allowed request types, start/stop resource etc.\n"
+ "\t3. Adding attributes.");
- resOption = ResourceOption.SIMPLE;
+ option = Option.SIMPLE;
getWizard().getContainer().updateButtons();
}
});
+ "\t2. Supports multi-instance creation.\n"
+ "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
+ "\t4. Allows to start or stop the resource(s).");
- resOption = ResourceOption.SIMPLE_FROM_RAML;
+ option = Option.SIMPLE_FROM_RAML;
getWizard().getContainer().updateButtons();
}
});
+ "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
+ "\t2. Start/stop the resource.\n"
+ "\t3. Adding existing simple resources to this collection.");
- resOption = ResourceOption.COLLECTION;
+ option = Option.COLLECTION;
getWizard().getContainer().updateButtons();
}
});
+ "\t2. Supports multi-instance creation.\n"
+ "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
+ "\t4. Allows to start or stop the resource(s).");
- resOption = ResourceOption.COLLECTION_FROM_RAML;
+ option = Option.COLLECTION_FROM_RAML;
getWizard().getContainer().updateButtons();
}
});
.setText("Create a logical device that acts as a top-level logical classification.\n"
+ "\t1. Takes a device name for identication.\n"
+ "\t2. One or more simple and collection resources can be added to it.");
- resOption = ResourceOption.DEVICE;
+ option = Option.DEVICE;
getWizard().getContainer().updateButtons();
}
});
@Override
public boolean canFlipToNextPage() {
- if (resOption != ResourceOption.NONE) {
+ if (option != Option.NONE) {
return true;
}
return false;
return null;
}
- public ResourceOption getResourceOption() {
- return resOption;
+ public Option getOption() {
+ return option;
}
}
package oic.simulator.serviceprovider.view.dialogs;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
+
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardDialog;
loadRamlPage.setResource(null);
prevPage = loadRamlPage;
} else if (curPage == addResourcesToCollectionPage) {
- prevPage = collectionResourceBasicDetailsPage;
+ if (mainPage.getOption() == Option.COLLECTION_FROM_RAML) {
+ prevPage = updatePropPage;
+ } else {
+ prevPage = collectionResourceBasicDetailsPage;
+ }
} else if (curPage == simpleResourceAddAttributesPage) {
prevPage = simpleResourceBasicDetailsPage;
} else if (curPage == simpleResourceOtherDetailsPage) {
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
@Override
public void modifyText(ModifyEvent arg0) {
resURI = resUriTxt.getText();
+ if (null == resURI) {
+ return;
+ }
+
getWizard().getContainer().updateButtons();
}
});
observable = observeBtn.getSelection();
}
});
-
- /*
- * startBtn.addSelectionListener(new SelectionAdapter() {
- *
- * @Override public void widgetSelected(SelectionEvent e) { start =
- * startBtn.getSelection(); } });
- */
}
private void changeVisibility() {
@Override
public IWizardPage getNextPage() {
+ if (!Utility.isUriValid(resURI)) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+ return null;
+ }
+
// Checking whether the uri is used by any other resource.
if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
MessageDialog
// itself.
return null;
}
+
return ((CreateResourceWizard) getWizard())
.getSimpleResourceAddAttributePage();
}
public boolean isObservable() {
return observable;
}
-
- /*
- * public boolean isStart() { return start; }
- */
-
}
+++ /dev/null
-package oic.simulator.serviceprovider.view.dialogs;
-
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-public class SimpleResourcePage extends WizardPage {
-
- Button manualBtn;
- Button ramlBtn;
-
- protected SimpleResourcePage() {
- super("Simle Page");
- }
-
- @Override
- public void createControl(Composite parent) {
- setPageComplete(false);
- setTitle(Constants.SIMPLE_PAGE_TITLE);
- setMessage(Constants.SIMPLE_PAGE_MESSAGE);
- Composite compContent = new Composite(parent, SWT.NONE);
- GridLayout gridLayout = new GridLayout();
- compContent.setLayout(gridLayout);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- compContent.setLayoutData(gd);
-
- manualBtn = new Button(compContent, SWT.RADIO);
- manualBtn.setText("Manually");
-
- ramlBtn = new Button(compContent, SWT.RADIO);
- ramlBtn.setText("From RAML file");
-
- Label lbl = new Label(compContent, SWT.NULL);
- lbl.setText("Details:");
- gd = new GridData();
- gd.verticalIndent = 20;
- lbl.setLayoutData(gd);
-
- Text desc = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
- | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
- desc.setBackground(compContent.getBackground());
- desc.setText("[Select an option to view more details]");
- gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- desc.setLayoutData(gd);
-
- addUIListeners();
-
- setControl(compContent);
- }
-
- private void addUIListeners() {
- manualBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- getWizard().getContainer().updateButtons();
- }
- });
-
- ramlBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- getWizard().getContainer().updateButtons();
- }
- });
- }
-
- @Override
- public boolean canFlipToNextPage() {
- if (manualBtn.getSelection() || ramlBtn.getSelection()) {
- return true;
- }
- return false;
- }
-
- @Override
- public IWizardPage getNextPage() {
- CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
- if (manualBtn.getSelection()) {
- return createWizard.getSimpleResourceBasicDetailsPage();
- }
- if (ramlBtn.getSelection()) {
- return createWizard.getLoadRamlPage();
- }
- return null;
- }
-}
package oic.simulator.serviceprovider.view.dialogs;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Date;
-
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
-import oic.simulator.serviceprovider.view.dialogs.MainPage.ResourceOption;
+import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-import org.oic.simulator.ILogger.Level;
-import org.oic.simulator.SimulatorException;
public class UpdatePropertiesPage extends WizardPage {
public void modifyText(ModifyEvent e) {
resName = resNameTxt.getText();
setPageComplete(isSelectionDone());
- // getWizard().getContainer().updateButtons();
}
});
@Override
public void modifyText(ModifyEvent e) {
resURI = resUriTxt.getText();
+ if (null == resURI) {
+ return;
+ }
+
setPageComplete(isSelectionDone());
- // getWizard().getContainer().updateButtons();
}
});
}
public boolean canFlipToNextPage() {
CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
if (isSelectionDone()
- && (createWizard.getMainPage().getResourceOption() == ResourceOption.COLLECTION_FROM_RAML)
+ && (createWizard.getMainPage().getOption() == Option.COLLECTION_FROM_RAML)
&& Activator.getDefault().getResourceManager()
.isAnyResourceExist()) {
return true;
@Override
public IWizardPage getNextPage() {
- final boolean done[] = new boolean[1];
+ if (null == resName || resName.trim().length() < 1) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource Name.", "Resource name is invalid.");
+ return null;
+ }
+
+ if (!Utility.isUriValid(resURI)) {
+ MessageDialog.openError(Display.getDefault().getActiveShell(),
+ "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
+ return null;
+ }
+
CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
// Checking whether the uri is used by any other resource.
if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
// itself.
return null;
}
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- try {
- monitor.beginTask(
- "Completing Collection Resource Creation With RAML",
- 2);
- monitor.worked(1);
- done[0] = completeCollectionResourceCreationWithRAML();
- monitor.worked(1);
- } finally {
- monitor.done();
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- return null;
- } catch (InterruptedException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- return null;
- }
- if (!done[0]) {
- return null;
- }
return createWizard.getAddResourcesToCollectionPage();
}
public String getResURI() {
return resURI;
}
-
- private boolean completeCollectionResourceCreationWithRAML() {
- boolean result = false;
- String status;
- CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
- try {
- result = Activator
- .getDefault()
- .getResourceManager()
- .completeCollectionResourceCreationByRAML(
- createWizard.getLoadRamlPage().getResource(),
- resURI, resName);
- if (result)
- status = "Resource created.";
- else {
- status = "Failed to create resource.";
- }
- } catch (SimulatorException e) {
- status = "Failed to create resource.\n"
- + Utility.getSimulatorErrorString(e, null);
- }
- createWizard.setStatus(status);
- return result;
- }
}
m_env->SetObjectField(jDeviceInfo, fieldID, valueStr);
}
-void onDeviceInfoReceived(jobject listener, DeviceInfo &deviceInfo)
+void onDeviceInfoReceived(jobject listener, const std::string &hostUri, DeviceInfo &deviceInfo)
{
JNIEnv *env = getEnv();
if (!env)
jclass listenerCls = env->GetObjectClass(listener);
jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onDeviceFound",
- "(Lorg/oic/simulator/DeviceInfo;)V");
+ "(Ljava/lang/String;Lorg/oic/simulator/DeviceInfo;)V");
+
+ jstring jHostUri = env->NewStringUTF(hostUri.c_str());
jobject jDeviceInfo = JniDeviceInfo(env).toJava(deviceInfo);
if (!jDeviceInfo)
{
return;
}
- env->CallVoidMethod(listener, listenerMethodId, jDeviceInfo);
+ env->CallVoidMethod(listener, listenerMethodId, jHostUri, jDeviceInfo);
if (env->ExceptionCheck())
{
releaseEnv();
JNIEnv *m_env;
};
-void onDeviceInfoReceived(jobject listener, DeviceInfo &deviceInfo);
+void onDeviceInfoReceived(jobject listener, const std::string &host, DeviceInfo &deviceInfo);
#endif
{
VALIDATE_CALLBACK(env, listener)
- DeviceInfoCallback callback = std::bind([](DeviceInfo & deviceInfo,
+ DeviceInfoCallback callback = std::bind([](const std::string & host, DeviceInfo & deviceInfo,
const std::shared_ptr<JniListenerHolder> &listenerRef)
{
- onDeviceInfoReceived(listenerRef->get(), deviceInfo);
- }, std::placeholders::_1, JniListenerHolder::create(env, listener));
+ onDeviceInfoReceived(listenerRef->get(), host, deviceInfo);
+ }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
try
{
{
VALIDATE_CALLBACK(env, listener)
- PlatformInfoCallback callback = std::bind([](PlatformInfo & platformInfo,
+ PlatformInfoCallback callback = std::bind([](const std::string & host, PlatformInfo & platformInfo,
const std::shared_ptr<JniListenerHolder> &listenerRef)
{
- onPlatformInfoReceived(listenerRef->get(), platformInfo);
- }, std::placeholders::_1, JniListenerHolder::create(env, listener));
+ onPlatformInfoReceived(listenerRef->get(), host, platformInfo);
+ }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
try
{
return value.get();
}
-void onPlatformInfoReceived(jobject listener, PlatformInfo &platformInfo)
+void onPlatformInfoReceived(jobject listener, const std::string &hostUri, PlatformInfo &platformInfo)
{
JNIEnv *env = getEnv();
if (!env)
jclass listenerCls = env->GetObjectClass(listener);
jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPlatformFound",
- "(Lorg/oic/simulator/PlatformInfo;)V");
+ "(Ljava/lang/String;Lorg/oic/simulator/PlatformInfo;)V");
+ jstring jHostUri = env->NewStringUTF(hostUri.c_str());
jobject jPlatformInfo = JniPlatformInfo(env).toJava(platformInfo);
if (!jPlatformInfo)
{
return;
}
- env->CallVoidMethod(listener, listenerMethodId, jPlatformInfo);
+ env->CallVoidMethod(listener, listenerMethodId, jHostUri, jPlatformInfo);
if (env->ExceptionCheck())
{
releaseEnv();
JNIEnv *m_env;
};
-void onPlatformInfoReceived(jobject listener, PlatformInfo &platformInfo);
+void onPlatformInfoReceived(jobject listener, const std::string &host, PlatformInfo &platformInfo);
#endif
/**
* Method which provides remote device information.
*
+ * @param hostUri
+ * Holds the address and port information.
* @param devInfo
* {@link DeviceInfo} object holding the device information.
*/
- public void onDeviceFound(DeviceInfo devInfo);
+ public void onDeviceFound(String hostUri, DeviceInfo devInfo);
}
/**
* Method which provides remote device platform information.
*
+ * @param hostUri
+ * Holds the address and port information.
* @param platformInfo
* {@link PlatformInfo} object holding the platform information.
*/
- public void onPlatformFound(PlatformInfo platformInfo);
+ public void onPlatformFound(String hostUri, PlatformInfo platformInfo);
}
else
{
response = std::make_shared<OC::OCResourceResponse>();
- response->setErrorCode(400);
+ response->setErrorCode(403);
response->setResponseResult(OC_EH_ERROR);
if ("PUT" == request->getRequestType())
{
VALIDATE_CALLBACK(callback)
OC::FindDeviceCallback deviceCallback = std::bind(
- [](const OC::OCRepresentation & rep, DeviceInfoCallback callback)
+ [](const OC::OCRepresentation & rep, const std::string & hostUri, DeviceInfoCallback callback)
{
std::string deviceName = rep.getValue<std::string>("n");
std::string deviceID = rep.getValue<std::string>("di");
std::string deviceDMV = rep.getValue<std::string>("dmv");
DeviceInfo deviceInfo(deviceName, deviceID, deviceSpecVersion, deviceDMV);
- callback(deviceInfo);
- }, std::placeholders::_1, callback);
+ callback(hostUri, deviceInfo);
+ }, std::placeholders::_1, host, callback);
typedef OCStackResult (*GetDeviceInfo)(const std::string &, const std::string &,
OCConnectivityType, OC::FindDeviceCallback);
VALIDATE_CALLBACK(callback)
OC::FindPlatformCallback platformCallback = std::bind(
- [](const OC::OCRepresentation & rep, PlatformInfoCallback callback)
+ [](const OC::OCRepresentation & rep, const std::string & hostUri, PlatformInfoCallback callback)
{
PlatformInfo platformInfo;
platformInfo.setPlatformID(rep.getValue<std::string>("pi"));
platformInfo.setSupportUrl(rep.getValue<std::string>("mnsl"));
platformInfo.setSystemTime(rep.getValue<std::string>("st"));
- callback(platformInfo);
- }, std::placeholders::_1, callback);
+ callback(hostUri, platformInfo);
+ }, std::placeholders::_1, host, callback);
typedef OCStackResult (*GetPlatformInfo)(const std::string &, const std::string &,
OCConnectivityType, OC::FindPlatformCallback);