Commit a1327fad authored by Larry Sachs's avatar Larry Sachs

Move oic.d.light type to /oic/d resource

Change-Id: Id94538768bbcd5aecff3da708d7ec64d580361c0
Signed-off-by: Larry Sachs's avatarLarry Sachs <larry.j.sachs@intel.com>
parent ad83434c
......@@ -123,7 +123,9 @@ public class IotivityClient implements
tracked = true;
} else {
AlexaIotivityBridgeDemo.msg("URI of the new (for now, untracked) resource: " + resourceUri);
if (!resourceUri.equals("/oic/d")) {
AlexaIotivityBridgeDemo.msg("URI of the new (for now, untracked) resource: " + resourceUri);
}
}
if (tracked) {
......@@ -315,27 +317,29 @@ public class IotivityClient implements
Links links = device.getLinks();
for (Link link : links.getLinks()) {
String href = link.getHref();
// rt could be String or String[]
Object rt = link.getRt();
String rtAsString = null;
if (rt instanceof String) {
rtAsString = (String) rt;
} else if (rt instanceof String[]) {
if (((String[]) rt).length > 0) {
rtAsString = ((String[]) rt)[0];
if (!href.equals("/oic/d")) {
// rt could be String or String[]
Object rt = link.getRt();
String rtAsString = null;
if (rt instanceof String) {
rtAsString = (String) rt;
} else if (rt instanceof String[]) {
if (((String[]) rt).length > 0) {
rtAsString = ((String[]) rt)[0];
} else {
AlexaIotivityBridgeDemo.msgError("(String[])rt is empty");
}
} else {
AlexaIotivityBridgeDemo.msgError("(String[])rt is empty");
AlexaIotivityBridgeDemo.msgError("Unknown rt type of " + rt.getClass().getName());
}
} else {
AlexaIotivityBridgeDemo.msgError("Unknown rt type of " + rt.getClass().getName());
}
if ((rtAsString != null) && (!mResourceLookup.containsKey(href))) {
AlexaIotivityBridgeDemo.msg("Finding all resources of type " + rtAsString);
String requestUri = OcPlatform.WELL_KNOWN_QUERY + "?rt=" + rtAsString;
OcPlatform.findResource("", requestUri, EnumSet.of(OcConnectivityType.CT_DEFAULT), new ResourceFoundListener(ocRepUri, href));
if ((rtAsString != null) && (!mResourceLookup.containsKey(href))) {
AlexaIotivityBridgeDemo.msg("Finding all resources of type " + rtAsString);
String requestUri = OcPlatform.WELL_KNOWN_QUERY + "?rt=" + rtAsString;
OcPlatform.findResource("", requestUri, EnumSet.of(OcConnectivityType.CT_DEFAULT), new ResourceFoundListener(ocRepUri, href));
}
}
}
......
......@@ -114,7 +114,9 @@ public class IotivityScannerClient implements
tracked = true;
} else {
IotivityScanner.msg("URI of the new (for now, untracked) resource: " + resourceUri);
if (!resourceUri.equals("/oic/d")) {
IotivityScanner.msg("URI of the new (for now, untracked) resource: " + resourceUri);
}
}
if (tracked) {
......@@ -306,27 +308,29 @@ public class IotivityScannerClient implements
Links links = device.getLinks();
for (Link link : links.getLinks()) {
String href = link.getHref();
// rt could be String or String[]
Object rt = link.getRt();
String rtAsString = null;
if (rt instanceof String) {
rtAsString = (String) rt;
} else if (rt instanceof String[]) {
if (((String[]) rt).length > 0) {
rtAsString = ((String[]) rt)[0];
if (!href.equals("/oic/d")) {
// rt could be String or String[]
Object rt = link.getRt();
String rtAsString = null;
if (rt instanceof String) {
rtAsString = (String) rt;
} else if (rt instanceof String[]) {
if (((String[]) rt).length > 0) {
rtAsString = ((String[]) rt)[0];
} else {
IotivityScanner.msgError("(String[])rt is empty");
}
} else {
IotivityScanner.msgError("(String[])rt is empty");
IotivityScanner.msgError("Unknown rt type of " + rt.getClass().getName());
}
} else {
IotivityScanner.msgError("Unknown rt type of " + rt.getClass().getName());
}
if ((rtAsString != null) && (!mResourceLookup.containsKey(href))) {
IotivityScanner.msg("Finding all resources of type " + rtAsString);
String requestUri = OcPlatform.WELL_KNOWN_QUERY + "?rt=" + rtAsString;
OcPlatform.findResource("", requestUri, EnumSet.of(OcConnectivityType.CT_DEFAULT), new ResourceFoundListener(ocRepUri, href));
if ((rtAsString != null) && (!mResourceLookup.containsKey(href))) {
IotivityScanner.msg("Finding all resources of type " + rtAsString);
String requestUri = OcPlatform.WELL_KNOWN_QUERY + "?rt=" + rtAsString;
OcPlatform.findResource("", requestUri, EnumSet.of(OcConnectivityType.CT_DEFAULT), new ResourceFoundListener(ocRepUri, href));
}
}
}
......
......@@ -34,11 +34,18 @@ import org.iotivity.base.PayloadType;
* This class represents a light resource
*/
public class Light extends Resource implements LightImageObserver {
static private final String RES_TYPE = "oic.d.light";
static public final String RES_TYPE = "oic.d.light";
static public final String DEVICE_RES_TYPE = "oic.wk.d";
static private final String COL_RES_TYPE = "oic.wk.col";
static private final String VENDOR_RES_TYPE = "x.org.examples.light";
static private final String RTS_KEY = "rts";
static private final String LINKS_KEY = "links";
private Links resourceLinks;
private String[] collectionResTypes = {Switch.RES_TYPE, Brightness.RES_TYPE};
private LightConfig lightConfigRes;
private Switch switchRes;
......@@ -49,7 +56,7 @@ public class Light extends Resource implements LightImageObserver {
private int brightness;
public Light(boolean useLinks, String name, String uuid, boolean powerOn, int brightness, LightPanel ui) {
super("/ocf/light/" + uuid, RES_TYPE, OcPlatform.DEFAULT_INTERFACE);
super("/ocf/light/" + uuid, (useLinks ? RES_TYPE : VENDOR_RES_TYPE), OcPlatform.DEFAULT_INTERFACE);
if (useLinks) {
lightConfigRes = new LightConfig(name, uuid, this);
......@@ -89,14 +96,16 @@ public class Light extends Resource implements LightImageObserver {
}
if (useLinks) {
Link[] links = new Link[3];
Link[] links = new Link[4];
links[0] = new Link(lightConfigRes.getResourceUri(), new String[] { LightConfig.RES_TYPE });
links[1] = new Link(switchRes.getResourceUri(), new String[] { Switch.RES_TYPE });
links[2] = new Link(brightnessRes.getResourceUri(), new String[] { Brightness.RES_TYPE });
links[3] = new Link("/oic/d", new String[] { DEVICE_RES_TYPE, RES_TYPE });
resourceLinks = new Links(links);
try {
OcPlatform.bindInterfaceToResource(getResourceHandle(), OcPlatform.LINK_INTERFACE);
OcPlatform.bindTypeToResource(getResourceHandle(), COL_RES_TYPE);
} catch (OcException e) {
OcfLightDevice.msgError("Failed to bind link interface for " + getResourceUri());
......@@ -118,7 +127,6 @@ public class Light extends Resource implements LightImageObserver {
OcfLightDevice.msgError("Failed to bind interface or type for " + getResourceUri());
e.printStackTrace();
}
}
OcfLightDevice.msg("Created light resource: " + this);
......@@ -194,6 +202,7 @@ public class Light extends Resource implements LightImageObserver {
OcRepresentation rep = new OcRepresentation();
try {
if (resourceLinks != null) {
rep.setValue(RTS_KEY, collectionResTypes);
OcRepresentation[] links = resourceLinks.getOcRepresentation();
rep.setValue(LINKS_KEY, links);
......
......@@ -23,7 +23,9 @@
package org.iotivity.base.examples;
import org.iotivity.base.ModeType;
import org.iotivity.base.OcException;
import org.iotivity.base.OcPlatform;
import org.iotivity.base.OcResourceHandle;
import org.iotivity.base.PlatformConfig;
import org.iotivity.base.QualityOfService;
import org.iotivity.base.ServiceType;
......@@ -53,15 +55,18 @@ public class OcfLightDevice {
static boolean isTest;
static int testFrequency = 3;
static boolean useLinks;
static boolean useLinks = true;
static String name;
static boolean powerOn = true;
static int brightness = 100;
static OcResourceHandle deviceResourceHandle;
public static void main(String args[]) throws IOException, InterruptedException {
if ((args.length > 0) && (args[0].startsWith("-"))) {
if (args[0].startsWith("-t")) {
// toggle test
isTest = true;
try {
testFrequency = Integer.valueOf(args[0].substring(2));
......@@ -71,9 +76,10 @@ public class OcfLightDevice {
testFrequency = Math.max(1, testFrequency);
testFrequency = Math.min(60, testFrequency);
msg("Server in test mode with frequecy of " + testFrequency);
} else if (args[0].equalsIgnoreCase("-l")) {
useLinks = true;
msg("Server using links");
} else if (args[0].equalsIgnoreCase("-v")) {
// vendor specific resource
useLinks = false;
msg("Server using vendor resource type");
} else {
msg("Unknown runtime parameter: " + args[0]);
}
......@@ -89,6 +95,17 @@ public class OcfLightDevice {
OcPlatform.Configure(platformConfig);
msg("Platform configured");
try {
deviceResourceHandle = OcPlatform.getResourceHandleAtUri(OcPlatform.WELL_KNOWN_DEVICE_QUERY);
if (deviceResourceHandle != null) {
OcPlatform.bindTypeToResource(deviceResourceHandle, Light.RES_TYPE);
}
} catch (OcException e) {
OcfLightDevice.msgError("Failed to bind device type to /oic/d resource");
e.printStackTrace();
}
String uuid = null;
if (NamesPropertyFile.getInstance().hasName(name)) {
uuid = NamesPropertyFile.getInstance().getUuidForName(name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment