From 8c044c478ccafb2faccbff398db02f79e4f58747 Mon Sep 17 00:00:00 2001 From: Tim Kourt Date: Thu, 30 Jul 2015 09:22:31 -0700 Subject: [PATCH] Fixed a merge of OcConnectivityType and OcConnectivityFlags throughout the android stack A small Android API change was introduced as part of the merge: all discovery calls now take a Set of OcConnectivtyTypes instead of a single enum. In addition, it fixes a setHeaderOptions bug. Change-Id: Ib269e39a0168055b4a1f46353cbd620fbff1dbad Signed-off-by: Tim Kourt Reviewed-on: https://gerrit.iotivity.org/gerrit/1992 Tested-by: jenkins-iotivity Reviewed-by: Joseph Morrow Reviewed-by: Erich Keane --- android/android_api/base/jni/JniOcPlatform.cpp | 25 ++- android/android_api/base/jni/JniUtils.cpp | 5 +- android/android_api/base/jni/JniUtils.h | 17 -- .../org/iotivity/base/OcRepresentationTest.java | 16 -- .../java/org/iotivity/base/SmokeTest.java | 180 ++++++++++----------- .../org/iotivity/base/OcConnectivityFlags.java | 65 -------- .../java/org/iotivity/base/OcConnectivityType.java | 78 +++++++-- .../main/java/org/iotivity/base/OcPlatform.java | 114 +++++++++---- .../java/org/iotivity/base/OcRepresentation.java | 2 - .../main/java/org/iotivity/base/OcResource.java | 19 +-- .../main/java/org/iotivity/ca/CaWiFiInterface.java | 72 --------- .../base/examples/fridgeclient/FridgeClient.java | 13 +- .../examples/fridgeclient/StringConstants.java | 2 +- .../base/examples/fridgeserver/DeviceResource.java | 5 +- .../main/java/org/iotivity/guiclient/OcWorker.java | 3 +- .../base/examples/simpleclient/SimpleClient.java | 3 +- 16 files changed, 264 insertions(+), 355 deletions(-) delete mode 100644 android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityFlags.java delete mode 100644 android/android_api/base/src/main/java/org/iotivity/ca/CaWiFiInterface.java diff --git a/android/android_api/base/jni/JniOcPlatform.cpp b/android/android_api/base/jni/JniOcPlatform.cpp index 4860e85..c8a619e 100644 --- a/android/android_api/base/jni/JniOcPlatform.cpp +++ b/android/android_api/base/jni/JniOcPlatform.cpp @@ -578,7 +578,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0 OCStackResult result = OCPlatform::findResource( host, resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), findCallback); if (OC_STACK_OK != result) @@ -630,7 +630,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1 OCStackResult result = OCPlatform::findResource( host, resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), findCallback, JniUtils::getQOS(env, static_cast(jQoS))); @@ -683,7 +683,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0 OCStackResult result = OCPlatform::getDeviceInfo( host, resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), findDeviceCallback); if (OC_STACK_OK != result) @@ -734,7 +734,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1 OCStackResult result = OCPlatform::getDeviceInfo( host, resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), findDeviceCallback, JniUtils::getQOS(env, static_cast(jQoS))); @@ -786,7 +786,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo0 OCStackResult result = OCPlatform::getPlatformInfo( host, resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), findPlatformCallback); if (OC_STACK_OK != result) @@ -837,7 +837,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1 OCStackResult result = OCPlatform::getPlatformInfo( host, resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), findDeviceCallback, JniUtils::getQOS(env, static_cast(jQoS))); @@ -869,15 +869,13 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0 } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, jResource); if (!resource) return nullptr; - LOGD("OcPlatform_registerResource1"); + OCResourceHandle resourceHandle; try { - LOGD("OcPlatform_registerResource2"); OCStackResult result = OCPlatform::registerResource( resourceHandle, resource->getOCResource()); - LOGD("OcPlatform_registerResource3"); if (OC_STACK_OK != result) { @@ -890,11 +888,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0 ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); return nullptr; } - LOGD("OcPlatform_registerResource4"); JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle); jlong handle = reinterpret_cast(jniHandle); jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle); - LOGD("OcPlatform_registerResource5"); + if (!jResourceHandle) { LOGE("Failed to create OcResourceHandle"); @@ -1583,7 +1580,7 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0 OCStackResult result = OCPlatform::subscribePresence( presenceHandle, host, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), subscribeCallback); if (OC_STACK_OK != result) @@ -1650,7 +1647,7 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1 presenceHandle, host, resourceType, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), subscribeCallback); if (OC_STACK_OK != result) @@ -1758,7 +1755,7 @@ jboolean jIsObservable, jobjectArray jResourceTypeArray, jobjectArray jInterface std::shared_ptr resource = OCPlatform::constructResourceObject( host, uri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jConnectivityType), static_cast(jIsObservable), resourceTypes, interfaces); diff --git a/android/android_api/base/jni/JniUtils.cpp b/android/android_api/base/jni/JniUtils.cpp index 38d22a3..e26a82c 100644 --- a/android/android_api/base/jni/JniUtils.cpp +++ b/android/android_api/base/jni/JniUtils.cpp @@ -57,16 +57,13 @@ void JniUtils::convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHe OC::HeaderOptions &headerOptions) { if (!jHeaderOptions) return; - jsize len = env->GetArrayLength(jHeaderOptions); for (jsize i = 0; i < len; ++i) { jobject header = env->GetObjectArrayElement(jHeaderOptions, i); - if (!header) nullptr; + if (!header) return; jint jId = env->CallIntMethod(header, g_mid_OcHeaderOption_get_id); jstring jData = (jstring)env->CallObjectMethod(header, g_mid_OcHeaderOption_get_data); - if (jData) return; - OC::HeaderOption::OCHeaderOption hopt( static_cast(jId), env->GetStringUTFChars(jData, NULL)); diff --git a/android/android_api/base/jni/JniUtils.h b/android/android_api/base/jni/JniUtils.h index 0d9d1a7..70e8054 100644 --- a/android/android_api/base/jni/JniUtils.h +++ b/android/android_api/base/jni/JniUtils.h @@ -124,23 +124,6 @@ public: }; } - static OCConnectivityType getConnectivityType(JNIEnv *env, int type) - { - switch (type) { - case 0: - return OCConnectivityType::CT_DEFAULT; - case 1: - return OCConnectivityType::CT_ADAPTER_IP; - case 2: - return OCConnectivityType::CT_ADAPTER_RFCOMM_BTEDR; - case 3: - return OCConnectivityType::CT_ADAPTER_GATT_BTLE; - default: - ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected connectivity type"); - return OCConnectivityType::CT_DEFAULT; - }; - } - static std::string stackResultToStr(const int result) { switch (result) diff --git a/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java b/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java index 27191df..cbed2d5 100644 --- a/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java +++ b/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java @@ -76,22 +76,6 @@ public class OcRepresentationTest extends InstrumentationTestCase { assertEquals(expected, actual); } - public void testJSONRepresentation() throws OcException { - OcRepresentation representation = new OcRepresentation(); - String key = "key"; - int value = 75; - - String emptyJson1 = representation.getJSONRepresentation(); - representation.setValue(key, value); - String intValue1 = representation.getJSONRepresentation(); - representation.remove(key); - String emptyJson2 = representation.getJSONRepresentation(); - assertEquals(emptyJson1, emptyJson2); - representation.setValue(key, value); - String intValue2 = representation.getJSONRepresentation(); - assertEquals(intValue1, intValue2); - } - public void testResourceTypesGetSet() { OcRepresentation representation = new OcRepresentation(); diff --git a/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java b/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java index d8356bc..eb981b5 100644 --- a/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java +++ b/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java @@ -78,8 +78,10 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { Log.i(TAG, "Host: " + resource.getHost()); Log.i(TAG, "Server ID: " + resource.getServerId()); - Log.i(TAG, "Connectivity Type: " + resource.getConnectivityType()); - Log.i(TAG, "Connectivity Type: " + resource.getConnectivityFlags()); + Log.i(TAG, "Connectivity Types: "); + for (OcConnectivityType connectivityType : resource.getConnectivityTypeSet()) { + Log.i(TAG, " " + connectivityType); + } signal.countDown(); } }; @@ -97,7 +99,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -139,7 +141,7 @@ public class SmokeTest extends InstrumentationTestCase { // //client // OcPresenceHandle presenceHandle = OcPlatform.subscribePresence( // resource.getHost(), -// OcConnectivityType.CT_DEFAULT, +// EnumSet.of(OcConnectivityType.CT_DEFAULT), // presenceListener // ); // @@ -163,13 +165,13 @@ public class SmokeTest extends InstrumentationTestCase { // resourceType, // OcPlatform.DEFAULT_INTERFACE, // entityHandler, -// EnumSet.of(ResourceProperty.DISCOVERABLE) +// EnumSet.of(ResourceProperty.DISCOVERABLE, ResourceProperty.OBSERVABLE) // ); // // //client // OcPlatform.findResource("", // OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, -// OcConnectivityType.CT_DEFAULT, +// EnumSet.of(OcConnectivityType.CT_DEFAULT), // resourceFoundListener); // // //server @@ -224,12 +226,11 @@ public class SmokeTest extends InstrumentationTestCase { if (ex instanceof OcException) { OcException ocEx = (OcException) ex; ErrorCode errCode = ocEx.getErrorCode(); - if(ErrorCode.NO_RESOURCE != errCode){ + if (ErrorCode.NO_RESOURCE != errCode) { Log.e(TAG, ocEx.getMessage()); assertTrue(false); } - } - else{ + } else { Log.e(TAG, ex.getMessage()); assertTrue(false); } @@ -321,7 +322,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource(null, OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -371,12 +372,11 @@ public class SmokeTest extends InstrumentationTestCase { if (ex instanceof OcException) { OcException ocEx = (OcException) ex; ErrorCode errCode = ocEx.getErrorCode(); - if(ErrorCode.NO_RESOURCE != errCode){ + if (ErrorCode.NO_RESOURCE != errCode) { Log.e(TAG, ocEx.getMessage()); assertTrue(false); } - } - else{ + } else { Log.e(TAG, ex.getMessage()); assertTrue(false); } @@ -413,12 +413,11 @@ public class SmokeTest extends InstrumentationTestCase { if (ex instanceof OcException) { OcException ocEx = (OcException) ex; ErrorCode errCode = ocEx.getErrorCode(); - if(ErrorCode.NO_RESOURCE != errCode){ + if (ErrorCode.NO_RESOURCE != errCode) { Log.e(TAG, ocEx.getMessage()); assertTrue(false); } - } - else{ + } else { Log.e(TAG, ex.getMessage()); assertTrue(false); } @@ -496,7 +495,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -546,12 +545,11 @@ public class SmokeTest extends InstrumentationTestCase { if (ex instanceof OcException) { OcException ocEx = (OcException) ex; ErrorCode errCode = ocEx.getErrorCode(); - if(ErrorCode.NO_RESOURCE != errCode){ + if (ErrorCode.NO_RESOURCE != errCode) { Log.e(TAG, ocEx.getMessage()); assertTrue(false); } - } - else{ + } else { Log.e(TAG, ex.getMessage()); assertTrue(false); } @@ -588,12 +586,11 @@ public class SmokeTest extends InstrumentationTestCase { if (ex instanceof OcException) { OcException ocEx = (OcException) ex; ErrorCode errCode = ocEx.getErrorCode(); - if(ErrorCode.NO_RESOURCE != errCode){ + if (ErrorCode.NO_RESOURCE != errCode) { Log.e(TAG, ocEx.getMessage()); assertTrue(false); } - } - else{ + } else { Log.e(TAG, ex.getMessage()); assertTrue(false); } @@ -674,7 +671,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -710,12 +707,11 @@ public class SmokeTest extends InstrumentationTestCase { if (ex instanceof OcException) { OcException ocEx = (OcException) ex; ErrorCode errCode = ocEx.getErrorCode(); - if(ErrorCode.NO_RESOURCE != errCode){ + if (ErrorCode.NO_RESOURCE != errCode) { Log.e(TAG, ocEx.getMessage()); assertTrue(false); } - } - else{ + } else { Log.e(TAG, ex.getMessage()); assertTrue(false); } @@ -784,7 +780,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -962,7 +958,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -1024,7 +1020,7 @@ public class SmokeTest extends InstrumentationTestCase { OcPlatform.getPlatformInfo( "", OcPlatform.MULTICAST_PREFIX + "/oic/p", - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), platformFoundListener); //wait for onPlatformFound event @@ -1035,62 +1031,50 @@ public class SmokeTest extends InstrumentationTestCase { } } -// public void testRegisterDeviceInfoGetDeviceInfo() throws InterruptedException { -// final String resourceType = "unit.test.resource" + new Date().getTime(); -// final CountDownLatch signal = new CountDownLatch(1); -// -// OcPlatform.OnDeviceFoundListener deviceFoundListener = new OcPlatform.OnDeviceFoundListener() { -// @Override -// public void onDeviceFound(OcRepresentation ocRepresentation) { -// try { -// Log.i(TAG, "Device Name: " + ocRepresentation.getValue("n")); -// } catch (OcException e) { -// Log.e(TAG, e.toString()); -// assertTrue(false); -// } -// boolean hasDeviceNameAtr = ocRepresentation.hasAttribute("n"); -// assertTrue(hasDeviceNameAtr); -// boolean hasNonExistingAtr = ocRepresentation.hasAttribute("NonExisting"); -// assertFalse(hasNonExistingAtr); -// Log.i(TAG, "URI: " + ocRepresentation.getUri()); -// signal.countDown(); -// } -// }; -// -// OcDeviceInfo devInfo = new OcDeviceInfo(); -// -// devInfo.setContentType("myContentType"); -// devInfo.setDateOfManufacture("myDateOfManufacture"); -// devInfo.setDeviceName("myDeviceName"); -// devInfo.setDeviceUuid("myDeviceUUID"); -// devInfo.setFirmwareVersion("myFirmwareVersion"); -// devInfo.setHostName("myHostName"); -// devInfo.setManufacturerName("myManufacturerNa"); -// devInfo.setManufacturerUrl("myManufacturerUrl"); -// devInfo.setModelNumber("myModelNumber"); -// devInfo.setPlatformVersion("myPlatformVersion"); -// devInfo.setSupportUrl("mySupportUrl"); -// devInfo.setVersion("myVersion"); -// -// try { -// //server -// OcPlatform.registerDeviceInfo(devInfo); -// -// //client -// OcPlatform.getDeviceInfo( -// "", -// OcPlatform.MULTICAST_PREFIX + DEVICE_URI, -// OcConnectivityType.CT_DEFAULT, -// deviceFoundListener); -// -// //wait for onDeviceFound event -// assertTrue(signal.await(60, TimeUnit.SECONDS)); -// -// } catch (OcException e) { -// Log.e(TAG, e.getMessage()); -// assertTrue(false); -// } -// } + public void testRegisterDeviceInfoGetDeviceInfo() throws InterruptedException { + final String resourceType = "unit.test.resource" + new Date().getTime(); + final CountDownLatch signal = new CountDownLatch(1); + + OcPlatform.OnDeviceFoundListener deviceFoundListener = new OcPlatform.OnDeviceFoundListener() { + @Override + public void onDeviceFound(OcRepresentation ocRepresentation) { + try { + Log.i(TAG, "Device Name: " + ocRepresentation.getValue("n")); + } catch (OcException e) { + Log.e(TAG, e.toString()); + assertTrue(false); + } + boolean hasDeviceNameAtr = ocRepresentation.hasAttribute("n"); + assertTrue(hasDeviceNameAtr); + boolean hasNonExistingAtr = ocRepresentation.hasAttribute("NonExisting"); + assertFalse(hasNonExistingAtr); + Log.i(TAG, "URI: " + ocRepresentation.getUri()); + signal.countDown(); + } + }; + + OcDeviceInfo devInfo = new OcDeviceInfo(); + devInfo.setDeviceName("myDeviceName"); + + try { + //server + OcPlatform.registerDeviceInfo(devInfo); + + //client + OcPlatform.getDeviceInfo( + "", + OcPlatform.MULTICAST_PREFIX + OcPlatform.DEVICE_URI, + EnumSet.of(OcConnectivityType.CT_DEFAULT), + deviceFoundListener); + + //wait for onDeviceFound event + assertTrue(signal.await(60, TimeUnit.SECONDS)); + + } catch (OcException e) { + Log.e(TAG, e.getMessage()); + assertTrue(false); + } + } public void testBindUnbindResources() throws InterruptedException { final String resourceType = "unit.test.resource" + new Date().getTime(); @@ -1180,7 +1164,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener1); //wait for onResourceFound event to find 3 registered resources @@ -1193,7 +1177,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener3); //wait for onResourceFound event to find 1 collection resources @@ -1205,7 +1189,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener2); //wait for onResourceFound event to find 2 resources @@ -1217,7 +1201,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener4); //wait for onResourceFound event to find 3 registered resources @@ -1232,7 +1216,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener6); //wait for onResourceFound event to find 1 collection resources @@ -1243,7 +1227,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener5); //wait for onResourceFound event to find 1 collection resources @@ -1327,12 +1311,12 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType1, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType2, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -1376,7 +1360,7 @@ public class SmokeTest extends InstrumentationTestCase { OcResource resourceProxy = OcPlatform.constructResourceObject( resource.getHost(), resource.getUri(), - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resource.isObservable(), resource.getResourceTypes(), resource.getResourceInterfaces()); @@ -1406,7 +1390,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -1433,7 +1417,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event @@ -1605,7 +1589,7 @@ public class SmokeTest extends InstrumentationTestCase { //client OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), resourceFoundListener); //wait for onResourceFound event diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityFlags.java b/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityFlags.java deleted file mode 100644 index a4b4920..0000000 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityFlags.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // 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 org.iotivity.base; - -import java.security.InvalidParameterException; -public enum OcConnectivityFlags { - OC_DEFAULT_FLAGS (0), - // Insecure transport is the default (subject to change) - OC_FLAG_SECURE (1 << 4), // secure the transport path - - // IPv4 & IPv6 autoselection is the default - OC_IP_USE_V6 (1 << 5), // IP adapter only - OC_IP_USE_V4 (1 << 6), // IP adapter only - - // Link-Local multicast is the default multicast scope for IPv6. - // These are placed here to correspond to the IPv6 address bits. - OC_SCOPE_INTERFACE (0x1), // IPv6 Interface-Local scope (loopback) - OC_SCOPE_LINK (0x2), // IPv6 Link-Local scope (default) - OC_SCOPE_REALM (0x3), // IPv6 Realm-Local scope - OC_SCOPE_ADMIN (0x4), // IPv6 Admin-Local scope - OC_SCOPE_SITE (0x5), // IPv6 Site-Local scope - OC_SCOPE_ORG (0x8), // IPv6 Organization-Local scope - OC_SCOPE_GLOBAL (0xE), // IPv6 Global scope - ; - private int value; - - private OcConnectivityFlags(int value) { - this.value = value; - } - - public int getValue() { - return this.value; - } - - public static OcConnectivityFlags get(int val) { - for (OcConnectivityType v : OcConnectivityType.values()) { - for (OcConnectivityFlags f : OcConnectivityFlags.values()) { - int value = v.getValue() + f.getValue(); - if (value == val) - return f; - } - } - throw new InvalidParameterException("Unexpected OcConnectivityFlags value:" + val); - } -} \ No newline at end of file diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java b/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java index 512f2ba..7d42144 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java @@ -23,12 +23,60 @@ package org.iotivity.base; import java.security.InvalidParameterException; +import java.util.EnumSet; public enum OcConnectivityType { - CT_DEFAULT (0), - CT_ADAPTER_IP (1 << 16), - CT_ADAPTER_GATT_BTLE (1 << 17), + /** use when defaults are ok. */ + CT_DEFAULT (0), + + /** IPv4 and IPv6, including 6LoWPAN.*/ + CT_ADAPTER_IP (1 << 16), + + /** GATT over Bluetooth LE.*/ + CT_ADAPTER_GATT_BTLE (1 << 17), + + /** RFCOMM over Bluetooth EDR.*/ CT_ADAPTER_RFCOMM_BTEDR (1 << 18), + + /** Remote Access over XMPP.*/ + CT_ADAPTER_REMOTE_ACCESS(1 << 19), + + /** Insecure transport is the default (subject to change).*/ + + /** secure the transport path.*/ + CT_FLAG_SECURE (1 << 4), + + /** IPv4 & IPv6 autoselection is the default.*/ + + /** IP adapter only.*/ + CT_IP_USE_V6 (1 << 5), + + /** IP adapter only.*/ + CT_IP_USE_V4 (1 << 6), + + /** Link-Local multicast is the default multicast scope for IPv6. + * These are placed here to correspond to the IPv6 address bits.*/ + + /** IPv6 Interface-Local scope(loopback).*/ + CT_SCOPE_INTERFACE (0x1), + + /** IPv6 Link-Local scope (default).*/ + CT_SCOPE_LINK (0x2), + + /** IPv6 Realm-Local scope.*/ + CT_SCOPE_REALM (0x3), + + /** IPv6 Admin-Local scope.*/ + CT_SCOPE_ADMIN (0x4), + + /** IPv6 Site-Local scope.*/ + CT_SCOPE_SITE (0x5), + + /** IPv6 Organization-Local scope.*/ + CT_SCOPE_ORG (0x8), + + /** IPv6 Global scope.*/ + CT_SCOPE_GLOBAL (0xE), ; private int value; @@ -41,15 +89,23 @@ public enum OcConnectivityType { return this.value; } - public static OcConnectivityType get(int val) { - // val is a combination of OcConnectivityType and OcConnectivityFlags - for (OcConnectivityType v : OcConnectivityType.values()) { - for (OcConnectivityFlags f : OcConnectivityFlags.values()) { - int value = v.getValue() + f.getValue(); - if (value == val) - return v; + public static EnumSet convertToEnumSet(int value) { + EnumSet typeSet = null; + + for (OcConnectivityType v : values()) { + if (0 != (value & v.getValue())) { + if (null == typeSet) { + typeSet = EnumSet.of(v); + } else { + typeSet.add(v); + } } } - throw new InvalidParameterException("Unexpected OcConnectivityType value:" + val); + + if (null == typeSet || typeSet.isEmpty()) { + throw new InvalidParameterException("Unexpected OcConnectivityType value:" + value); + } + + return typeSet; } } diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java index 9c54d7d..d042e9e 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java @@ -227,13 +227,21 @@ public final class OcPlatform { public static void findResource( String host, String resourceUri, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, OnResourceFoundListener onResourceFoundListener) throws OcException { OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } + OcPlatform.findResource0( host, resourceUri, - connectivityType.getValue(), + connTypeInt, onResourceFoundListener ); } @@ -260,13 +268,21 @@ public final class OcPlatform { public static void findResource( String host, String resourceUri, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, OnResourceFoundListener onResourceFoundListener, QualityOfService qualityOfService) throws OcException { OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } + OcPlatform.findResource1(host, resourceUri, - connectivityType.getValue(), + connTypeInt, onResourceFoundListener, qualityOfService.getValue() ); @@ -292,13 +308,19 @@ public final class OcPlatform { public static void getDeviceInfo( String host, String deviceUri, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, OnDeviceFoundListener onDeviceFoundListener) throws OcException { OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } OcPlatform.getDeviceInfo0( host, deviceUri, - connectivityType.getValue(), + connTypeInt, onDeviceFoundListener ); } @@ -323,14 +345,20 @@ public final class OcPlatform { public static void getDeviceInfo( String host, String deviceUri, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, OnDeviceFoundListener onDeviceFoundListener, QualityOfService qualityOfService) throws OcException { OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } OcPlatform.getDeviceInfo1( host, deviceUri, - connectivityType.getValue(), + connTypeInt, onDeviceFoundListener, qualityOfService.getValue() ); @@ -346,10 +374,10 @@ public final class OcPlatform { /** * API for Platform Discovery * - * @param host Host IP Address. If null or empty, Multicast is performed. - * @param platformUri Uri containing address to the platform - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL + * @param host Host IP Address. If null or empty, Multicast is performed. + * @param platformUri Uri containing address to the platform + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL * @param onPlatformFoundListener Handles events, success states and failure states. * @throws OcException */ @@ -357,13 +385,19 @@ public final class OcPlatform { public static void getPlatformInfo( String host, String platformUri, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, OnPlatformFoundListener onPlatformFoundListener) throws OcException { OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } OcPlatform.getPlatformInfo0( host, platformUri, - connectivityType.getValue(), + connTypeInt, onPlatformFoundListener ); } @@ -377,26 +411,32 @@ public final class OcPlatform { /** * API for Platform Discovery * - * @param host Host IP Address. If null or empty, Multicast is performed. - * @param platformUri Uri containing address to the platform - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL + * @param host Host IP Address. If null or empty, Multicast is performed. + * @param platformUri Uri containing address to the platform + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL * @param onPlatformFoundListener Handles events, success states and failure states. - * @param qualityOfService the quality of communication + * @param qualityOfService the quality of communication * @throws OcException */ public static void getPlatformInfo( String host, String platformUri, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, OnPlatformFoundListener onPlatformFoundListener, QualityOfService qualityOfService) throws OcException { OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } OcPlatform.getPlatformInfo1( host, platformUri, - connectivityType.getValue(), + connTypeInt, onPlatformFoundListener, qualityOfService.getValue() ); @@ -481,7 +521,7 @@ public final class OcPlatform { private static native void registerDeviceInfo0( String deviceName - ) throws OcException; + ) throws OcException; /** * Register Platform Info @@ -688,12 +728,18 @@ public final class OcPlatform { */ public static OcPresenceHandle subscribePresence( String host, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, OnPresenceListener onPresenceListener) throws OcException { OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } return OcPlatform.subscribePresence0( host, - connectivityType.getValue(), + connTypeInt, onPresenceListener ); } @@ -719,13 +765,19 @@ public final class OcPlatform { public static OcPresenceHandle subscribePresence( String host, String resourceType, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, OnPresenceListener onPresenceListener) throws OcException { OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } return OcPlatform.subscribePresence1( host, resourceType, - connectivityType.getValue(), + connTypeInt, onPresenceListener); } @@ -777,15 +829,21 @@ public final class OcPlatform { public static OcResource constructResourceObject( String host, String uri, - OcConnectivityType connectivityType, + EnumSet connectivityTypeSet, boolean isObservable, List resourceTypeList, List interfaceList) throws OcException { OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } return OcPlatform.constructResourceObject0( host, uri, - connectivityType.getValue(), + connTypeInt, isObservable, resourceTypeList.toArray(new String[resourceTypeList.size()]), interfaceList.toArray(new String[interfaceList.size()]) diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java b/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java index 8dca1cc..eba1001 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java @@ -265,8 +265,6 @@ public class OcRepresentation { } } - public native String getJSONRepresentation(); - public native void addChild(OcRepresentation representation); public native void clearChildren(); diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java index 2393549..92e38e6 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java @@ -22,6 +22,7 @@ package org.iotivity.base; +import java.util.EnumSet; import java.util.List; import java.util.Map; @@ -460,10 +461,10 @@ public class OcResource { /** * Method to get the connectivity type of this resource * - * @return OcConnectivityType connectivity type + * @return EnumSet connectivity type set */ - public OcConnectivityType getConnectivityType() { - return OcConnectivityType.get( + public EnumSet getConnectivityTypeSet() { + return OcConnectivityType.convertToEnumSet( this.getConnectivityTypeN() ); } @@ -471,18 +472,6 @@ public class OcResource { private native int getConnectivityTypeN(); /** - * Method to get the connectivity flags of this resource - * - * @return OcConnectivityFlags connectivity type - */ - public OcConnectivityFlags getConnectivityFlags() { - OcConnectivityType connType = this.getConnectivityType(); - int connTypeN = this.getConnectivityTypeN(); - int flag = connTypeN - connType.getValue(); - return OcConnectivityFlags.get(flag); - } - - /** * Method to provide ability to check if this resource is observable or not * * @return true indicates resource is observable; false indicates resource is not observable diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaWiFiInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaWiFiInterface.java deleted file mode 100644 index 9ec6eb8..0000000 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaWiFiInterface.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // 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 org.iotivity.ca; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.wifi.WifiManager; - -public class CaWiFiInterface { - - private static Context mContext; - - private CaWiFiInterface(Context context) { - mContext = context; - registerWiFiStateReceiver(); - } - - private void registerWiFiStateReceiver() { - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); - intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - - mContext.registerReceiver(mReceiver, intentFilter); - } - - private static BroadcastReceiver mReceiver = new BroadcastReceiver() { - - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, - WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_DISABLED) { - CAWiFiStateDisabled(); - } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { - ConnectivityManager manager = (ConnectivityManager) - mContext.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo nwInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - - if (nwInfo.isConnected()) { - CAWiFiStateEnabled(); - } - } - } - }; - - private native static void CAWiFiStateEnabled(); - - private native static void CAWiFiStateDisabled(); -} \ No newline at end of file diff --git a/android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/fridgeclient/FridgeClient.java b/android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/fridgeclient/FridgeClient.java index 5d0913b..b2109e8 100644 --- a/android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/fridgeclient/FridgeClient.java +++ b/android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/fridgeclient/FridgeClient.java @@ -49,6 +49,7 @@ import org.iotivity.base.PlatformConfig; import org.iotivity.base.QualityOfService; import org.iotivity.base.ServiceType; +import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -88,7 +89,7 @@ public class FridgeClient extends Activity implements OcPlatform.Configure(cfg); try { OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "intel.fridge", - OcConnectivityType.CT_DEFAULT, this); + EnumSet.of(OcConnectivityType.CT_DEFAULT), this); } catch (OcException e) { logMessage(TAG + " init Error. " + e.getMessage()); Log.e(TAG, e.getMessage()); @@ -195,23 +196,23 @@ public class FridgeClient extends Activity implements lightTypes.add("intel.fridge.light"); try { OcResource light = OcPlatform.constructResourceObject(ocResource.getHost(), - StringConstants.LIGHT, OcConnectivityType.CT_DEFAULT, false, lightTypes, ifaces); + StringConstants.LIGHT, EnumSet.of(OcConnectivityType.CT_DEFAULT), false, lightTypes, ifaces); List doorTypes = new LinkedList<>(); doorTypes.add("intel.fridge.door"); OcResource leftDoor = OcPlatform.constructResourceObject(ocResource.getHost(), - StringConstants.LEFT_DOOR, OcConnectivityType.CT_DEFAULT, false, doorTypes, ifaces); + StringConstants.LEFT_DOOR, EnumSet.of(OcConnectivityType.CT_DEFAULT), false, doorTypes, ifaces); OcResource rightDoor = OcPlatform.constructResourceObject(ocResource.getHost(), - StringConstants.RIGHT_DOOR, OcConnectivityType.CT_DEFAULT, false, doorTypes, ifaces); + StringConstants.RIGHT_DOOR, EnumSet.of(OcConnectivityType.CT_DEFAULT), false, doorTypes, ifaces); OcResource randomDoor = OcPlatform.constructResourceObject(ocResource.getHost(), - StringConstants.RANDOM_DOOR, OcConnectivityType.CT_DEFAULT, false, doorTypes, ifaces); + StringConstants.RANDOM_DOOR, EnumSet.of(OcConnectivityType.CT_DEFAULT), false, doorTypes, ifaces); List headerOptions = new LinkedList<>(); OcHeaderOption apiVersion = new OcHeaderOption(StringConstants.API_VERSION_KEY, StringConstants.API_VERSION); - OcHeaderOption clientToken = new OcHeaderOption(StringConstants.CLIENT_VERSION_KEY, + OcHeaderOption clientToken = new OcHeaderOption(StringConstants.CLIENT_TOKEN_KEY, StringConstants.CLIENT_TOKEN); headerOptions.add(apiVersion); headerOptions.add(clientToken); diff --git a/android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/fridgeclient/StringConstants.java b/android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/fridgeclient/StringConstants.java index 1fd690f..4c2f197 100644 --- a/android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/fridgeclient/StringConstants.java +++ b/android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/fridgeclient/StringConstants.java @@ -26,7 +26,7 @@ public interface StringConstants { public static final int WAIT_TIME = 1000; public static final int API_VERSION_KEY = 2048; - public static final int CLIENT_VERSION_KEY = 3000; + public static final int CLIENT_TOKEN_KEY = 3000; public static final boolean ENABLE_PRINTING = true; // change to false to disable printing // of messages on the console and the screen diff --git a/android/examples/fridgeserver/src/main/java/org/iotivity/base/examples/fridgeserver/DeviceResource.java b/android/examples/fridgeserver/src/main/java/org/iotivity/base/examples/fridgeserver/DeviceResource.java index fd00402..9868f32 100644 --- a/android/examples/fridgeserver/src/main/java/org/iotivity/base/examples/fridgeserver/DeviceResource.java +++ b/android/examples/fridgeserver/src/main/java/org/iotivity/base/examples/fridgeserver/DeviceResource.java @@ -131,6 +131,7 @@ public class DeviceResource extends Resource implements IMessageLogger { logMessage(TAG + " Client Token: " + clientToken); } } + if (clientAPIVersion.equals(StringConstants.API_VERSION) && clientToken.equals(StringConstants.CLIENT_TOKEN)) { List serverHeaderOptions = new LinkedList<>(); @@ -157,10 +158,6 @@ public class DeviceResource extends Resource implements IMessageLogger { response.setErrorCode(StringConstants.OK); response.setResponseResult(EntityHandlerResult.OK); break; - case POST: - response.setResponseResult(EntityHandlerResult.ERROR); - OcPlatform.sendResponse(response); - break; } result = EntityHandlerResult.OK; } diff --git a/android/examples/guiclient/src/main/java/org/iotivity/guiclient/OcWorker.java b/android/examples/guiclient/src/main/java/org/iotivity/guiclient/OcWorker.java index f8b5d51..cb049a6 100644 --- a/android/examples/guiclient/src/main/java/org/iotivity/guiclient/OcWorker.java +++ b/android/examples/guiclient/src/main/java/org/iotivity/guiclient/OcWorker.java @@ -35,6 +35,7 @@ import org.iotivity.base.QualityOfService; import org.iotivity.base.ServiceType; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import static org.iotivity.guiclient.OcProtocolStrings.COAP_CORE; @@ -503,7 +504,7 @@ public class OcWorker extends Thread Log.d(TAG, String.format("discoverResources(): Calling OcPlatform.findResource(%s)", s)); OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + s, - OcConnectivityType.CT_DEFAULT, + EnumSet.of(OcConnectivityType.CT_DEFAULT), this); } } catch (OcException e) { diff --git a/android/examples/simpleclient/src/main/java/org/iotivity/base/examples/simpleclient/SimpleClient.java b/android/examples/simpleclient/src/main/java/org/iotivity/base/examples/simpleclient/SimpleClient.java index 90c287b..d20794e 100644 --- a/android/examples/simpleclient/src/main/java/org/iotivity/base/examples/simpleclient/SimpleClient.java +++ b/android/examples/simpleclient/src/main/java/org/iotivity/base/examples/simpleclient/SimpleClient.java @@ -55,6 +55,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.EnumSet; import java.util.HashMap; import java.util.List; @@ -99,7 +100,7 @@ public class SimpleClient extends Activity implements OcPlatform.OnResourceFound * find all resources */ OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "core.light", - OcConnectivityType.CT_DEFAULT, this); + EnumSet.of(OcConnectivityType.CT_DEFAULT), this); } catch (OcException e) { logMessage(TAG + "findResource error: " + e.getMessage()); Log.e(TAG, e.getMessage()); -- 2.7.4