OCStackResult result = OCPlatform::findResource(
host,
resourceUri,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
findCallback);
if (OC_STACK_OK != result)
OCStackResult result = OCPlatform::findResource(
host,
resourceUri,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
findCallback,
JniUtils::getQOS(env, static_cast<int>(jQoS)));
OCStackResult result = OCPlatform::getDeviceInfo(
host,
resourceUri,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
findDeviceCallback);
if (OC_STACK_OK != result)
OCStackResult result = OCPlatform::getDeviceInfo(
host,
resourceUri,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
findDeviceCallback,
JniUtils::getQOS(env, static_cast<int>(jQoS)));
OCStackResult result = OCPlatform::getPlatformInfo(
host,
resourceUri,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
findPlatformCallback);
if (OC_STACK_OK != result)
OCStackResult result = OCPlatform::getPlatformInfo(
host,
resourceUri,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
findDeviceCallback,
JniUtils::getQOS(env, static_cast<int>(jQoS)));
}
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)
{
ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
return nullptr;
}
- LOGD("OcPlatform_registerResource4");
JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle);
jlong handle = reinterpret_cast<jlong>(jniHandle);
jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle);
- LOGD("OcPlatform_registerResource5");
+
if (!jResourceHandle)
{
LOGE("Failed to create OcResourceHandle");
OCStackResult result = OCPlatform::subscribePresence(
presenceHandle,
host,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
subscribeCallback);
if (OC_STACK_OK != result)
presenceHandle,
host,
resourceType,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
subscribeCallback);
if (OC_STACK_OK != result)
std::shared_ptr<OCResource> resource = OCPlatform::constructResourceObject(
host,
uri,
- JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ static_cast<OCConnectivityType>(jConnectivityType),
static_cast<bool>(jIsObservable),
resourceTypes,
interfaces);
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<int>(jId),
env->GetStringUTFChars(jData, NULL));
};
}
- 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)
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();
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();
}
};
//client
OcPlatform.findResource("",
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
// //client
// OcPresenceHandle presenceHandle = OcPlatform.subscribePresence(
// resource.getHost(),
-// OcConnectivityType.CT_DEFAULT,
+// EnumSet.of(OcConnectivityType.CT_DEFAULT),
// presenceListener
// );
//
// 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
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);
}
//client
OcPlatform.findResource(null,
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
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);
}
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);
}
//client
OcPlatform.findResource("",
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
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);
}
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);
}
//client
OcPlatform.findResource("",
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
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);
}
//client
OcPlatform.findResource("",
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
//client
OcPlatform.findResource("",
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
OcPlatform.getPlatformInfo(
"",
OcPlatform.MULTICAST_PREFIX + "/oic/p",
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
platformFoundListener);
//wait for onPlatformFound event
}
}
-// 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();
//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
//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
//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
//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
//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
//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
//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
OcResource resourceProxy = OcPlatform.constructResourceObject(
resource.getHost(),
resource.getUri(),
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resource.isObservable(),
resource.getResourceTypes(),
resource.getResourceInterfaces());
//client
OcPlatform.findResource("",
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
//client
OcPlatform.findResource("",
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
//client
OcPlatform.findResource("",
OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
- OcConnectivityType.CT_DEFAULT,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
resourceFoundListener);
//wait for onResourceFound event
+++ /dev/null
-/*
- * //******************************************************************
- * //
- * // 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
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;
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<OcConnectivityType> convertToEnumSet(int value) {
+ EnumSet<OcConnectivityType> 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;
}
}
public static void findResource(
String host,
String resourceUri,
- OcConnectivityType connectivityType,
+ EnumSet<OcConnectivityType> 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
);
}
public static void findResource(
String host,
String resourceUri,
- OcConnectivityType connectivityType,
+ EnumSet<OcConnectivityType> 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()
);
public static void getDeviceInfo(
String host,
String deviceUri,
- OcConnectivityType connectivityType,
+ EnumSet<OcConnectivityType> 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
);
}
public static void getDeviceInfo(
String host,
String deviceUri,
- OcConnectivityType connectivityType,
+ EnumSet<OcConnectivityType> 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()
);
/**
* 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
*/
public static void getPlatformInfo(
String host,
String platformUri,
- OcConnectivityType connectivityType,
+ EnumSet<OcConnectivityType> 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
);
}
/**
* 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<OcConnectivityType> 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()
);
private static native void registerDeviceInfo0(
String deviceName
- ) throws OcException;
+ ) throws OcException;
/**
* Register Platform Info
*/
public static OcPresenceHandle subscribePresence(
String host,
- OcConnectivityType connectivityType,
+ EnumSet<OcConnectivityType> 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
);
}
public static OcPresenceHandle subscribePresence(
String host,
String resourceType,
- OcConnectivityType connectivityType,
+ EnumSet<OcConnectivityType> 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);
}
public static OcResource constructResourceObject(
String host,
String uri,
- OcConnectivityType connectivityType,
+ EnumSet<OcConnectivityType> connectivityTypeSet,
boolean isObservable,
List<String> resourceTypeList,
List<String> 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()])
}
}
- public native String getJSONRepresentation();
-
public native void addChild(OcRepresentation representation);
public native void clearChildren();
package org.iotivity.base;
+import java.util.EnumSet;
import java.util.List;
import java.util.Map;
/**
* Method to get the connectivity type of this resource
*
- * @return OcConnectivityType connectivity type
+ * @return EnumSet<OcConnectivityType></OcConnectivityType> connectivity type set
*/
- public OcConnectivityType getConnectivityType() {
- return OcConnectivityType.get(
+ public EnumSet<OcConnectivityType> getConnectivityTypeSet() {
+ return OcConnectivityType.convertToEnumSet(
this.getConnectivityTypeN()
);
}
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
+++ /dev/null
-/*
- * //******************************************************************
- * //
- * // 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
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;
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());
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<String> 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<OcHeaderOption> 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);
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
logMessage(TAG + " Client Token: " + clientToken);
}
}
+
if (clientAPIVersion.equals(StringConstants.API_VERSION) &&
clientToken.equals(StringConstants.CLIENT_TOKEN)) {
List<OcHeaderOption> serverHeaderOptions = new LinkedList<>();
response.setErrorCode(StringConstants.OK);
response.setResponseResult(EntityHandlerResult.OK);
break;
- case POST:
- response.setResponseResult(EntityHandlerResult.ERROR);
- OcPlatform.sendResponse(response);
- break;
}
result = EntityHandlerResult.OK;
}
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;
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) {
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
* 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());