Commit 633dc231 authored by George Nash's avatar George Nash Committed by Rick Bell

IOT-2774 Add getResourceHandleAtUri

This is needed to be able to set a deivice type to
the /oic/d resource.

Bug: https://jira.iotivity.org/browse/IOT-2774
Change-Id: I179d593f4b1e0408c18f7c28e6f8bda586223a9e
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parent 6888f190
......@@ -71,6 +71,13 @@ public class Light implements OcPlatform.EntityHandler {
}
public synchronized void registerResource() throws OcException {
OcResourceHandle deviceResourceHandle = OcPlatform.getResourceHandleAtUri(OcPlatform.WELL_KNOWN_DEVICE_QUERY);
if (deviceResourceHandle != null)
{
OcPlatform.bindTypeToResource(deviceResourceHandle, "oic.d.simpleServer");
}
if (null == mResourceHandle) {
mResourceHandle = OcPlatform.registerResource(
mResourceUri,
......
......@@ -689,6 +689,21 @@ public final class OcPlatform {
String[] deviceTypes
) throws OcException;
/**
* This function gets a resource handle by resource uri.
*
* @param resourceUri Uri of Resource to get Resource handle.
*
* @return Found resource handle or NULL if not found.
* @throws OcException if failure
*/
public static OcResourceHandle getResourceHandleAtUri(String resourceUri) throws OcException {
OcPlatform.initCheck();
return getResourceHandleAtUri0(resourceUri);
}
private static native OcResourceHandle getResourceHandleAtUri0(String resourceUri);
/**
* Set Property Value (to a single value)
*
......
......@@ -667,8 +667,7 @@ public final class OcPlatform {
* @throws OcException if failure
*/
@Deprecated
public static void registerDeviceInfo(
OcDeviceInfo ocDeviceInfo) throws OcException {
public static void registerDeviceInfo(OcDeviceInfo ocDeviceInfo) throws OcException {
OcPlatform.initCheck();
OcPlatform.registerDeviceInfo0(
ocDeviceInfo.getDeviceName(),
......@@ -683,6 +682,21 @@ public final class OcPlatform {
String[] deviceTypes
) throws OcException;
/**
* This function gets a resource handle by resource uri.
*
* @param resourceUri Uri of Resource to get Resource handle.
*
* @return Found resource handle or NULL if not found.
* @throws OcException if failure
*/
public static OcResourceHandle getResourceHandleAtUri(String resourceUri) throws OcException {
OcPlatform.initCheck();
return getResourceHandleAtUri0(resourceUri);
}
private static native OcResourceHandle getResourceHandleAtUri0(String resourceUri);
/**
* Set Property Value (to a single value)
*
......
......@@ -1473,6 +1473,41 @@ jobject jListener, jint jResourceProperty)
return jResourceHandle;
}
/*
* Class: org_iotivity_base_OcPlatform
* Method: getResourceHandleAtUri0
* Signature: (Ljava/lang/String;)Lorg/iotivity/base/OcResourceHandle;
*/
JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_getResourceHandleAtUri0(
JNIEnv *env,
jclass clazz,
jstring jResourceUri)
{
OC_UNUSED(clazz);
LOGI("OcPlatform_registerResource1");
std::string resourceUri;
if (jResourceUri)
{
resourceUri = env->GetStringUTFChars(jResourceUri, nullptr);
}
OCResourceHandle resourceHandle;
resourceHandle = OCGetResourceHandleAtUri(resourceUri.c_str());
JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle);
jlong handle = reinterpret_cast<jlong>(jniHandle);
jobject jResourceHandle;
jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle);
if (!jResourceHandle)
{
LOGE("Failed to create OcResourceHandle");
delete jniHandle;
}
return jResourceHandle;
}
/*
* Class: org_iotivity_base_OcPlatform
* Method: registerDeviceInfo0
......
......@@ -219,6 +219,14 @@ extern "C" {
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerPlatformInfo0
(JNIEnv *, jclass, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring);
/*
* Class: org_iotivity_base_OcPlatform
* Method: getResourceHandleAtUri0
* Signature: (Ljava/lang/String;)Lorg/iotivity/base/OcResourceHandle;
*/
JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_getResourceHandleAtUri0
(JNIEnv *, jclass, jstring);
/*
* Class: org_iotivity_base_OcPlatform
* Method: setPropertyValue0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment