GDBusProxy *proxy;
GError *error = NULL;
GVariant *result;
+ struct hal_ev_discovery_state_changed ev;
DBG("+");
+ memset(&ev, 0, sizeof(ev));
+
proxy = _bt_hal_get_adapter_proxy();
if (!proxy) {
DBG("_bt_hal_dbus_stop_discovery: Adapter proxy get failed!!!");
return BT_STATUS_FAIL;
}
+ /* Stop success */
+ ev.state = HAL_DISCOVERY_STATE_STOPPED;
+
+ if (!event_cb)
+ event_cb = _bt_hal_get_stack_message_handler();
+ if (event_cb) {
+ DBG("Sending HAL_EV_DISCOVERY_STATE_CHANGED event");
+ event_cb(HAL_EV_DISCOVERY_STATE_CHANGED, (void*)&ev, sizeof(ev));
+ }
+
/* discovery status will be change in event */
DBG("-");
g_variant_unref(result);
return BT_STATUS_SUCCESS;
}
+int _bt_hal_dbus_get_energy_info(uint32_t *tx_time, uint32_t *rx_time,
+ uint32_t *idle_time, uint32_t *energy_used)
+{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *result;
+
+ if (!tx_time || !rx_time || !idle_time || !energy_used) {
+ ERR("Invalid parameter");
+ return BT_STATUS_FAIL;
+ }
+
+ proxy = _bt_hal_get_adapter_proxy();
+ if (!proxy) {
+ DBG("_bt_hal_dbus_get_energy_info: Adapter proxy get failed!!!");
+ return BT_STATUS_FAIL;
+ }
+
+ result = g_dbus_proxy_call_sync(proxy,
+ "GetEnergyInfo",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (!result) {
+ if (error != NULL) {
+ ERR("GetEnergyInfo failed (Error: %s)", error->message);
+ g_clear_error(&error);
+ } else {
+ ERR("GetEnergyInfo failed");
+ }
+ return BT_STATUS_FAIL;
+ }
+
+ g_variant_get(result, "(uuuu)", tx_time, rx_time, idle_time, energy_used);
+
+ DBG("Tx time: %d, Rx time: %d, Idle time: %d", *tx_time, *rx_time, *idle_time);
+
+ g_variant_unref(result);
+ return BT_STATUS_SUCCESS;
+}
+
+int _bt_hal_dbus_get_profile_connected_devices(const char *profile_uuid)
+{
+ GDBusConnection *conn;
+ GDBusProxy *manager_proxy;
+ GVariant *result = NULL;
+ GVariant *result1 = NULL;
+ GVariantIter *iter = NULL;
+ GError *error = NULL;
+ char *object_path = NULL;
+ GVariantIter *interface_iter;
+ char *interface_str = NULL;
+ GDBusProxy *device_proxy = NULL;
+ gboolean is_connected = FALSE;
+ struct hal_ev_adapter_profile_connected_devices ev;
+
+ DBG("Get Profile Connected Devices. UUID: %s", profile_uuid);
+ memset(&ev, 0, sizeof(ev));
+
+ conn = __bt_hal_get_system_gconn();
+ if (conn == NULL)
+ return BT_STATUS_FAIL;
+
+ manager_proxy = _bt_hal_get_manager_proxy();
+ if (manager_proxy == NULL)
+ return BT_STATUS_FAIL;
+
+ result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (!result) {
+ if (error != NULL) {
+ ERR("GetManagedObjects failed (Error: %s)", error->message);
+ g_clear_error(&error);
+ error = NULL;
+ } else
+ ERR("GetManagedObjects failed");
+ return BT_STATUS_FAIL;
+ }
+
+ /* signature of GetManagedObjects: a{oa{sa{sv}}} */
+ g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
+
+ /* Parse the signature: oa{sa{sv}}} */
+ while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
+ if (object_path == NULL)
+ continue;
+
+ while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
+ &interface_str, NULL)) {
+ if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
+ DBG("Found a device: %s", object_path);
+ g_free(interface_str);
+
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_HAL_BLUEZ_NAME,
+ object_path, BT_HAL_DEVICE_INTERFACE, NULL, NULL);
+
+ if (device_proxy == NULL) {
+ DBG("Device don't have this service");
+ break;
+ }
+
+ result1 = g_dbus_proxy_call_sync(device_proxy, "IsConnectedProfile",
+ g_variant_new("(s)", profile_uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (result1 == NULL) {
+ if (error) {
+ ERR("Error occured in Proxy call [%s]", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ g_object_unref(device_proxy);
+ break;
+ }
+ g_variant_get(result1, "(b)", &is_connected);
+
+ if (is_connected == TRUE) {
+ char address[BT_HAL_ADDRESS_STRING_SIZE];
+ _bt_hal_convert_device_path_to_address(object_path, address);
+ DBG("Address: %s", address);
+ if (ev.count >= 10) {
+ INFO("Too many address");
+ break;
+ }
+ _bt_hal_convert_addr_string_to_type(ev.bdaddr_list[ev.count], address);
+ ev.count++;
+ }
+
+ g_variant_unref(result1);
+ g_object_unref(device_proxy);
+ break;
+ }
+ }
+ }
+
+ if (!event_cb)
+ event_cb = _bt_hal_get_stack_message_handler();
+ if (event_cb) {
+ DBG("Sending HAL_EV_ADAPTER_PROFILE_CONNECTED_DEVICES event");
+ event_cb(HAL_EV_ADAPTER_PROFILE_CONNECTED_DEVICES, (void *)&ev, sizeof(ev));
+ }
+
+ g_variant_unref(result);
+ g_variant_iter_free(iter);
+
+ DBG("-");
+ return BT_STATUS_SUCCESS;
+}
+
static gboolean __bt_adapter_all_properties_cb(gpointer user_data)
{
GVariant *result = user_data;
_bt_hal_update_le_feature_support(name, val, &le_features);
le_features_present = TRUE;
}
+ g_free(val);
g_variant_iter_free(iter);
if (le_features_present) {
int _bt_hal_dbus_get_scan_mode(void)
{
GDBusProxy *proxy;
- gboolean discoverable;
- gboolean connectable;
+ gboolean discoverable = FALSE;
+ gboolean connectable = FALSE;
GVariant *result;
GVariant *temp;
GError *error = NULL;
/* Buffer and propety count management */
uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
uint8_t addresses[BT_HAL_MAX_PROPERTY_BUF_SIZE];
- struct hal_ev_adapter_props_changed *ev = (void*) buf;;
+ struct hal_ev_adapter_props_changed *ev = (void *)buf;
size_t size = 0;
size_t count = 0;
break;
}
}
+
+ if (count >= (int)(sizeof(addresses) / BT_HAL_ADDRESS_LENGTH_MAX)) {
+ DBG("Reached the max length of addresses. do not stored anymore");
+ break;
+ }
}
g_variant_iter_free(iter);