#endif
+static inline void simple_device_dump(pa_log_level_t level, const char *prefix, int id, const char *type, const char *name, int direction, int state, int avail_mode) {
+ pa_logl(level, "%s device id(%d) type(%s) name (%s) direction(%d) state(%d) avail-mode(%d)",
+ pa_strempty(prefix), id, pa_strnull(type), pa_strnull(name), direction, state, avail_mode);
+}
+
static void type_info_free_func(struct device_type_info *type_info) {
if (!type_info)
return;
return avail_mode;
}
-static void send_device_connected_signal(uint32_t event_id, pa_tz_device *device, bool connected, pa_device_manager *dm) {
+static void send_device_connection_changed_signal(uint32_t event_id, pa_tz_device *device, bool connected, pa_device_manager *dm) {
DBusMessage *signal_msg;
DBusMessageIter msg_iter, device_iter;
dbus_bool_t _connected = connected;
pa_assert(device);
pa_assert(dm);
- pa_log_info("Send device %s signal, event_id(%u) device(%u)",
- connected ? "Connected" : "Disconnected", event_id, device->id);
+ pa_log_info("Send device connection changed signal, event_id(%u)", event_id);
pa_assert_se(signal_msg = dbus_message_new_signal(DBUS_OBJECT_DEVICE_MANAGER, DBUS_INTERFACE_DEVICE_MANAGER, "DeviceConnected"));
dbus_message_iter_init_append(signal_msg, &msg_iter);
type = pa_tz_device_get_type(device);
name = pa_tz_device_get_name(device);
avail_mode = _get_avail_mode(device);
-
device_id = (dbus_int32_t) pa_tz_device_get_id(device);
compound_state = pa_tz_device_get_state(device, DM_DEVICE_DIRECTION_BOTH);
+
+ simple_device_dump(PA_LOG_INFO, connected ? "[Connected]" : "[Disconnected]", device_id, type, name, direction, compound_state, avail_mode);
+
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &device_id);
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_STRING, &type);
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &direction);
dm_device_state_t compound_state;
dbus_int32_t device_id, direction, avail_mode;
char *type, *name;
+ const char *changed_prefix[] = {"[State Changed]", "[Direction Changed]", "[Avail-Mode Changed]"};
pa_assert(device);
pa_assert(dm);
- pa_log_debug("Send device info changed signal, event_id(%u) device(%u) changed_type(%d)",
- event_id, device->id, changed_type);
+ pa_log_debug("Send device info changed signal, event_id(%u)", event_id);
pa_assert_se(signal_msg = dbus_message_new_signal(DBUS_OBJECT_DEVICE_MANAGER, DBUS_INTERFACE_DEVICE_MANAGER, "DeviceInfoChanged"));
dbus_message_iter_init_append(signal_msg, &msg_iter);
compound_state = pa_tz_device_get_state(device, DM_DEVICE_DIRECTION_BOTH);
avail_mode = (dbus_int32_t) _get_avail_mode(device);
+ simple_device_dump(PA_LOG_DEBUG, changed_prefix[changed_type], device_id, type, name, direction, compound_state, avail_mode);
+
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &device_id);
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_STRING, &type);
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &direction);
dbus_message_unref(signal_msg);
}
-static bool device_item_match_for_mask(pa_tz_device *device, int device_flags, pa_device_manager *dm) {
- bool match = false;
- int need_to_check_for_io_direction = device_flags & DEVICE_IO_DIRECTION_FLAGS;
- int need_to_check_for_state = device_flags & DEVICE_STATE_FLAGS;
- int need_to_check_for_type = device_flags & DEVICE_TYPE_FLAGS;
+static bool device_is_match_direction(pa_tz_device *device, int direction_mask) {
dm_device_direction_t direction;
- char *type;
- pa_assert(device);
-
- if (device_flags == DEVICE_ALL_FLAG)
+ if (direction_mask == DEVICE_IO_DIRECTION_FLAGS || direction_mask == 0)
return true;
direction = pa_tz_device_get_direction(device);
+
+ if ((direction_mask & DEVICE_IO_DIRECTION_IN_FLAG) && (direction & DM_DEVICE_DIRECTION_IN))
+ return true;
+ if ((direction_mask & DEVICE_IO_DIRECTION_OUT_FLAG) && (direction & DM_DEVICE_DIRECTION_OUT))
+ return true;
+ if ((direction_mask & DEVICE_IO_DIRECTION_BOTH_FLAG) && (direction & DM_DEVICE_DIRECTION_BOTH))
+ return true;
+
+ return false;
+}
+
+static bool device_is_match_state(pa_tz_device *device, int state_mask) {
+ dm_device_state_t state;
+
+ if (state_mask == DEVICE_STATE_FLAGS || state_mask == 0)
+ return true;
+
+ state = pa_tz_device_get_state(device, DM_DEVICE_DIRECTION_BOTH);
+
+ if ((state_mask & DEVICE_STATE_DEACTIVATED_FLAG) && (state == DM_DEVICE_STATE_DEACTIVATED))
+ return true;
+ if ((state_mask & DEVICE_STATE_ACTIVATED_FLAG) && (state == DM_DEVICE_STATE_ACTIVATED))
+ return true;
+
+ return false;
+}
+
+static bool device_is_match_type(pa_tz_device *device, int type_mask) {
+ char *type;
+ bool is_builtin;
+
+ if (type_mask == DEVICE_TYPE_FLAGS || type_mask == 0)
+ return true;
+
type = pa_tz_device_get_type(device);
+ is_builtin = device_type_is_builtin(type);
- if (need_to_check_for_io_direction) {
- if ((direction == DM_DEVICE_DIRECTION_IN) && (device_flags & DEVICE_IO_DIRECTION_IN_FLAG)) match = true;
- else if ((direction == DM_DEVICE_DIRECTION_OUT) && (device_flags & DEVICE_IO_DIRECTION_OUT_FLAG)) match = true;
- else if ((direction == DM_DEVICE_DIRECTION_BOTH) && (device_flags & DEVICE_IO_DIRECTION_BOTH_FLAG)) match = true;
- if (match) {
- if (!need_to_check_for_state && !need_to_check_for_type) return true;
- } else {
- return false;
- }
- }
- if (need_to_check_for_state) {
- match = false;
- if ((pa_tz_device_get_state(device, DM_DEVICE_DIRECTION_BOTH) == DM_DEVICE_STATE_DEACTIVATED) && (device_flags & DEVICE_STATE_DEACTIVATED_FLAG))
- match = true;
- else if ((pa_tz_device_get_state(device, DM_DEVICE_DIRECTION_BOTH) == DM_DEVICE_STATE_ACTIVATED) && (device_flags & DEVICE_STATE_ACTIVATED_FLAG))
- match = true;
- if (match) {
- if (!need_to_check_for_type)
- return true;
- } else {
- return false;
- }
- }
- if (need_to_check_for_type) {
- if (device_type_is_builtin(type) && (device_flags & DEVICE_TYPE_INTERNAL_FLAG))
- return true;
- else if (!device_type_is_builtin(type) && (device_flags & DEVICE_TYPE_EXTERNAL_FLAG))
- return true;
- }
+ if ((type_mask & DEVICE_TYPE_INTERNAL_FLAG) && is_builtin)
+ return true;
+ if ((type_mask & DEVICE_TYPE_EXTERNAL_FLAG) && !is_builtin)
+ return true;
return false;
}
+static bool device_is_match_with_mask(pa_tz_device *device, int mask) {
+ pa_assert(device);
+
+ if (mask == DEVICE_ALL_FLAG)
+ return true;
+
+ return (device_is_match_direction(device, mask & DEVICE_IO_DIRECTION_FLAGS) &&
+ device_is_match_state(device, mask & DEVICE_STATE_FLAGS) &&
+ device_is_match_type(device, mask & DEVICE_TYPE_FLAGS));
+}
+
static int method_call_bt_get_name(DBusConnection *conn, const char *device_path, char **name) {
const char *intf = DBUS_INTERFACE_BLUEZ_DEVICE, *prop = "Alias";
DBusMessage *msg, *reply;
dm_device_state_t compound_state;
uint32_t device_idx;
dbus_int32_t device_id, direction, avail_mode;
- int mask_flags;
+ int mask;
char *type, *name;
pa_assert(conn);
pa_assert(msg);
pa_assert(userdata);
- pa_log_info("Get connected device list");
dm = (pa_device_manager*) userdata;
pa_assert_se((reply = dbus_message_new_method_return(msg)));
pa_assert_se(dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &mask_flags,
+ DBUS_TYPE_INT32, &mask,
DBUS_TYPE_INVALID));
+ pa_log_info("Get connected device list (mask : %d)", mask);
+
dbus_message_iter_init_append(reply, &msg_iter);
pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "(isiiis)", &array_iter));
type = pa_tz_device_get_type(device);
name = pa_tz_device_get_name(device);
avail_mode = _get_avail_mode(device);
- if (device_item_match_for_mask(device, mask_flags, dm)) {
+ if (device_is_match_with_mask(device, mask)) {
device_id = (dbus_int32_t)pa_tz_device_get_id(device);
+
+ simple_device_dump(PA_LOG_INFO, "[MATCH]", device_id, type, name, direction, compound_state, avail_mode);
pa_assert_se(dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &device_iter));
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &device_id);
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_STRING, &type);
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_INT32, &avail_mode);
dbus_message_iter_append_basic(&device_iter, DBUS_TYPE_STRING, &name);
pa_assert_se(dbus_message_iter_close_container(&array_iter, &device_iter));
+ } else {
+ simple_device_dump(PA_LOG_INFO, "[UNMATCH]", device_id, type, name, direction, compound_state, avail_mode);
}
}
}
static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_tz_device_hook_data_for_conn_changed *data, pa_device_manager *dm) {
- send_device_connected_signal(data->event_id, data->device, data->is_connected, dm);
+ send_device_connection_changed_signal(data->event_id, data->device, data->is_connected, dm);
return PA_HOOK_OK;
}