Match both direction device with direction in or out mask 73/96773/1
authorJeongho Mok <jho.mok@samsung.com>
Mon, 7 Nov 2016 10:15:11 +0000 (19:15 +0900)
committerJeongho Mok <jho.mok@samsung.com>
Thu, 10 Nov 2016 06:28:36 +0000 (15:28 +0900)
[Version] 5.0.91
[Profile] Common
[Issue Type] Policy

Change-Id: I3875b62ca85388236a68e518b95d7593336ae0f4

packaging/pulseaudio-modules-tizen.spec
src/device-manager.c

index 5bf79a1..698916f 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.90
+Version:          5.0.91
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index f0f3b96..a386729 100644 (file)
@@ -430,6 +430,11 @@ static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = {
 
 #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;
@@ -2617,7 +2622,7 @@ static int _get_avail_mode(pa_tz_device *device) {
     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;
@@ -2628,8 +2633,7 @@ static void send_device_connected_signal(uint32_t event_id, pa_tz_device *device
     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);
@@ -2640,9 +2644,11 @@ static void send_device_connected_signal(uint32_t event_id, pa_tz_device *device
     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);
@@ -2663,12 +2669,12 @@ static void send_device_info_changed_signal(uint32_t event_id, pa_tz_device *dev
     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);
@@ -2682,6 +2688,8 @@ static void send_device_info_changed_signal(uint32_t event_id, pa_tz_device *dev
     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);
@@ -2696,55 +2704,69 @@ static void send_device_info_changed_signal(uint32_t event_id, pa_tz_device *dev
     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;
@@ -2798,23 +2820,24 @@ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage *
     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));
 
@@ -2824,8 +2847,10 @@ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage *
         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);
@@ -2834,6 +2859,8 @@ static void handle_get_connected_device_list(DBusConnection *conn, DBusMessage *
             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);
         }
     }
 
@@ -3233,7 +3260,7 @@ fail:
 }
 
 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;
 }