{
(void)object;
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return;
}
oc_mutex_lock(g_threadScanIntervalMutex);
{
OIC_LOG(DEBUG, TAG, "CALECreateJniInterfaceObject");
- if (!g_context)
- {
- OIC_LOG(ERROR, TAG, "g_context is null");
- return CA_STATUS_FAILED;
- }
-
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_context, TAG, "g_context is null", CA_STATUS_FAILED);
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
jmethodID mid_getApplicationContext = CAGetJNIMethodID(env, "android/content/Context",
CALEClientAddUuid(OIC_GATT_CUSTOM_UUID2, CA_LE_TYPE_CUSTOM_UUID);
CALEClientAddUuid(OIC_GATT_CUSTOM_UUID3, CA_LE_TYPE_CUSTOM_UUID);
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
g_jniIntSdk = CALEGetBuildVersion(env);
{
OIC_LOG(DEBUG, TAG, "CALEClientTerminate");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return;
- }
+ VERIFY_NON_NULL_VOID(g_jvm, TAG, "g_jvm is null");
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return ;
}
// stop scan
{
OIC_LOG(INFO, TAG, "IN - CALEClientHiddenConnectGatt");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return NULL;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", NULL);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return NULL;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return NULL;
}
jstring jni_address = (*env)->NewStringUTF(env, address);
{
OIC_LOG(DEBUG, TAG, "CALEClientDestroyJniInterface");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
jclass jni_LeInterface = (*env)->FindClass(env, "org/iotivity/ca/CaLeClientInterface");
OIC_LOG_V(DEBUG, TAG, "CALEClientSendMulticastMessage(%p)", data);
VERIFY_NON_NULL(data, TAG, "data is null");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEClientSendMulticastMessageImpl(env, data, dataLen);
data);
VERIFY_NON_NULL(address, TAG, "address is null");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
oc_mutex_lock(g_threadSendMutex);
return CA_STATUS_FAILED;
}
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
+
+ JNIEnv* env = NULL;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
return CA_STATUS_FAILED;
}
{
g_setFullScanFlag = true;
}
- bool isAttached = false;
- JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
- }
OIC_LOG(DEBUG, TAG, "CALEClientStartScan");
CAResult_t CALEClientStopScan()
{
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CA_STATUS_FAILED;
static void CALEWriteCharacteristicThread(void* object)
{
VERIFY_NON_NULL_VOID(object, TAG, "object is null");
+ VERIFY_NON_NULL_VOID(g_jvm, TAG, "g_jvm is null");
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return ;
}
jobject gatt = (jobject)object;
CAResult_t CALEClientCreateUUIDList()
{
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
// create new object array
void CALEClientTerminateGattMutexVariables()
{
-
+
oc_mutex_free(g_bleServerBDAddressMutex);
g_bleServerBDAddressMutex = NULL;
{
OIC_LOG(DEBUG, TAG, "CAStopBLEGattClient");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return;
- }
+ VERIFY_NON_NULL_VOID(g_jvm, TAG, "g_jvm is null");
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return ;
}
CAResult_t ret = CALEClientDisconnectAll(env);
void CASetLEReqRespClientCallback(CABLEDataReceivedCallback callback)
{
-
+
g_CABLEClientDataReceivedCallback = callback;
-
+
}
void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle)
{
OIC_LOG(DEBUG, TAG, "CALEServerCreateJniInterfaceObject");
- if (!g_context)
- {
- OIC_LOG(ERROR, TAG, "g_context is null");
- return CA_STATUS_FAILED;
- }
-
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_context, TAG, "g_context is null",CA_STATUS_FAILED);
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
jclass jni_LEInterface = (*env)->FindClass(env, "org/iotivity/ca/CaLeServerInterface");
return CA_STATUS_OK;
}
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
// start advertise
CAResult_t CALEServerStopAdvertise()
{
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEServerStopAdvertiseImpl(env, g_leAdvertiseCallback);
CALeServerJniInit();
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALECheckPlatformVersion(env, 21);
{
OIC_LOG(DEBUG, TAG, "IN - CALEServerTerminate");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return;
- }
+ VERIFY_NON_NULL_VOID(g_jvm, TAG, "g_jvm is null");
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return ;
}
if (g_sendBuffer)
VERIFY_NON_NULL(address, TAG, "address is null");
VERIFY_NON_NULL(data, TAG, "data is null");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEServerSendUnicastMessageImpl(env, address, data, dataLen);
OIC_LOG_V(DEBUG, TAG, "CALEServerSendMulticastMessage(%p)", data);
VERIFY_NON_NULL(data, TAG, "data is null");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEServerSendMulticastMessageImpl(env, data, dataLen);
return CA_STATUS_FAILED;
}
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
g_isStartServer = true;
{
OIC_LOG(DEBUG, TAG, "CAStopLEGattServer");
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
+ VERIFY_NON_NULL_RET(g_jvm, TAG, "g_jvm is null", CA_STATUS_FAILED);
- bool isAttached = false;
JNIEnv* env = NULL;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
+ bool isAttached = false;
+ if (!CALEAttachCurrentThread(&env, g_jvm, &isAttached)){
+ return CA_STATUS_FAILED;
}
CAResult_t ret = CALEServerGattClose(env, g_bluetoothGattServer);