Added implementation for getDeviceId and setDeviceId
authorSunil Kumar K R <sunil.k14@samsung.com>
Fri, 7 Oct 2016 05:09:48 +0000 (10:39 +0530)
committerRandeep Singh <randeep.s@samsung.com>
Fri, 7 Oct 2016 10:43:47 +0000 (10:43 +0000)
code formatted

Signed-off-by: Sunil Kumar K R <sunil.k14@samsung.com>
Change-Id: Ic0d640638bd0c1a258db6c21bbecbd73e2c6dd3f
Signed-off-by: Ashwini Kumar <k.ashwini@samsung.com>
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10621
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: dongik Lee <dongik.lee@samsung.com>
Signed-off-by: Sunil Kumar K R <sunil.k14@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12929

android/android_api/base/jni/JniOcPlatform.cpp
android/android_api/base/jni/JniOcPlatform.h
android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java
android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java
resource/csdk/octbstack_product.def
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/src/ocstack.c
resource/include/OCPlatform.h
resource/include/OCPlatform_impl.h
resource/src/OCPlatform.cpp
resource/src/OCPlatform_impl.cpp

index 6b03638..a746cfe 100644 (file)
@@ -2992,3 +2992,84 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructAccountMana
     return jAccountManager;
 #endif
 }
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    getDeviceId
+* Signature: (I)V
+*/
+JNIEXPORT jbyteArray JNICALL Java_org_iotivity_base_OcPlatform_getDeviceId
+(JNIEnv *env, jobject thiz)
+{
+    LOGD("OcPlatform_getDeviceId");
+    OCUUIdentity deviceId;
+
+    jbyteArray ret = env->NewByteArray(UUID_IDENTITY_SIZE);
+    jbyte uuid[UUID_IDENTITY_SIZE];
+    try
+    {
+
+        OCStackResult result = OCPlatform::getDeviceId(&deviceId);
+        LOGD("OcPlatform_getDeviceId return from CPP");
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Error while getting my device Id");
+        }
+        else
+        {
+            for(int i=0;i < UUID_IDENTITY_SIZE; i++)
+            {
+                uuid[i] =(jbyte) deviceId.id[i];
+            }
+        }
+
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+
+    env->SetByteArrayRegion(ret, 0, UUID_IDENTITY_SIZE, uuid);
+
+    return ret;
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    setDeviceId
+* Signature: (Ljava/lang/byte;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setDeviceId(
+    JNIEnv *env, jobject thiz, jbyteArray data)
+{
+    LOGI("OcPlatform_setDeviceId");
+    OCUUIdentity deviceId;
+    try
+    {
+        OCStackResult result;
+        jbyte* uuid = env->GetByteArrayElements(data, 0);
+        jsize arrayLength = env->GetArrayLength(data);
+        if(arrayLength!=UUID_IDENTITY_SIZE)
+        {
+            ThrowOcException(OC_STACK_INVALID_PARAM, "Byte length not equal to UUID_IDENTITY_SIZE");
+        }
+        else
+        {
+            for(int i=0;i < UUID_IDENTITY_SIZE; i++)
+            {
+                deviceId.id[i]=(jchar)uuid[i];
+            }
+            result = OCPlatform::setDeviceId(&deviceId);
+            if (OC_STACK_OK != result)
+            {
+                ThrowOcException(result, "Failed to set DeviceId");
+            }
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
index b6c59c2..cf6e20f 100644 (file)
@@ -393,6 +393,22 @@ extern "C" {
     JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructAccountManagerObject0
         (JNIEnv *, jclass, jstring, jint);
 
+    /*
+     * Class:     org_iotivity_base_OcPlatform
+     * Method:    getDeviceId
+     * Signature: (I)V
+     */
+    JNIEXPORT jbyteArray JNICALL Java_org_iotivity_base_OcPlatform_getDeviceId
+        (JNIEnv *, jobject);
+
+    /*
+     * Class:     org_iotivity_base_OcPlatform
+     * Method:    setDeviceId
+     * Signature: (Ljava/lang/byte;)V
+     */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setDeviceId(
+            JNIEnv *, jobject, jbyteArray);
+
 #ifdef __cplusplus
 }
 #endif
index 589bdf1..74fcfb9 100644 (file)
@@ -1437,4 +1437,14 @@ public final class OcPlatform {
     private static native OcAccountManager constructAccountManagerObject0(
             String host,
             int connectivityType) throws OcException;
+    /**
+     * Method to get device Id in byte array.
+     * @return My DeviceId.
+     */
+    public static native byte[] getDeviceId();
+
+    /**
+     * Method to set DeviceId.
+     */
+    public static native void setDeviceId(byte[] deviceId);
 }
index 07ae29b..b2e857c 100644 (file)
@@ -205,6 +205,16 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
                 0,
                 QualityOfService.LOW, filePath + StringConstants.OIC_CLIENT_CBOR_DB_FILE);
         OcPlatform.Configure(cfg);
+
+        //Get deviceId
+        byte [] deviceIdBytes= OcPlatform.getDeviceId();
+        String devId = new String(deviceIdBytes);
+        Log.d(TAG, "Get Device Id "+devId);
+        //Set deviceId
+        String setId = "adminDeviceUuid1";
+        OcPlatform.setDeviceId(setId.getBytes());
+        Log.d(TAG, "Set Device Id done");
+
         try {
             /*
              * Initialize DataBase
index f55aa1d..916f8ce 100644 (file)
@@ -100,3 +100,5 @@ OCUnBindResource
 OCSetHeaderOption
 OCGetHeaderOption
 FindResourceByUri
+OCGetDeviceId
+OCSetDeviceId
index b517bee..40bafa3 100644 (file)
@@ -637,6 +637,21 @@ OCGetHeaderOption(OCHeaderOption* ocHdrOpt,
                   size_t optionDataLength,
                   uint16_t* receivedDatalLength);
 
+/**
+ * gets the deviceId of the client
+ *
+ * @param deviceId pointer.
+ * @return Returns ::OC_STACK_OK if success.
+ */
+OCStackResult OCGetDeviceId(OCUUIdentity *deviceId);
+
+/**
+ * sets the deviceId of the client
+ *
+ * @param deviceId pointer.
+ * @return Returns ::OC_STACK_OK if success.
+ */
+OCStackResult OCSetDeviceId(const OCUUIdentity *deviceId);
 #ifdef __cplusplus
 }
 #endif // __cplusplus
index b90fac4..9584cab 100644 (file)
@@ -5020,3 +5020,34 @@ void OCSetNetworkMonitorHandler(CAAdapterStateChangedCB adapterHandler,
     g_connectionHandler = connectionHandler;
 }
 
+OCStackResult OCGetDeviceId(OCUUIdentity *deviceId)
+{
+    OicUuid_t oicUuid;
+    OCStackResult ret;
+
+    ret = GetDoxmDeviceID(&oicUuid);
+    if (OC_STACK_OK == ret)
+    {
+        memcpy(deviceId, &oicUuid, UUID_IDENTITY_SIZE);
+    }
+    else
+    {
+        OIC_LOG(ERROR, TAG, "Device ID Get error");
+    }
+    return ret;
+}
+
+OCStackResult OCSetDeviceId(const OCUUIdentity *deviceId)
+{
+    OicUuid_t oicUuid;
+    OCStackResult ret;
+    OIC_LOG(ERROR, TAG, "Set deviceId DOXM");
+
+    memcpy(&oicUuid, deviceId, UUID_LENGTH);
+    for(int i=0;i < UUID_LENGTH; i++)
+    {
+        OIC_LOG_V(INFO, TAG, "Set Device Id %x", oicUuid.id[i]);
+    }
+    ret = SetDoxmDeviceID(&oicUuid);
+    return ret;
+}
index 335d08a..257a5a7 100644 (file)
@@ -799,6 +799,22 @@ namespace OC
                                            ResourceHandles& resourceHandles,
                                            DeleteResourceCallback callback, QualityOfService QoS);
 #endif
+
+        /**
+         * gets the deviceId of the client
+         *
+         * @param deviceId pointer.
+         * @return Returns ::OC_STACK_OK if success.
+         */
+        OCStackResult getDeviceId(OCUUIdentity *deviceId);
+
+        /**
+         * sets the deviceId of the client
+         *
+         * @param deviceId pointer.
+         * @return Returns ::OC_STACK_OK if success.
+         */
+        OCStackResult setDeviceId(const OCUUIdentity *deviceId);
     }
 }
 
index 49d59d9..0a6c063 100644 (file)
@@ -277,6 +277,11 @@ namespace OC
         OCAccountManager::Ptr constructAccountManagerObject(const std::string& host,
                                                             OCConnectivityType connectivityType);
 #endif // WITH_CLOUD
+
+        OCStackResult getDeviceId(OCUUIdentity *myUuid);
+
+        OCStackResult setDeviceId(const OCUUIdentity *myUuid);
+
     private:
         PlatformConfig m_cfg;
 
index 4ab35a8..21f8204 100644 (file)
@@ -393,6 +393,15 @@ namespace OC
                                                                     QoS);
         }
 #endif
+        OCStackResult getDeviceId(OCUUIdentity *deviceId)
+        {
+            return OCPlatform_impl::Instance().getDeviceId(deviceId);
+        }
+
+        OCStackResult setDeviceId(const OCUUIdentity *deviceId)
+        {
+            return OCPlatform_impl::Instance().setDeviceId(deviceId);
+        }
     } // namespace OCPlatform
 } //namespace OC
 
index d816e30..547b4d9 100644 (file)
@@ -483,5 +483,15 @@ namespace OC
                                                                       connectivityType));
     }
 #endif // WITH_CLOUD
+
+    OCStackResult OCPlatform_impl::getDeviceId(OCUUIdentity *myUuid)
+    {
+        return OCGetDeviceId(myUuid);
+    }
+
+    OCStackResult OCPlatform_impl::setDeviceId(const OCUUIdentity *myUuid)
+    {
+        return OCSetDeviceId(myUuid);
+    }
 } //namespace OC