Revert "[AudioManager] Remove deprecated symbols (#1395)" (#1438)
authorSangchul Lee <sangchul1011@gmail.com>
Tue, 3 Mar 2020 02:37:35 +0000 (11:37 +0900)
committerGitHub <noreply@github.com>
Tue, 3 Mar 2020 02:37:34 +0000 (11:37 +0900)
This reverts commit 10637a6853b4d0334acad1a61fc634677f60ce6c.

src/Tizen.Multimedia/AudioManager/AudioDevice.cs
src/Tizen.Multimedia/AudioManager/AudioDeviceOptions.cs
src/Tizen.Multimedia/AudioManager/AudioDeviceRunningChangedEventArgs.cs [changed mode: 0644->0755]
src/Tizen.Multimedia/AudioManager/AudioDeviceState.cs [new file with mode: 0644]
src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs [new file with mode: 0644]
src/Tizen.Multimedia/AudioManager/AudioManager.cs
src/Tizen.Multimedia/Interop/Interop.Device.cs

index 773a04a..bf4ec24 100644 (file)
@@ -78,6 +78,23 @@ namespace Tizen.Multimedia
         public AudioDeviceIoDirection IoDirection => _ioDirection;
 
         /// <summary>
+        /// Gets the state of the device.
+        /// </summary>
+        /// <value>The <see cref="AudioDeviceState"/> of the device.</value>
+        /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 5. Please use the IsRunning property instead.")]
+        public AudioDeviceState State
+        {
+            get
+            {
+                Interop.AudioDevice.GetDeviceState(Id, out var state).
+                    ThrowIfError("Failed to get the state of the device");
+
+                return state;
+            }
+        }
+
+        /// <summary>
         /// Gets the running state of the device.
         /// </summary>
         /// <value>true if the audio stream of device is running actually; otherwise, false.</value>
index 5500757..8a32950 100644 (file)
@@ -53,6 +53,18 @@ namespace Tizen.Multimedia
         External = 0x0020,
 
         /// <summary>
+        /// Deactivated devices.
+        /// </summary>
+        [Obsolete("Deprecated since API level 5.")]
+        Deactivated = 0x1000,
+
+        /// <summary>
+        /// Activated devices.
+        /// </summary>
+        [Obsolete("Deprecated since API level 5.")]
+        Activated = 0x2000,
+
+        /// <summary>
         /// All devices.
         /// </summary>
         All = 0xFFFF
diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceState.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceState.cs
new file mode 100644 (file)
index 0000000..85991d4
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2016 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+namespace Tizen.Multimedia
+{
+    /// <summary>
+    /// Specifies the audio device states.
+    /// </summary>
+    /// <since_tizen> 3 </since_tizen>
+    [Obsolete("Deprecated since API level 5.")]
+    public enum AudioDeviceState
+    {
+        /// <summary>
+        /// Deactivated state.
+        /// </summary>
+        Deactivated,
+
+        /// <summary>
+        /// Activated state.
+        /// </summary>
+        Activated
+    }
+}
diff --git a/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioManager/AudioDeviceStateChangedEventArgs.cs
new file mode 100644 (file)
index 0000000..34eb612
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Multimedia
+{
+    /// <summary>
+    /// Provides data for the <see cref="AudioManager.DeviceStateChanged"/> event.
+    /// </summary>
+    /// <since_tizen> 3 </since_tizen>
+    [Obsolete("Deprecated since API level 5. Please use the AudioDeviceRunningChangedEventArgs class instead.")]
+    public class AudioDeviceStateChangedEventArgs : EventArgs
+    {
+        internal AudioDeviceStateChangedEventArgs(AudioDevice device, AudioDeviceState changedState)
+        {
+            Device = device;
+            State = changedState;
+        }
+
+        /// <summary>
+        /// Gets the device.
+        /// </summary>
+        /// <value>The <see cref="AudioDevice"/>.</value>
+        /// <since_tizen> 3 </since_tizen>
+        public AudioDevice Device { get; }
+
+        /// <summary>
+        /// Gets the state of the device.
+        /// </summary>
+        /// <value>The <see cref="AudioDeviceState"/> of the device.</value>
+        /// <since_tizen> 4 </since_tizen>
+        public AudioDeviceState State { get; }
+    }
+}
index 2f566bf..890c319 100644 (file)
@@ -152,6 +152,78 @@ namespace Tizen.Multimedia
         }
         #endregion
 
+        #region DeviceStateChanged event
+        private static int _deviceStateChangedCallbackId = -1;
+
+#pragma warning disable CS0618 // Type or member is obsolete
+
+        private static Interop.AudioDevice.StateChangedCallback _audioDeviceStateChangedCallback;
+        private static EventHandler<AudioDeviceStateChangedEventArgs> _audioDeviceStateChanged;
+        private static readonly object _audioDeviceStateLock = new object();
+
+        /// <summary>
+        /// Occurs when the state of an audio device changes.
+        /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 5. Please use the DeviceRunningStateChanged property instead.")]
+        public static event EventHandler<AudioDeviceStateChangedEventArgs> DeviceStateChanged
+        {
+            add
+            {
+                if (value == null)
+                {
+                    return;
+                }
+
+                lock (_audioDeviceStateLock)
+                {
+                    if (_audioDeviceStateChanged == null)
+                    {
+                        RegisterDeviceStateChangedEvent();
+                    }
+                    _audioDeviceStateChanged += value;
+                }
+            }
+            remove
+            {
+                if (value == null)
+                {
+                    return;
+                }
+
+                lock (_audioDeviceStateLock)
+                {
+                    if (_audioDeviceStateChanged == value)
+                    {
+                        UnregisterDeviceStateChangedEvent();
+                    }
+                    _audioDeviceStateChanged -= value;
+                }
+            }
+        }
+
+        private static void RegisterDeviceStateChangedEvent()
+        {
+            _audioDeviceStateChangedCallback = (device, changedState, _) =>
+            {
+                _audioDeviceStateChanged?.Invoke(null,
+                    new AudioDeviceStateChangedEventArgs(new AudioDevice(device), changedState));
+            };
+
+            Interop.AudioDevice.AddDeviceStateChangedCallback(AudioDeviceOptions.All,
+                _audioDeviceStateChangedCallback, IntPtr.Zero, out _deviceStateChangedCallbackId).
+                ThrowIfError("Failed to add device state changed event");
+        }
+
+#pragma warning restore CS0618 // Type or member is obsolete
+
+        private static void UnregisterDeviceStateChangedEvent()
+        {
+            Interop.AudioDevice.RemoveDeviceStateChangedCallback(_deviceStateChangedCallbackId).
+                ThrowIfError("Failed to remove device state changed event");
+        }
+        #endregion
+
         #region DeviceRunningStateChanged event
         private static int _deviceRunningChangedCallbackId = -1;
         private static Interop.AudioDevice.RunningChangedCallback _audioDeviceRunningChangedCallback;
index 17f92f3..00e0459 100755 (executable)
@@ -26,6 +26,11 @@ namespace Tizen.Multimedia
             [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
             internal delegate void ConnectionChangedCallback(IntPtr device, bool isConnected, IntPtr userData);
 
+#pragma warning disable CS0618 // Type or member is obsolete
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void StateChangedCallback(IntPtr device, AudioDeviceState changedState, IntPtr userData);
+#pragma warning restore CS0618 // Type or member is obsolete
+
             [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
             internal delegate void RunningChangedCallback(IntPtr device, bool isRunning, IntPtr userData);
 
@@ -51,6 +56,11 @@ namespace Tizen.Multimedia
             [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_name")]
             internal static extern int GetDeviceName(IntPtr device, out IntPtr name);
 
+#pragma warning disable CS0618 // Type or member is obsolete
+            [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_state_by_id")]
+            internal static extern AudioManagerError GetDeviceState(int deviceId, out AudioDeviceState state);
+#pragma warning restore CS0618 // Type or member is obsolete
+
             [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_is_device_running_by_id")]
             internal static extern AudioManagerError IsDeviceRunning(int deviceId, out bool isRunning);
 
@@ -91,6 +101,13 @@ namespace Tizen.Multimedia
             [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_connection_changed_cb")]
             internal static extern AudioManagerError RemoveDeviceConnectionChangedCallback(int id);
 
+            [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_state_changed_cb")]
+            internal static extern AudioManagerError AddDeviceStateChangedCallback(AudioDeviceOptions deviceMask,
+                StateChangedCallback callback, IntPtr userData, out int id);
+
+            [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_state_changed_cb")]
+            internal static extern AudioManagerError RemoveDeviceStateChangedCallback(int id);
+
             [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_running_changed_cb")]
             internal static extern AudioManagerError AddDeviceRunningChangedCallback(AudioDeviceOptions deviceMask,
                 RunningChangedCallback callback, IntPtr userData, out int id);