[MediaController] Add new API to check Response request (#5672)
authorHaesu Gwon <haesu.gwon@samsung.com>
Tue, 2 Jan 2024 01:17:58 +0000 (10:17 +0900)
committerGitHub <noreply@github.com>
Tue, 2 Jan 2024 01:17:58 +0000 (10:17 +0900)
* [MediaController] Add new API to check Response request

src/Tizen.Multimedia.Remoting/MediaController/MediaControlCommand.cs

index 39ec1528bda7c81388a5a3ffa1d9e0160cd467fc..7c4f14cb3ae433c25e598c66aedcc6bdfca44eb7 100644 (file)
@@ -17,6 +17,7 @@
 using Tizen.Applications;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using NativeClient = Interop.MediaControllerClient;
 using NativeServer = Interop.MediaControllerServer;
 using NativeClientHandle = Interop.MediaControllerClientHandle;
@@ -59,10 +60,33 @@ namespace Tizen.Multimedia.Remoting
         /// <param name="requestId">The request Id for each command.</param>
         internal void SetResponseInformation(string receiverId, string requestId)
         {
-            ReceiverId = receiverId ?? throw new ArgumentNullException(nameof(receiverId)); ;
-            _requestId = requestId ?? throw new ArgumentNullException(nameof(requestId)); ;
+            ReceiverId = receiverId ?? throw new ArgumentNullException(nameof(receiverId));
+            _requestId = requestId;
+
+            if (_requestId == null)
+            {
+                Log.Info(GetType().FullName, "request_id is null. Response() should not be called.");
+            }
         }
 
+        /// <summary>
+        /// Indicates if the response is needed.
+        /// </summary>
+        /// <remarks>If false, the receiver should not respond to the received command.</remarks>
+        /// <since_tizen> 12 </since_tizen>
+        public bool IsResponseNeeded => NeedToResponse;
+
+        /// <summary>
+        /// Indicates if the response is needed.
+        /// </summary>
+        /// <remarks>
+        /// This internal API is retained for backward compatibility but is not recommended for new development.
+        /// Please use <see cref="IsResponseNeeded"/> instead.<br/>
+        /// If false, the receiver should not respond to the received command.
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool NeedToResponse => _requestId != null;
+
         /// <summary>
         /// Requests command to server.
         /// </summary>
@@ -83,13 +107,18 @@ namespace Tizen.Multimedia.Remoting
         protected virtual void OnResponseCompleted() { }
 
         /// <summary>
-        /// Responses command to the client.
+        /// Responds to the clients command.
         /// </summary>
         /// <param name="serverHandle">The server handle.</param>
         /// <param name="result">The result of each command.</param>
         /// <param name="bundle">The extra data.</param>
         internal void Response(IntPtr serverHandle, int result, Bundle bundle)
         {
+            if (NeedToResponse == false)
+            {
+                throw new InvalidOperationException("The receiver should not call this, if NeedToResponse is false.");
+            }
+
             try
             {
                 if (bundle != null)
@@ -114,13 +143,18 @@ namespace Tizen.Multimedia.Remoting
         }
 
         /// <summary>
-        /// Responses command to the server.
+        /// Responds to the clients command.
         /// </summary>
         /// <param name="clientHandle">The client handle.</param>
         /// <param name="result">The result of each command.</param>
         /// <param name="bundle">The extra data.</param>
         internal void Response(NativeClientHandle clientHandle, int result, Bundle bundle)
         {
+            if (NeedToResponse == false)
+            {
+                throw new InvalidOperationException("The receiver should not call this, if NeedToResponse is false.");
+            }
+
             try
             {
                 if (bundle != null)
@@ -645,7 +679,7 @@ namespace Tizen.Multimedia.Remoting
             NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle.");
 
             try
-            {   
+            {
                 if (condition.Bundle != null)
                 {
                     NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category,