combined getting JNI methodID for several connectivity type.
authorjihwan.seo <jihwan.seo@samsung.com>
Mon, 11 Apr 2016 05:50:41 +0000 (14:50 +0900)
committerJon A. Cruz <jon@joncruz.org>
Wed, 13 Apr 2016 04:35:51 +0000 (04:35 +0000)
- BLE : caedrserver.c / caedrutils.c
- EDR : caleserver.c / caleutils.h / caleutils.c,
- NFC : canfcserver.c

Change-Id: Ibe936afb320e5112bfc221d6b5a16f53b170210a
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7733
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/connectivity/src/adapter_util/caadapterutils.c
resource/csdk/connectivity/src/bt_edr_adapter/android/caedrserver.c
resource/csdk/connectivity/src/bt_edr_adapter/android/caedrutils.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleutils.c
resource/csdk/connectivity/src/bt_le_adapter/android/caleutils.h
resource/csdk/connectivity/src/nfc_adapter/android/canfcserver.c

index a26fc4a..83f24eb 100644 (file)
@@ -275,9 +275,11 @@ jmethodID CAGetJNIMethodID(JNIEnv *env, const char* className,
     if (!jni_midID)
     {
         OIC_LOG_V(ERROR, CA_ADAPTER_UTILS_TAG, "jni_midID [%s] is null", methodName);
+        (*env)->DeleteLocalRef(env, jni_cid);
         return NULL;
     }
 
+    (*env)->DeleteLocalRef(env, jni_cid);
     return jni_midID;
 }
 
index c842a26..0a54f98 100644 (file)
@@ -39,6 +39,8 @@
 static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
 static const char CLASSPATH_BT_ADPATER[] = "android/bluetooth/BluetoothAdapter";
 static const char CLASSPATH_BT_UUID[] = "java/util/UUID";
+static const char CLASSPATH_BT_SERVER_SOCKET[] = "android/bluetooth/BluetoothServerSocket";
+static const char CLASSPATH_BT_SOCKET[] = "android/bluetooth/BluetoothSocket";
 
 static ca_thread_pool_t g_threadPoolHandle = NULL;
 
@@ -577,22 +579,16 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id)
     }
 
     // start to read through InputStream
-    jclass jni_cid_BTsocket = (*env)->FindClass(env, "android/bluetooth/BluetoothSocket");
-    if (!jni_cid_BTsocket)
-    {
-        OIC_LOG(ERROR, TAG, "jni_cid_BTsocket is null");
-        return CA_STATUS_FAILED;
-    }
-    jmethodID jni_mid_getInputStream = (*env)->GetMethodID(env, jni_cid_BTsocket,
-                                                           "getInputStream",
-                                                           "()Ljava/io/InputStream;");
+    jmethodID jni_mid_getInputStream = CAGetJNIMethodID(env,
+                                                        CLASSPATH_BT_SOCKET,
+                                                        "getInputStream",
+                                                        "()Ljava/io/InputStream;");
 
     jobject jni_obj_inputStream = (*env)->CallObjectMethod(env, jni_obj_socket,
                                                            jni_mid_getInputStream);
     if (!jni_obj_inputStream)
     {
         OIC_LOG(ERROR, TAG, "jni_obj_inputStream is null");
-        (*env)->DeleteLocalRef(env, jni_cid_BTsocket);
         return CA_STATUS_FAILED;
     }
 
@@ -601,7 +597,6 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id)
     {
         OIC_LOG(ERROR, TAG, "jni_cid_InputStream is null");
         (*env)->DeleteLocalRef(env, jni_obj_inputStream);
-        (*env)->DeleteLocalRef(env, jni_cid_BTsocket);
         return CA_STATUS_FAILED;
     }
 
@@ -770,14 +765,12 @@ CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id)
     }
     (*env)->DeleteLocalRef(env, jni_cid_InputStream);
     (*env)->DeleteLocalRef(env, jni_obj_inputStream);
-    (*env)->DeleteLocalRef(env, jni_cid_BTsocket);
 
     return CA_STATUS_OK;
 
 exit:
     (*env)->DeleteLocalRef(env, jni_cid_InputStream);
     (*env)->DeleteLocalRef(env, jni_obj_inputStream);
-    (*env)->DeleteLocalRef(env, jni_cid_BTsocket);
 
     return CA_STATUS_FAILED;
 }
@@ -899,16 +892,9 @@ void CAEDRNativeAccept(JNIEnv *env, jobject serverSocketObject)
 
     if (NULL != serverSocketObject)
     {
-        jclass jni_cid_BTServerSocket = (*env)->FindClass(
-                env, "android/bluetooth/BluetoothServerSocket");
-        if (!jni_cid_BTServerSocket)
-        {
-            OIC_LOG(ERROR, TAG, "jni_cid_BTServerSocket is null");
-            return;
-        }
-
-        jmethodID jni_mid_accept = (*env)->GetMethodID(env, jni_cid_BTServerSocket, "accept",
-                                                       "()Landroid/bluetooth/BluetoothSocket;");
+        jmethodID jni_mid_accept = CAGetJNIMethodID(env, CLASSPATH_BT_SERVER_SOCKET,
+                                                    "accept",
+                                                    "()Landroid/bluetooth/BluetoothSocket;");
         if (!jni_mid_accept)
         {
             OIC_LOG(ERROR, TAG, "jni_mid_accept is null");
@@ -976,22 +962,15 @@ void CAEDRNatvieCloseServerTask(JNIEnv* env)
     {
         OIC_LOG(DEBUG, TAG, "Accept Resource will be close");
 
-        jclass jni_cid_BTServerSocket = (*env)->FindClass(
-                env, "android/bluetooth/BluetoothServerSocket");
-        if (!jni_cid_BTServerSocket)
+        jmethodID jni_mid_close = CAGetJNIMethodID(env, CLASSPATH_BT_SERVER_SOCKET,
+                                                   "close", "()V");
+        if (!jni_mid_close)
         {
-            OIC_LOG(ERROR, TAG, "jni_cid_BTServerSocket is null");
+            OIC_LOG(ERROR, TAG, "jni_mid_close is null");
             return;
         }
 
-        jmethodID jni_mid_accept = (*env)->GetMethodID(env, jni_cid_BTServerSocket,
-                                                       "close", "()V");
-        if (!jni_mid_accept)
-        {
-            OIC_LOG(ERROR, TAG, "jni_mid_accept is null");
-            return;
-        }
-        (*env)->CallVoidMethod(env, g_serverSocket, jni_mid_accept);
+        (*env)->CallVoidMethod(env, g_serverSocket, jni_mid_close);
         (*env)->DeleteGlobalRef(env, g_serverSocket);
         g_serverSocket = NULL;
 
index f61f705..858b808 100644 (file)
@@ -27,6 +27,7 @@
 #include "oic_string.h"
 #include "cathreadpool.h"
 #include "uarraylist.h"
+#include "caadapterutils.h"
 
 #define ERROR_CODE (-1)
 #define TAG PCF("OIC_CA_EDR_UTILS")
@@ -49,19 +50,11 @@ jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSock
         return NULL;
     }
 
-    jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
-    if (!jni_cid_BTSocket)
-    {
-        OIC_LOG(ERROR, TAG, "jni_cid_BTSocket is null");
-        return NULL;
-    }
-
-    jmethodID jni_mid_getRemoteDevice = (*env)->GetMethodID(
-            env, jni_cid_BTSocket, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;");
+    jmethodID jni_mid_getRemoteDevice = CAGetJNIMethodID(
+            env, CLASSPATH_BT_SOCKET, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;");
     if (!jni_mid_getRemoteDevice)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getRemoteDevice is null");
-        (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
         return NULL;
     }
 
@@ -70,26 +63,16 @@ jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSock
     if (!jni_obj_remoteBTDevice)
     {
         OIC_LOG(ERROR, TAG, "jni_obj_remoteBTDevice is null");
-        (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
         return NULL;
     }
 
-    jclass jni_cid_BTDevice = (*env)->FindClass(env, CLASSPATH_BT_DEVICE);
-    if (!jni_cid_BTDevice)
-    {
-        OIC_LOG(ERROR, TAG, "jni_cid_BTDevice is null");
-        (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
-        (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
-        return NULL;
-    }
-    jmethodID j_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTDevice, "getAddress",
-                                                     METHODID_STRINGNONPARAM);
+    jmethodID j_mid_getAddress = CAGetJNIMethodID(env, CLASSPATH_BT_DEVICE,
+                                                  "getAddress",
+                                                  METHODID_STRINGNONPARAM);
     if (!j_mid_getAddress)
     {
         OIC_LOG(ERROR, TAG, "j_mid_getAddress is null");
         (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
-        (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
-        (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
         return NULL;
     }
 
@@ -99,14 +82,10 @@ jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSock
     {
         OIC_LOG(ERROR, TAG, "j_str_address is null");
         (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
-        (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
-        (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
         return NULL;
     }
 
     (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
-    (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
-    (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
 
     return j_str_address;
 }
@@ -216,15 +195,8 @@ jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env)
 
     // Convert the set to an object array
     // object[] array = Set<BluetoothDevice>.toArray();
-    jclass jni_cid_Set = (*env)->FindClass(env, "java/util/Set");
-    if (!jni_cid_Set)
-    {
-        OIC_LOG(ERROR, TAG, "jni_cid_Set is null");
-        goto exit;
-    }
-    jmethodID jni_mid_toArray = (*env)->GetMethodID(env, jni_cid_Set, "toArray",
-                                                    "()[Ljava/lang/Object;");
-
+    jmethodID jni_mid_toArray = CAGetJNIMethodID(env, "java/util/Set",
+                                                 "toArray", "()[Ljava/lang/Object;");
     if (!jni_mid_toArray)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_toArray is null");
@@ -331,15 +303,11 @@ jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice)
         OIC_LOG(ERROR, TAG, "bluetoothDevice is null");
         return NULL;
     }
-    jclass jni_cid_device_list = (*env)->FindClass(env, "android/bluetooth/BluetoothDevice");
-    if (!jni_cid_device_list)
-    {
-        OIC_LOG(ERROR, TAG, "jni_cid_device_list is null");
-        return NULL;
-    }
 
-    jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_device_list, "getAddress",
-                                                       METHODID_STRINGNONPARAM);
+    jmethodID jni_mid_getAddress = CAGetJNIMethodID(env,
+                                                    CLASSPATH_BT_DEVICE,
+                                                    "getAddress",
+                                                    METHODID_STRINGNONPARAM);
     if (!jni_mid_getAddress)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getAddress is null");
@@ -660,14 +628,8 @@ void CAEDRNativeSocketCloseToAll(JNIEnv *env)
         return;
     }
 
-    jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
-    if (!jni_cid_BTSocket)
-    {
-        OIC_LOG(ERROR, TAG, "jni_cid_BTSocket is null");
-        return;
-    }
-
-    jmethodID jni_mid_close = (*env)->GetMethodID(env, jni_cid_BTSocket, "close", "()V");
+    jmethodID jni_mid_close = CAGetJNIMethodID(env, CLASSPATH_BT_SOCKET,
+                                               "close", "()V");
     if (!jni_mid_close)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_close is null");
index 3ff4085..3327161 100644 (file)
@@ -162,10 +162,11 @@ static jint CALEServerGetConnectionState(JNIEnv *env, jobject device)
     VERIFY_NON_NULL_RET(env, TAG, "env", -1);
     VERIFY_NON_NULL_RET(device, TAG, "device", -1);
 
-    jmethodID jni_mid_getConnectionState = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothManager",
-                                                              "getConnectionState",
-                                                              "(Landroid/bluetooth/BluetoothDevice"
-                                                              ";I)I");
+    jmethodID jni_mid_getConnectionState = CAGetJNIMethodID(env, "android/bluetooth"
+                                                            "/BluetoothManager",
+                                                            "getConnectionState",
+                                                            "(Landroid/bluetooth/BluetoothDevice"
+                                                            ";I)I");
     if (!jni_mid_getConnectionState)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getConnectionState is null");
@@ -204,10 +205,10 @@ jobject CALEServerSetResponseData(JNIEnv *env, jbyteArray responseData)
     }
 
     OIC_LOG(DEBUG, TAG, "CALEServerSetResponseData");
-    jmethodID jni_mid_getService = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
-                                                      "getService",
-                                                      "(Ljava/util/UUID;)Landroid/bluetooth/"
-                                                      "BluetoothGattService;");
+    jmethodID jni_mid_getService = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+                                                    "getService",
+                                                    "(Ljava/util/UUID;)Landroid/bluetooth/"
+                                                    "BluetoothGattService;");
     if (!jni_mid_getService)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getService is null");
@@ -230,12 +231,12 @@ jobject CALEServerSetResponseData(JNIEnv *env, jbyteArray responseData)
         return NULL;
     }
 
-    jmethodID jni_mid_getCharacteristic = CALEGetJNIMethodID(env, "android/bluetooth/"
-                                                             "BluetoothGattService",
-                                                             "getCharacteristic",
-                                                             "(Ljava/util/UUID;)"
-                                                             "Landroid/bluetooth/"
-                                                             "BluetoothGattCharacteristic;");
+    jmethodID jni_mid_getCharacteristic = CAGetJNIMethodID(env, "android/bluetooth/"
+                                                           "BluetoothGattService",
+                                                           "getCharacteristic",
+                                                           "(Ljava/util/UUID;)"
+                                                           "Landroid/bluetooth/"
+                                                           "BluetoothGattCharacteristic;");
     if (!jni_mid_getCharacteristic)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getCharacteristic is null");
@@ -258,9 +259,9 @@ jobject CALEServerSetResponseData(JNIEnv *env, jbyteArray responseData)
         return NULL;
     }
 
-    jmethodID jni_mid_setValue = CALEGetJNIMethodID(env, "android/bluetooth/"
-                                                    "BluetoothGattCharacteristic",
-                                                    "setValue", "([B)Z");
+    jmethodID jni_mid_setValue = CAGetJNIMethodID(env, "android/bluetooth/"
+                                                  "BluetoothGattCharacteristic",
+                                                  "setValue", "([B)Z");
     if (!jni_mid_setValue)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_setValue is null");
@@ -298,7 +299,7 @@ CAResult_t CALEServerSendResponseData(JNIEnv *env, jobject device, jobject respo
         return CA_STATUS_FAILED;
     }
 
-    jmethodID jni_mid_notifyCharacteristicChanged = CALEGetJNIMethodID(env,
+    jmethodID jni_mid_notifyCharacteristicChanged = CAGetJNIMethodID(env,
                                                       CLASSPATH_BT_GATTSERVER,
                                                       "notifyCharacteristicChanged",
                                                       "(Landroid/bluetooth/BluetoothDevice;"
@@ -357,10 +358,10 @@ CAResult_t CALEServerSendResponse(JNIEnv *env, jobject device, jint requestId, j
         return CA_ADAPTER_NOT_ENABLED;
     }
 
-    jmethodID jni_mid_sendResponse = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
-                                                        "sendResponse",
-                                                        "(Landroid/bluetooth/BluetoothDevice;"
-                                                        "III[B)Z");
+    jmethodID jni_mid_sendResponse = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+                                                      "sendResponse",
+                                                      "(Landroid/bluetooth/BluetoothDevice;"
+                                                      "III[B)Z");
     if (!jni_mid_sendResponse)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_sendResponse is null");
@@ -690,14 +691,14 @@ CAResult_t CALEServerStartAdvertise(JNIEnv *env, jobject advertiseCallback)
         return CA_STATUS_FAILED;
     }
 
-    jmethodID jni_mid_startAdvertising = CALEGetJNIMethodID(env, "android/bluetooth/le/"
-                                                            "BluetoothLeAdvertiser",
-                                                            "startAdvertising",
-                                                            "(Landroid/bluetooth/le/"
-                                                            "AdvertiseSettings;Landroid/bluetooth/"
-                                                            "le/AdvertiseData;Landroid/bluetooth/"
-                                                            "le/AdvertiseData;Landroid/bluetooth/"
-                                                            "le/AdvertiseCallback;)V");
+    jmethodID jni_mid_startAdvertising = CAGetJNIMethodID(env, "android/bluetooth/le/"
+                                                          "BluetoothLeAdvertiser",
+                                                          "startAdvertising",
+                                                          "(Landroid/bluetooth/le/"
+                                                          "AdvertiseSettings;Landroid/bluetooth/"
+                                                          "le/AdvertiseData;Landroid/bluetooth/"
+                                                          "le/AdvertiseData;Landroid/bluetooth/"
+                                                          "le/AdvertiseCallback;)V");
     if (!jni_mid_startAdvertising)
     {
        OIC_LOG(ERROR, TAG, "jni_mid_startAdvertising is null");
@@ -761,11 +762,11 @@ CAResult_t CALEServerStopAdvertise(JNIEnv *env, jobject advertiseCallback)
         return CA_STATUS_FAILED;
     }
 
-    jmethodID jni_mid_stopAdvertising = CALEGetJNIMethodID(env, "android/bluetooth/le/"
-                                                           "BluetoothLeAdvertiser",
-                                                          "stopAdvertising",
-                                                          "(Landroid/bluetooth/le/"
-                                                          "AdvertiseCallback;)V");
+    jmethodID jni_mid_stopAdvertising = CAGetJNIMethodID(env, "android/bluetooth/le/"
+                                                         "BluetoothLeAdvertiser",
+                                                         "stopAdvertising",
+                                                         "(Landroid/bluetooth/le/"
+                                                         "AdvertiseCallback;)V");
     if (!jni_mid_stopAdvertising)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_stopAdvertising is null");
@@ -891,14 +892,14 @@ jobject CALEServerOpenGattServer(JNIEnv *env)
         return NULL;
     }
 
-    jmethodID jni_mid_openGattServer = CALEGetJNIMethodID(env, "android/bluetooth/"
-                                                          "BluetoothManager",
-                                                          "openGattServer",
-                                                          "(Landroid/content/Context;"
-                                                          "Landroid/bluetooth/"
-                                                          "BluetoothGattServerCallback;)"
-                                                          "Landroid/bluetooth/"
-                                                          "BluetoothGattServer;");
+    jmethodID jni_mid_openGattServer = CAGetJNIMethodID(env, "android/bluetooth/"
+                                                        "BluetoothManager",
+                                                        "openGattServer",
+                                                        "(Landroid/content/Context;"
+                                                        "Landroid/bluetooth/"
+                                                        "BluetoothGattServerCallback;)"
+                                                        "Landroid/bluetooth/"
+                                                        "BluetoothGattServer;");
     if (!jni_mid_openGattServer)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_openGattServer is null");
@@ -1229,10 +1230,10 @@ CAResult_t CALEServerAddGattService(JNIEnv *env, jobject bluetoothGattServer,
         return CA_ADAPTER_NOT_ENABLED;
     }
 
-    jmethodID jni_mid_addService = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
-                                                      "addService",
-                                                      "(Landroid/bluetooth/BluetoothGattService;)"
-                                                      "Z");
+    jmethodID jni_mid_addService = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+                                                    "addService",
+                                                    "(Landroid/bluetooth/BluetoothGattService;)"
+                                                    "Z");
      if (!jni_mid_addService)
      {
          OIC_LOG(ERROR, TAG, "jni_mid_addService is null");
@@ -1265,9 +1266,9 @@ CAResult_t CALEServerConnect(JNIEnv *env, jobject bluetoothDevice)
         return CA_ADAPTER_NOT_ENABLED;
     }
 
-    jmethodID jni_mid_connect = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
-                                                   "connect",
-                                                   "(Landroid/bluetooth/BluetoothDevice;Z)Z");
+    jmethodID jni_mid_connect = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+                                                 "connect",
+                                                 "(Landroid/bluetooth/BluetoothDevice;Z)Z");
     if (!jni_mid_connect)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_connect is null");
@@ -1336,10 +1337,10 @@ CAResult_t CALEServerDisconnect(JNIEnv *env, jobject bluetoothDevice)
         return CA_ADAPTER_NOT_ENABLED;
     }
 
-    jmethodID jni_mid_cancelConnection = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
-                                                            "cancelConnection",
-                                                            "(Landroid/bluetooth/BluetoothDevice;)"
-                                                            "V");
+    jmethodID jni_mid_cancelConnection = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+                                                          "cancelConnection",
+                                                          "(Landroid/bluetooth/BluetoothDevice;)"
+                                                          "V");
     if (!jni_mid_cancelConnection)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_cancelConnection is null");
@@ -1369,8 +1370,8 @@ CAResult_t CALEServerGattClose(JNIEnv *env, jobject bluetoothGattServer)
 
     // get BluetoothGatt class
     OIC_LOG(DEBUG, TAG, "get BluetoothGatt class");
-    jmethodID jni_mid_closeGatt = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
-                                                     "close", "()V");
+    jmethodID jni_mid_closeGatt = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+                                                   "close", "()V");
     if (!jni_mid_closeGatt)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_closeGatt is null");
index 45ff52a..b6ad36f 100644 (file)
 
 #define TAG PCF("OIC_CA_LE_UTILS")
 
-jmethodID CALEGetJNIMethodID(JNIEnv *env, const char* className,
-                             const char* methodName,
-                             const char* methodFormat)
-{
-    VERIFY_NON_NULL_RET(env, TAG, "env", NULL);
-    VERIFY_NON_NULL_RET(className, TAG, "className", NULL);
-    VERIFY_NON_NULL_RET(methodName, TAG, "methodName", NULL);
-    VERIFY_NON_NULL_RET(methodFormat, TAG, "methodFormat", NULL);
-
-    jclass jni_cid = (*env)->FindClass(env, className);
-    if (!jni_cid)
-    {
-        OIC_LOG_V(ERROR, TAG, "jni_cid [%s] is null", className);
-        return NULL;
-    }
-
-    jmethodID jni_midID = (*env)->GetMethodID(env, jni_cid, methodName, methodFormat);
-    if (!jni_midID)
-    {
-        OIC_LOG_V(ERROR, TAG, "jni_midID [%s] is null", methodName);
-        return NULL;
-    }
-
-    return jni_midID;
-}
-
 jobject CALEGetUuidFromString(JNIEnv *env, const char* uuid)
 {
     VERIFY_NON_NULL_RET(uuid, TAG, "uuid is null", NULL);
@@ -130,9 +104,9 @@ bool CALEIsBondedDevice(JNIEnv *env, jobject bluetoothDevice)
     VERIFY_NON_NULL_RET(env, TAG, "env is null", false);
     VERIFY_NON_NULL_RET(bluetoothDevice, TAG, "bluetoothDevice is null", false);
 
-    jmethodID jni_mid_getBondState = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
-                                                        "getBondState",
-                                                        "()I");
+    jmethodID jni_mid_getBondState = CAGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+                                                      "getBondState",
+                                                      "()I");
     if (!jni_mid_getBondState)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getBondState is null");
@@ -198,8 +172,8 @@ jobjectArray CALEGetBondedDevices(JNIEnv *env)
         return NULL;
     }
 
-    jmethodID jni_mid_toArray = CALEGetJNIMethodID(env, "java/util/Set", "toArray",
-                                                   "()[Ljava/lang/Object;");
+    jmethodID jni_mid_toArray = CAGetJNIMethodID(env, "java/util/Set", "toArray",
+                                                 "()[Ljava/lang/Object;");
     if (!jni_mid_toArray)
     {
         OIC_LOG(ERROR, TAG, "getBondedDevices: jni_mid_toArray is null");
@@ -351,9 +325,9 @@ jstring CALEGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice)
     VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
     VERIFY_NON_NULL_RET(bluetoothDevice, TAG, "bluetoothDevice is null", NULL);
 
-    jmethodID jni_mid_getAddress = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
-                                                      "getAddress",
-                                                      "()Ljava/lang/String;");
+    jmethodID jni_mid_getAddress = CAGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+                                                    "getAddress",
+                                                    "()Ljava/lang/String;");
     if (!jni_mid_getAddress)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getAddress is null");
@@ -457,8 +431,8 @@ jstring CALEGetAddressFromGatt(JNIEnv *env, jobject gatt)
     VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
     VERIFY_NON_NULL_RET(gatt, TAG, "gatt is null", NULL);
 
-    jmethodID jni_mid_getDevice = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT, "getDevice",
-                                                     METHODID_BT_DEVICE);
+    jmethodID jni_mid_getDevice = CAGetJNIMethodID(env, CLASSPATH_BT_GATT, "getDevice",
+                                                   METHODID_BT_DEVICE);
     if (!jni_mid_getDevice)
     {
         OIC_LOG(ERROR, TAG, "jni_mid_getDevice is null");
index 8c90437..478b264 100644 (file)
@@ -69,18 +69,6 @@ static const uint16_t STATE_SERVICE_CONNECTED = 2;
 static const uint16_t STATE_DISCONNECTED = 1;
 
 /**
- * get method ID for method Name and class
- * @param[in]   env              JNI interface pointer.
- * @param[in]   className        android class.
- * @param[in]   methodName       android method name.
- * @param[in]   methodFormat     method type of methodName.
- * @return  jmethodID of the method.
- */
-jmethodID CALEGetJNIMethodID(JNIEnv *env, const char* className,
-                             const char* methodName,
-                             const char* methodFormat);
-
-/**
  * get uuid(jni object) from uuid(character).
  * @param[in]   env              JNI interface pointer.
  * @param[in]   uuid             uuid(character).
index 4718c5c..9247bc3 100644 (file)
@@ -166,7 +166,7 @@ CAResult_t CANfcCreateJniInterfaceObject()
         return CA_STATUS_FAILED;\r
     }\r
 \r
-    jclass jni_NfcInterface = (*env)->FindClass(env, "org/iotivity/ca/CaNfcInterface");\r
+    jclass jni_NfcInterface = (*env)->FindClass(env, CLASS_NFCINTERFACE);\r
     if (!jni_NfcInterface)\r
     {\r
         OIC_LOG(ERROR, TAG, "Could not get CaNfcInterface class");\r
@@ -258,7 +258,7 @@ CAResult_t CANFCStartServer()
         isAttached = true;\r
     }\r
 \r
-    jclass jni_NfcInterface = (*env)->FindClass(env, "org/iotivity/ca/CaNfcInterface");\r
+    jclass jni_NfcInterface = (*env)->FindClass(env, CLASS_NFCINTERFACE);\r
     if (!jni_NfcInterface)\r
     {\r
         OIC_LOG(ERROR, TAG, "Could not get CaNFCClientInterface class");\r
@@ -341,15 +341,8 @@ Java_org_iotivity_ca_CaNfcInterface_caNativeNfcCreateNdefMessage(JNIEnv *env, jo
         return NULL;\r
     }\r
 \r
-    jclass cid_string = (*env)->FindClass(env, "java/lang/String");\r
-    if (!cid_string)\r
-    {\r
-        OIC_LOG(ERROR, TAG, "Could not get NfcAdapter class for cid_string");\r
-        return NULL;\r
-    }\r
-\r
-    jmethodID mid_getBytes = (*env)->GetMethodID(env, cid_string, "getBytes",\r
-                                                 "(Ljava/lang/String;)[B");\r
+    jmethodID mid_getBytes = CAGetJNIMethodID(env, "java/lang/String", "getBytes",\r
+                                              "(Ljava/lang/String;)[B");\r
     if (!mid_getBytes)\r
     {\r
         OIC_LOG(ERROR, TAG, "Could not get methodId for mid_getBytes");\r