Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.WiFiDirect / Tizen.Network.WiFiDirect / WiFiDirectData.cs
1 /*
2  * Copyright (c) 2016 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 System.Collections.ObjectModel;
20
21 namespace Tizen.Network.WiFiDirect
22 {
23     [StructLayout(LayoutKind.Sequential)]
24     internal struct DiscoveredPeerStruct
25     {
26         [MarshalAsAttribute(UnmanagedType.LPStr)]
27         internal string _name;
28
29         [MarshalAsAttribute(UnmanagedType.LPStr)]
30         internal string _macAddress;
31
32         [MarshalAsAttribute(UnmanagedType.LPStr)]
33         internal string _interfaceAddress;
34
35         internal int _channel;
36
37         [MarshalAsAttribute(UnmanagedType.I1)]
38         internal bool _isConnected;
39
40         [MarshalAsAttribute(UnmanagedType.I1)]
41         internal bool _isGroupOwner;
42
43         internal WiFiDirectPrimaryDeviceType _primaryType;
44
45         internal WiFiDirectSecondaryDeviceType _secondaryType;
46
47         internal int _wpsTypes;
48
49         [MarshalAsAttribute(UnmanagedType.I1)]
50         internal bool _isP2PInvitationSupported;
51
52         internal uint _serviceCount;
53
54         internal IntPtr _serviceList;
55
56         [MarshalAsAttribute(UnmanagedType.I1)]
57         internal bool _isMiracast;
58     }
59     [StructLayout(LayoutKind.Sequential)]
60     internal struct ConnectedPeerStruct
61     {
62         [MarshalAsAttribute(UnmanagedType.LPStr)]
63         internal string _name;
64
65         [MarshalAsAttribute(UnmanagedType.LPStr)]
66         internal string _ipAddress;
67
68         [MarshalAsAttribute(UnmanagedType.LPStr)]
69         internal string _macAddress;
70
71         [MarshalAsAttribute(UnmanagedType.LPStr)]
72         internal string _interfaceAddress;
73
74         internal int _channel;
75
76         [MarshalAsAttribute(UnmanagedType.I1)]
77         internal bool _isP2PSupport;
78
79         internal WiFiDirectPrimaryDeviceType _primaryType;
80
81         internal WiFiDirectSecondaryDeviceType _secondaryType;
82
83         internal uint _serviceCount;
84
85         internal IntPtr _serviceList;
86
87         [MarshalAsAttribute(UnmanagedType.I1)]
88         internal bool _isMiracast;
89     }
90
91     internal static class WiFiDirectUtils
92     {
93         internal static WiFiDirectPeer ConvertStructToDiscoveredPeer(DiscoveredPeerStruct peer)
94         {
95             WiFiDirectPeer resultPeer = new WiFiDirectPeer();
96             resultPeer._peerDeviceName = peer._name;
97             resultPeer._peerMacAddress = peer._macAddress;
98             resultPeer._peerInterfaceAddress = peer._interfaceAddress;
99             resultPeer._peerChannel = peer._channel;
100             resultPeer._isPeerConnected = peer._isConnected;
101             resultPeer._isPeerGroupOwner = peer._isGroupOwner;
102             resultPeer._peerPrimaryType = peer._primaryType;
103             resultPeer._peerSecondaryType = peer._secondaryType;
104             resultPeer._peerWpsTypes = peer._wpsTypes;
105             resultPeer._p2PInvitationSupported = peer._isP2PInvitationSupported;
106             Collection<string> uuidList = null;
107
108             if (peer._serviceCount > 0)
109             {
110                 IntPtr[] serviceList = new IntPtr[peer._serviceCount];
111                 Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount);
112                 uuidList = new Collection<string>();
113                 foreach (IntPtr service in serviceList)
114                 {
115                     string registeredService = Marshal.PtrToStringAnsi(service);
116                     uuidList.Add(registeredService);
117                 }
118
119                 resultPeer._peerServiceCount = peer._serviceCount;
120                 resultPeer._peerServiceList = uuidList;
121             }
122
123             resultPeer._isPeerMiracastDevice = peer._isMiracast;
124             return resultPeer;
125         }
126
127         internal static WiFiDirectPeer ConvertStructToConnectedPeer(ConnectedPeerStruct peer)
128         {
129             WiFiDirectPeer resultPeer = new WiFiDirectPeer();
130             resultPeer._peerDeviceName = peer._name;
131             resultPeer._peerIpAddress = peer._ipAddress;
132             resultPeer._peerMacAddress = peer._macAddress;
133             resultPeer._peerInterfaceAddress = peer._interfaceAddress;
134             resultPeer._peerChannel = peer._channel;
135             resultPeer._peerP2PSupport = peer._isP2PSupport;
136             resultPeer._peerPrimaryType = peer._primaryType;
137             resultPeer._peerSecondaryType = peer._secondaryType;
138             Collection<string> uuidList = null;
139
140             if (peer._serviceCount > 0)
141             {
142                 IntPtr[] serviceList = new IntPtr[peer._serviceCount];
143                 Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount);
144                 uuidList = new Collection<string>();
145                 foreach (IntPtr service in serviceList)
146                 {
147                     string registeredService = Marshal.PtrToStringAnsi(service);
148                     uuidList.Add(registeredService);
149                 }
150
151                 resultPeer._peerServiceCount = peer._serviceCount;
152                 resultPeer._peerServiceList = uuidList;
153             }
154
155             resultPeer._isPeerMiracastDevice = peer._isMiracast;
156             return resultPeer;
157         }
158     }
159
160 }