modified connection state callback for cleaing recv buffer.
authorjihwan.seo <jihwan.seo@samsung.com>
Wed, 2 Mar 2016 08:42:39 +0000 (17:42 +0900)
committerJon A. Cruz <jon@joncruz.org>
Fri, 4 Mar 2016 00:00:58 +0000 (00:00 +0000)
and removed wrong callback logic for bond state.

Change-Id: I6dbfe286a10b644fb180dd4b5a8e62b309946d42
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5295
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java
android/android_api/base/src/main/java/org/iotivity/ca/CaLeServerInterface.java
resource/csdk/connectivity/src/bt_le_adapter/android/calenwmonitor.c
resource/csdk/connectivity/src/bt_le_adapter/android/org_iotivity_ca_CaLeClientInterface.h
resource/csdk/connectivity/src/bt_le_adapter/android/org_iotivity_ca_CaLeServerInterface.h

index 5d0d90b..0801bdb 100644 (file)
@@ -86,6 +86,9 @@ public class CaLeClientInterface {
     private native static void caManagerLeGattConnectionStateChangeCB(
             BluetoothGatt gatt, int status, int newState);
 
+    private native static void caLeGattNWConnectionStateChangeCallback(
+            BluetoothGatt gatt, int status, int newState);
+
     private native static void caLeGattServicesDiscoveredCallback(BluetoothGatt gatt, int status);
 
     private native static void caLeGattCharacteristicWriteCallback(
@@ -199,6 +202,7 @@ public class CaLeClientInterface {
 
             caLeGattConnectionStateChangeCallback(gatt, status, newState);
             caManagerLeGattConnectionStateChangeCB(gatt, status, newState);
+            caLeGattNWConnectionStateChangeCallback(gatt, status, newState);
         }
 
         @Override
index 281beac..0a4bb5c 100644 (file)
@@ -52,6 +52,9 @@ public class CaLeServerInterface {
     private native static void caLeGattServerConnectionStateChangeCallback(
             BluetoothDevice device, int status, int newState);
 
+    private native static void caLeGattServerNWConnectionStateChangeCallback(
+            BluetoothDevice device, int status, int newState);
+
     private native static void caLeGattServerServiceAddedCallback(int status,
                                                                   BluetoothGattService service);
 
@@ -79,6 +82,7 @@ public class CaLeServerInterface {
             super.onConnectionStateChange(device, status, newState);
 
             caLeGattServerConnectionStateChangeCallback(device, status, newState);
+            caLeGattServerNWConnectionStateChangeCallback(device, status, newState);
         }
 
         @Override
index 488b269..f397b26 100644 (file)
@@ -362,3 +362,82 @@ Java_org_iotivity_ca_CaLeClientInterface_caLeBondStateChangedCallback(JNIEnv *en
         OIC_LOG(ERROR, TAG, "CALEServerRemoveDevice has failed");
     }
 }
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeClientInterface_caLeGattNWConnectionStateChangeCallback(JNIEnv *env,
+                                                                                 jobject obj,
+                                                                                 jobject gatt,
+                                                                                 jint status,
+                                                                                 jint newstate)
+{
+    VERIFY_NON_NULL_VOID(env, TAG, "env is null");
+    VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
+    VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null");
+
+    OIC_LOG_V(DEBUG, TAG, "CALeGattNWConnectionStateChangeCallback - status %d, newstate %d",
+              status, newstate);
+
+    jint state_disconnected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE,
+                                                    "STATE_DISCONNECTED");
+    if (state_disconnected == newstate)
+    {
+        jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
+        if (!jni_address)
+        {
+            OIC_LOG(ERROR, TAG, "jni_address is null");
+            return;
+        }
+
+        const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
+        if (!address)
+        {
+            OIC_LOG(ERROR, TAG, "address is null");
+            return;
+        }
+
+        if (g_bleConnectionStateChangedCallback)
+        {
+            g_bleConnectionStateChangedCallback(CA_ADAPTER_GATT_BTLE, address, false);
+        }
+
+        (*env)->ReleaseStringUTFChars(env, jni_address, address);
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaLeServerInterface_caLeGattServerNWConnectionStateChangeCallback(
+        JNIEnv *env, jobject obj, jobject device, jint status, jint newState)
+{
+    OIC_LOG(DEBUG, TAG, " Gatt Server NWConnectionStateChange Callback");
+
+    VERIFY_NON_NULL_VOID(env, TAG, "env");
+    VERIFY_NON_NULL_VOID(obj, TAG, "obj");
+    VERIFY_NON_NULL_VOID(device, TAG, "device");
+
+    // STATE_DISCONNECTED
+    jint state_disconnected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE,
+                                                    "STATE_DISCONNECTED");
+    if (state_disconnected == newState)
+    {
+        jstring jni_remoteAddress = CALEGetAddressFromBTDevice(env, device);
+        if (!jni_remoteAddress)
+        {
+            OIC_LOG(ERROR, TAG, "jni_remoteAddress is null");
+            return;
+        }
+
+        const char* address = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
+        if (!address)
+        {
+            OIC_LOG(ERROR, TAG, "address is null");
+            return;
+        }
+
+        if (g_bleConnectionStateChangedCallback)
+        {
+            g_bleConnectionStateChangedCallback(CA_ADAPTER_GATT_BTLE, address, false);
+        }
+
+        (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, address);
+    }
+}
index a39910b..fd351f2 100644 (file)
@@ -66,6 +66,15 @@ Java_org_iotivity_ca_caLeClientInterface_caLeGattConnectionStateChangeCallback
 
 /*
  * Class:     org_iotivity_ca_caLeClientInterface
+ * Method:    caLeGattNWConnectionStateChangeCallback
+ * Signature: (Landroid/bluetooth/BluetoothGatt;II)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_caLeClientInterface_caLeGattNWConnectionStateChangeCallback
+(JNIEnv *, jobject, jobject, jint, jint);
+
+/*
+ * Class:     org_iotivity_ca_caLeClientInterface
  * Method:    caLeGattServicesDiscoveredCallback
  * Signature: (Landroid/bluetooth/BluetoothGatt;I)V
  */
index f8b4810..fd4f813 100644 (file)
@@ -58,6 +58,15 @@ Java_org_iotivity_ca_caLeServerInterface_caLeGattServerConnectionStateChangeCall
 
 /*
  * Class:     org_iotivity_ca_caLeServerInterface
+ * Method:    caLeGattServerNWConnectionStateChangeCallback
+ * Signature: (Landroid/bluetooth/BluetoothDevice;II)V
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_caLeServerInterface_caLeGattServerNWConnectionStateChangeCallback
+(JNIEnv *, jobject, jobject, jint, jint);
+
+/*
+ * Class:     org_iotivity_ca_caLeServerInterface
  * Method:    caLeGattServerServiceAddedCallback
  * Signature: (ILandroid/bluetooth/BluetoothGattService;)V
  */