// 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)]
// 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)]
/// <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;
}
/// <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;
/// 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.
/// 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)
{
}
/// <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
#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>
/// -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)
command.SetRequestInformation(clientId);
- var tcs = new TaskCompletionSource<MediaControllerError>();
+ var tcs = new TaskCompletionSource<int>();
string reqeustId = null;
Bundle bundle = null;
reqeustId = command.Request(Handle);
- (await tcs.Task).ThrowIfError("Failed to request event.");
+ ((MediaControllerError)await tcs.Task).ThrowIfError("Failed to request event.");
return bundle;
}
/// <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)
{
#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>
/// 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)
command.SetRequestInformation(ServerAppId);
- var tcs = new TaskCompletionSource<MediaControllerError>();
+ var tcs = new TaskCompletionSource<int>();
string reqeustId = null;
Bundle bundle = null;
reqeustId = command.Request(Manager.Handle);
- (await tcs.Task).ThrowIfError("Failed to request command");
+ ((MediaControllerError)await tcs.Task).ThrowIfError("Failed to request command");
return bundle;
}
// Command
private Native.CommandCompletedCallback _commandCompletedCallback;
- private Native.CustomCommandReceivedCallback _customCommandReceivedCallback;
+ private Native.CustomCommandReceivedCallback _customEventReceivedCallback;
/// <summary>
private void RegisterCustomCommandReceivedEvent()
{
- _customCommandReceivedCallback = (serverName, requestId, customEvent, bundleHandle, _) =>
+ _customEventReceivedCallback = (serverName, requestId, customEvent, bundleHandle, _) =>
{
CustomCommand command = null;
if (bundleHandle != IntPtr.Zero)
GetController(serverName)?.RaiseCustomCommandReceivedEvent(command);
};
- Native.SetCustomEventCb(Handle, _customCommandReceivedCallback).
+ Native.SetCustomEventCb(Handle, _customEventReceivedCallback).
ThrowIfError("Failed to register CustomCommandReceived event.");
}
#endregion