Commit 5abfe2ad authored by jihwan.seo's avatar jihwan.seo Committed by Erich Keane

add descriptor in andorid BLE server

actually, it had removed previously for Tizen 2.4
but as not only Tizen 2.4 delay to release but also
OIC spec/linux BLE is supporting descriptor.
we decided that it should add.

Change-Id: I07e8b42e566d56d71bd65f5b590f40484c4a8492
Signed-off-by: default avatarjihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1656Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarErich Keane <erich.keane@intel.com>
parent b98fcc1d
......@@ -879,7 +879,7 @@ jobject CALEServerCreateGattService(JNIEnv *env)
jfieldID jni_fid_readProperties = (*env)->GetStaticFieldID(env,
jni_cid_bluetoothGattCharacteristic,
"PROPERTY_NOTIFY", "I");
"PROPERTY_READ", "I");
if (!jni_fid_readProperties)
{
OIC_LOG(ERROR, TAG, "jni_fid_readProperties is null");
......@@ -978,21 +978,23 @@ jobject CALEServerCreateGattService(JNIEnv *env)
jni_cid_bluetoothGattCharacteristic,
jni_fid_readPermissions);
jint jni_int_writePermissions = (*env)->GetStaticIntField(env,
jni_cid_bluetoothGattCharacteristic,
jni_fid_writePermissions);
jobject jni_readCharacteristic = (*env)->NewObject(env, jni_cid_bluetoothGattCharacteristic,
jni_mid_bluetoothGattCharacteristic,
jni_obj_readUuid, jni_int_readProperties,
jni_int_readPermissions|
jni_int_writePermissions);
jni_int_readPermissions);
if (!jni_readCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_readCharacteristic is null");
return NULL;
}
CAResult_t res = CALEServerAddDescriptor(env, jni_readCharacteristic);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "CALEServerAddDescriptor has failed");
return NULL;
}
jboolean jni_boolean_addReadCharacteristic = (*env)->CallBooleanMethod(
env, jni_bluetoothGattService, jni_mid_addCharacteristic, jni_readCharacteristic);
if (!jni_boolean_addReadCharacteristic)
......@@ -1012,6 +1014,10 @@ jobject CALEServerCreateGattService(JNIEnv *env)
jni_cid_bluetoothGattCharacteristic,
jni_fid_writeProperties);
jint jni_int_writePermissions = (*env)->GetStaticIntField(env,
jni_cid_bluetoothGattCharacteristic,
jni_fid_writePermissions);
jobject jni_writeCharacteristic = (*env)->NewObject(env, jni_cid_bluetoothGattCharacteristic,
jni_mid_bluetoothGattCharacteristic,
jni_obj_writeUuid, jni_int_writeProperties,
......@@ -1034,6 +1040,96 @@ jobject CALEServerCreateGattService(JNIEnv *env)
return jni_bluetoothGattService;
}
CAResult_t CALEServerAddDescriptor(JNIEnv *env, jobject characteristic)
{
OIC_LOG(DEBUG, TAG, "IN - CALEServerAddDescriptor");
VERIFY_NON_NULL(env, TAG, "env is null");
VERIFY_NON_NULL(characteristic, TAG, "characteristic is null");
jclass jni_cid_bluetoothGattDescriptor = (*env)->FindClass(env, "android/bluetooth/"
"BluetoothGattDescriptor");
if (!jni_cid_bluetoothGattDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattDescriptor is null");
return CA_STATUS_FAILED;
}
jmethodID jni_mid_bluetoothGattDescriptor = (*env)->GetMethodID(env,
jni_cid_bluetoothGattDescriptor,
"<init>",
"(Ljava/util/UUID;I)V");
if (!jni_mid_bluetoothGattDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_mid_bluetoothGattDescriptor is null");
return CA_STATUS_FAILED;
}
jfieldID jni_fid_readPermissions = (*env)->GetStaticFieldID(env,
jni_cid_bluetoothGattDescriptor,
"PERMISSION_READ", "I");
if (!jni_fid_readPermissions)
{
OIC_LOG(ERROR, TAG, "jni_fid_readPermissions is null");
return CA_STATUS_FAILED;
}
jobject jni_obj_readUuid = CALEGetUuidFromString(env, OIC_GATT_CHARACTERISTIC_CONFIG_UUID);
if (!jni_obj_readUuid)
{
OIC_LOG(ERROR, TAG, "jni_obj_readUuid is null");
return CA_STATUS_FAILED;
}
jint jni_int_readPermissions = (*env)->GetStaticIntField(env, jni_cid_bluetoothGattDescriptor,
jni_fid_readPermissions);
OIC_LOG(DEBUG, TAG, "initialize new Descriptor");
jobject jni_readDescriptor = (*env)->NewObject(env, jni_cid_bluetoothGattDescriptor,
jni_mid_bluetoothGattDescriptor,
jni_obj_readUuid, jni_int_readPermissions);
if (!jni_readDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_readDescriptor is null");
return CA_STATUS_FAILED;
}
jclass jni_cid_GattCharacteristic = (*env)->FindClass(env, "android/bluetooth/"
"BluetoothGattCharacteristic");
if (!jni_cid_GattCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_cid_GattCharacteristic is null");
return CA_STATUS_FAILED;
}
jmethodID jni_mid_addDescriptor = (*env)->GetMethodID(env, jni_cid_GattCharacteristic,
"addDescriptor",
"(Landroid/bluetooth/"
"BluetoothGattDescriptor;)Z");
if (!jni_mid_addDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_mid_addDescriptor is null");
return CA_STATUS_FAILED;
}
jboolean jni_boolean_addDescriptor = (*env)->CallBooleanMethod(env, characteristic,
jni_mid_addDescriptor,
jni_readDescriptor);
if (JNI_FALSE == jni_boolean_addDescriptor)
{
OIC_LOG(ERROR, TAG, "addDescriptor has failed");
return CA_STATUS_FAILED;
}
else
{
OIC_LOG(DEBUG, TAG, "addDescriptor success");
}
OIC_LOG(DEBUG, TAG, "OUT - CALEServerAddDescriptor");
return CA_STATUS_OK;
}
CAResult_t CALEServerAddGattService(JNIEnv *env, jobject bluetoothGattServer,
jobject bluetoothGattService)
{
......
......@@ -165,6 +165,14 @@ jobject CALEServerOpenGattServer(JNIEnv *env);
*/
jobject CALEServerCreateGattService(JNIEnv *env);
/**
* @brief add a descriptor to the characteristic
* @param env [IN] JNI interface pointer
* @param characteristic [IN] Characteristic object
* @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CALEServerAddDescriptor(JNIEnv *env, jobject characteristic);
/**
* @brief create gatt service
* @param env [IN] JNI interface pointer
......
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