Commit 7140b056 authored by Larry Sachs's avatar Larry Sachs Committed by Rick Bell

Update Server to run w/ client_collections_linux

Change-Id: I04dea9d0742389be17fb00dcf002875d86c3321c
Signed-off-by: Larry Sachs's avatarLarry Sachs <larry.j.sachs@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/29381Tested-by: default avatarIoTivity Jenkins <jenkins-daemon@iotivity.org>
Reviewed-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
Reviewed-by: default avatarRick Bell <richard.s.bell@intel.com>
parent 040bf0af
...@@ -54,7 +54,7 @@ public class GetLightResponseHandler implements OCResponseHandler { ...@@ -54,7 +54,7 @@ public class GetLightResponseHandler implements OCResponseHandler {
if (OCMain.doPut()) { if (OCMain.doPut()) {
activity.msg("\tSent PUT request"); activity.msg("\tSent PUT request");
} else { } else {
activity.msg("\tCould no send PUT request"); activity.msg("\tCould not send PUT request");
} }
} else { } else {
activity.msg("\tCould not init PUT request"); activity.msg("\tCould not init PUT request");
......
...@@ -43,7 +43,7 @@ public class GetLightResponseHandler implements OCResponseHandler { ...@@ -43,7 +43,7 @@ public class GetLightResponseHandler implements OCResponseHandler {
if (OCMain.doPut()) { if (OCMain.doPut()) {
System.out.println("\tSent PUT request"); System.out.println("\tSent PUT request");
} else { } else {
System.out.println("\tCould no send PUT request"); System.out.println("\tCould not send PUT request");
} }
} else { } else {
System.out.println("\tCould not init PUT request"); System.out.println("\tCould not init PUT request");
......
package java_lite_simple_server;
public class Counter {
public static String name;
public static long count;
}
package java_lite_simple_server;
import org.iotivity.CborEncoder;
import org.iotivity.OCInterfaceMask;
import org.iotivity.OCMain;
import org.iotivity.OCRequest;
import org.iotivity.OCStatus;
import org.iotivity.OCRequestHandler;
public class GetCounter implements OCRequestHandler {
@Override
public void handler(OCRequest request, int interfaces) {
System.out.println("Inside the GetCounter RequestHandler");
Counter.count++;
System.out.println("GET COUNTER:");
CborEncoder root = OCMain.repBeginRootObject();
switch (interfaces) {
case OCInterfaceMask.BASELINE: {
OCMain.processBaselineInterface(request.getResource());
/* fall through */
}
case OCInterfaceMask.R: {
OCMain.repSetLong(root, "count", Counter.count);
OCMain.repSetTextString(root, "name", Counter.name);
break;
}
default:
break;
}
OCMain.repEndRootObject();
OCMain.sendResponse(request, OCStatus.OC_STATUS_OK);
}
}
...@@ -12,18 +12,15 @@ public class GetLight implements OCRequestHandler { ...@@ -12,18 +12,15 @@ public class GetLight implements OCRequestHandler {
@Override @Override
public void handler(OCRequest request, int interfaces) { public void handler(OCRequest request, int interfaces) {
System.out.println("Inside the GetLight RequestHandler"); System.out.println("Inside the GetLight RequestHandler");
Light.power++; Light.power++;
System.out.println("GET LIGHT:"); System.out.println("GET LIGHT:");
CborEncoder root = OCMain.repBeginRootObject(); CborEncoder root = OCMain.repBeginRootObject();
switch(interfaces) { switch (interfaces) {
case OCInterfaceMask.BASELINE: case OCInterfaceMask.BASELINE: {
{
OCMain.processBaselineInterface(request.getResource()); OCMain.processBaselineInterface(request.getResource());
break; /* fall through */
} }
case OCInterfaceMask.RW: case OCInterfaceMask.RW: {
{
OCMain.repSetBoolean(root, "state", Light.state); OCMain.repSetBoolean(root, "state", Light.state);
OCMain.repSetLong(root, "power", Light.power); OCMain.repSetLong(root, "power", Light.power);
OCMain.repSetTextString(root, "name", Light.name); OCMain.repSetTextString(root, "name", Light.name);
......
...@@ -4,5 +4,4 @@ public class Light { ...@@ -4,5 +4,4 @@ public class Light {
public static String name; public static String name;
public static long power; public static long power;
public static boolean state; public static boolean state;
} }
...@@ -11,6 +11,8 @@ public class MyInitHandler implements OCMainInitHandler { ...@@ -11,6 +11,8 @@ public class MyInitHandler implements OCMainInitHandler {
Light.name = "John's Light"; Light.name = "John's Light";
Light.power = 0; Light.power = 0;
Light.state = false; Light.state = false;
Counter.name = "John's Counter";
Counter.count = 0;
return ret; return ret;
} }
...@@ -28,6 +30,39 @@ public class MyInitHandler implements OCMainInitHandler { ...@@ -28,6 +30,39 @@ public class MyInitHandler implements OCMainInitHandler {
OCMain.resourceSetRequestHandler(resource, OCMethod.OC_PUT, new PutLight()); OCMain.resourceSetRequestHandler(resource, OCMethod.OC_PUT, new PutLight());
OCMain.resourceSetRequestHandler(resource, OCMethod.OC_POST, new PostLight()); OCMain.resourceSetRequestHandler(resource, OCMethod.OC_POST, new PostLight());
OCMain.addResource(resource); OCMain.addResource(resource);
// for running with client_collections_linux
OCResource resource1 = OCMain.newResource("lightbulb", "/light/1", (short) 1, 0);
OCMain.resourceBindResourceType(resource1, "oic.r.light");
OCMain.resourceBindResourceInterface(resource1, OCInterfaceMask.RW);
OCMain.resourceSetDefaultInterface(resource1, OCInterfaceMask.RW);
OCMain.resourceSetDiscoverable(resource1, true);
OCMain.resourceSetPeriodicObservable(resource1, 1);
OCMain.resourceSetRequestHandler(resource1, OCMethod.OC_GET, new GetLight());
OCMain.resourceSetRequestHandler(resource1, OCMethod.OC_PUT, new PutLight());
OCMain.resourceSetRequestHandler(resource1, OCMethod.OC_POST, new PostLight());
OCMain.addResource(resource1);
OCResource resource2 = OCMain.newResource("counter", "/count/1", (short) 1, 0);
OCMain.resourceBindResourceType(resource2, "oic.r.counter");
OCMain.resourceBindResourceInterface(resource2, OCInterfaceMask.R);
OCMain.resourceSetDefaultInterface(resource2, OCInterfaceMask.R);
OCMain.resourceSetDiscoverable(resource2, true);
OCMain.resourceSetPeriodicObservable(resource2, 1);
OCMain.resourceSetRequestHandler(resource2, OCMethod.OC_GET, new GetCounter());
OCMain.resourceSetRequestHandler(resource2, OCMethod.OC_POST, new PostCounter());
OCMain.addResource(resource2);
OCResource collection = OCMain.newCollection("roomlights", "/lights", (short) 1, (short) 0, (short) 0, 0);
OCMain.resourceBindResourceType(collection, "oic.wk.col");
OCMain.resourceSetDiscoverable(collection, true);
OCLink link1 = OCMain.newLink(resource1);
OCMain.collectionAddLink(collection, link1);
OCLink link2 = OCMain.newLink(resource2);
OCMain.collectionAddLink(collection, link2);
OCMain.addCollection(collection);
} }
@Override @Override
......
package java_lite_simple_server;
import org.iotivity.CborEncoder;
import org.iotivity.OCMain;
import org.iotivity.OCRequest;
import org.iotivity.OCRequestHandler;
import org.iotivity.OCRepresentation;
import org.iotivity.OCStatus;
public class PostCounter implements OCRequestHandler {
@Override
public void handler(OCRequest request, int interfaces) {
System.out.println("Inside the PostCounter RequestHandler");
System.out.println("POST COUNTER:");
OCRepresentation rep = request.getRequest_payload();
while (rep != null) {
System.out.println("-----------------------------------------------------");
System.out.println("Key: " + rep.getName());
System.out.println("Type: " + rep.getType());
switch (rep.getType()) {
case OC_REP_INT:
Counter.count = rep.getValue().getInteger();
System.out.println("value: " + Counter.count);
break;
case OC_REP_STRING:
Counter.name = rep.getValue().getString();
System.out.println("value: " + Counter.name);
break;
default:
System.out.println("NOT YET HANDLED VALUE");
OCMain.sendResponse(request, OCStatus.OC_STATUS_BAD_REQUEST);
}
System.out.println("-----------------------------------------------------");
rep = rep.getNext();
}
CborEncoder root = OCMain.repBeginRootObject();
OCMain.repSetLong(root, "count", Counter.count);
OCMain.repEndRootObject();
OCMain.sendResponse(request, OCStatus.OC_STATUS_CHANGED);
}
}
package java_lite_simple_server; package java_lite_simple_server;
import org.iotivity.CborEncoder;
import org.iotivity.OCMain; import org.iotivity.OCMain;
import org.iotivity.OCRequest; import org.iotivity.OCRequest;
import org.iotivity.OCRequestHandler; import org.iotivity.OCRequestHandler;
...@@ -13,11 +14,11 @@ public class PostLight implements OCRequestHandler { ...@@ -13,11 +14,11 @@ public class PostLight implements OCRequestHandler {
System.out.println("Inside the PostLight RequestHandler"); System.out.println("Inside the PostLight RequestHandler");
System.out.println("POST LIGHT:"); System.out.println("POST LIGHT:");
OCRepresentation rep = request.getRequest_payload(); OCRepresentation rep = request.getRequest_payload();
while(rep != null) { while (rep != null) {
System.out.println("-----------------------------------------------------"); System.out.println("-----------------------------------------------------");
System.out.println("Key: " + rep.getName()); System.out.println("Key: " + rep.getName());
System.out.println("Type: " + rep.getType()); System.out.println("Type: " + rep.getType());
switch(rep.getType()) { switch (rep.getType()) {
case OC_REP_BOOL: case OC_REP_BOOL:
Light.state = rep.getValue().getBool(); Light.state = rep.getValue().getBool();
System.out.println("value: " + Light.state); System.out.println("value: " + Light.state);
...@@ -37,7 +38,12 @@ public class PostLight implements OCRequestHandler { ...@@ -37,7 +38,12 @@ public class PostLight implements OCRequestHandler {
System.out.println("-----------------------------------------------------"); System.out.println("-----------------------------------------------------");
rep = rep.getNext(); rep = rep.getNext();
} }
CborEncoder root = OCMain.repBeginRootObject();
OCMain.repSetBoolean(root, "state", Light.state);
OCMain.repSetLong(root, "power", Light.power);
OCMain.repEndRootObject();
OCMain.sendResponse(request, OCStatus.OC_STATUS_CHANGED); OCMain.sendResponse(request, OCStatus.OC_STATUS_CHANGED);
} }
} }
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