[MediaController] fix bugs (#493)
authorhsgwon <haesu.gwon@samsung.com>
Mon, 1 Oct 2018 09:13:06 +0000 (18:13 +0900)
committerGitHub <noreply@github.com>
Mon, 1 Oct 2018 09:13:06 +0000 (18:13 +0900)
* [MediaController] fix bugs and svace issues.

18 files changed:
src/Tizen.Multimedia.Remoting/MediaController/CommandCompletedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReceivedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlCommand.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStartedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStoppedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs
src/Tizen.Multimedia.Remoting/MediaController/MetadataUpdatedEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Multimedia.Remoting/MediaController/PlaybackActionCommandReceivedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/PlaybackPositionCommandReceivedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/PlaylistCommandReceivedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/PlaylistUpdatedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/RepeatModeCapabilityUpdatedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/RepeatModeCommandReceivedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/SearchCommandReceivedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeCapabilityUpdatedEventArgs.cs
src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeCommandReceivedEventArgs.cs

index 0741fd0..a252105 100644 (file)
@@ -31,10 +31,14 @@ namespace Tizen.Multimedia.Remoting
         /// </summary>
         /// <param name="requestId">The request id for each command.</param>
         /// <param name="result">The result of commands.</param>
+        /// <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)
         {
-            RequestId = requestId;
+            ValidationUtil.ValidateEnum(typeof(MediaControllerError), result, nameof(result));
+
+            RequestId = requestId ?? throw new ArgumentNullException(nameof(requestId));
             Result = result;
         }
 
index e18594f..9e12c2d 100644 (file)
@@ -29,10 +29,11 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="CustomCommandReceivedEventArgs"/> class.
         /// </summary>
         /// <param name="command">The playback position command.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
         public CustomCommandReceivedEventArgs(CustomCommand command)
         {
-            Command = command;
+            Command = command ?? throw new ArgumentNullException(nameof(command));
         }
 
         /// <summary>
index 43a30ad..374ba55 100644 (file)
@@ -148,9 +148,12 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="PlaybackCommand"/> class.
         /// </summary>
         /// <param name="action">A <see cref="MediaControlPlaybackCommand"/>.</param>
+        /// <exception cref="ArgumentException"><paramref name="action"/> is not valid.</exception>
         /// <since_tizen> 5 </since_tizen>
         public PlaybackCommand(MediaControlPlaybackCommand action)
         {
+            ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), action, nameof(action));
+
             Action = action;
         }
 
@@ -162,7 +165,7 @@ namespace Tizen.Multimedia.Remoting
 
         internal override string Request(NativeClientHandle clientHandle)
         {
-            ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), Action, nameof(MediaControlPlaybackCommand));
+            ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), Action, nameof(Action));
 
             NativeClient.SendPlaybackActionCommand(clientHandle, ReceiverId, Action.ToNative(), out string requestId)
                 .ThrowIfError("Failed to send playback command.");
@@ -213,13 +216,15 @@ namespace Tizen.Multimedia.Remoting
         /// <param name="playlistName">The playlist name of the server.</param>
         /// <param name="index">The index of the media in the playlist.</param>
         /// <param name="position">The playback position in milliseconds.</param>
-        /// <exception cref="ArgumentException"><paramref name="index"/> cannot be converted to number.</exception>
+        /// <exception cref="ArgumentException"><paramref name="action"/>is not valid.</exception>
         /// <exception cref="ArgumentNullException">
-        /// <paramref name="playlistName"/> or <paramref name="index"/> is not vailed.
+        /// <paramref name="playlistName"/> or <paramref name="index"/> is null.
         /// </exception>
         /// <since_tizen> 5 </since_tizen>
         public PlaylistCommand(MediaControlPlaybackCommand action, string playlistName, string index, ulong position)
         {
+            ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), action, nameof(action));
+
             Action = action;
             Index = index ?? throw new ArgumentNullException(nameof(index));
             Name = playlistName ?? throw new ArgumentNullException(nameof(playlistName));
@@ -232,7 +237,6 @@ namespace Tizen.Multimedia.Remoting
         /// <param name="action">A <see cref="MediaControlPlaybackCommand"/>.</param>
         /// <param name="playlistName">The playlist name of the server.</param>
         /// <param name="index">The index of the media in the playlist.</param>
-        /// <exception cref="ArgumentException"><paramref name="index"/> cannot be converted to number.</exception>
         /// <exception cref="ArgumentNullException">
         /// <paramref name="playlistName"/> or <paramref name="index"/> is null.
         /// </exception>
@@ -268,7 +272,7 @@ namespace Tizen.Multimedia.Remoting
 
         internal override string Request(NativeClientHandle clientHandle)
         {
-            ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), Action, nameof(MediaControlPlaybackCommand));
+            ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), Action, nameof(Action));
 
             NativeClient.SendPlaylistCommand(clientHandle, ReceiverId, Name, Index, Action.ToNative(),
                 Position, out string requestId).ThrowIfError("Failed to send playlist command.");
@@ -319,9 +323,12 @@ 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>
         /// <since_tizen> 5 </since_tizen>
         public RepeatModeCommand(MediaControlRepeatMode mode)
         {
+            ValidationUtil.ValidateEnum(typeof(MediaControlRepeatMode), mode, nameof(mode));
+
             Mode = mode;
         }
 
@@ -333,7 +340,7 @@ namespace Tizen.Multimedia.Remoting
 
         internal override string Request(NativeClientHandle clientHandle)
         {
-            ValidationUtil.ValidateEnum(typeof(MediaControlRepeatMode), Mode, nameof(MediaControlRepeatMode));
+            ValidationUtil.ValidateEnum(typeof(MediaControlRepeatMode), Mode, nameof(Mode));
 
             NativeClient.SendRepeatModeCommand(clientHandle, ReceiverId, Mode.ToNative(), out string requestId).
                 ThrowIfError("Failed to send playback repeat command.");
@@ -487,11 +494,17 @@ namespace Tizen.Multimedia.Remoting
         /// <summary>
         /// Initializes a new instance of the <see cref="SearchCommand"/> class.
         /// </summary>
+        /// <exception cref="ArgumentNullException"><paramref name="condition"/> is not set.</exception>
         /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
         /// <param name="condition">The set of <see cref="MediaControlSearchCondition"/>.</param>
         /// <since_tizen> 5 </since_tizen>
         public SearchCommand(MediaControlSearchCondition condition)
         {
+            if (condition == null)
+            {
+                throw new ArgumentNullException(nameof(condition));
+            }
+
             NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle.");
 
             try
index e8fa129..d5cecdc 100644 (file)
@@ -118,7 +118,7 @@ namespace Tizen.Multimedia.Remoting
         {
             get
             {
-                return _metadata != null ? _metadata.Count : 0;
+                return _metadata?.Count ?? 0;
             }
         }
 
@@ -139,7 +139,7 @@ namespace Tizen.Multimedia.Remoting
         /// <returns>The dictionary set of index and <see cref="MediaControlMetadata"/> pair.</returns>
         public Dictionary<string, MediaControlMetadata> GetMetadata()
         {
-            if (_metadata == null)
+            if (TotalCount == 0)
             {
                 UpdateMetadata(Handle);
             }
@@ -151,10 +151,16 @@ namespace Tizen.Multimedia.Remoting
         /// Gets the metadata by index.
         /// </summary>
         /// <param name="index">The index of media in the playlist.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="index"/> is null.</exception>
         /// <returns>A <see cref="MediaControlMetadata"/> instance.</returns>
         public MediaControlMetadata GetMetadata(string index)
         {
-            if (_metadata == null)
+            if (index == null)
+            {
+                throw new ArgumentNullException(nameof(index));
+            }
+
+            if (TotalCount == 0)
             {
                 UpdateMetadata(Handle);
             }
@@ -171,9 +177,15 @@ namespace Tizen.Multimedia.Remoting
         /// Sets the metadata to the playlist.
         /// </summary>
         /// <param name="metadata">The metadata of media.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="metadata"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
         public void AddMetadata(Dictionary<string, MediaControlMetadata> metadata)
         {
+            if (metadata == null)
+            {
+                throw new ArgumentNullException(nameof(metadata));
+            }
+
             foreach (var data in metadata)
             {
                 AddMetadata(data.Key, data.Value);
@@ -187,9 +199,21 @@ namespace Tizen.Multimedia.Remoting
         /// </summary>
         /// <param name="index">The index of media in the playlist.</param>
         /// <param name="metadata">The metadata of media.</param>
+        /// <exception cref="ArgumentNullException">
+        /// <paramref name="index"/> or <paramref name="metadata"/> is null.
+        /// </exception>
         /// <since_tizen> 5 </since_tizen>
         public void AddMetadata(string index, MediaControlMetadata metadata)
         {
+            if (index == null)
+            {
+                throw new ArgumentNullException(nameof(index));
+            }
+            if (metadata == null)
+            {
+                throw new ArgumentNullException(nameof(metadata));
+            }
+
             AddItemToPlaylist(index, metadata);
             _metadata.Add(index, metadata);
 
index 62a1a0b..2ac583a 100644 (file)
@@ -388,24 +388,26 @@ namespace Tizen.Multimedia.Remoting
         /// </remarks>
         /// <param name="command">A <see cref="Command"/> class.</param>
         /// <param name="clientId">The client Id to send command.</param>
-        /// <returns>A task that represents the asynchronous operation.</returns>
+        /// <returns><see cref="Bundle"/> represents the extra data from client and it can be null.</returns>
         /// <exception cref="InvalidOperationException">
         ///     The server has already been stopped.<br/>
         ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <since_tizen> 5 </since_tizen>
-        public static async Task RequestAsync(Command command, string clientId)
+        public static async Task<Bundle> RequestAsync(Command command, string clientId)
         {
             command.SetRequestInformation(clientId);
 
             var tcs = new TaskCompletionSource<MediaControllerError>();
             string reqeustId = null;
+            Bundle bundle = null;
 
             EventHandler<CommandCompletedEventArgs> eventHandler = (s, e) =>
             {
                 if (e.RequestId == reqeustId)
                 {
+                    bundle = e.Bundle;
                     tcs.TrySetResult(e.Result);
                 }
             };
@@ -417,6 +419,8 @@ namespace Tizen.Multimedia.Remoting
                 reqeustId = command.Request(Handle);
 
                 (await tcs.Task).ThrowIfError("Failed to request event.");
+
+                return bundle;
             }
             finally
             {
index 2a3fcb5..f0c53cd 100644 (file)
@@ -32,12 +32,7 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 4 </since_tizen>
         public MediaControlServerStartedEventArgs(MediaController mediaController)
         {
-            if (mediaController == null)
-            {
-                throw new ArgumentNullException(nameof(mediaController));
-            }
-
-            Controller = mediaController;
+            Controller = mediaController ?? throw new ArgumentNullException(nameof(mediaController));
         }
 
         /// <summary>
index ca24154..97bf7b4 100644 (file)
@@ -32,12 +32,7 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 4 </since_tizen>
         public MediaControlServerStoppedEventArgs(string serverAppId)
         {
-            if (serverAppId == null)
-            {
-                throw new ArgumentNullException(nameof(serverAppId));
-            }
-
-            ServerAppId = serverAppId;
+            ServerAppId = serverAppId ?? throw new ArgumentNullException(nameof(serverAppId));
         }
 
         /// <summary>
index 622390d..693d140 100644 (file)
@@ -320,7 +320,7 @@ namespace Tizen.Multimedia.Remoting
         /// and then, the client receive the result of each request(command).
         /// </remarks>
         /// <param name="command">A <see cref="Command"/> class.</param>
-        /// <returns>A task that represents the asynchronous operation.</returns>
+        /// <returns><see cref="Bundle"/> represents the extra data from server and it can be null.</returns>
         /// <exception cref="InvalidOperationException">
         ///     The server has already been stopped.<br/>
         ///     -or-<br/>
@@ -328,7 +328,7 @@ namespace Tizen.Multimedia.Remoting
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed of.</exception>
         /// <since_tizen> 5 </since_tizen>
-        public async Task RequestAsync(Command command)
+        public async Task<Bundle> RequestAsync(Command command)
         {
             ThrowIfStopped();
 
@@ -336,11 +336,13 @@ namespace Tizen.Multimedia.Remoting
 
             var tcs = new TaskCompletionSource<MediaControllerError>();
             string reqeustId = null;
+            Bundle bundle = null;
 
             EventHandler<CommandCompletedEventArgs> eventHandler = (s, e) =>
             {
                 if (e.RequestId == reqeustId)
                 {
+                    bundle = e.Bundle;
                     tcs.TrySetResult(e.Result);
                 }
             };
@@ -352,6 +354,8 @@ namespace Tizen.Multimedia.Remoting
                 reqeustId = command.Request(Manager.Handle);
 
                 (await tcs.Task).ThrowIfError("Failed to request command");
+
+                return bundle;
             }
             finally
             {
index e0b5721..666ab3f 100644 (file)
@@ -28,10 +28,11 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="PlaybackActionCommandReceivedEventArgs"/> class.
         /// </summary>
         /// <param name="command">The playback command.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
         public PlaybackActionCommandReceivedEventArgs(PlaybackCommand command)
         {
-            Command = command;
+            Command = command ?? throw new ArgumentNullException(nameof(command));
         }
 
         /// <summary>
index 8750c37..cb748d1 100644 (file)
@@ -28,10 +28,11 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="PlaybackPositionCommandReceivedEventArgs"/> class.
         /// </summary>
         /// <param name="command">The playback position command.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
         public PlaybackPositionCommandReceivedEventArgs(PlaybackPositionCommand command)
         {
-            Command = command;
+            Command = command ?? throw new ArgumentNullException(nameof(command));
         }
 
         /// <summary>
index 3d7519e..2e16ac0 100644 (file)
@@ -28,10 +28,11 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="PlaylistCommandReceivedEventArgs"/> class.
         /// </summary>
         /// <param name="command">The playback position command.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
         public PlaylistCommandReceivedEventArgs(PlaylistCommand command)
         {
-            Command = command;
+            Command = command ?? throw new ArgumentNullException(nameof(command));
         }
 
         /// <summary>
index eb11df8..bc2e47a 100644 (file)
@@ -31,14 +31,17 @@ namespace Tizen.Multimedia.Remoting
         /// <param name="name">A value indicating the playlist name.</param>
         /// <param name="playlist">A value indicating the playlist.</param>
         /// <exception cref="ArgumentException"><paramref name="mode"/> is invalid.</exception>
+        /// <exception cref="ArgumentNullException">
+        /// <paramref name="name"/> or <paramref name="playlist"/> is null.
+        /// </exception>
         /// <since_tizen> 5 </since_tizen>
         public PlaylistUpdatedEventArgs(MediaControlPlaylistMode mode, string name, MediaControlPlaylist playlist)
         {
             ValidationUtil.ValidateEnum(typeof(MediaControlPlaylistMode), mode, nameof(mode));
 
             Mode = mode;
-            Name = name;
-            Playlist = playlist;
+            Name = name ?? throw new ArgumentNullException(nameof(name));
+            Playlist = playlist ?? throw new ArgumentNullException(nameof(playlist));
         }
 
         /// <summary>
index 9dbe3ff..11f6acb 100644 (file)
@@ -30,9 +30,12 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="RepeatModeCapabilityUpdatedEventArgs"/> class.
         /// </summary>
         /// <param name="support">The repeat mode capabilities.</param>
+        /// <exception cref="ArgumentException"><paramref name="support"/> is not vaild.</exception>
         /// <since_tizen> 5 </since_tizen>
         public RepeatModeCapabilityUpdatedEventArgs(MediaControlCapabilitySupport support)
         {
+            ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support));
+
             Support = support;
         }
 
index 7489d77..a63f9e0 100644 (file)
@@ -28,10 +28,11 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="RepeatModeCommandReceivedEventArgs"/> class.
         /// </summary>
         /// <param name="command">The playback position command.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
         public RepeatModeCommandReceivedEventArgs(RepeatModeCommand command)
         {
-            Command = command;
+            Command = command ?? throw new ArgumentNullException(nameof(command));
         }
 
         /// <summary>
index 843cef5..212e203 100644 (file)
@@ -28,10 +28,11 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="SearchCommandReceivedEventArgs"/> class.
         /// </summary>
         /// <param name="command">The search command.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
         public SearchCommandReceivedEventArgs(SearchCommand command)
         {
-            Command = command;
+            Command = command ?? throw new ArgumentNullException(nameof(command));
         }
 
         /// <summary>
index c795fd6..a4229a8 100644 (file)
@@ -30,9 +30,12 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="ShuffleModeCapabilityUpdatedEventArgs"/> class.
         /// </summary>
         /// <param name="support">The shuffle mode capabilities.</param>
+        /// <exception cref="ArgumentException"><paramref name="support"/> is not vaild.</exception>
         /// <since_tizen> 5 </since_tizen>
         public ShuffleModeCapabilityUpdatedEventArgs(MediaControlCapabilitySupport support)
         {
+            ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support));
+
             Support = support;
         }
 
index 0683980..666cd1f 100644 (file)
@@ -28,10 +28,11 @@ namespace Tizen.Multimedia.Remoting
         /// Initializes a new instance of the <see cref="ShuffleModeCommandReceivedEventArgs"/> class.
         /// </summary>
         /// <param name="command">The playback position command.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="command"/> is null.</exception>
         /// <since_tizen> 5 </since_tizen>
         public ShuffleModeCommandReceivedEventArgs(ShuffleModeCommand command)
         {
-            Command = command;
+            Command = command ?? throw new ArgumentNullException(nameof(command));
         }
 
         /// <summary>