X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fconnectivity%2Fsrc%2Fbt_edr_adapter%2Ftizen%2Fcaedrnwmonitor.c;h=dd3e11d9553ff78bf0c1de9f90f8f3e78b78f7b6;hb=17c68b2fd1e74586f85e552eeab4e32dc121f8a0;hp=3cafd341f70e3676235f048d96a53e7f9249c342;hpb=8c01dff2c5bc5496f7dc1632c498943ec6ecb015;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/connectivity/src/bt_edr_adapter/tizen/caedrnwmonitor.c b/resource/csdk/connectivity/src/bt_edr_adapter/tizen/caedrnwmonitor.c index 3cafd34..dd3e11d 100644 --- a/resource/csdk/connectivity/src/bt_edr_adapter/tizen/caedrnwmonitor.c +++ b/resource/csdk/connectivity/src/bt_edr_adapter/tizen/caedrnwmonitor.c @@ -24,6 +24,7 @@ * This file provides the APIs for EDR Network Monitor. */ +#include #include #include @@ -34,6 +35,9 @@ #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. @@ -47,19 +51,16 @@ static CAEDRNetworkStatusCallback g_edrNetworkChangeCallback = NULL; static void CAEDRAdapterStateChangeCallback(int result, bt_adapter_state_e adapterState, void *userData); +void *GMainLoopThread (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; } @@ -80,6 +81,28 @@ CAResult_t CAEDRStartNetworkMonitor() { 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, GMainLoopThread, (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) { @@ -101,6 +124,11 @@ CAResult_t CAEDRStopNetworkMonitor() 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; }