[Multimedia] Deprecate constructors related to ElmSharp (#4540)
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Remoting / WebRTC / WebRTCDataChannelMessageReceivedEventArgs.cs
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19 using static Interop;
20
21 namespace Tizen.Multimedia.Remoting
22 {
23     /// <summary>
24     /// Provides data for the <see cref="WebRTCDataChannel.MessageReceived"/> event.
25     /// </summary>
26     /// <since_tizen> 9 </since_tizen>
27     public class WebRTCDataChannelMessageReceivedEventArgs : EventArgs
28     {
29         internal WebRTCDataChannelMessageReceivedEventArgs(DataChannelType type, IntPtr message)
30         {
31             Type = type;
32
33             if (type == DataChannelType.Strings)
34             {
35                 Message = Marshal.PtrToStringAnsi(message);
36             }
37             else
38             {
39                 NativeDataChannel.GetData(message, out IntPtr data, out ulong size).
40                     ThrowIfFailed("Failed to get data");
41
42                 Data = new byte[(int)size];
43                 Marshal.Copy(data, Data, 0, (int)size);
44             }
45         }
46
47         /// <summary>
48         /// Gets the data channel type.
49         /// </summary>
50         /// <value>The data channel type.</value>
51         /// <since_tizen> 9 </since_tizen>
52         public DataChannelType Type { get; }
53
54         /// <summary>
55         /// Gets the string message from remote peer.
56         /// </summary>
57         /// <remarks>
58         /// If <see cref="WebRTCDataChannelMessageReceivedEventArgs.Type"/> is <see cref="DataChannelType.Bytes"/>, this property is null.
59         /// </remarks>
60         /// <value>The message.</value>
61         /// <since_tizen> 9 </since_tizen>
62         public string Message { get; }
63
64         #pragma warning disable CA1819 // the purpose of this member is to pass received data to user, no need to protect it from changes
65         /// <summary>
66         /// Gets the byte data from remote peer.
67         /// </summary>
68         /// <remarks>
69         /// If <see cref="WebRTCDataChannelMessageReceivedEventArgs.Type"/> is <see cref="DataChannelType.Strings"/>, this property is null.
70         /// </remarks>
71         /// <value>The message.</value>
72         /// <since_tizen> 9 </since_tizen>
73         public byte[] Data { get; }
74         #pragma warning restore CA1819
75
76         /// <summary>
77         /// Returns a string that represents the current object.
78         /// </summary>
79         /// <returns>A string that represents the current object.</returns>
80         /// <since_tizen> 9 </since_tizen>
81         public override string ToString() => $"Channel type={Type}, Message={Message}";
82     }
83 }