#include "logger.h"
#include "oic_malloc.h"
#include "cathreadpool.h" /* for thread pool */
-#include "camutex.h"
+#include "octhread.h"
#include "uarraylist.h"
#include "caadapterutils.h"
#include "caedrserver.h"
#include "org_iotivity_ca_CaEdrInterface.h"
//#define DEBUG_MODE
-#define TAG PCF("CA_EDR_MONITOR")
+#define TAG PCF("OIC_CA_EDR_MONITOR")
static JavaVM *g_jvm;
static jobject g_context;
CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
if (!threadPool)
{
return CA_STATUS_FAILED;
CANativeJNIGetJavaVM();
}
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
void CAEDRTerminateNetworkMonitor(void)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
- OIC_LOG(DEBUG, TAG, "OUT");
}
CAResult_t CAEDRStartNetworkMonitor()
{
- OIC_LOG(DEBUG, TAG, "IN");
-
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t CAEDRStopNetworkMonitor()
{
- OIC_LOG(DEBUG, TAG, "IN");
-
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t CAEDRClientSetCallbacks(void)
{
- OIC_LOG(DEBUG, TAG, "IN");
-
- OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
if (NULL == g_networkChangeCb)
{
- OIC_LOG_V(DEBUG, TAG, "gNetworkChangeCb is null", status);
+ OIC_LOG(DEBUG, TAG, "g_networkChangeCb is null");
+ return;
}
jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
if (!jni_cid_BTAdapter)
{
- OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_BTAdapter is null");
+ OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
return;
}
jfieldID id_state_on = (*env)->GetStaticFieldID(env, jni_cid_BTAdapter, "STATE_ON", "I");
if (!id_state_on)
{
- OIC_LOG(ERROR, TAG, "[EDR][Native] id_state_on is null");
+ OIC_LOG(ERROR, TAG, "id_state_on is null");
return;
}
jfieldID id_state_off = (*env)->GetStaticFieldID(env, jni_cid_BTAdapter, "STATE_OFF", "I");
if (!id_state_off)
{
- OIC_LOG(ERROR, TAG, "[EDR][Native] id_state_off is null");
+ OIC_LOG(ERROR, TAG, "id_state_off is null");
return;
}
if (state_on == status)
{
CANetworkStatus_t newStatus = CA_INTERFACE_UP;
+
+ CAResult_t res = CAEDRStartReceiveThread(false);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to CAEDRStartReceiveThread");
+ return;
+ }
CAEDRServerStartAcceptThread();
g_networkChangeCb(newStatus);
}
else if (state_off == status)
{
CANetworkStatus_t newStatus = CA_INTERFACE_DOWN;
+ CAEDRServerStop();
+ CAEDRNativeSocketCloseToAll(env);
+ CAEDRNativeRemoveAllDeviceState();
CAEDRNativeRemoveAllDeviceSocket(env);
- CAEDRNativeRemoveAllDeviceState(env);
g_networkChangeCb(newStatus);
}
}
CAEDRNativeRemoveDevice(addr);
}
}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaEdrInterface_caEdrConnectionStateChangedCallback(JNIEnv *env,
+ jobject obj,
+ jstring addr,
+ jint isConnected)
+{
+ if (!env || !obj || !addr)
+ {
+ OIC_LOG(ERROR, TAG, "parameter is null");
+ return;
+ }
+
+ OIC_LOG_V(DEBUG, TAG, "CaEdrInterface - Connection State Changed : %d", isConnected);
+
+ if (!isConnected)
+ {
+ const char *address = (*env)->GetStringUTFChars(env, addr, NULL);
+ if (!address)
+ {
+ OIC_LOG(ERROR, TAG, "address is null");
+ return;
+ }
+
+ CAEDRNativeRemoveDeviceSocketBaseAddr(env, addr);
+ CAEDRNativeRemoveDevice(address);
+ (*env)->ReleaseStringUTFChars(env, addr, address);
+ }
+}