* This file provides the APIs for EDR Network Monitor.
*/
+#include <glib.h>
#include <string.h>
#include <bluetooth.h>
#include "caqueueingthread.h"
#include "caremotehandler.h"
+static GMainLoop *g_mainloop = NULL;
+static ca_thread_pool_t g_threadPoolHandle = NULL;
+
/**
* @var g_edrNetworkChangeCallback
* @brief Maintains the callback to be notified on local bluetooth adapter status change.
static void CAEDRAdapterStateChangeCallback(int result, bt_adapter_state_e adapterState,
void *userData);
+void *CAEDRMainLoopThread (void *param)
+{
+ g_main_loop_run(g_mainloop);
+ return NULL;
+}
+
CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool)
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
-
- // Initialize Bluetooth service
- int err = bt_initialize();
- if (BT_ERROR_NONE != err)
- {
- OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Bluetooth initialization failed!, error num [%x]",
- err);
- return CA_STATUS_FAILED;
- }
-
+ g_threadPoolHandle = threadPool;
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
return CA_STATUS_OK;
}
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
+ g_mainloop = g_main_loop_new(NULL, 0);
+ if(!g_mainloop)
+ {
+ OIC_LOG(ERROR, EDR_ADAPTER_TAG, "g_main_loop_new failed\n");
+ return CA_STATUS_FAILED;
+ }
+
+ if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle, CAEDRMainLoopThread, (void *) NULL))
+ {
+ OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create thread!");
+ return CA_STATUS_FAILED;
+ }
+
+ // Initialize Bluetooth service
+ int err = bt_initialize();
+ if (BT_ERROR_NONE != err)
+ {
+ OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Bluetooth initialization failed!, error num [%x]",
+ err);
+ return CA_STATUS_FAILED;
+ }
+
int ret = bt_adapter_set_state_changed_cb(CAEDRAdapterStateChangeCallback, NULL);
if(BT_ERROR_NONE != ret)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "bt_adapter_set_state_changed_cb failed");
return CA_STATUS_FAILED;
}
+
+ if (g_mainloop)
+ {
+ g_main_loop_quit(g_mainloop);
+ }
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
return CA_STATUS_OK;
}