[MediaController] Add new request method (#1823)
authorhsgwon <haesu.gwon@samsung.com>
Thu, 23 Jul 2020 03:30:14 +0000 (12:30 +0900)
committerGitHub <noreply@github.com>
Thu, 23 Jul 2020 03:30:14 +0000 (12:30 +0900)
* [MediaController] Add new request method

src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs
src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs
src/Tizen.Multimedia.Remoting/MediaController/CommandCompletedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlCommand.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlEnums.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaController.Events.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.Events.cs

index 61d88c8..ce3f3b0 100644 (file)
@@ -69,7 +69,7 @@ internal static partial class Interop
 
         // Command callbacks
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate void CommandCompletedCallback(string serverName, string requestId, MediaControllerError result,
+        internal delegate void CommandCompletedCallback(string serverName, string requestId, int result,
             IntPtr bundleHandle, IntPtr userData);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
index 306e28c..fce62d9 100644 (file)
@@ -73,7 +73,7 @@ internal static partial class Interop
 
         // Command callbacks
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate void CommandCompletedCallback(string clientName, string requestId, MediaControllerError result, IntPtr bundleHandle,
+        internal delegate void CommandCompletedCallback(string clientName, string requestId, int result, IntPtr bundleHandle,
             IntPtr userData = default(IntPtr));
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
index a252105..23ea54a 100644 (file)
@@ -34,10 +34,8 @@ namespace Tizen.Multimedia.Remoting
         /// <exception cref="ArgumentException"><paramref name="result"/> is not vailid.</exception>
         /// <exception cref="ArgumentNullException"><paramref name="requestId"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
-        internal CommandCompletedEventArgs(string requestId, MediaControllerError result)
+        internal CommandCompletedEventArgs(string requestId, int result)
         {
-            ValidationUtil.ValidateEnum(typeof(MediaControllerError), result, nameof(result));
-
             RequestId = requestId ?? throw new ArgumentNullException(nameof(requestId));
             Result = result;
         }
@@ -49,7 +47,7 @@ namespace Tizen.Multimedia.Remoting
         /// <param name="result">The result of commands.</param>
         /// <param name="bundle">The extra data.</param>
         /// <since_tizen> 5 </since_tizen>
-        internal CommandCompletedEventArgs(string requestId, MediaControllerError result, Bundle bundle)
+        internal CommandCompletedEventArgs(string requestId, int result, Bundle bundle)
             : this(requestId, result)
         {
             Bundle = bundle;
@@ -65,7 +63,7 @@ namespace Tizen.Multimedia.Remoting
         /// Gets the result code for matched commands.
         /// </summary>
         /// <since_tizen> 5 </since_tizen>
-        internal MediaControllerError Result { get; }
+        internal int Result { get; }
 
         /// <summary>
         /// Gets the extra data.
index 1f0e07b..39ec152 100644 (file)
@@ -330,7 +330,7 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="RepeatModeCommand"/> class.
         /// </summary>
         /// <param name="mode">The <see cref="MediaControlRepeatMode"/>.</param>
-        /// <exception cref="ArgumentException"><paramref name="mode"/> is not vailid.</exception>
+        /// <exception cref="ArgumentException"><paramref name="mode"/> is not valid.</exception>
         /// <since_tizen> 5 </since_tizen>
         public RepeatModeCommand(MediaControlRepeatMode mode)
         {
index b066a65..2797d6d 100644 (file)
@@ -295,7 +295,7 @@ namespace Tizen.Multimedia.Remoting
     }
 
     /// <summary>
-    /// Specifies the code which represents the result of commnunication between client and server.
+    /// Specifies the code which represents the result of communication between client and server.
     /// </summary>
     /// <since_tizen> 8 </since_tizen>
     public enum MediaControlResult
index 5d3aa48..7e0d5e3 100644 (file)
@@ -766,12 +766,71 @@ namespace Tizen.Multimedia.Remoting
 
         #region Command
         /// <summary>
+        /// Requests a command to the client and server receives the result of each request(command).
+        /// </summary>
+        /// <param name="command">A <see cref="Command"/> class.</param>
+        /// <param name="clientId">The client Id to send command.</param>
+        /// <returns>
+        /// The type of return value is Tuple.<br/>
+        /// First item of Tuple represents the <see cref="Bundle"/> and it represents the extra data from client. It can be null.<br/>
+        /// Second item of Tuple represents the result of each request(command).
+        /// </returns>
+        /// <exception cref="ArgumentNullException">
+        /// <paramref name="command"/> or <paramref name="clientId"/> is null.
+        /// </exception>
+        /// <exception cref="InvalidOperationException">
+        ///     The server has already been stopped.<br/>
+        ///     -or-<br/>
+        ///     An internal error occurs.
+        /// </exception>
+        /// <exception cref="NotImplementedException">The command which is not supported is used.</exception>
+        /// <seealso cref="CustomCommand"/>
+        /// <since_tizen> 8 </since_tizen>
+        public static async Task<(Bundle bundle, int result)> RequestCommandAsync(Command command, string clientId)
+        {
+            if (command == null)
+            {
+                throw new ArgumentNullException(nameof(command));
+            }
+            if (clientId == null)
+            {
+                throw new ArgumentNullException(nameof(clientId));
+            }
+
+            command.SetRequestInformation(clientId);
+
+            var tcs = new TaskCompletionSource<int>();
+            string reqeustId = null;
+            Bundle bundle = null;
+
+            EventHandler<CommandCompletedEventArgs> eventHandler = (s, e) =>
+            {
+                if (e.RequestId == reqeustId)
+                {
+                    bundle = e.Bundle;
+                    tcs.TrySetResult(e.Result);
+                }
+            };
+
+            try
+            {
+                CommandCompleted += eventHandler;
+
+                reqeustId = command.Request(Handle);
+
+                var result = await tcs.Task;
+
+                return (bundle, result);
+            }
+            finally
+            {
+                CommandCompleted -= eventHandler;
+            }
+        }
+
+        /// <summary>
         /// Requests commands to the client.
         /// </summary>
-        /// <remarks>
-        /// The client can request the command to execute <see cref="Command"/>, <br/>
-        /// and then, the server receive the result of each request(command).
-        /// </remarks>
         /// <param name="command">A <see cref="Command"/> class.</param>
         /// <param name="clientId">The client Id to send command.</param>
         /// <returns><see cref="Bundle"/> represents the extra data from client and it can be null.</returns>
@@ -783,7 +842,9 @@ namespace Tizen.Multimedia.Remoting
         ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
+        /// <seealso cref="CustomCommand"/>
         /// <since_tizen> 5 </since_tizen>
+        [Obsolete("Deprecated since API8; Will be removed in API10. Please use RequestCommandAsync(Command command) instead.")]
         public static async Task<Bundle> RequestAsync(Command command, string clientId)
         {
             if (command == null)
@@ -797,7 +858,7 @@ namespace Tizen.Multimedia.Remoting
 
             command.SetRequestInformation(clientId);
 
-            var tcs = new TaskCompletionSource<MediaControllerError>();
+            var tcs = new TaskCompletionSource<int>();
             string reqeustId = null;
             Bundle bundle = null;
 
@@ -816,7 +877,7 @@ namespace Tizen.Multimedia.Remoting
 
                 reqeustId = command.Request(Handle);
 
-                (await tcs.Task).ThrowIfError("Failed to request event.");
+                ((MediaControllerError)await tcs.Task).ThrowIfError("Failed to request event.");
 
                 return bundle;
             }
index 757bea0..a9b0fa7 100644 (file)
@@ -292,7 +292,7 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 5 </since_tizen>
         internal event EventHandler<CommandCompletedEventArgs> CommandCompleted;
 
-        internal void RaiseCommandCompletedEvent(string requestId, MediaControllerError result, IntPtr bundleHandle)
+        internal void RaiseCommandCompletedEvent(string requestId, int result, IntPtr bundleHandle)
         {
             if (bundleHandle != IntPtr.Zero)
             {
index dbb8f64..51ac909 100644 (file)
@@ -731,13 +731,76 @@ namespace Tizen.Multimedia.Remoting
 
         #region Command
         /// <summary>
+        /// Requests a command to the server and client receives the result of each request(command).
+        /// </summary>
+        /// <param name="command">A <see cref="Command"/> class.</param>
+        /// <returns>
+        /// The type of return value is Tuple.<br/>
+        /// First item of Tuple represents the <see cref="Bundle"/> and it represents the extra data from client. It can be null.<br/>
+        /// Second item of Tuple represents the result of each request(command).
+        /// </returns>
+        /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
+        /// <exception cref="InvalidOperationException">
+        ///     The server has already been stopped.<br/>
+        ///     -or-<br/>
+        ///     An internal error occurs.
+        /// </exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed.</exception>
+        /// <seealso cref="PlaybackCommand"/>
+        /// <seealso cref="PlaybackPositionCommand"/>
+        /// <seealso cref="PlaylistCommand"/>
+        /// <seealso cref="ShuffleModeCommand"/>
+        /// <seealso cref="RepeatModeCommand"/>
+        /// <seealso cref="SubtitleModeCommand"/>
+        /// <seealso cref="Mode360Command"/>
+        /// <seealso cref="DisplayModeCommand"/>
+        /// <seealso cref="DisplayRotationCommand"/>
+        /// <seealso cref="CustomCommand"/>
+        /// <seealso cref="SearchCommand"/>
+        /// <since_tizen> 8 </since_tizen>
+        public async Task<(Bundle bundle, int result)> RequestCommandAsync(Command command)
+        {
+            if (command == null)
+            {
+                throw new ArgumentNullException(nameof(command));
+            }
+
+            ThrowIfStopped();
+
+            command.SetRequestInformation(ServerAppId);
+
+            var tcs = new TaskCompletionSource<int>();
+            string reqeustId = null;
+            Bundle bundle = null;
+
+            EventHandler<CommandCompletedEventArgs> eventHandler = (s, e) =>
+            {
+                if (e.RequestId == reqeustId)
+                {
+                    bundle = e.Bundle;
+                    tcs.TrySetResult(e.Result);
+                }
+            };
+
+            try
+            {
+                CommandCompleted += eventHandler;
+
+                reqeustId = command.Request(Manager.Handle);
+
+                var result = await tcs.Task;
+
+                return (bundle, result);
+            }
+            finally
+            {
+                CommandCompleted -= eventHandler;
+            }
+        }
+
+        /// <summary>
         /// Requests command to the server.
         /// </summary>
-        /// <remarks>
-        /// The client can request the server to execute <see cref="PlaybackCommand"/> or <see cref="ShuffleModeCommand"/> or
-        /// <see cref="RepeatModeCommand"/> or <see cref="CustomCommand"/>, <br/>
-        /// and then, the client receive the result of each request(command).
-        /// </remarks>
         /// <param name="command">A <see cref="Command"/> class.</param>
         /// <returns><see cref="Bundle"/> represents the extra data from server and it can be null.</returns>
         /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
@@ -747,7 +810,19 @@ namespace Tizen.Multimedia.Remoting
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed.</exception>
+        /// <seealso cref="PlaybackCommand"/>
+        /// <seealso cref="PlaybackPositionCommand"/>
+        /// <seealso cref="PlaylistCommand"/>
+        /// <seealso cref="ShuffleModeCommand"/>
+        /// <seealso cref="RepeatModeCommand"/>
+        /// <seealso cref="SubtitleModeCommand"/>
+        /// <seealso cref="Mode360Command"/>
+        /// <seealso cref="DisplayModeCommand"/>
+        /// <seealso cref="DisplayRotationCommand"/>
+        /// <seealso cref="CustomCommand"/>
+        /// <seealso cref="SearchCommand"/>
         /// <since_tizen> 5 </since_tizen>
+        [Obsolete("Deprecated since API8; Will be removed in API10. Please use RequestCommandAsync(Command command) instead.")]
         public async Task<Bundle> RequestAsync(Command command)
         {
             if (command == null)
@@ -759,7 +834,7 @@ namespace Tizen.Multimedia.Remoting
 
             command.SetRequestInformation(ServerAppId);
 
-            var tcs = new TaskCompletionSource<MediaControllerError>();
+            var tcs = new TaskCompletionSource<int>();
             string reqeustId = null;
             Bundle bundle = null;
 
@@ -778,7 +853,7 @@ namespace Tizen.Multimedia.Remoting
 
                 reqeustId = command.Request(Manager.Handle);
 
-                (await tcs.Task).ThrowIfError("Failed to request command");
+                ((MediaControllerError)await tcs.Task).ThrowIfError("Failed to request command");
 
                 return bundle;
             }
index 0ce3364..7fa8125 100644 (file)
@@ -43,7 +43,7 @@ namespace Tizen.Multimedia.Remoting
 
         // Command
         private Native.CommandCompletedCallback _commandCompletedCallback;
-        private Native.CustomCommandReceivedCallback _customCommandReceivedCallback;
+        private Native.CustomCommandReceivedCallback _customEventReceivedCallback;
 
 
         /// <summary>
@@ -228,7 +228,7 @@ namespace Tizen.Multimedia.Remoting
 
         private void RegisterCustomCommandReceivedEvent()
         {
-            _customCommandReceivedCallback = (serverName, requestId, customEvent, bundleHandle, _) =>
+            _customEventReceivedCallback = (serverName, requestId, customEvent, bundleHandle, _) =>
             {
                 CustomCommand command = null;
                 if (bundleHandle != IntPtr.Zero)
@@ -245,7 +245,7 @@ namespace Tizen.Multimedia.Remoting
                 GetController(serverName)?.RaiseCustomCommandReceivedEvent(command);
             };
 
-            Native.SetCustomEventCb(Handle, _customCommandReceivedCallback).
+            Native.SetCustomEventCb(Handle, _customEventReceivedCallback).
                 ThrowIfError("Failed to register CustomCommandReceived event.");
         }
         #endregion