return CA_STATUS_OK;
}
-CAResult_t CALEStartAdvertise()
+CAResult_t CALEServerStartAdvertise()
{
if (!g_jvm)
{
}
// start advertise
- CAResult_t ret = CALEServerStartAdvertise(env, g_leAdvertiseCallback);
+ CAResult_t ret = CALEServerStartAdvertiseImpl(env, g_leAdvertiseCallback);
if (CA_STATUS_OK != ret)
{
- OIC_LOG(ERROR, TAG, "CALEServerStartAdvertise has failed");
+ OIC_LOG(ERROR, TAG, "CALEServerStartAdvertiseImpl has failed");
}
if (isAttached)
return ret;
}
-CAResult_t CALEServerStartAdvertise(JNIEnv *env, jobject advertiseCallback)
+CAResult_t CALEServerStartAdvertiseImpl(JNIEnv *env, jobject advertiseCallback)
{
- OIC_LOG(DEBUG, TAG, "IN - CALEServerStartAdvertise");
+ OIC_LOG(DEBUG, TAG, "IN - CALEServerStartAdvertiseImpl");
VERIFY_NON_NULL(env, TAG, "env is null");
VERIFY_NON_NULL(advertiseCallback, TAG, "advertiseCallback is null");
return CA_STATUS_FAILED;
}
-CAResult_t CALEServerStopAdvertise(JNIEnv *env, jobject advertiseCallback)
+CAResult_t CALEServerStopAdvertise()
{
- OIC_LOG(DEBUG, TAG, "LEServerStopAdvertise");
+ if (!g_jvm)
+ {
+ OIC_LOG(ERROR, TAG, "g_jvm is null");
+ return 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;
+ }
+
+ CAResult_t ret = CALEServerStopAdvertiseImpl(env, g_leAdvertiseCallback);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "CALEServerStopAdvertise has failed");
+ }
+
+ if (isAttached)
+ {
+ (*g_jvm)->DetachCurrentThread(g_jvm);
+ }
+
+ return ret;
+}
+
+CAResult_t CALEServerStopAdvertiseImpl(JNIEnv *env, jobject advertiseCallback)
+{
+ OIC_LOG(DEBUG, TAG, "CALEServerStopAdvertiseImpl");
VERIFY_NON_NULL(env, TAG, "env is null");
VERIFY_NON_NULL(advertiseCallback, TAG, "advertiseCallback is null");
return CA_STATUS_FAILED;
}
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return 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;
- }
-
- CAResult_t ret = CALEServerStopAdvertise(env, g_leAdvertiseCallback);
+ CAResult_t ret = CALEServerStopAdvertise();
if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, TAG, "CALEServerStopAdvertise has failed");
g_isStartServer = false;
- if (isAttached)
- {
- (*g_jvm)->DetachCurrentThread(g_jvm);
- }
-
OIC_LOG(DEBUG, TAG, "OUT - CALEServerStopMulticastServer");
return ret;
}
OIC_LOG(DEBUG, TAG, "add connected device to cache");
CALEServerAddDeviceToList(env, device);
}
+
+ CAResult_t res = CALEServerStopAdvertise();
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(DEBUG, TAG, "CALEServerStopAdvertise has failed");
+ }
+
(*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
}
else if (newState == g_state_disconnected)
}
// start advertise
- ret = CALEServerStartAdvertise(env, g_leAdvertiseCallback);
+ ret = CALEServerStartAdvertise();
if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, TAG, "CALEServerStartAdvertise has failed");
/**
* start advertise in gatt server.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CALEStartAdvertise();
+CAResult_t CALEServerStartAdvertise();
/**
* start advertise in gatt server.
* advertisement result.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CALEServerStartAdvertise(JNIEnv *env, jobject advertiseCallback);
+CAResult_t CALEServerStartAdvertiseImpl(JNIEnv *env, jobject advertiseCallback);
+
+/**
+ * stop advertise in gatt server.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEServerStopAdvertise();
/**
* stop advertise in gatt server.
* advertisement result.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CALEServerStopAdvertise(JNIEnv *env, jobject advertiseCallback);
+CAResult_t CALEServerStopAdvertiseImpl(JNIEnv *env, jobject advertiseCallback);
/**
* open a gatt server.
{
VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address");
+ CAResult_t res = CA_STATUS_OK;
if (connected)
{
OIC_LOG_V(DEBUG, TAG, "Connected to [%s]", remoteAddress);
char *addr = OICStrdup(remoteAddress);
oc_mutex_lock(g_LEClientListMutex);
- CAResult_t result = CAAddLEClientInfoToList(&g_LEClientList, addr);
- if (CA_STATUS_OK != result)
+ res = CAAddLEClientInfoToList(&g_LEClientList, addr);
+ if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "CAAddLEClientInfoToList failed");
oc_mutex_unlock(g_LEClientListMutex);
return;
}
oc_mutex_unlock(g_LEClientListMutex);
+
+ res = CALEStopAdvertise();
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "Failed to stop advertising [%d]", res);
+ return;
+ }
}
else
{
oc_mutex_lock(g_LEClientListMutex);
CARemoveLEClientInfoFromList(&g_LEClientList, remoteAddress);
oc_mutex_unlock(g_LEClientListMutex);
+
+ res = CALEStartAdvertise(CA_GATT_SERVICE_UUID);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "Failed to start advertising [%d]", res);
+ return;
+ }
}
}