Setting since_tizen 3/4 on Tizen.NET API
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.WiFiDirect / Tizen.Network.WiFiDirect / WiFiDirectPeer.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.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Collections.Concurrent;
21 using System.Collections.ObjectModel;
22 using System.Collections.Specialized;
23
24 namespace Tizen.Network.WiFiDirect
25 {
26     /// <summary>
27     /// The WiFiDirectPeer class is used to handle the connection with remote devices using Wi-Fi Direct.
28     /// </summary>
29     /// <privilege> http://tizen.org/privilege/wifidirect </privilege>
30     /// <since_tizen> 3 </since_tizen>
31     public class WiFiDirectPeer
32     {
33         private event EventHandler<ConnectionStateChangedEventArgs> _connectionStateChanged;
34         private event EventHandler<IpAddressAssignedEventArgs> _ipAddressAssigned;
35         private event EventHandler<ServiceStateChangedEventArgs> _serviceStateChanged;
36
37         private Interop.WiFiDirect.ConnectionStateChangedCallback _connectionStateChangedCallback;
38         private Interop.WiFiDirect.ClientIpAddressAssignedCallback _ipAddressAssignedCallback;
39         private Interop.WiFiDirect.ServiceStateChangedCallback _serviceStateChangedCallback;
40
41         internal string _peerDeviceName;
42         internal string _peerIpAddress;
43         internal string _peerMacAddress;
44         internal string _peerInterfaceAddress;
45         internal int _peerChannel;
46         internal bool _isPeerConnected;
47         internal bool _isPeerGroupOwner;
48         internal bool _peerP2PSupport;
49         internal WiFiDirectPrimaryDeviceType _peerPrimaryType;
50         internal WiFiDirectSecondaryDeviceType _peerSecondaryType;
51         internal int _peerWpsTypes;
52         internal bool _p2PInvitationSupported;
53         internal uint _peerServiceCount;
54         internal IEnumerable<string> _peerServiceList;
55         internal bool _isPeerMiracastDevice;
56
57         internal WiFiDirectPeer()
58         {
59         }
60
61         /// <summary>
62         /// The name of the peer device.
63         /// </summary>
64         /// <since_tizen> 3 </since_tizen>
65         public string Name
66         {
67             get
68             {
69                 return _peerDeviceName;
70             }
71         }
72
73         /// <summary>
74         /// The IP address of the peer device.
75         /// </summary>
76         /// <since_tizen> 3 </since_tizen>
77         public string IpAddress
78         {
79             get
80             {
81                 return _peerIpAddress;
82             }
83         }
84
85         /// <summary>
86         /// The MAC address of the peer device.
87         /// </summary>
88         /// <since_tizen> 3 </since_tizen>
89         public string MacAddress
90         {
91             get
92             {
93                 return _peerMacAddress;
94             }
95         }
96
97         /// <summary>
98         /// The Interface address of the peer device.
99         /// </summary>
100         /// <since_tizen> 3 </since_tizen>
101         public string InterfaceAddress
102         {
103             get
104             {
105                 return _peerInterfaceAddress;
106             }
107         }
108
109         /// <summary>
110         /// The listening channel of the peer device.
111         /// </summary>
112         /// <since_tizen> 3 </since_tizen>
113         public int Channel
114         {
115             get
116             {
117                 return _peerChannel;
118             }
119         }
120
121         /// <summary>
122         /// The connected state of the peer device.
123         /// </summary>
124         /// <since_tizen> 3 </since_tizen>
125         public bool IsConnected
126         {
127             get
128             {
129                 return _isPeerConnected;
130             }
131         }
132
133         /// <summary>
134         /// The P2P group state of the peer device.
135         /// </summary>
136         /// <since_tizen> 3 </since_tizen>
137         public bool IsGroupOwner
138         {
139             get
140             {
141                 return _isPeerGroupOwner;
142             }
143         }
144
145         /// <summary>
146         /// The P2P state of the peer device.
147         /// </summary>
148         /// <since_tizen> 3 </since_tizen>
149         public bool P2PSupport
150         {
151             get
152             {
153                 return _peerP2PSupport;
154             }
155         }
156
157         /// <summary>
158         /// The primary catagory of the peer device.
159         /// </summary>
160         /// <since_tizen> 3 </since_tizen>
161         public WiFiDirectPrimaryDeviceType PrimaryType
162         {
163             get
164             {
165                 return _peerPrimaryType;
166             }
167         }
168
169         /// <summary>
170         /// The sub category of the peer device.
171         /// </summary>
172         /// <since_tizen> 3 </since_tizen>
173         public WiFiDirectSecondaryDeviceType SecondaryType
174         {
175             get
176             {
177                 return _peerSecondaryType;
178             }
179         }
180
181         /// <summary>
182         /// The list of the supported WPS type of the peer device.
183         /// </summary>
184         /// <since_tizen> 3 </since_tizen>
185         public int WpsTypes
186         {
187             get
188             {
189                 return _peerWpsTypes;
190             }
191         }
192
193         /// <summary>
194         /// The P2P invitation state of the peer device.
195         /// </summary>
196         /// <since_tizen> 3 </since_tizen>
197         public bool IsP2PInvitationSupported
198         {
199             get
200             {
201                 return _p2PInvitationSupported;
202             }
203         }
204
205         /// <summary>
206         /// The number of registered services of the peer device.
207         /// </summary>
208         /// <since_tizen> 3 </since_tizen>
209         public uint ServiceCount
210         {
211             get
212             {
213                 return _peerServiceCount;
214             }
215         }
216
217         /// <summary>
218         /// The list of registered services of the peer device.
219         /// </summary>
220         /// <since_tizen> 3 </since_tizen>
221         public IEnumerable<string> ServiceList
222         {
223             get
224             {
225                 return _peerServiceList;
226             }
227         }
228
229         /// <summary>
230         /// Checks if the peer device is a Wi-Fi display device.
231         /// </summary>
232         /// <since_tizen> 3 </since_tizen>
233         public bool IsMiracastDevice
234         {
235             get
236             {
237                 return _isPeerMiracastDevice;
238             }
239         }
240
241         /// <summary>
242         /// The Wi-Fi display device type of the peer device.
243         /// </summary>
244         /// <remarks>
245         /// Wi-Fi Direct must be activated.
246         /// If there is any error, a default value of WiFiDirectDisplayType will be returned.
247         /// </remarks>
248         /// <since_tizen> 3 </since_tizen>
249         public WiFiDirectDisplayType Display
250         {
251             get
252             {
253                 if (Globals.IsActivated)
254                 {
255                     WiFiDirectDisplayType displayType;
256                     int ret = Interop.WiFiDirect.GetDisplayType(_peerMacAddress, out displayType);
257                     if (ret != (int)WiFiDirectError.None)
258                     {
259                         Log.Error(Globals.LogTag, "Failed to get the peer display type, Error - " + (WiFiDirectError)ret);
260                     }
261
262                     return displayType;
263                 }
264
265                 else
266                 {
267                     return default(WiFiDirectDisplayType);
268                 }
269             }
270         }
271
272         /// <summary>
273         /// The Wi-Fi display session availability of the peer device.
274         /// </summary>
275         /// <remarks>
276         /// Wi-Fi Direct must be activated.
277         /// If there is any error, false will be returned.
278         /// </remarks>
279         /// <since_tizen> 3 </since_tizen>
280         public bool DisplayAvailability
281         {
282             get
283             {
284                 if (Globals.IsActivated)
285                 {
286                     bool displayAvailability;
287                     int ret = Interop.WiFiDirect.GetDisplayAvailability(_peerMacAddress, out displayAvailability);
288                     if (ret != (int)WiFiDirectError.None)
289                     {
290                         Log.Error(Globals.LogTag, "Failed to get the peer display availability, Error - " + (WiFiDirectError)ret);
291                     }
292
293                     return displayAvailability;
294                 }
295
296                 else
297                 {
298                     return false;
299                 }
300             }
301         }
302
303         /// <summary>
304         /// The HDCP information of the peer device.
305         /// </summary>
306         /// <remarks>
307         /// Wi-Fi Direct must be activated.
308         /// If there is any error, -1 will be returned.
309         /// </remarks>
310         /// <since_tizen> 3 </since_tizen>
311         public int Hdcp
312         {
313             get
314             {
315                 if (Globals.IsActivated)
316                 {
317                     int hdcpSupport;
318                     int ret = Interop.WiFiDirect.GetDisplayHdcp(_peerMacAddress, out hdcpSupport);
319                     if (ret != (int)WiFiDirectError.None)
320                     {
321                         Log.Error(Globals.LogTag, "Failed to get the peer display hdcp support, Error - " + (WiFiDirectError)ret);
322                         return -1;
323                     }
324
325                     return hdcpSupport;
326                 }
327
328                 else
329                 {
330                     return -1;
331                 }
332             }
333         }
334
335         /// <summary>
336         /// The port of the connected peer device.
337         /// </summary>
338         /// <remarks>
339         /// Wi-Fi Direct must be activated.
340         /// If there is any error, -1 will be returned.
341         /// </remarks>
342         /// <since_tizen> 3 </since_tizen>
343         public int Port
344         {
345             get
346             {
347                 if (Globals.IsActivated)
348                 {
349                     int displayPort;
350                     int ret = Interop.WiFiDirect.GetDisplayPort(_peerMacAddress, out displayPort);
351                     if (ret != (int)WiFiDirectError.None)
352                     {
353                         Log.Error(Globals.LogTag, "Failed to get the peer display port, Error - " + (WiFiDirectError)ret);
354                         return -1;
355                     }
356
357                     return displayPort;
358                 }
359
360                 else
361                 {
362                     return -1;
363                 }
364             }
365         }
366
367         /// <summary>
368         /// The Wi-Fi display maximum throughput of the peer device.
369         /// </summary>
370         /// <remarks>
371         /// Wi-Fi Direct must be activated.
372         /// If there is any error, -1 will be returned.
373         /// </remarks>
374         /// <since_tizen> 3 </since_tizen>
375         public int Throughput
376         {
377             get
378             {
379                 if (Globals.IsActivated)
380                 {
381                     int displayThroughput;
382                     int ret = Interop.WiFiDirect.GetDisplayThroughput(_peerMacAddress, out displayThroughput);
383                     if (ret != (int)WiFiDirectError.None)
384                     {
385                         Log.Error(Globals.LogTag, "Failed to get the peer display max throughput, Error - " + (WiFiDirectError)ret);
386                         return -1;
387                     }
388
389                     return displayThroughput;
390                 }
391
392                 else
393                 {
394                     return -1;
395                 }
396             }
397         }
398
399         /// <summary>
400         /// The Wi-Fi RSSI value of the peer device.
401         /// </summary>
402         /// <remarks>
403         /// Wi-Fi Direct must be activated.
404         /// If there is any error, -1 will be returned.
405         /// </remarks>
406         /// <since_tizen> 3 </since_tizen>
407         public int Rssi
408         {
409             get
410             {
411                 if (Globals.IsActivated)
412                 {
413                     int rssi;
414                     int ret = Interop.WiFiDirect.GetRssi(_peerMacAddress, out rssi);
415                     if (ret != (int)WiFiDirectError.None)
416                     {
417                         Log.Error(Globals.LogTag, "Failed to get the peer RSSI, Error - " + (WiFiDirectError)ret);
418                         return -1;
419                     }
420
421                     return rssi;
422                 }
423
424                 else
425                 {
426                     return -1;
427                 }
428             }
429         }
430         /// <summary>
431         /// The ConnectionStateChanged event is raised when the connection state of the peer device changes.
432         /// </summary>
433         /// <since_tizen> 3 </since_tizen>
434         public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
435         {
436             add
437             {
438                 if (Globals.IsInitialize)
439                 {
440                     if (_connectionStateChanged == null)
441                     {
442                         RegisterConnectionStateChangedEvent();
443                     }
444
445                     _connectionStateChanged += value;
446                 }
447             }
448
449             remove
450             {
451                 if (Globals.IsInitialize)
452                 {
453                     _connectionStateChanged -= value;
454                     if (_connectionStateChanged == null)
455                     {
456                         UnregisterConnectionStateChangedEvent();
457                     }
458                 }
459             }
460         }
461
462         /// <summary>
463         /// The IpAddressAssigned event is raised when the IP address of the peer device is assigned.
464         /// </summary>
465         /// <since_tizen> 3 </since_tizen>
466         public event EventHandler<IpAddressAssignedEventArgs> IpAddressAssigned
467         {
468             add
469             {
470                 if (Globals.IsInitialize)
471                 {
472                     if (_ipAddressAssigned == null)
473                     {
474                         RegisterIpAddressAssignedEvent();
475                     }
476
477                     _ipAddressAssigned += value;
478                 }
479             }
480
481             remove
482             {
483                 if (Globals.IsInitialize)
484                 {
485                     _ipAddressAssigned -= value;
486                     if (_ipAddressAssigned == null)
487                     {
488                         UnregisterIpAddressAssignedEvent();
489                     }
490                 }
491             }
492         }
493
494         /// <summary>
495         /// The ServiceStateChanged event is raised when the state of service discovery is changed.
496         /// </summary>
497         /// <since_tizen> 3 </since_tizen>
498         public event EventHandler<ServiceStateChangedEventArgs> ServiceStateChanged
499         {
500             add
501             {
502                 if (Globals.IsInitialize)
503                 {
504                     if (_serviceStateChanged == null)
505                     {
506                         RegisterServiceStateChangedEvent();
507                     }
508
509                     _serviceStateChanged += value;
510                 }
511             }
512
513             remove
514             {
515                 if (Globals.IsInitialize)
516                 {
517                     _serviceStateChanged -= value;
518                     if (_serviceStateChanged == null)
519                     {
520                         UnregisterServiceStateChangedEvent();
521                     }
522                 }
523             }
524         }
525
526         private void RegisterConnectionStateChangedEvent()
527         {
528             _connectionStateChangedCallback = (int result, WiFiDirectConnectionState state, string address, IntPtr userData) =>
529             {
530                 if (_connectionStateChanged != null)
531                 {
532                     WiFiDirectError res = (WiFiDirectError)result;
533                     _connectionStateChanged(null, new ConnectionStateChangedEventArgs(res, state, address));
534                 }
535             };
536             int ret = Interop.WiFiDirect.SetConnectionChangedCallback(_connectionStateChangedCallback, IntPtr.Zero);
537             if (ret != (int)WiFiDirectError.None)
538             {
539                 Log.Error(Globals.LogTag, "Failed to set connection state changed callback, Error - " + (WiFiDirectError)ret);
540             }
541         }
542
543         private void UnregisterConnectionStateChangedEvent()
544         {
545             int ret = Interop.WiFiDirect.UnsetConnectionChangedCallback();
546             if (ret != (int)WiFiDirectError.None)
547             {
548                 Log.Error(Globals.LogTag, "Failed to unset connection state changed callback, Error - " + (WiFiDirectError)ret);
549             }
550         }
551
552         private void RegisterIpAddressAssignedEvent()
553         {
554             _ipAddressAssignedCallback = (string macAddress, string ipAddress, string interfaceAddress, IntPtr userData) =>
555             {
556                 if (_ipAddressAssigned != null)
557                 {
558                     _ipAddressAssigned(null, new IpAddressAssignedEventArgs(macAddress, ipAddress, interfaceAddress));
559                 }
560             };
561             int ret = Interop.WiFiDirect.SetIpAddressAssignedCallback(_ipAddressAssignedCallback, IntPtr.Zero);
562             if (ret != (int)WiFiDirectError.None)
563             {
564                 Log.Error(Globals.LogTag, "Failed to set ip address assigned callback, Error - " + (WiFiDirectError)ret);
565             }
566         }
567
568         private void UnregisterIpAddressAssignedEvent()
569         {
570             int ret = Interop.WiFiDirect.UnsetIpAddressAssignedCallback();
571             if (ret != (int)WiFiDirectError.None)
572             {
573                 Log.Error(Globals.LogTag, "Failed to unset ip address assigned callback, Error - " + (WiFiDirectError)ret);
574             }
575         }
576
577         private void RegisterServiceStateChangedEvent()
578         {
579             _serviceStateChangedCallback = (int result, WiFiDirectServiceDiscoveryState stateInfo, WiFiDirectServiceType typeInfo, IntPtr responseData, string address, IntPtr userData) =>
580             {
581                 if (_serviceStateChanged != null)
582                 {
583                     WiFiDirectError error = (WiFiDirectError)result;
584                     WiFiDirectServiceDiscoveryState state = stateInfo;
585                     WiFiDirectServiceType type = typeInfo;
586                     string response = Marshal.PtrToStringAnsi(responseData);
587                     IntPtr peer;
588                     Interop.WiFiDirect.GetDiscoveredPeerInfo(address, out peer);
589                     DiscoveredPeerStruct peerStruct = (DiscoveredPeerStruct)Marshal.PtrToStructure(peer, typeof(DiscoveredPeerStruct));
590
591                     _serviceStateChanged(null, new ServiceStateChangedEventArgs(error, state, type, response, WiFiDirectUtils.ConvertStructToDiscoveredPeer(peerStruct)));
592                 }
593             };
594             int ret = Interop.WiFiDirect.SetServiceStateChangedCallback(_serviceStateChangedCallback, IntPtr.Zero);
595             if (ret != (int)WiFiDirectError.None)
596             {
597                 Log.Error(Globals.LogTag, "Failed to set service state changed callback, Error - " + (WiFiDirectError)ret);
598             }
599         }
600
601         private void UnregisterServiceStateChangedEvent()
602         {
603             int ret = Interop.WiFiDirect.UnsetServiceStateChangedCallback();
604             if (ret != (int)WiFiDirectError.None)
605             {
606                 Log.Error(Globals.LogTag, "Failed to unset service state changed callback, Error - " + (WiFiDirectError)ret);
607             }
608         }
609
610         /// <summary>
611         /// Connects to a specified remote device.
612         /// </summary>
613         /// <remarks>
614         /// Wi-Fi Direct must be activated.
615         /// If this succeeds, the ConnectionStateChanged event will be invoked.
616         /// </remarks>
617         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi Direct is not supported</exception>
618         /// <since_tizen> 3 </since_tizen>
619         public void Connect()
620         {
621             if (Globals.IsActivated)
622             {
623                 int ret = Interop.WiFiDirect.Connect(_peerMacAddress);
624                 if (ret != (int)WiFiDirectError.None)
625                 {
626                     Log.Error(Globals.LogTag, "Failed to connect, Error - " + (WiFiDirectError)ret);
627                     WiFiDirectErrorFactory.ThrowWiFiDirectException(ret);
628                 }
629             }
630
631             else
632             {
633                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
634                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
635             }
636         }
637
638         /// <summary>
639         /// Cancels the connection now in progress.
640         /// </summary>
641         /// <remarks>
642         /// Wi-Fi Direct must be activated.
643         /// </remarks>
644         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi Direct is not supported.</exception>
645         /// <since_tizen> 3 </since_tizen>
646         public void CancelConnection()
647         {
648             if (Globals.IsActivated)
649             {
650                 int ret = Interop.WiFiDirect.CancelConnection(_peerMacAddress);
651                 if (ret != (int)WiFiDirectError.None)
652                 {
653                     Log.Error(Globals.LogTag, "Failed to cancel the connection, Error - " + (WiFiDirectError)ret);
654                     WiFiDirectErrorFactory.ThrowWiFiDirectException(ret);
655                 }
656             }
657
658             else
659             {
660                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
661                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
662             }
663         }
664
665         /// <summary>
666         /// Disconnects the specified remote device.
667         /// </summary>
668         /// <remarks>
669         /// Wi-Fi Direct must be activated.
670         /// If this succeeds, the ConnectionStateChanged event will be invoked.
671         /// </remarks>
672         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi Direct is not supported.</exception>
673         /// <since_tizen> 3 </since_tizen>
674         public void Disconnect()
675         {
676             if (Globals.IsActivated)
677             {
678                 int ret = Interop.WiFiDirect.Disconnect(_peerMacAddress);
679                 if (ret != (int)WiFiDirectError.None)
680                 {
681                     Log.Error(Globals.LogTag, "Failed to disconnect, Error - " + (WiFiDirectError)ret);
682                     WiFiDirectErrorFactory.ThrowWiFiDirectException(ret);
683                 }
684             }
685
686             else
687             {
688                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
689                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
690             }
691         }
692
693         /// <summary>
694         /// Allows a device to connect automatically.
695         /// </summary>
696         /// <remarks>
697         /// Wi-Fi Direct must be activated.
698         /// </remarks>
699         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi Direct is not supported.</exception>
700         /// <since_tizen> 3 </since_tizen>
701         public void SetAutoConnect()
702         {
703             if (Globals.IsActivated)
704             {
705                 int ret = Interop.WiFiDirect.SetAutoConnectionPeer(_peerMacAddress);
706                 if (ret != (int)WiFiDirectError.None)
707                 {
708                     Log.Error(Globals.LogTag, "Failed to set auto connection, Error - " + (WiFiDirectError)ret);
709                     WiFiDirectErrorFactory.ThrowWiFiDirectException(ret);
710                 }
711             }
712
713             else
714             {
715                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
716                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
717             }
718         }
719
720         /// <summary>
721         /// Starts the Wi-Fi Direct service discovery.
722         /// </summary>
723         /// <remarks>
724         /// Wi-Fi Direct must be activated.
725         /// If this succeeds, the ServiceStateChanged event will be invoked.
726         /// </remarks>
727         /// <exception cref="NotSupportedException">
728         /// Thrown during one of the following cases:
729         /// 1. When the Wi-Fi Direct is not supported.
730         /// 2. When the Wi-Fi Direct service discovery is not supported.
731         /// </exception>
732         /// <param name="type">The type of the service.</param>
733         /// <since_tizen> 3 </since_tizen>
734         public void StartServiceDiscovery(WiFiDirectServiceType type)
735         {
736             if (Globals.IsActivated)
737             {
738                 int ret = Interop.WiFiDirect.StartServiceDiscovery(_peerMacAddress, type);
739                 if (ret != (int)WiFiDirectError.None)
740                 {
741                     Log.Error(Globals.LogTag, "Failed to start Wi-Fi Direct service discovery, Error - " + (WiFiDirectError)ret);
742                     WiFiDirectErrorFactory.ThrowWiFiDirectException(ret);
743                 }
744             }
745
746             else
747             {
748                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
749                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
750             }
751         }
752
753         /// <summary>
754         /// Stops the Wi-Fi Direct service discovery.
755         /// </summary>
756         /// <remarks>
757         /// Wi-Fi Direct must be activated.
758         /// </remarks>
759         /// <exception cref="NotSupportedException">
760         /// Thrown during one of the following cases:
761         /// 1. When the Wi-Fi Direct is not supported.
762         /// 2. When the Wi-Fi Direct service discovery is not supported.
763         /// </exception>
764         /// <param name="type">The type of the service.</param>
765         /// <since_tizen> 3 </since_tizen>
766         public void CancelServiceDiscovery(WiFiDirectServiceType type)
767         {
768             if (Globals.IsActivated)
769             {
770                 int ret = Interop.WiFiDirect.StopServiceDiscovery(_peerMacAddress, type);
771                 if (ret != (int)WiFiDirectError.None)
772                 {
773                     Log.Error(Globals.LogTag, "Failed to stop Wi-Fi Direct service discovery, Error - " + (WiFiDirectError)ret);
774                     WiFiDirectErrorFactory.ThrowWiFiDirectException(ret);
775                 }
776             }
777
778             else
779             {
780                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
781                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
782             }
783         }
784     }
785 }