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());
+ }
+}
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
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);
}
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
OCSetHeaderOption
OCGetHeaderOption
FindResourceByUri
+OCGetDeviceId
+OCSetDeviceId
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
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;
+}
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);
}
}
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;
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
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