Release 4.0.0-preview1-00321
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Remoting / ScreenMirroring / ScreenMirroring.cs
index 7e98f84..19643d0 100644 (file)
@@ -29,6 +29,7 @@ namespace Tizen.Multimedia.Remoting
     /// </summary>
     public class ScreenMirroring : IDisposable, IDisplayable<ScreenMirroringErrorCode>
     {
+        private const string Feature = "http://tizen.org/feature/network.wifi.direct.display";
         private const int Port = 2022;
 
         private IntPtr _handle;
@@ -41,15 +42,17 @@ namespace Tizen.Multimedia.Remoting
         {
             get
             {
-                if (_disposed)
-                {
-                    throw new ObjectDisposedException(nameof(ScreenMirroring));
-                }
+                ThrowIfDisposed();
 
                 return _handle;
             }
         }
 
+        private static bool IsSupported()
+        {
+            return System.Information.TryGetValue(Feature, out bool isSupported) ? isSupported : false;
+        }
+
         /// <summary>
         /// Initializes a new instance of the ScreenMirroring class.
         /// </summary>
@@ -57,6 +60,11 @@ namespace Tizen.Multimedia.Remoting
         /// <exception cref="NotSupportedException">The feature is not supported.</exception>
         public ScreenMirroring()
         {
+            if (IsSupported() == false)
+            {
+                throw new PlatformNotSupportedException($"The feature({Feature}) is not supported on the current device");
+            }
+
             Native.Create(out _handle).ThrowIfError("Failed to create ScreenMirroring.");
 
             _state = new AtomicState();
@@ -67,6 +75,9 @@ namespace Tizen.Multimedia.Remoting
             RegisterStateChangedEvent();
         }
 
+        /// <summary>
+        /// Finalizes an instance of the ScreenMirroring class.
+        /// </summary>
         ~ScreenMirroring()
         {
             Dispose(false);
@@ -115,6 +126,11 @@ namespace Tizen.Multimedia.Remoting
 
             return Native.SetDisplay(Handle, (int)type, evasObject);
         }
+
+        ScreenMirroringErrorCode IDisplayable<ScreenMirroringErrorCode>.ApplyEcoreWindow(IntPtr windowHandle)
+        {
+            throw new NotSupportedException("ScreenMirroring does not support NUI.Window display.");
+        }
         #endregion
 
         /// <summary>
@@ -138,6 +154,8 @@ namespace Tizen.Multimedia.Remoting
 
         internal void ThrowIfNotConnected()
         {
+            ThrowIfDisposed();
+
             if (IsConnected == false)
             {
                 throw new InvalidOperationException("ScreenMirroring is not connected.");
@@ -148,8 +166,8 @@ namespace Tizen.Multimedia.Remoting
         /// Prepares the screen mirroring with the specified display.
         /// </summary>
         /// <remarks>
-        /// The state must be <see cref="ScreenMirroringState.Idle"/>.\n
-        /// \n
+        /// The state must be <see cref="ScreenMirroringState.Idle"/>.<br/>
+        /// <br/>
         /// All supported resolutions will be candidates.
         /// </remarks>
         /// <param name="display">The display where the mirroring will be played on.</param>
@@ -158,8 +176,8 @@ namespace Tizen.Multimedia.Remoting
         /// </exception>
         /// <exception cref="ArgumentNullException"><paramref name="display"/> is null.</exception>
         /// <exception cref="InvalidOperationException">
-        ///     The current state is not in the valid.\n
-        ///     -or-\n
+        ///     The current state is not in the valid.<br/>
+        ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="ScreenMirroring"/> has already been disposed.</exception>
@@ -177,14 +195,14 @@ namespace Tizen.Multimedia.Remoting
         /// <param name="display">The display where the mirroring will be played on.</param>
         /// <param name="resolutions">The desired resolutions.</param>
         /// <exception cref="ArgumentException">
-        ///    <paramref name="resolutions"/> contain invalid flags.\n
-        ///    -or-\n
+        ///    <paramref name="resolutions"/> contain invalid flags.<br/>
+        ///    -or-<br/>
         ///    <paramref name="display"/> has already been assigned to another.
         /// </exception>
         /// <exception cref="ArgumentNullException"><paramref name="display"/> is null.</exception>
         /// <exception cref="InvalidOperationException">
-        ///     The current state is not in the valid.\n
-        ///     -or-\n
+        ///     The current state is not in the valid.<br/>
+        ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="ScreenMirroring"/> has already been disposed.</exception>
@@ -226,8 +244,8 @@ namespace Tizen.Multimedia.Remoting
         /// <privilege>http://tizen.org/privilege/internet</privilege>
         /// <exception cref="ArgumentNullException"><paramref name="sourceIp"/> is null.</exception>
         /// <exception cref="InvalidOperationException">
-        ///     The current state is not in the valid.\n
-        ///     -or-\n
+        ///     The current state is not in the valid.<br/>
+        ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ArgumentException"><paramref name="sourceIp"/> is a zero-length string, contains only white space.</exception>
@@ -270,8 +288,8 @@ namespace Tizen.Multimedia.Remoting
         /// <returns>A task that represents the asynchronous operation.</returns>
         /// <privilege>http://tizen.org/privilege/internet</privilege>
         /// <exception cref="InvalidOperationException">
-        ///     The current state is not in the valid.\n
-        ///     -or-\n
+        ///     The current state is not in the valid.<br/>
+        ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="ScreenMirroring"/> has already been disposed.</exception>
@@ -301,8 +319,8 @@ namespace Tizen.Multimedia.Remoting
         /// <returns>A task that represents the asynchronous operation.</returns>
         /// <privilege>http://tizen.org/privilege/internet</privilege>
         /// <exception cref="InvalidOperationException">
-        ///     The current state is not in the valid.\n
-        ///     -or-\n
+        ///     The current state is not in the valid.<br/>
+        ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="ScreenMirroring"/> has already been disposed.</exception>
@@ -332,8 +350,8 @@ namespace Tizen.Multimedia.Remoting
         /// <returns>A task that represents the asynchronous operation.</returns>
         /// <privilege>http://tizen.org/privilege/internet</privilege>
         /// <exception cref="InvalidOperationException">
-        ///     The current state is not in the valid.\n
-        ///     -or-\n
+        ///     The current state is not in the valid.<br/>
+        ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="ScreenMirroring"/> has already been disposed.</exception>
@@ -362,8 +380,8 @@ namespace Tizen.Multimedia.Remoting
         /// </remarks>
         /// <privilege>http://tizen.org/privilege/internet</privilege>
         /// <exception cref="InvalidOperationException">
-        ///     The current state is not in the valid.\n
-        ///     -or-\n
+        ///     The current state is not in the valid.<br/>
+        ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="ScreenMirroring"/> has already been disposed.</exception>
@@ -384,8 +402,8 @@ namespace Tizen.Multimedia.Remoting
         /// or <see cref="ScreenMirroringState.Disconnected"/>.
         /// </remarks>
         /// <exception cref="InvalidOperationException">
-        ///     The current state is not in the valid.\n
-        ///     -or-\n
+        ///     The current state is not in the valid.<br/>
+        ///     -or-<br/>
         ///     An internal error occurs.
         /// </exception>
         /// <exception cref="ObjectDisposedException">The <see cref="ScreenMirroring"/> has already been disposed.</exception>
@@ -398,13 +416,21 @@ namespace Tizen.Multimedia.Remoting
             DetachDisplay();
         }
 
+        private void ThrowIfDisposed()
+        {
+            if (_disposed)
+            {
+                throw new ObjectDisposedException(nameof(ScreenMirroring));
+            }
+        }
+
         /// <summary>
         /// Releases all resource used by the <see cref="ScreenMirroring"/> object.
         /// </summary>
         /// <remarks>
         /// Call <see cref="Dispose()"/> when you are finished using the <see cref="ScreenMirroring"/>.
         /// The <see cref="Dispose()"/> method leaves the <see cref="ScreenMirroring"/> in an unusable
-        /// state. After calling <see cref="Dispose"()/>, you must release all references to the
+        /// state. After calling <see cref="Dispose()"/>, you must release all references to the
         /// <see cref="ScreenMirroring"/> so the garbage collector can reclaim the memory that the
         /// <see cref="ScreenMirroring"/> was occupying.
         /// </remarks>
@@ -440,7 +466,7 @@ namespace Tizen.Multimedia.Remoting
 
         private void RegisterStateChangedEvent()
         {
-            _stateChangedCallback = (_, state, error) =>
+            _stateChangedCallback = (error, state, _) =>
             {
                 var prevState = _state.Value;