[MediaController] Replace deprecated pinvoke function (#994)
authorhsgwon <haesu.gwon@samsung.com>
Thu, 29 Aug 2019 23:41:16 +0000 (08:41 +0900)
committerGitHub <noreply@github.com>
Thu, 29 Aug 2019 23:41:16 +0000 (08:41 +0900)
src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs
src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs
src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.Events.cs

index fa1fd34a774ac48d7d400363bdf48a770033e5e2..9489e6207270fce34028159ff95cd85e2c1103cb 100644 (file)
@@ -190,6 +190,10 @@ internal static partial class Interop
         internal delegate void RepeatCapabilityUpdatedCallback(string serverName, MediaControlCapabilitySupport support,
             IntPtr userData = default(IntPtr));
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void SimpleCapabilityCallback(string serverName, MediaControlCapabilityCategory category,
+            MediaControlCapabilitySupport support, IntPtr userData = default(IntPtr));
+
 
         [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playback_content_type")]
         internal static extern MediaControllerError GetPlaybackContentType(IntPtr playbackHandle,
@@ -203,14 +207,6 @@ internal static partial class Interop
         internal static extern MediaControllerError GetPlaybackCapabilityHandle(MediaControllerClientHandle clientHandle,
             string serverName, out IntPtr capaHandle);
 
-        [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_shuffle_ability_support")]
-        internal static extern MediaControllerError GetShuffleCapability(MediaControllerClientHandle clientHandle,
-            string serverName, out MediaControlCapabilitySupport type);
-
-        [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_repeat_ability_support")]
-        internal static extern MediaControllerError GetRepeatCapability(MediaControllerClientHandle clientHandle,
-            string serverName, out MediaControlCapabilitySupport type);
-
         [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_playback_ability_updated_cb")]
         internal static extern MediaControllerError SetPlaybackCapabilityUpdatedCb(MediaControllerClientHandle clientHandle,
             PlaybackCapabilityUpdatedCallback callback, IntPtr userData = default(IntPtr));
@@ -218,19 +214,13 @@ internal static partial class Interop
         [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_playback_ability_updated_cb")]
         internal static extern MediaControllerError UnsetPlaybackCapabilityUpdatedCb(MediaControllerClientHandle clientHandle);
 
-        [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_shuffle_ability_updated_cb")]
-        internal static extern MediaControllerError SetShuffleCapabilityUpdatedCb(MediaControllerClientHandle clientHandle,
-            ShuffleCapabilityUpdatedCallback callback, IntPtr userData = default(IntPtr));
-
-        [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_shuffle_ability_updated_cb")]
-        internal static extern MediaControllerError UnsetShuffleCapabilityUpdatedCb(MediaControllerClientHandle clientHandle);
-
-        [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_repeat_ability_updated_cb")]
-        internal static extern MediaControllerError SetRepeatCapabilityUpdatedCb(MediaControllerClientHandle clientHandle,
-            RepeatCapabilityUpdatedCallback callback, IntPtr userData = default(IntPtr));
+        [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_ability_support_updated_cb")]
+        internal static extern MediaControllerError SetSimpleCapabilityUpdatedCb(MediaControllerClientHandle clientHandle,
+            SimpleCapabilityCallback callback, IntPtr userData = default(IntPtr));
 
-        [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_repeat_ability_updated_cb")]
-        internal static extern MediaControllerError UnsetRepeatCapabilityUpdatedCb(MediaControllerClientHandle clientHandle);
+        [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_ability_support")]
+        internal static extern MediaControllerError GetSimpleCapability(MediaControllerClientHandle clientHandle,
+            string serverName, MediaControlCapabilityCategory category, out MediaControlCapabilitySupport type);
 
         [DllImport(Libraries.MediaController, EntryPoint = "mc_playback_ability_clone")]
         internal static extern MediaControllerError CloneCapability(IntPtr capaSrcHandle, out IntPtr capaDstHandle);
index 16e3cd3bb47fc5cab74d1c1bed3b42a40555f3b9..63c905d6cd4f878868125ec6c3516bbd1a03e020 100644 (file)
@@ -224,13 +224,9 @@ internal static partial class Interop
         [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_playback_ability")]
         internal static extern MediaControllerError SaveAndNotifyPlaybackCapabilityUpdated(IntPtr serverHandle);
 
-        [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_shuffle_ability")]
-        internal static extern MediaControllerError SetShuffleModeCapability(IntPtr serverHandle,
-            MediaControlCapabilitySupport support);
-
-        [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_repeat_ability")]
-        internal static extern MediaControllerError SetRepeatModeCapability(IntPtr serverHandle,
-            MediaControlCapabilitySupport support);
+        [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_ability_support")]
+        internal static extern MediaControllerError SetSimpleCapability(IntPtr serverHandle,
+            MediaControlCapabilityCategory category, MediaControlCapabilitySupport support);
         #endregion Capability
 
         #region Search
index f3820f3c66c2c7204e86b11b9a5b918679ff81c9..9b3d0ad1352ad4b1827f21882f32c4da560d2b45 100644 (file)
@@ -81,4 +81,16 @@ namespace Tizen.Multimedia.Remoting
         Episode,
         Resolution
     }
+
+    internal enum MediaControlCapabilityCategory
+    {
+        Shuffle,
+        Repeat,
+        PlaybackPosition,
+        Playlist,
+        ClientCustom,
+        Search,
+        Subtitle,
+        Mode360
+    }
 }
\ No newline at end of file
index 1d97a3c7d2b9a96a0c51d7953f3ea26ed7bc4b3e..907ef03105ed2ec1ed4ba7cbeb418edf41c3c7bf 100644 (file)
@@ -605,7 +605,8 @@ namespace Tizen.Multimedia.Remoting
         {
             ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support));
 
-            Native.SetShuffleModeCapability(Handle, support).ThrowIfError("Failed to set shuffle mode capability.");
+            Native.SetSimpleCapability(Handle, MediaControlCapabilityCategory.Shuffle, support).
+                ThrowIfError("Failed to set shuffle mode capability.");
         }
 
         /// <summary>
@@ -623,7 +624,8 @@ namespace Tizen.Multimedia.Remoting
         {
             ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support));
 
-            Native.SetRepeatModeCapability(Handle, support).ThrowIfError("Failed to set shuffle mode capability.");
+            Native.SetSimpleCapability(Handle, MediaControlCapabilityCategory.Repeat, support).
+                ThrowIfError("Failed to set repeat mode capability.");
         }
         #endregion Capabilities
 
index 096f05c48230c54b7a9b508fa9f6e0c31aeb204e..cf4da2a8980fa31b93017c6316c18eda1b9971e6 100644 (file)
@@ -650,7 +650,8 @@ namespace Tizen.Multimedia.Remoting
                 Native.GetPlaybackCapabilityHandle(Manager.Handle, ServerAppId, out playbackCapaHandle).
                     ThrowIfError("Failed to get playback capability handle.");
 
-                Native.GetShuffleCapability(Manager.Handle, ServerAppId, out MediaControlCapabilitySupport support);
+                Native.GetSimpleCapability(Manager.Handle, ServerAppId, MediaControlCapabilityCategory.Shuffle, out MediaControlCapabilitySupport support).
+                    ThrowIfError("Failed to get shuffle mode capability");
 
                 return support;
             }
@@ -685,7 +686,8 @@ namespace Tizen.Multimedia.Remoting
                 Native.GetPlaybackCapabilityHandle(Manager.Handle, ServerAppId, out playbackCapaHandle).
                     ThrowIfError("Failed to get playback capability handle.");
 
-                Native.GetRepeatCapability(Manager.Handle, ServerAppId, out MediaControlCapabilitySupport support);
+                Native.GetSimpleCapability(Manager.Handle, ServerAppId, MediaControlCapabilityCategory.Repeat, out MediaControlCapabilitySupport support).
+                    ThrowIfError("Failed to get repeat mode capability");
 
                 return support;
             }
index 924cc82615dac79ac976940f8372657009b6b06d..d0c31fd5b702ec9fa17157b2ac4f7eb25b3497e8 100644 (file)
@@ -31,8 +31,7 @@ namespace Tizen.Multimedia.Remoting
         private NativePlaylist.MetadataUpdatedCallback _metadataUpdatedCallback;
         private NativePlaylist.PlaylistUpdatedCallback _playlistUpdatedCallback;
         private Native.PlaybackCapabilityUpdatedCallback _playbackCapabilityUpdatedCallback;
-        private Native.ShuffleCapabilityUpdatedCallback _shuffleModeCapabilityUpdatedCallback;
-        private Native.RepeatCapabilityUpdatedCallback _repeatModeCapabilityUpdatedCallback;
+        private Native.SimpleCapabilityCallback _simpleCapabilityUpdatedCallback;
         private Native.CustomCommandReceivedCallback _customCommandReceivedCallback;
 
         /// <summary>
@@ -57,9 +56,8 @@ namespace Tizen.Multimedia.Remoting
             RegisterPlaylistUpdatedEvent();
             RegisterCommandCompletedEvent();
             RegisterPlaybackCapabilitiesEvent();
-            RegisterRepeatModeCapabilitiesEvent();
-            RegisterShuffleModeCapabilitiesEvent();
             RegisterCustomCommandReceivedEvent();
+            RegisterSimpleCapabilityEvent();
         }
 
         private void RaiseServerChangedEvent(MediaControllerNativeServerState state, MediaController controller)
@@ -168,28 +166,6 @@ namespace Tizen.Multimedia.Remoting
                 ThrowIfError("Failed to init PlaybackCapabilityUpdated event.");
         }
 
-        private void RegisterRepeatModeCapabilitiesEvent()
-        {
-            _repeatModeCapabilityUpdatedCallback = (serverName, support, _) =>
-            {
-                GetController(serverName)?.RaiseRepeatModeCapabilityUpdatedEvent(support);
-            };
-
-            Native.SetRepeatCapabilityUpdatedCb(Handle, _repeatModeCapabilityUpdatedCallback).
-                ThrowIfError("Failed to init RepeatModeCapabilityUpdated event.");
-        }
-
-        private void RegisterShuffleModeCapabilitiesEvent()
-        {
-            _shuffleModeCapabilityUpdatedCallback = (serverName, support, _) =>
-            {
-                GetController(serverName)?.RaiseShuffleModeCapabilityUpdatedEvent(support);
-            };
-
-            Native.SetShuffleCapabilityUpdatedCb(Handle, _shuffleModeCapabilityUpdatedCallback).
-                ThrowIfError("Failed to init ShuffleModeCapabilityUpdated event.");
-        }
-
         private void RegisterCustomCommandReceivedEvent()
         {
             _customCommandReceivedCallback = (serverName, requestId, customEvent, bundleHandle, _) =>
@@ -212,5 +188,24 @@ namespace Tizen.Multimedia.Remoting
             Native.SetCustomEventCb(Handle, _customCommandReceivedCallback).
                 ThrowIfError("Failed to init CustomCommandReceived event.");
         }
+
+        private void RegisterSimpleCapabilityEvent()
+        {
+            _simpleCapabilityUpdatedCallback = (serverName, category, support, _) =>
+            {
+                switch (category)
+                {
+                    case MediaControlCapabilityCategory.Repeat:
+                        GetController(serverName)?.RaiseRepeatModeCapabilityUpdatedEvent(support);
+                        break;
+                    case MediaControlCapabilityCategory.Shuffle:
+                        GetController(serverName)?.RaiseShuffleModeCapabilityUpdatedEvent(support);
+                        break;
+                }
+            };
+
+            Native.SetSimpleCapabilityUpdatedCb(Handle, _simpleCapabilityUpdatedCallback).
+                ThrowIfError("Failed to init capability updated event.");
+        }
     }
 }
\ No newline at end of file