#include <vconf.h>
#include <vconf-keys.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus.h>
+#include <glib.h>
+
#include "bt_core.h"
#include "bt-internal-types.h"
static GMainLoop *main_loop = NULL;
+static DBusGConnection *conn = NULL;
typedef enum {
BT_DEACTIVATED,
return g_error_new(BT_CORE_ERROR, error, err_msg, NULL);
}
+static DBusGProxy *_bt_get_adapter_proxy(void)
+{
+ DBusGProxy *proxy;
+ char *adapter_path = NULL;
+
+ if (conn == NULL) {
+ conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
+ retv_if(conn == NULL, NULL);
+ }
+
+ proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
+ BT_BLUEZ_HCI_PATH, BT_PROPERTIES_INTERFACE);
+ retv_if(proxy == NULL, NULL);
+
+ return proxy;
+}
+
+static int _bt_power_adapter(gboolean powered)
+{
+ GValue state = { 0 };
+ GError *error = NULL;
+ DBusGProxy *proxy;
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ g_value_init(&state, G_TYPE_BOOLEAN);
+ g_value_set_boolean(&state, powered);
+
+ BT_DBG("send power state: %d to bluez", powered);
+
+ dbus_g_proxy_call(proxy, "Set", &error,
+ G_TYPE_STRING, BT_ADAPTER_INTERFACE,
+ G_TYPE_STRING, "Powered",
+ G_TYPE_VALUE, &state,
+ G_TYPE_INVALID, G_TYPE_INVALID);
+
+ if (error != NULL) {
+ BT_ERR("Powered set err:[%s]", error->message);
+ g_error_free(error);
+ g_value_unset(&state);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ return BLUETOOTH_ERROR_NONE;
+}
+
static int __bt_enable_adapter(void)
{
int ret;
__bt_core_set_status(BT_ACTIVATING);
- ret = system("/usr/etc/bluetooth/bt-stack-up.sh &");
- if (ret < 0) {
- BT_DBG("running script failed");
- ret = system("/usr/etc/bluetooth/bt-dev-end.sh &");
- __bt_core_set_status(BT_DEACTIVATED);
- return -1;
- }
+ _bt_power_adapter(TRUE);
return 0;
}
#endif
__bt_core_set_status(BT_DEACTIVATING);
- if (system("/usr/etc/bluetooth/bt-stack-down.sh &") < 0) {
- BT_DBG("running script failed");
- __bt_core_set_status(BT_ACTIVATED);
- return -1;
- }
-#ifndef __TIZEN_MOBILE__
+ _bt_power_adapter(FALSE);
+
__bt_core_terminate();
-#endif
+
return 0;
}
int main(void)
{
- DBusGConnection *conn = NULL;
GError *error = NULL;
BtCore *bt_core;
DBusGProxy *dbus_proxy = NULL;
BT_DBG("+");
- g_type_init();
-
conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
if (error != NULL) {
BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
#define BT_ERR(fmt, args...) \
SLOGE(fmt, ##args)
+#define retv_if(expr, val) \
+ do { \
+ if (expr) { \
+ BT_ERR("(%s) return", #expr); \
+ return (val); \
+ } \
+ } while (0)
+
+#define BT_BLUEZ_NAME "org.bluez"
+#define BT_BLUEZ_HCI_PATH "/org/bluez/hci0"
+#define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
+#define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
+
#define BT_CORE_NAME "org.projectx.bt_core"
#define BT_CORE_PATH "/org/projectx/bt_core"
return (core_proxy) ? core_proxy : _bt_init_core_proxy();
}
-gboolean __bt_enable_timeout_cb(gpointer user_data)
-{
- DBusGProxy *proxy;
-
- retv_if(_bt_adapter_get_status() == BT_ACTIVATED, FALSE);
-
- proxy = __bt_get_core_proxy();
- if (!proxy)
- return BLUETOOTH_ERROR_INTERNAL;
-
- /* Clean up the process */
- if (dbus_g_proxy_call(proxy, "DisableAdapter", NULL,
- G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
- BT_ERR("Bt core call failed");
- }
-
- __bt_adapter_set_status(BT_DEACTIVATED);
-
- __bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT);
-
- /* Display notification */
- status_message_post(BT_STR_NOT_SUPPORT);
-
- _bt_terminate_service(NULL);
-
- return FALSE;
-}
-
int _bt_enable_adapter(void)
{
DBusGProxy *proxy;
return BLUETOOTH_ERROR_INTERNAL;
}
- g_timeout_add(BT_ENABLE_TIMEOUT,
- (GSourceFunc)__bt_enable_timeout_cb,
- NULL);
-
return BLUETOOTH_ERROR_NONE;
}
DBUS_TYPE_INT32, &result,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID);
+ } else if (strcasecmp(property, "Powered") == 0) {
+ gboolean power = FALSE;
+ int power_event;
+
+ dbus_message_iter_recurse(&dict_iter, &value_iter);
+ dbus_message_iter_get_basic(&value_iter, &power);
+
+ power_event = (power == TRUE) ? BLUETOOTH_EVENT_ENABLED :
+ BLUETOOTH_EVENT_DISABLED;
+
+ BT_ERR("send power state: %d", power);
+ /* Send event to application */
+ _bt_send_event(BT_ADAPTER_EVENT,
+ power_event,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID);
} else if (strcasecmp(property, "Discoverable") == 0) {
gboolean discoverable = FALSE;