[C# Wi-Fi Direct] Adding C# Wi-Fi Direct code
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.WiFiDirect / Tizen.Network.WiFiDirect / WiFiDirectManager.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
20 namespace Tizen.Network.WiFiDirect
21 {
22     /// <summary>
23     /// A class which is used to manage settings of Wi-Fi Direct.<br>
24     /// This class is used to discover peer devices and manage settings of Wi-Fi Direct.
25     /// </summary>
26     /// <privilege> http://tizen.org/privilege/wifidirect </privilege>
27     public static class WiFiDirectManager
28     {
29         /// <summary>
30         /// A property to check whether the device is group owner or not.
31         /// </summary>
32         /// <remarks>
33         /// Wi-Fi Direct must be activated.
34         /// If it is deactivated, false will be returned.
35         /// </remarks>
36         public static bool IsGroupOwner
37         {
38             get
39             {
40                 if (Globals.IsActivated)
41                 {
42                     return WiFiDirectManagerImpl.Instance.IsGroupOwner;
43                 }
44
45                 else
46                 {
47                     return false;
48                 }
49             }
50         }
51
52         /// <summary>
53         /// A property to check whether the current group is the autonomous group or not.
54         /// </summary>
55         /// <remarks>
56         /// Wi-Fi Direct must be activated.
57         /// If it is deactivated, false will be returned.
58         /// </remarks>
59         public static bool IsAutonomousGroup
60         {
61             get
62             {
63                 if (Globals.IsActivated)
64                 {
65                     return WiFiDirectManagerImpl.Instance.IsAutonomousGroup;
66                 }
67
68                 else
69                 {
70                     return false;
71                 }
72             }
73         }
74
75         /// <summary>
76         /// SSID of local device.
77         /// </summary>
78         /// <remarks>
79         /// If there is any error, null will be returned.
80         /// </remarks>
81         public static string Ssid
82         {
83             get
84             {
85                 if (Globals.IsInitialize)
86                 {
87                     return WiFiDirectManagerImpl.Instance.Ssid;
88                 }
89
90                 else
91                 {
92                     return null;
93                 }
94             }
95         }
96
97         /// <summary>
98         /// Name of network interface.
99         /// </summary>
100         /// <remarks>
101         /// Wi-Fi Direct must be activated.
102         /// If it is deactivated, null will be returned.
103         /// </remarks>
104         public static string NetworkInterface
105         {
106             get
107             {
108                 if (Globals.IsActivated)
109                 {
110                     return WiFiDirectManagerImpl.Instance.NetworkInterface;
111                 }
112
113                 else
114                 {
115                     return null;
116                 }
117             }
118         }
119
120         /// <summary>
121         /// IP address of a local device.
122         /// </summary>
123         /// <remarks>
124         /// Wi-Fi Direct must be activated.
125         /// If it is deactivated, null will be returned.
126         /// </remarks>
127         public static string IpAddress
128         {
129             get
130             {
131                 if (Globals.IsActivated)
132                 {
133                     return WiFiDirectManagerImpl.Instance.IpAddress;
134                 }
135
136                 else
137                 {
138                     return null;
139                 }
140             }
141         }
142
143         /// <summary>
144         /// Subnet mask.
145         /// </summary>
146         /// <remarks>
147         /// Wi-Fi Direct must be activated.
148         /// If it is deactivated, null will be returned.
149         /// </remarks>
150         public static string SubnetMask
151         {
152             get
153             {
154                 if (Globals.IsActivated)
155                 {
156                     return WiFiDirectManagerImpl.Instance.SubnetMask;
157                 }
158
159                 else
160                 {
161                     return null;
162                 }
163             }
164         }
165
166         /// <summary>
167         /// Gateway address.
168         /// </summary>
169         /// <remarks>
170         /// Wi-Fi Direct must be activated.
171         /// If it is deactivated, null will be returned.
172         /// </remarks>
173         public static string GatewayAddress
174         {
175             get
176             {
177                 if (Globals.IsActivated)
178                 {
179                     return WiFiDirectManagerImpl.Instance.GatewayAddress;
180                 }
181
182                 else
183                 {
184                     return null;
185                 }
186             }
187         }
188
189         /// <summary>
190         /// Mac address of a local device.
191         /// </summary>
192         /// <remarks>
193         /// If there is any error, null will be returned.
194         /// </remarks>
195         public static string MacAddress
196         {
197             get
198             {
199                 if (Globals.IsInitialize)
200                 {
201                     return WiFiDirectManagerImpl.Instance.MacAddress;
202                 }
203
204                 else
205                 {
206                     return null;
207                 }
208             }
209         }
210
211         /// <summary>
212         /// State of Wi-Fi direct service.
213         /// </summary>
214         public static WiFiDirectState State
215         {
216             get
217             {
218                 return WiFiDirectManagerImpl.Instance.State;
219             }
220         }
221
222         /// <summary>
223         /// A property to check whether the device is discoverable or not by P2P discovery.
224         /// </summary>
225         public static bool IsDiscoverable
226         {
227             get
228             {
229                 if (Globals.IsInitialize)
230                 {
231                     return WiFiDirectManagerImpl.Instance.IsDiscoverable;
232                 }
233
234                 else
235                 {
236                     return false;
237                 }
238             }
239         }
240
241         /// <summary>
242         /// A property to check whether the local device is listening only.
243         /// </summary>
244         /// <remarks>
245         /// Wi-Fi Direct must be activated.
246         /// If it is deactivated, false will be returned.
247         /// </remarks>
248         public static bool IsListenOnly
249         {
250             get
251             {
252                 if (Globals.IsActivated)
253                 {
254                     return WiFiDirectManagerImpl.Instance.IsListenOnly;
255                 }
256
257                 else
258                 {
259                     return false;
260                 }
261             }
262         }
263
264         /// <summary>
265         /// Primary device type of local device.
266         /// </summary>
267         /// <remarks>
268         /// If there is any error, 0 will be returned.
269         /// </remarks>
270         public static WiFiDirectPrimaryDeviceType PrimaryType
271         {
272             get
273             {
274                 if (Globals.IsInitialize)
275                 {
276                     return WiFiDirectManagerImpl.Instance.PrimaryType;
277                 }
278
279                 else
280                 {
281                     return default(WiFiDirectPrimaryDeviceType);
282                 }
283             }
284         }
285
286         /// <summary>
287         /// Secondary device type of local device.
288         /// </summary>
289         /// <remarks>
290         /// If there is any error, 0 will be returned.
291         /// </remarks>
292         public static WiFiDirectSecondaryDeviceType SecondaryType
293         {
294             get
295             {
296                 if (Globals.IsInitialize)
297                 {
298                     return WiFiDirectManagerImpl.Instance.SecondaryType;
299                 }
300
301                 else
302                 {
303                     return default(WiFiDirectSecondaryDeviceType);
304                 }
305             }
306         }
307
308         /// <summary>
309         /// Supported WPS (Wi-Fi Protected Setup) types at local device.
310         /// </summary>
311         /// <remarks>
312         /// If there is any error, -1 will be returned.
313         /// </remarks>
314         public static int WpsMode
315         {
316             get
317             {
318                 if (Globals.IsInitialize)
319                 {
320                     return WiFiDirectManagerImpl.Instance.WpsMode;
321                 }
322
323                 else
324                 {
325                     return -1;
326                 }
327             }
328         }
329
330         /// <summary>
331         /// WPS (Wi-Fi Protected Setup) type.
332         /// </summary>
333         public static WiFiDirectWpsType Wps
334         {
335             get
336             {
337                 if (Globals.IsInitialize)
338                 {
339                     return WiFiDirectManagerImpl.Instance.WpsType;
340                 }
341
342                 else
343                 {
344                     return default(WiFiDirectWpsType);
345                 }
346             }
347         }
348
349         /// <summary>
350         /// Channel number on which the P2P Device is operating as the P2P Group.
351         /// </summary>
352         /// <remarks>
353         /// If there is any error, -1 will be returned.
354         /// </remarks>
355         public static int OperatingChannel
356         {
357             get
358             {
359                 if (Globals.IsInitialize)
360                 {
361                     return WiFiDirectManagerImpl.Instance.OperatingChannel;
362                 }
363
364                 else
365                 {
366                     return -1;
367                 }
368             }
369         }
370
371         /// <summary>
372         /// A property to check whether persistent group is enabled.
373         /// </summary>
374         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
375         public static bool PersistentGroupEnabled
376         {
377             get
378             {
379                 if (Globals.IsInitialize)
380                 {
381                     return WiFiDirectManagerImpl.Instance.PersistentGroupEnabled;
382                 }
383
384                 else
385                 {
386                     return false;
387                 }
388             }
389
390             set
391             {
392                 if (Globals.IsInitialize)
393                 {
394                     WiFiDirectManagerImpl.Instance.PersistentGroupEnabled = value;
395                 }
396             }
397         }
398
399         /// <summary>
400         /// Autoconnection mode status.
401         /// </summary>
402         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
403         public static bool AutoConnect
404         {
405             get
406             {
407                 if (Globals.IsInitialize)
408                 {
409                     return WiFiDirectManagerImpl.Instance.AutoConnect;
410                 }
411
412                 else
413                 {
414                     return false;
415                 }
416             }
417
418             set
419             {
420                 if (Globals.IsInitialize)
421                 {
422                     WiFiDirectManagerImpl.Instance.AutoConnect = value;
423                 }
424             }
425         }
426
427         /// <summary>
428         /// WPS PIN number.
429         /// </summary>
430         /// <remarks>
431         /// Wi-Fi Direct must be activated.
432         /// If it is deactivated, null will be returned during get and Not permitted exception message will be returned during set.
433         /// </remarks>
434         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
435         public static string WpsPin
436         {
437             get
438             {
439                 if (Globals.IsActivated)
440                 {
441                     return WiFiDirectManagerImpl.Instance.WpsPin;
442                 }
443
444                 else
445                 {
446                     return null;
447                 }
448             }
449
450             set
451             {
452                 if (Globals.IsActivated)
453                 {
454                     WiFiDirectManagerImpl.Instance.WpsPin = value;
455                 }
456
457                 else
458                 {
459                     Log.Error(Globals.LogTag, "Wifi-direct is not activated");
460                     WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
461                 }
462             }
463         }
464
465         /// <summary>
466         /// Name of local device.
467         /// </summary>
468         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
469         public static string Name
470         {
471             get
472             {
473                 if (Globals.IsInitialize)
474                 {
475                     return WiFiDirectManagerImpl.Instance.Name;
476                 }
477
478                 else
479                 {
480                     return null;
481                 }
482             }
483
484             set
485             {
486                 if (Globals.IsInitialize)
487                 {
488                     WiFiDirectManagerImpl.Instance.Name = value;
489                 }
490             }
491         }
492
493         /// <summary>
494         /// Requested WPS (Wi-Fi Protected Setup) type.
495         /// </summary>
496         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
497         public static WiFiDirectWpsType RequestedWps
498         {
499             get
500             {
501                 if (Globals.IsInitialize)
502                 {
503                     return WiFiDirectManagerImpl.Instance.RequestedWps;
504                 }
505
506                 else
507                 {
508                     return default(WiFiDirectWpsType);
509                 }
510             }
511
512             set
513             {
514                 if (Globals.IsInitialize)
515                 {
516                     WiFiDirectManagerImpl.Instance.RequestedWps = value;
517                 }
518             }
519         }
520
521         /// <summary>
522         /// Intent of the group owner.
523         /// </summary>
524         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
525         public static int GroupOwnerIntent
526         {
527             get
528             {
529                 if (Globals.IsInitialize)
530                 {
531                     return WiFiDirectManagerImpl.Instance.GroupOwnerIntent;
532                 }
533
534                 else
535                 {
536                     return -1;
537                 }
538             }
539
540             set
541             {
542                 if (Globals.IsInitialize)
543                 {
544                     WiFiDirectManagerImpl.Instance.GroupOwnerIntent = value;
545                 }
546             }
547         }
548
549         /// <summary>
550         /// Max number of clients.
551         /// </summary>
552         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
553         public static int MaxClients
554         {
555             get
556             {
557                 if (Globals.IsInitialize)
558                 {
559                     return WiFiDirectManagerImpl.Instance.MaxClients;
560                 }
561
562                 else
563                 {
564                     return -1;
565                 }
566             }
567
568             set
569             {
570                 if (Globals.IsInitialize)
571                 {
572                     WiFiDirectManagerImpl.Instance.MaxClients = value;
573                 }
574             }
575         }
576
577         /// <summary>
578         /// Wi-Fi Protected Access (WPA) password.
579         /// It is used during Wi-Fi Direct Group creation.
580         /// </summary>
581         /// <remarks>
582         /// Wi-Fi Direct must be activated.
583         /// If it is deactivated, null will be returned during get and Not permitted exception message will be returned during set.
584         /// </remarks>
585         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
586         public static string Passphrase
587         {
588             get
589             {
590                 if (Globals.IsActivated)
591                 {
592                     return WiFiDirectManagerImpl.Instance.Passphrase;
593                 }
594
595                 else
596                 {
597                     return null;
598                 }
599             }
600
601             set
602             {
603                 if (Globals.IsActivated)
604                 {
605                     WiFiDirectManagerImpl.Instance.Passphrase = value;
606                 }
607
608                 else
609                 {
610                     Log.Error(Globals.LogTag, "Wi-Fi direct is not activated");
611                     WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
612                 }
613             }
614         }
615
616         /// <summary>
617         /// Connection session timer value in second.
618         /// </summary>
619         /// <remarks>
620         /// Wi-Fi Direct must be activated.
621         /// If it is deactivated, -1 will be returned during get and Not permitted exception message will be returned during set.
622         /// </remarks>
623         /// <exception cref="NotSupportedException">Thrown while setting this property when the wifidirect is not supported</exception>
624         public static int SessionTimer
625         {
626             get
627             {
628                 if (Globals.IsActivated)
629                 {
630                     return WiFiDirectManagerImpl.Instance.SessionTimer;
631                 }
632
633                 else
634                 {
635                     return -1;
636                 }
637             }
638
639             set
640             {
641                 if (Globals.IsActivated)
642                 {
643                     WiFiDirectManagerImpl.Instance.SessionTimer = value;
644                 }
645
646                 else
647                 {
648                     Log.Error(Globals.LogTag, "Wi-Fi direct is not activated");
649                     WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
650                 }
651             }
652         }
653
654         /// <summary>
655         /// (event) StateChanged is raised when Wi-Fi Direct state is changed.
656         /// </summary>
657         public static event EventHandler<StateChangedEventArgs> StateChanged
658         {
659             add
660             {
661                 WiFiDirectManagerImpl.Instance.StateChanged += value;
662             }
663
664             remove
665             {
666                 WiFiDirectManagerImpl.Instance.StateChanged -= value;
667             }
668         }
669
670         /// <summary>
671         /// (event) DiscoveryStateChanged is raised when Wi-Fi Direct discovery state is changed.
672         /// </summary>
673         public static event EventHandler<DiscoveryStateChangedEventArgs> DiscoveryStateChanged
674         {
675             add
676             {
677                 if (Globals.IsInitialize)
678                 {
679                     WiFiDirectManagerImpl.Instance.DiscoveryStateChanged += value;
680                 }
681             }
682
683             remove
684             {
685                 if (Globals.IsInitialize)
686                 {
687                     WiFiDirectManagerImpl.Instance.DiscoveryStateChanged -= value;
688                 }
689             }
690         }
691
692         /// <summary>
693         /// (event) DeviceStateChanged is raised when device state is changed.
694         /// </summary>
695         public static event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
696         {
697             add
698             {
699                 if (Globals.IsInitialize)
700                 {
701                     WiFiDirectManagerImpl.Instance.DeviceStateChanged += value;
702                 }
703             }
704
705             remove
706             {
707                 if (Globals.IsInitialize)
708                 {
709                     WiFiDirectManagerImpl.Instance.DeviceStateChanged -= value;
710                 }
711             }
712         }
713
714         /// <summary>
715         /// (event) PeerFound is raised when peer is found.
716         /// </summary>
717         public static event EventHandler<PeerFoundEventArgs> PeerFound
718         {
719             add
720             {
721                 if (Globals.IsInitialize)
722                 {
723                     WiFiDirectManagerImpl.Instance.PeerFound += value;
724                 }
725             }
726
727             remove
728             {
729                 if (Globals.IsInitialize)
730                 {
731                     WiFiDirectManagerImpl.Instance.PeerFound -= value;
732                 }
733             }
734         }
735
736         /// <summary>
737         /// (event) ConnectionStatusChanged is raised when status of connection is changed.
738         /// </summary>
739         public static event EventHandler<ConnectionStatusChangedEventArgs> ConnectionStatusChanged
740         {
741             add
742             {
743                 if (Globals.IsInitialize)
744                 {
745                     WiFiDirectManagerImpl.Instance.ConnectionStatusChanged += value;
746                 }
747             }
748
749             remove
750             {
751                 if (Globals.IsInitialize)
752                 {
753                     WiFiDirectManagerImpl.Instance.ConnectionStatusChanged -= value;
754                 }
755             }
756         }
757
758         /// <summary>
759         /// Activates the Wi-Fi Direct service.
760         /// </summary>
761         /// <remarks>
762         /// If this succeeds, DeviceStateChanged event will be invoked.
763         /// </remarks>
764         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
765         public static void Activate()
766         {
767             if (Globals.IsInitialize)
768             {
769                 WiFiDirectManagerImpl.Instance.Activate();
770             }
771
772             else
773             {
774                 Log.Error(Globals.LogTag, "Wi-Fi direct is not initialized");
775                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotInitialized);
776             }
777         }
778
779         /// <summary>
780         /// Deactivates the Wi-Fi Direct service.
781         /// </summary>
782         /// <remarks>
783         /// Wi-Fi Direct must be activated.
784         /// If this succeeds, DeviceStateChanged event will be invoked.
785         /// </remarks>
786         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
787         public static void Deactivate()
788         {
789             if (Globals.IsActivated)
790             {
791                 WiFiDirectManagerImpl.Instance.Deactivate();
792             }
793
794             else
795             {
796                 Log.Error(Globals.LogTag, "Wi-Fi direct is not activated");
797                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
798             }
799         }
800
801         /// <summary>
802         /// Starts discovery to find all P2P capable devices.
803         /// </summary>
804         /// <remarks>
805         /// Wi-Fi Direct must be activated.
806         /// If this succeeds, DiscoveryStateChanged and PeerFound event will be invoked.
807         /// </remarks>
808         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
809         /// <param name="listenOnly">Listen status.If False, then cycle between Scan and Listen.If True, then skip the initial 802.11 Scan and enter Listen state.</param>
810         /// <param name="duration">Duration of discovery period, in seconds.</param>
811         /// <param name="channel">Discovery channel.It is optional, default enum value FullScan is assigned.</param>
812         public static void StartDiscovery(bool listenOnly, int duration, WiFiDirectDiscoveryChannel channel = WiFiDirectDiscoveryChannel.FullScan)
813         {
814             if (Globals.IsActivated)
815             {
816                 WiFiDirectManagerImpl.Instance.StartDiscovery(listenOnly, duration, channel);
817             }
818
819             else
820             {
821                 Log.Error(Globals.LogTag, "Wi-Fi direct is not activated");
822                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
823             }
824         }
825
826         /// <summary>
827         /// Cancels discovery process.
828         /// </summary>
829         /// <remarks>
830         /// Discovery must be started by StartDiscovery.
831         /// If this succeeds, DiscoveryStateChanged and PeerFound event will be invoked.
832         /// </remarks>
833         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
834         public static void CancelDiscovery()
835         {
836             if (WiFiDirectManager.State == WiFiDirectState.Discovering)
837             {
838                 WiFiDirectManagerImpl.Instance.CancelDiscovery();
839             }
840
841             else
842             {
843                 Log.Error(Globals.LogTag, "Wi-Fi direct discovery is not started");
844                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
845             }
846         }
847
848         /// <summary>
849         /// Gets the information of discovered peers.
850         /// </summary>
851         /// <remarks>
852         /// Wi-Fi Direct must be activated.
853         /// </remarks>
854         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
855         /// <returns> List of discovered peer objects.</returns>
856         public static IEnumerable<WiFiDirectPeer> GetDiscoveredPeers()
857         {
858             if (Globals.IsActivated)
859             {
860                 return WiFiDirectManagerImpl.Instance.GetDiscoveredPeers();
861             }
862
863             else
864             {
865                 return null;
866             }
867         }
868
869         /// <summary>
870         /// Gets the information of connected peers.
871         /// </summary>
872         /// <remarks>
873         /// Wi-Fi Direct must be activated.
874         /// </remarks>
875         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
876         /// <returns> List of connected peer objects.</returns>
877         public static IEnumerable<WiFiDirectPeer> GetConnectedPeers()
878         {
879             if (Globals.IsActivated)
880             {
881                 return WiFiDirectManagerImpl.Instance.GetConnectedPeers();
882             }
883
884             else
885             {
886                 return null;
887             }
888         }
889
890         /// <summary>
891         /// Disconnects all connected links to peers.
892         /// </summary>
893         /// <remarks>
894         /// Wi-Fi Direct must be activated.
895         /// If this succeeds, ConnectionStatusChanged event will be invoked.
896         /// </remarks>
897         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
898         public static void DisconnectAll()
899         {
900             if (Globals.IsActivated)
901             {
902                 WiFiDirectManagerImpl.Instance.DisconnectAll();
903             }
904
905             else
906             {
907                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
908                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
909             }
910         }
911
912         /// <summary>
913         /// Creates a Wi-Fi Direct group and sets up device as the group owner.
914         /// </summary>
915         /// <remarks>
916         /// Wi-Fi Direct must be activated.
917         /// If this succeeds, ConnectionStatusChanged event will be invoked with GroupCreated.
918         /// </remarks>
919         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
920         public static void CreateGroup()
921         {
922             if (Globals.IsActivated)
923             {
924                 WiFiDirectManagerImpl.Instance.CreateGroup();
925             }
926
927             else
928             {
929                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
930                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
931             }
932         }
933
934         /// <summary>
935         /// Destroys the Wi-Fi Direct group owned by a local device.If creating a group is in progress, this API cancels that process.
936         /// </summary>
937         /// <remarks>
938         /// Wi-Fi Direct must be activated.
939         /// If this succeeds, ConnectionStatusChanged event will be invoked with GroupDestroyed.
940         /// </remarks>
941         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
942         public static void DestroyGroup()
943         {
944             if (Globals.IsActivated)
945             {
946                 WiFiDirectManagerImpl.Instance.DestroyGroup();
947             }
948
949             else
950             {
951                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
952                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
953             }
954         }
955
956         /// <summary>
957         /// Set the WPS config PBC as preferred method for connection.
958         /// </summary>
959         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
960         public static void ActivatePushButton()
961         {
962             if (Globals.IsActivated)
963             {
964                 WiFiDirectManagerImpl.Instance.ActivatePushButton();
965             }
966
967             else
968             {
969                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
970                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
971             }
972         }
973
974         /// <summary>
975         /// Gets the supported WPS types.
976         /// </summary>
977         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
978         /// <returns>The list of supported wps types.</returns>
979         public static IEnumerable<WiFiDirectWpsType> GetSupportedWpsTypes()
980         {
981             if (Globals.IsInitialize)
982             {
983                 return WiFiDirectManagerImpl.Instance.GetSupportedWpsTypes();
984             }
985
986             else
987             {
988                 return null;
989             }
990         }
991
992         /// <summary>
993         /// Gets the persistent groups.
994         /// </summary>
995         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
996         /// <returns>List of the persistent group objects.</returns>
997         public static IEnumerable<WiFiDirectPersistentGroup> GetPersistentGroups()
998         {
999             if (Globals.IsInitialize)
1000             {
1001                 return WiFiDirectManagerImpl.Instance.GetPersistentGroups();
1002             }
1003
1004             else
1005             {
1006                 return null;
1007             }
1008         }
1009
1010         /// <summary>
1011         /// Removes a persistent group.
1012         /// </summary>
1013         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
1014         /// <param name="group">Persistent group owner.</param>
1015         public static void RemovePersistentGroup(WiFiDirectPersistentGroup group)
1016         {
1017             if (Globals.IsInitialize)
1018             {
1019                 WiFiDirectManagerImpl.Instance.RemovePersistentGroup(group);
1020             }
1021
1022             else
1023             {
1024                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
1025                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotInitialized);
1026             }
1027         }
1028
1029         /// <summary>
1030         /// Initializes or Deintializes the WiFi-Direct Display(MIRACAST) service.
1031         /// </summary>
1032         /// <remarks>
1033         /// Wi-Fi Direct must be activated.
1034         /// </remarks>
1035         /// <exception cref="NotSupportedException">
1036         /// Thrown during one of the following cases :
1037         /// 1. When the wifidirect is not supported
1038         /// 2. When the wifidirect display feature is not supported
1039         /// </exception>
1040         /// <param name="enable">Enables/Disables service.</param>
1041         public static void InitMiracast(bool enable)
1042         {
1043             if (Globals.IsActivated)
1044             {
1045                 WiFiDirectManagerImpl.Instance.InitMiracast(enable);
1046             }
1047
1048             else
1049             {
1050                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
1051                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
1052             }
1053         }
1054
1055         /// <summary>
1056         /// Enables Wi-Fi Display functionality.
1057         /// </summary>
1058         /// <remarks>
1059         /// Wi-Fi Direct must be activated.
1060         /// </remarks>
1061         /// <exception cref="NotSupportedException">
1062         /// Thrown during one of the following cases :
1063         /// 1. When the wifidirect is not supported
1064         /// 2. When the wifidirect display feature is not supported
1065         /// </exception>
1066         public static void InitDisplay()
1067         {
1068             if (Globals.IsActivated)
1069             {
1070                 WiFiDirectManagerImpl.Instance.InitDisplay();
1071             }
1072
1073             else
1074             {
1075                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
1076                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
1077             }
1078         }
1079
1080         /// <summary>
1081         /// Disable Wi-Fi Display(WFD) functionality and disable the support of WFD Information Element(IE).
1082         /// </summary>
1083         /// <remarks>
1084         /// Wi-Fi Direct must be activated and WFD must be enabled.
1085         /// </remarks>
1086         /// <exception cref="NotSupportedException">
1087         /// Thrown during one of the following cases :
1088         /// 1. When the wifidirect is not supported
1089         /// 2. When the wifidirect display feature is not supported
1090         /// </exception>
1091         public static void DeinitDisplay()
1092         {
1093             if (Globals.IsActivated && Globals.s_isDisplay)
1094             {
1095                 WiFiDirectManagerImpl.Instance.DeinitDisplay();
1096             }
1097
1098             else
1099             {
1100                 Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled");
1101                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
1102             }
1103         }
1104
1105         /// <summary>
1106         /// Sets the Wi-Fi Display parameters for the WFD IE of local device.
1107         /// </summary>
1108         /// <remarks>
1109         /// Wi-Fi Direct must be activated and WFD must be enabled.
1110         /// </remarks>
1111         /// <exception cref="NotSupportedException">
1112         /// Thrown during one of the following cases :
1113         /// 1. When the wifidirect is not supported
1114         /// 2. When the wifidirect display feature is not supported
1115         /// </exception>
1116         /// <param name="type">WFD Device Type: define the Role of WFD device like source or sink.</param>
1117         /// <param name="port">Specifies Session Management Control Port number. It should be 2 bytes(0~65535).</param>
1118         /// <param name="hdcp">CP support bit: (1 = enable the hdcp support, 0 = disable the hdcp support).</param>
1119         public static void SetDisplay(WiFiDirectDisplayType type, int port, int hdcp)
1120         {
1121             if (Globals.IsActivated && Globals.s_isDisplay)
1122             {
1123                 WiFiDirectManagerImpl.Instance.SetDisplay(type, port, hdcp);
1124             }
1125
1126             else
1127             {
1128                 Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled");
1129                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
1130             }
1131         }
1132
1133         /// <summary>
1134         /// Sets the Wi-Fi Display session availability.
1135         /// </summary>
1136         /// <remarks>
1137         /// Wi-Fi Direct must be activated and WFD must be enabled.
1138         /// </remarks>
1139         /// <exception cref="NotSupportedException">
1140         /// Thrown during one of the following cases :
1141         /// 1. When the wifidirect is not supported
1142         /// 2. When the wifidirect display feature is not supported
1143         /// </exception>
1144         /// <param name="availability">Wi-Fi Display session availability.</param>
1145         public static void SetDisplayAvailability(bool availability)
1146         {
1147             if (Globals.IsActivated && Globals.s_isDisplay)
1148             {
1149                 WiFiDirectManagerImpl.Instance.SetDisplayAvailability(availability);
1150             }
1151
1152             else
1153             {
1154                 Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled");
1155                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
1156             }
1157         }
1158
1159         /// <summary>
1160         /// Sets the automatic group removal feature when all peers are disconnected.
1161         /// </summary>
1162         /// <remarks>
1163         /// Wi-Fi Direct must be activated.
1164         /// ConnectionStatusChanged event will be invoked with GroupDestroyed when this feature is enabled and there's no connected group client and if device is group owner.
1165         /// </remarks>
1166         /// <exception cref="NotSupportedException">Thrown when the wifidirect is not supported</exception>
1167         /// <param name="enable">Enables/Disables group removal feature.</param>
1168         public static void SetAutoGroupRemove(bool enable)
1169         {
1170             if (Globals.IsActivated)
1171             {
1172                 WiFiDirectManagerImpl.Instance.SetAutoGroupRemove(enable);
1173             }
1174
1175             else
1176             {
1177                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
1178                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
1179             }
1180         }
1181
1182         /// <summary>
1183         /// Registers the service.
1184         /// </summary>
1185         /// <remarks>
1186         /// Wi-Fi Direct must be activated.
1187         /// If there is any error while registering service, 0 will be returned.
1188         /// </remarks>
1189         /// <exception cref="NotSupportedException">
1190         /// Thrown during one of the following cases :
1191         /// 1. When the wifidirect is not supported
1192         /// 2. When the wifidirect service discovery is not supported
1193         /// </exception>
1194         /// <returns>The service Id of service getting registered.</returns>
1195         /// <param name="type">Type of Wi-Fi Direct Service.</param>
1196         /// <param name="info">Service specific information.</param>
1197         /// <param name="serviceInfo">Service information.</param>
1198         public static uint RegisterService(WiFiDirectServiceType type, string info, string serviceInfo)
1199         {
1200             if (Globals.IsActivated)
1201             {
1202                 return WiFiDirectManagerImpl.Instance.RegisterService(type, info, serviceInfo);
1203             }
1204
1205             else
1206             {
1207                 return 0;
1208             }
1209         }
1210
1211         /// <summary>
1212         /// Deregisters for a service used for WiFi Direct Service Discovery.
1213         /// </summary>
1214         /// <remarks>
1215         /// Wi-Fi Direct must be activated.
1216         /// </remarks>
1217         /// <exception cref="NotSupportedException">
1218         /// Thrown during one of the following cases :
1219         /// 1. When the wifidirect is not supported
1220         /// 2. When the wifidirect service discovery is not supported
1221         /// </exception>
1222         /// <param name="serviceId"> Service ID for which service has to be deregistered.</param>
1223         public static void DeregisterService(uint serviceId)
1224         {
1225             if (Globals.IsActivated)
1226             {
1227                 WiFiDirectManagerImpl.Instance.DeregisterService(serviceId);
1228             }
1229
1230             else
1231             {
1232                 Log.Error(Globals.LogTag, "Wifi-direct is not activated");
1233                 WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted);
1234             }
1235         }
1236     }
1237 }