From: Corentin Lecouvey Date: Thu, 27 Nov 2014 14:29:49 +0000 (+0100) Subject: check bt adapter state from bt-service daemon X-Git-Tag: accepted/tizen/common/20141215.134656^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b1f636114f7b284eb6035949da27e5424865fa69;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git check bt adapter state from bt-service daemon By this way if bt-service is not running when calling bt_adapter_get_state() CAPI, bt-service will be started by dbus activation. Change-Id: I05dcd3ef1aa9201042bd403c5e357c1126244f7c Signed-off-by: Corentin Lecouvey --- diff --git a/bt-api/bt-adapter.c b/bt-api/bt-adapter.c index bab009f..acd5f2a 100644 --- a/bt-api/bt-adapter.c +++ b/bt-api/bt-adapter.c @@ -17,7 +17,6 @@ * */ - #include #if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT) #include @@ -62,21 +61,22 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) BT_EXPORT_API int bluetooth_check_adapter(void) { -#ifdef __TIZEN_MOBILE__ - int ret; + int result; + bluetooth_adapter_state_t state; + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); - ret = _bt_get_adapter_path(_bt_get_system_gconn(), NULL); + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_CHECK_ADAPTER, + in_param1, in_param2, in_param3, in_param4, &out_param); - return ret == BLUETOOTH_ERROR_NONE ? BLUETOOTH_ADAPTER_ENABLED : - BLUETOOTH_ADAPTER_DISABLED; -#else - gboolean powered; + if (result == BLUETOOTH_ERROR_NONE) { + state = g_array_index(out_param, bluetooth_adapter_state_t, 0); + } - powered = _bt_get_adapter_power(_bt_get_system_gconn()); + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); - return powered == TRUE ? BLUETOOTH_ADAPTER_ENABLED : - BLUETOOTH_ADAPTER_DISABLED; -#endif + return state ? BLUETOOTH_ADAPTER_ENABLED : BLUETOOTH_ADAPTER_DISABLED; } BT_EXPORT_API int bluetooth_enable_adapter(void) diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index ce38ed3..74f8a24 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -320,36 +320,6 @@ DBusGProxy *_bt_get_adapter_proxy(DBusGConnection *conn) return adapter_proxy; } -gboolean _bt_get_adapter_power(DBusGConnection *conn) -{ - DBusGProxy *proxy = NULL; - gboolean powered; - GValue powered_v = { 0 }; - GError *err = NULL; - - proxy = _bt_get_adapter_proxy(conn); - retv_if(proxy == NULL, FALSE); - - if (!dbus_g_proxy_call(proxy, "Get", &err, - G_TYPE_STRING, BT_ADAPTER_INTERFACE, - G_TYPE_STRING, "Powered", - G_TYPE_INVALID, - G_TYPE_VALUE, &powered_v, - G_TYPE_INVALID)) { - if (err != NULL) { - BT_ERR("Getting property failed: [%s]\n", err->message); - g_error_free(err); - } - return FALSE; - } - - powered = (gboolean)g_value_get_boolean(&powered_v); - - BT_DBG("powered = %d", powered); - - return powered; -} - void _bt_device_path_to_address(const char *device_path, char *device_address) { char address[BT_ADDRESS_STRING_SIZE] = { 0 }; diff --git a/bt-api/include/bt-common.h b/bt-api/include/bt-common.h index f62ada3..bc67026 100644 --- a/bt-api/include/bt-common.h +++ b/bt-api/include/bt-common.h @@ -218,8 +218,6 @@ int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length); int _bt_get_adapter_path(DBusGConnection *g_conn, char *path); -gboolean _bt_get_adapter_power(DBusGConnection *conn); - DBusGProxy *_bt_get_adapter_proxy(DBusGConnection *conn); void _bt_device_path_to_address(const char *device_path, char *device_address); diff --git a/bt-service/bt-service-adapter.c b/bt-service/bt-service-adapter.c index 4ff70f7..3fa6644 100644 --- a/bt-service/bt-service-adapter.c +++ b/bt-service/bt-service-adapter.c @@ -893,18 +893,13 @@ int _bt_reset_adapter(void) int _bt_check_adapter(int *status) { - char *adapter_path = NULL; - BT_CHECK_PARAMETER(status, return); *status = 0; /* 0: disabled */ - adapter_path = _bt_get_adapter_path(); - - if (adapter_path != NULL) + if (_bt_get_adapter_power()) *status = 1; /* 1: enabled */ - g_free(adapter_path); return BLUETOOTH_ERROR_NONE; } diff --git a/bt-service/bt-service-common.c b/bt-service/bt-service-common.c index fa61108..028b455 100644 --- a/bt-service/bt-service-common.c +++ b/bt-service/bt-service-common.c @@ -166,6 +166,36 @@ DBusGProxy *_bt_get_adapter_properties_proxy(void) __bt_init_adapter_properties_proxy(); } +gboolean _bt_get_adapter_power(void) +{ + DBusGProxy *proxy = NULL; + gboolean powered; + GValue powered_v = { 0 }; + GError *err = NULL; + + proxy = _bt_get_adapter_properties_proxy(); + retv_if(proxy == NULL, FALSE); + + if (!dbus_g_proxy_call(proxy, "Get", &err, + G_TYPE_STRING, BT_ADAPTER_INTERFACE, + G_TYPE_STRING, "Powered", + G_TYPE_INVALID, + G_TYPE_VALUE, &powered_v, + G_TYPE_INVALID)) { + if (err != NULL) { + BT_ERR("Getting property failed: [%s]\n", err->message); + g_error_free(err); + } + return FALSE; + } + + powered = (gboolean)g_value_get_boolean(&powered_v); + + BT_DBG("powered = %d", powered); + + return powered; +} + static char *__bt_extract_adapter_path(DBusMessageIter *msg_iter) { char *object_path = NULL; diff --git a/bt-service/include/bt-service-common.h b/bt-service/include/bt-service-common.h index f56c8c8..944be45 100644 --- a/bt-service/include/bt-service-common.h +++ b/bt-service/include/bt-service-common.h @@ -215,6 +215,8 @@ DBusGProxy *_bt_get_adapter_properties_proxy(void); char *_bt_get_adapter_path(void); +gboolean _bt_get_adapter_power(void); + void _bt_deinit_proxys(void); void _bt_convert_device_path_to_address(const char *device_path,