Commit 9f66512d authored by George Nash's avatar George Nash

Merge remote-tracking branch 'origin/swig'

Bring in work that has been done on the swig branch

Expose the OCSoftwareUpdate (oc_swupdate.h) to the Java APIs

Exposed the Endpoint utility functions as member functions of
of the OCEndpoint class.  Note to prevent breaking things
already using the OCEndpoint_Util class the functions with the
same funtionality were not yet deleted.

Adds a java_smart_home_server sample. This is closely modeled
after the C version of the java_smart_home_server with the
addition of swupdate added.

Adds channel change sample that conforms to the chanel change specification.

Adds software update to the samples.

Adds introspection to the smart home server sample.
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parents fa750538 e3d587e5
Pipeline #834 passed with stage
in 6 minutes and 28 seconds
......@@ -509,16 +509,17 @@ oc_endpoint_string_parse_path(oc_string_t *endpoint_str, oc_string_t *path)
const char *address = NULL;
address = strstr(oc_string(*endpoint_str), "://");
if(!address) {
if (!address) {
return -1;
}
// 3 is string length of "://"
address += 3;
size_t len = oc_string_len(*endpoint_str) - (address - oc_string(*endpoint_str));
size_t len =
oc_string_len(*endpoint_str) - (address - oc_string(*endpoint_str));
// the smallest possible address is '0' anything smaller is invalid.
if(len < 1) {
if (len < 1) {
return -1;
}
/* Extract a uri path if available */
......@@ -556,7 +557,7 @@ oc_ipv6_endpoint_is_link_local(oc_endpoint_t *endpoint)
}
int
oc_endpoint_compare_address(oc_endpoint_t *ep1, oc_endpoint_t *ep2)
oc_endpoint_compare_address(const oc_endpoint_t *ep1, const oc_endpoint_t *ep2)
{
if (!ep1 || !ep2)
return -1;
......
......@@ -17,6 +17,7 @@
#include <stdint.h>
#include <stdio.h>
#include "oc_config.h"
#include "port/oc_assert.h"
#include "port/oc_clock.h"
#include "port/oc_connectivity.h"
......
......@@ -28,8 +28,7 @@
#endif /* OC_BLOCK_WISE */
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
typedef enum { HIGH_QOS = 0, LOW_QOS } oc_qos_t;
......
......@@ -23,8 +23,7 @@
#include "oc_uuid.h"
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
typedef enum { OCF_VER_1_0_0 = 2048, OIC_VER_1_1_0 = 2112 } ocf_version_t;
......@@ -92,7 +91,8 @@ int oc_string_to_endpoint(oc_string_t *endpoint_str, oc_endpoint_t *endpoint,
int oc_endpoint_string_parse_path(oc_string_t *endpoint_str, oc_string_t *path);
int oc_ipv6_endpoint_is_link_local(oc_endpoint_t *endpoint);
int oc_endpoint_compare(const oc_endpoint_t *ep1, const oc_endpoint_t *ep2);
int oc_endpoint_compare_address(oc_endpoint_t *ep1, oc_endpoint_t *ep2);
int oc_endpoint_compare_address(const oc_endpoint_t *ep1,
const oc_endpoint_t *ep2);
void oc_endpoint_set_local_address(oc_endpoint_t *ep, int interface_index);
void oc_endpoint_copy(oc_endpoint_t *dst, oc_endpoint_t *src);
void oc_endpoint_list_copy(oc_endpoint_t **dst, oc_endpoint_t *src);
......
......@@ -77,7 +77,7 @@ extern bool oc_ri_invoke_coap_entity_handler(
void *request, void *response, oc_blockwise_state_t **request_state,
oc_blockwise_state_t **response_state, uint16_t block2_size,
oc_endpoint_t *endpoint);
#else /* OC_BLOCK_WISE */
#else /* OC_BLOCK_WISE */
extern bool oc_ri_invoke_coap_entity_handler(void *request, void *response,
uint8_t *buffer,
oc_endpoint_t *endpoint);
......@@ -496,7 +496,7 @@ coap_receive(oc_message_t *msg)
if (oc_ri_invoke_coap_entity_handler(message, response, &request_buffer,
&response_buffer, block2_size,
&msg->endpoint)) {
#else /* OC_BLOCK_WISE */
#else /* OC_BLOCK_WISE */
if (oc_ri_invoke_coap_entity_handler(message, response,
transaction->message->data +
COAP_MAX_HEADER_SIZE,
......@@ -752,7 +752,8 @@ coap_receive(oc_message_t *msg)
message->token_len, coap_status_code,
&msg->endpoint);
} else {
coap_send_empty_response(message->type == COAP_TYPE_CON ? COAP_TYPE_ACK : COAP_TYPE_NON,
coap_send_empty_response(message->type == COAP_TYPE_CON ? COAP_TYPE_ACK
: COAP_TYPE_NON,
message->mid, message->token, message->token_len,
coap_status_code, &msg->endpoint);
}
......
......@@ -196,6 +196,7 @@ endif
ifeq ($(SWUPDATE),1)
EXTRA_CFLAGS += -DOC_SOFTWARE_UPDATE
export SWUPDATE
endif
ifneq ($(SECURE),0)
......
......@@ -14,7 +14,6 @@
// limitations under the License.
*/
#include "port/oc_random.h"
#include <assert.h>
#include <errno.h>
......
......@@ -163,6 +163,7 @@ endif
ifeq ($(SWUPDATE),1)
EXTRA_CFLAGS += -DOC_SOFTWARE_UPDATE
export SWUPDATE
endif
ifneq ($(SECURE),0)
......
......@@ -6,8 +6,7 @@
#include <time.h>
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
typedef uint64_t oc_clock_time_t;
......
......@@ -29,8 +29,7 @@
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#ifndef OC_DYNAMIC_ALLOCATION
......@@ -62,8 +61,7 @@ extern "C"
#define OC_BLOCK_SIZE (OC_MAX_APP_DATA_SIZE)
#endif /* !OC_BLOCK_WISE_SET_MTU */
enum
{
enum {
#ifdef OC_TCP // TODO: need to check about tls packet.
OC_PDU_SIZE = (OC_MAX_APP_DATA_SIZE + COAP_MAX_HEADER_SIZE)
#else /* OC_TCP */
......@@ -80,8 +78,7 @@ enum
#endif
#include "oc_buffer_settings.h"
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#ifdef OC_TCP
#define OC_PDU_SIZE (oc_get_max_app_data_size() + COAP_MAX_HEADER_SIZE)
......
......@@ -218,7 +218,9 @@
<ClInclude Include="..\..\..\api\oc_introspection_internal.h" />
<ClInclude Include="..\..\..\api\oc_main.h" />
<ClInclude Include="..\..\..\api\oc_mnt.h" />
<ClInclude Include="..\..\..\api\oc_resource_factory.h" />
<ClInclude Include="..\..\..\api\oc_session_events_internal.h" />
<ClInclude Include="..\..\..\api\oc_swupdate_internal.h" />
<ClInclude Include="..\..\..\deps\tinycbor\src\cbor.h" />
<ClInclude Include="..\..\..\deps\tinycbor\src\cborjson.h" />
<ClInclude Include="..\..\..\include\oc_acl.h" />
......@@ -323,9 +325,11 @@
<ClCompile Include="..\..\..\api\oc_mnt.c" />
<ClCompile Include="..\..\..\api\oc_network_events.c" />
<ClCompile Include="..\..\..\api\oc_rep.c" />
<ClCompile Include="..\..\..\api\oc_resource_factory.c" />
<ClCompile Include="..\..\..\api\oc_ri.c" />
<ClCompile Include="..\..\..\api\oc_server_api.c" />
<ClCompile Include="..\..\..\api\oc_session_events.c" />
<ClCompile Include="..\..\..\api\oc_swupdate.c" />
<ClCompile Include="..\..\..\api\oc_uuid.c" />
<ClCompile Include="..\..\..\deps\mbedtls\library\aes.c" />
<ClCompile Include="..\..\..\deps\mbedtls\library\aesni.c" />
......
......@@ -279,6 +279,7 @@ del $(SolutionDir)..\..\..\swig\iotivity-lite-java\src\org\iotivity\oc\*.java</C
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_rep_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_session_events_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_storage_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_swupdate_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_uuid_wrap.c" />
</ItemGroup>
<ItemGroup>
......
......@@ -55,6 +55,9 @@
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_random_wrap.c">
<Filter>c_wrap</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_swupdate_wrap.c">
<Filter>c_wrap</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
......
......@@ -395,6 +395,21 @@ xcopy /s /y /d /q $(SolutionDir)..\..\..\swig\oc_java\oc\*.java $(SolutionDir)..
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building SWIG %(Identity) interface</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Building SWIG %(Identity) interface</Message>
</CustomBuild>
<CustomBuild Include="..\..\..\..\swig\swig_interfaces\oc_swupdate.i">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building SWIG %(Identity) interface</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Building SWIG %(Identity) interface</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building SWIG %(Identity) interface</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Building SWIG %(Identity) interface</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
</CustomBuild>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -92,9 +92,14 @@ ifeq ($(TCP),1)
SWIG_CFLAG += -DOC_TCP
endif
ifeq ($(SWUPDATE),1)
EXTRA_FLAG += -DOC_SOFTWARE_UPDATE
SWIG_CFLAG += -DOC_SOFTWARE_UPDATE
endif
SRC = oc_api oc_buffer_settings oc_clock oc_cloud oc_collection oc_connectivity \
oc_core_res oc_cred oc_endpoint oc_introspection oc_obt oc_pki \
oc_random oc_rep oc_session_events oc_storage oc_uuid
oc_random oc_rep oc_session_events oc_swupdate oc_storage oc_uuid
# Swig interfaces source
SWIG_INTERFACE_SRC = $(addsuffix .i, $(SRC))
......
......@@ -15,6 +15,7 @@ public class MyInitHandler implements OCMainInitHandler {
Counter.count = 0;
OCMain.setRandomPinHandler(new RandomPinHandler());
OCSoftwareUpdate.setImpl(new MySoftwareUpdateHandler());
return ret;
}
......
package java_lite_simple_server;
import java.net.URI;
import java.net.URISyntaxException;
import org.iotivity.*;
public class MySoftwareUpdateHandler implements OCSoftwareUpdateHandler {
@Override
public int validatePURL(String url) {
System.out.println("swupdate validating url " + url);
try {
URI uriObject = new URI(url);
} catch (URISyntaxException e) {
System.err.println("Software Update URL is not in a valid form: " + url);
return -1;
}
return 0;
}
@Override
public int checkNewVersion(long device, String url, String version) {
System.out.println("swupdate checkNewVersion: device = " + device + ", url = " + url);
if (url == null) {
OCSoftwareUpdate.notifyDone(device, OCSoftwareUpdateResult.OC_SWUPDATE_RESULT_INVALID_URL);
return -1;
}
if (version != null) {
System.out.println("swupdate new version = " + version);
}
OCSoftwareUpdate.notifyNewVersionAvailable(device, "2.0", OCSoftwareUpdateResult.OC_SWUPDATE_RESULT_SUCCESS);
return 0;
}
@Override
public int downloadUpdate(long device, String url) {
System.out.println("swupdate downloadUpdate: device = " + device + ", url = " + url);
OCSoftwareUpdate.notifyDownload(device, "2.0", OCSoftwareUpdateResult.OC_SWUPDATE_RESULT_SUCCESS);
return 0;
}
@Override
public int performUpgrade(long device, String url) {
System.out.println("swupdate performUpgrade: device = " + device + ", url = " + url);
OCSoftwareUpdate.notifyUpgrading(device, "2.0", System.currentTimeMillis(),
OCSoftwareUpdateResult.OC_SWUPDATE_RESULT_SUCCESS);
OCSoftwareUpdate.notifyDone(device, OCSoftwareUpdateResult.OC_SWUPDATE_RESULT_SUCCESS);
return 0;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="iotivity-lite-java/libs"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/iotivity-lite-java"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin/
/smarthomeserver_creds/
*.jar
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>java_smart_home_server</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
#!/bin/bash
# remove existing .class files
rm -rf ./bin
# create .class files directory
mkdir ./bin
# compile server java files
javac -cp ../../iotivity-lite-java/libs/iotivity-lite.jar -sourcepath ./src -d ./bin ./src/java_smart_home_server/*.java
# create jar file
jar -cfv smart-home-server.jar -C ./bin . -C ./assets .
java -Djava.library.path=..\..\iotivity-lite-java\libs -cp smart-home-server.jar;..\..\iotivity-lite-java\libs\iotivity-lite.jar java_smart_home_server.Server
#!/bin/bash
java -Djava.library.path=../../iotivity-lite-java/libs -cp smart-home-server.jar:../../iotivity-lite-java/libs/iotivity-lite.jar java_smart_home_server.Server
package java_smart_home_server;
import org.iotivity.CborEncoder;
import org.iotivity.OCInterfaceMask;
import org.iotivity.OCMain;
import org.iotivity.OCRep;
import org.iotivity.OCRequest;
import org.iotivity.OCStatus;
import org.iotivity.OCRequestHandler;
public class GetSwitch implements OCRequestHandler {
private Switch binarySwitch;
public GetSwitch(Switch binarySwitch) {
this.binarySwitch = binarySwitch;
}
@Override
public void handler(OCRequest request, int interfaces) {
System.out.println("Inside the GetSwitch RequestHandler");
System.out.println("GET SWITCH:");
CborEncoder root = OCRep.beginRootObject();
switch (interfaces) {
case OCInterfaceMask.BASELINE: {
OCMain.processBaselineInterface(request.getResource());
/* fall through */
}
case OCInterfaceMask.A: {
OCRep.setBoolean(root, "value", binarySwitch.getValue());
break;
}
default:
break;
}
OCRep.endRootObject();
OCMain.sendResponse(request, OCStatus.OC_STATUS_OK);
}
}
package java_smart_home_server;
import java.util.List;
import org.iotivity.CborEncoder;
import org.iotivity.OCInterfaceMask;
import org.iotivity.OCMain;
import org.iotivity.OCRep;
import org.iotivity.OCRequest;
import org.iotivity.OCStatus;
import org.iotivity.OCRequestHandler;
import org.iotivity.OCQueryValue;
public class GetTemperature implements OCRequestHandler {
private Temperature temperature;
public GetTemperature(Temperature temperature) {
this.temperature = temperature;
}
@Override
public void handler(OCRequest request, int interfaces) {
System.out.println("Inside the GetTemperature RequestHandler");
System.out.println("GET TEMPERATURE:");
Temperature.Units requestedUnits = null;
List<OCQueryValue> queryParams = OCMain.getQueryValues(request);
if (queryParams != null) {
for (OCQueryValue param : queryParams) {
if (Temperature.UNITS_KEY.equalsIgnoreCase(param.getKey())) {
String units = param.getValue();
System.out.println("units: " + units);
if (units.equalsIgnoreCase(Temperature.Units.F.toString())) {
requestedUnits = Temperature.Units.F;
} else if (units.equalsIgnoreCase(Temperature.Units.C.toString())) {
requestedUnits = Temperature.Units.C;
} else if (units.equalsIgnoreCase(Temperature.Units.K.toString())) {
requestedUnits = Temperature.Units.K;
} else {
// handled below
}
}
}
}
CborEncoder root = OCRep.beginRootObject();
switch (interfaces) {
case OCInterfaceMask.BASELINE: {
OCMain.processBaselineInterface(request.getResource());
/* fall through */
}
case OCInterfaceMask.A:
case OCInterfaceMask.S: {
if (requestedUnits != null) {
switch (requestedUnits) {
case F:
OCRep.setDouble(root, Temperature.TEMPERATURE_KEY, temperature.getTemperatureAsF());
OCRep.setTextString(root, Temperature.UNITS_KEY, Temperature.Units.F.toString());
break;
case C:
OCRep.setDouble(root, Temperature.TEMPERATURE_KEY, temperature.getTemperatureAsC());
OCRep.setTextString(root, Temperature.UNITS_KEY, Temperature.Units.C.toString());
break;
case K:
OCRep.setDouble(root, Temperature.TEMPERATURE_KEY, temperature.getTemperatureAsK());
OCRep.setTextString(root, Temperature.UNITS_KEY, Temperature.Units.K.toString());
break;
default:
}
} else {
OCRep.setDouble(root, Temperature.TEMPERATURE_KEY, temperature.getTemperature());
OCRep.setTextString(root, Temperature.UNITS_KEY, temperature.getUnits().toString());
}
break;
}
default:
break;
}
CborEncoder range = OCRep.openArray(root, Temperature.RANGE_KEY);
if (requestedUnits != null) {
OCRep.addDouble(range, temperature.getMin(requestedUnits));
OCRep.addDouble(range, temperature.getMax(requestedUnits));
} else {
OCRep.addDouble(range, temperature.getMin());
OCRep.addDouble(range, temperature.getMax());
}
OCRep.closeArray(root, range);
OCRep.endRootObject();
OCMain.sendResponse(request, OCStatus.OC_STATUS_OK);
}
}
package java_smart_home_server;
import org.iotivity.*;
public class MyInitHandler implements OCMainInitHandler {
private Switch binarySwitch = new Switch();
private Temperature temperature = new Temperature();
@Override
public int initialize() {
System.out.println("inside MyInitHandler.initialize()");
int ret = OCMain.initPlatform("Intel");
ret |= OCMain.addDevice("/oic/d", "oic.d.switch", "Temperature Sensor", "ocf.2.1.0",
"ocf.res.1.3.0,ocf.sh.1.3.0");
OCIntrospection.setIntrospectionData(0,
SmartHomeIntrospectionData.getCborFileBytes("./assets/smart_home_introspection_data.cbor"));
System.out.println("Introspection data set for device");
OCMain.setRandomPinHandler(new RandomPinHandler());
OCSoftwareUpdate.setImpl(new MySoftwareUpdateHandler());
return ret;
}
@Override
public void registerResources() {
System.out.println("inside MyInitHandler.registerResources()");
OCResource resource = OCMain.newResource("", "/switch", (short) 1, 0);
OCMain.resourceBindResourceType(resource, "oic.r.switch.binary");
OCMain.resourceBindResourceInterface(resource, OCInterfaceMask.A);
OCMain.resourceSetDefaultInterface(resource, OCInterfaceMask.A);
OCMain.resourceSetDiscoverable(resource, true);
OCMain.resourceSetObservable(resource, true);
OCMain.resourceSetPeriodicObservable(resource, 1);
OCMain.resourceSetRequestHandler(resource, OCMethod.OC_GET, new GetSwitch(binarySwitch));
OCMain.resourceSetRequestHandler(resource, OCMethod.OC_PUT, new PutSwitch(binarySwitch));
OCMain.resourceSetRequestHandler(resource, OCMethod.OC_POST, new PostSwitch(binarySwitch));
OCMain.addResource(resource);
resource = OCMain.newResource("", "/temp", (short) 1, 0);
OCMain.resourceBindResourceType(resource, "oic.r.temperature");
OCMain.resourceBindResourceInterface(resource, OCInterfaceMask.A);
OCMain.resourceBindResourceInterface(resource, OCInterfaceMask.S);
OCMain.resourceSetDefaultInterface(resource, OCInterfaceMask.A);
OCMain.resourceSetDiscoverable(resource, true);
OCMain.resourceSetObservable(resource, true);
OCMain.resourceSetPeriodicObservable(resource, 1);
OCMain.resourceSetRequestHandler(resource, OCMethod.OC_GET, new GetTemperature(temperature));
OCMain.resourceSetRequestHandler(resource, OCMethod.OC_PUT, new PutTemperature(temperature));
OCMain.resourceSetRequestHandler(resource, OCMethod.OC_POST, new PostTemperature(temperature));
OCMain.addResource(resource);
}
@Override
public void requestEntry() {
System.out.println("inside MyInitHandler.requestEntry()");
}
}
package java_smart_home_server;
import java.net.URI;
import java.net.URISyntaxException;
import org.iotivity.*;
public class MySoftwareUpdateHandler implements OCSoftwareUpdateHandler {
@Override
public int validatePURL(String url) {
System.out.println("swupdate validating url " + url);
try {
URI uriObject = new URI(url);
} catch (URISyntaxException e) {
System.err.println("Software Update URL is not in a valid form: " + url);
return -1;
}
return 0;
}
@Override
public int checkNewVersion(long device, String url, String version) {
System.out.println("swupdate checkNewVersion: device = " + device + ", url = " + url);