Add sound_manager_is_device_running_by_id() for internal usage 29/187829/2 accepted/tizen/unified/20180830.060740 submit/tizen/20180829.052026
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 9 Aug 2018 07:51:26 +0000 (16:51 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 29 Aug 2018 03:57:14 +0000 (12:57 +0900)
It will be used for CSharp API.

[Version] 0.5.12
[Issue Type] New internal API

Change-Id: Iadbda94e2b02fe20d64a0b26845ed6f337604511
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/sound_manager_internal.h
include/sound_manager_internal_tv.h
include/sound_manager_private.h
packaging/capi-media-sound-manager.spec
src/sound_manager_internal.c
src/sound_manager_private.c
test/sound_manager_test.c

index 908a92087fd150b4e299e439394c98a654823300..ba7b29532dea2027eb8e0f9f59515dd64ec00a38 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2015 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -323,6 +323,24 @@ int sound_manager_remove_device_id_for_stream_routing(sound_stream_info_h stream
  */
 int sound_manager_get_device_state_by_id(int device_id, sound_device_state_e *state);
 
+/**
+ * @internal
+ * @brief Checks if the device is running.
+ * @since_tizen 5.0
+ * @param[in]  device_id       The device id
+ * @param[out] is_running      Whether the device is running or not: (@c true = running, @c false = not running)
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_prev_device()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_is_device_running_by_id(int device_id, bool *is_running);
+
 /**
  * @internal
  * @brief Creates a virtual stream handle.
index b2a74cd0a527a27ab2925a92ec32f3b181328608..ea39daf3a5e07ddf251a198ee4eeeb8a882460f1 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2015 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -280,20 +280,21 @@ int sound_manager_get_device_state_by_id(int device_id, sound_device_state_e *st
 
 /**
  * @internal
- * @brief Disable session backward compatibility.
- * @since_tizen 3.0
- *
- * @remarks    Multimedia framework support backward compatibility of legacy sound session. \n
- *     If a process does not want legacy sound session behavior in each multimedia framework, \n
- *     this function can be used explicitly not to support that.
- *
+ * @brief Checks if the device is running.
+ * @since_tizen 5.0
+ * @param[in]  device_id       The device id
+ * @param[out] is_running      Whether the device is running or not: (@c true = running, @c false = not running)
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #SOUND_MANAGER_ERROR_NONE Success
  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_prev_device()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
  */
-int sound_manager_disable_session_backward_compatibility(void);
+int sound_manager_is_device_running_by_id(int device_id, bool *is_running);
 
 /**
  * @internal
index b65f83511a51ebcaf9e471b7689763fe26cc489e..30aa35d0da40f4818d1c616d69d6fdc30323adac 100644 (file)
@@ -286,6 +286,8 @@ int _get_current_media_routing_path(const char *direction, sound_device_type_e *
 
 void _update_focus_status(unsigned int index, unsigned int acquired_focus_status);
 
+int _is_device_running_by_id(int device_id, bool *is_running);
+
 int _get_supported_sample_formats(int device_id, sound_sample_format_e **formats, unsigned int *num);
 
 int _set_sample_format(int device_id, sound_sample_format_e format);
index 0f2eb435736fabfd4268de5d39837b1d2ab79aa4..eb4bc371e59854973d1af48583153519c40d6d35 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.5.11
+Version:    0.5.12
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 7e9a09f97dd7606ce8c8c5fa6164c1e52dd10685..2e9c4e622684bd48f5865527b82ac6379d9855dc 100644 (file)
@@ -204,6 +204,17 @@ LEAVE:
        return _convert_sound_manager_error_code(__func__, ret);
 }
 
+int sound_manager_is_device_running_by_id(int device_id, bool *is_running)
+{
+       int ret = MM_ERROR_NONE;
+
+       LOGI(">> enter");
+
+       ret = _is_device_running_by_id(device_id, is_running);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
 int sound_manager_create_virtual_stream(sound_stream_info_h stream_info, virtual_sound_stream_h *virtual_stream)
 {
        int ret = MM_ERROR_NONE;
index a073399b1b9e8feb2f3af0164072e2ca74438434..5188fefbe36e2bb82c7feb7677424a7ff84fb92b 100644 (file)
@@ -36,6 +36,7 @@
 
 #define PA_DEVICE_MANAGER_OBJECT_PATH                           "/org/pulseaudio/DeviceManager"
 #define PA_DEVICE_MANAGER_INTERFACE                             "org.pulseaudio.DeviceManager"
+#define PA_DEVICE_MANAGER_METHOD_NAME_IS_DEVICE_RUNNING_BY_ID   "IsDeviceRunningById"
 #define PA_DEVICE_MANAGER_METHOD_NAME_GET_SUPPORTED_SAMPLE_FORMATS "GetSupportedSampleFormats"
 #define PA_DEVICE_MANAGER_METHOD_NAME_SET_SAMPLE_FORMAT         "SetSampleFormat"
 #define PA_DEVICE_MANAGER_METHOD_NAME_GET_SAMPLE_FORMAT         "GetSampleFormat"
@@ -1392,6 +1393,48 @@ LEAVE:
        return;
 }
 
+int _is_device_running_by_id(int device_id, bool *is_running)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       gboolean _is_running;
+
+       assert(is_running);
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       result = g_dbus_connection_call_sync(conn,
+                                                                         PA_BUS_NAME,
+                                                                         PA_DEVICE_MANAGER_OBJECT_PATH,
+                                                                         PA_DEVICE_MANAGER_INTERFACE,
+                                                                         PA_DEVICE_MANAGER_METHOD_NAME_IS_DEVICE_RUNNING_BY_ID,
+                                                                         g_variant_new("(i)", device_id),
+                                                                         G_VARIANT_TYPE("(b)"),
+                                                                         G_DBUS_CALL_FLAGS_NONE,
+                                                                         2000,
+                                                                         NULL,
+                                                                         &err);
+       if (err) {
+               LOGE("g_dbus_connection_call_sync() for IS_DEVICE_RUNNING_BY_ID error (%s)", err->message);
+               ret = _convert_dbus_error(err->message);
+               g_error_free(err);
+               goto LEAVE;
+       } else {
+               g_variant_get(result, "(b)", &_is_running);
+               *is_running = (bool)_is_running;
+               LOGI("device(id:%d) is (%s)", device_id, *is_running ? "Running" : "Not running");
+       }
+
+LEAVE:
+       g_variant_unref(result);
+       g_object_unref(conn);
+
+       return ret;
+}
+
 #define SM_SAMPLE_FORMAT_NUM    4 /* check declaration of sound_sample_format_e */
 int _get_supported_sample_formats(int device_id, sound_sample_format_e **formats, unsigned int *num)
 {
@@ -1743,6 +1786,7 @@ int _get_avoid_resampling(int device_id, bool *enabled)
        GVariant *result = NULL;
        GDBusConnection *conn = NULL;
        GError *err = NULL;
+       gboolean _enabled;
 
        SM_NULL_ARG_CHECK_FOR_PRIV(enabled);
 
@@ -1767,7 +1811,8 @@ int _get_avoid_resampling(int device_id, bool *enabled)
                goto LEAVE;
        }
 
-       g_variant_get(result, "(b)", enabled);
+       g_variant_get(result, "(b)", &_enabled);
+       *enabled = (bool)_enabled;
        g_variant_unref(result);
 
 LEAVE:
index e76047cbdc72269ab5f3bb8fabf442872f061b05..3dd9a7014d2ec9d467b4a6efd595ae9e2e92885e 100644 (file)
@@ -878,7 +878,7 @@ static void interpret(char *cmd)
        case CURRENT_STATUS_GET_DEVICE_NEXT: {
                sound_device_type_e type;
                sound_device_io_direction_e io_direction;
-               sound_device_state_e state;
+               bool is_running;
                int id;
                char *name;
                int ret = SOUND_MANAGER_ERROR_NONE;
@@ -892,10 +892,11 @@ static void interpret(char *cmd)
                                g_print("failed to get device id, ret[0x%x]\n", ret);
                        if ((ret = sound_manager_get_device_name(g_device, &name)))
                                g_print("failed to get device name, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_state(g_device, &state)))
+                       if ((ret = sound_manager_is_device_running(g_device, &is_running)))
                                g_print("failed to get device state, ret[0x%x]\n", ret);
                        if (!ret)
-                               g_print("-- NEXT device type[%d], io_direction[%d], id[%d], name[%s], state[%d]\n", type, io_direction, id, name, state);
+                               g_print("-- NEXT device type[%d], io_direction[%d], id[%d], name[%s], state[%s]\n",
+                                               type, io_direction, id, name, is_running ? "Running" : "Not running");
                } else {
                        g_print("failed to get next device, ret[0x%x]\n", ret);
                }
@@ -905,7 +906,7 @@ static void interpret(char *cmd)
        case CURRENT_STATUS_GET_DEVICE_PREV: {
                sound_device_type_e type;
                sound_device_io_direction_e io_direction;
-               sound_device_state_e state;
+               bool is_running;
                int id;
                char *name;
                int ret = SOUND_MANAGER_ERROR_NONE;
@@ -919,10 +920,11 @@ static void interpret(char *cmd)
                                g_print("failed to get device id, ret[0x%x]\n", ret);
                        if ((ret = sound_manager_get_device_name(g_device, &name)))
                                g_print("failed to get device name, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_state(g_device, &state)))
+                       if ((ret = sound_manager_is_device_running(g_device, &is_running)))
                                g_print("failed to get device state, ret[0x%x]\n", ret);
                        if (!ret)
-                               g_print("-- PREV device type[%d], io_direction[%d], id[%d], name[%s], state[%d]\n", type, io_direction, id, name, state);
+                               g_print("-- PREV device type[%d], io_direction[%d], id[%d], name[%s], state[%s]\n",
+                                               type, io_direction, id, name, is_running ? "Running" : "Not running");
                } else {
                        g_print("failed to get previous device, ret[0x%x]\n", ret);
                }
@@ -932,14 +934,14 @@ static void interpret(char *cmd)
        case CURRENT_STATUS_GET_DEVICE_STATE_BY_ID: {
                int ret = SOUND_MANAGER_ERROR_NONE;
                int device_id;
-               sound_device_state_e state;
+               bool is_running;
 
                device_id = atoi(cmd);
 
-               if ((ret = sound_manager_get_device_state_by_id(device_id, &state)))
-                       g_print("failed to get device state by id, ret[0x%x]\n", ret);
+               if ((ret = sound_manager_is_device_running_by_id(device_id, &is_running)))
+                       g_print("failed to is device running by id, ret[0x%x]\n", ret);
                else
-                       g_print("device id[%d], state[%d] (0:deactivated, 1:activated)\n", device_id, state);
+                       g_print("device id[%d], state[%s]\n", device_id, is_running ? "Running" : "Not running");
 
                reset_menu_state();
                break;