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