[C# Connection] Adding C# Connection code
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Connection / Tizen.Network.Connection / ConnectionProfileManager.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.Linq;
20 using System.Text;
21 using System.Threading.Tasks;
22 using System.Collections;
23
24 namespace Tizen.Network.Connection
25 {
26     /// <summary>
27     /// This class is ConnectionProfileManager
28     /// </summary>
29     public class ConnectionProfileManager
30     {
31         /// <summary>
32         /// Adds a new profile
33         /// </summary>
34         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
35         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
36         static public int AddProfile(RequestProfile profile)
37         {
38             return ConnectionInternalManager.AddProfile(profile);
39         }
40
41         /// <summary>
42         /// Gets the list of profile with profile list type
43         /// </summary>
44         /// <privilege>http://tizen.org/privilege/network.get</privilege>
45         static public Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
46         {
47             return ConnectionInternalManager.GetProfileListAsync(type);
48         }
49
50         /// <summary>
51         /// Opens a connection of profile, asynchronously.
52         /// </summary>
53         /// <privilege>http://tizen.org/privilege/network.get</privilege>
54         /// <privilege>http://tizen.org/privilege/network.set</privilege>
55         static public Task<ConnectionError> ConnectProfileAsync(ConnectionProfile profile)
56         {
57             return ConnectionInternalManager.OpenProfileAsync(profile);
58         }
59
60         /// <summary>
61         /// Closes a connection of profile.
62         /// </summary>
63         /// <privilege>http://tizen.org/privilege/network.set</privilege>
64         static public Task<ConnectionError> DisconnectProfileAsync(ConnectionProfile profile)
65         {
66             return ConnectionInternalManager.CloseProfileAsync(profile);
67         }
68
69         /// <summary>
70         /// Removes an existing profile.
71         /// </summary>
72         /// <privilege>http://tizen.org/privilege/network.get</privilege>
73         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
74         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
75         static public int RemoveProfile(ConnectionProfile profile)
76         {
77             Log.Debug(Globals.LogTag, "RemoveProfile. Id: " + profile.Id + ", Name: " + profile.Name + ", Type: " + profile.Type);
78             return ConnectionInternalManager.RemoveProfile(profile);
79         }
80
81         /// <summary>
82         /// Updates an existing profile.
83         /// When a profile is changed, these changes will be not applied to the ConnectionProfileManager immediately.
84         /// When you call this function, your changes affect the ConnectionProfileManager and the existing profile is updated.
85         /// </summary>
86         /// <privilege>http://tizen.org/privilege/network.get</privilege>
87         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
88         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
89         static public int UpdateProfile(ConnectionProfile profile)
90         {
91             return ConnectionInternalManager.UpdateProfile(profile);
92         }
93
94         /// <summary>
95         /// Gets the name of the default profile.
96         /// </summary>
97         /// <privilege>http://tizen.org/privilege/network.get</privilege>
98         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
99         static public ConnectionProfile GetCurrentProfile()
100         {
101             return ConnectionInternalManager.GetCurrentProfile();
102         }
103
104         /// <summary>
105         /// Gets the default profile which provides the given cellular service.
106         /// </summary>
107         /// <privilege>http://tizen.org/privilege/network.get</privilege>
108         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
109         static public ConnectionProfile GetDefaultCellularProfile(CellularServiceType type)
110         {
111             return ConnectionInternalManager.GetDefaultCellularProfile(type);
112         }
113
114         /// <summary>
115         /// Sets the default profile which provides the given cellular service.
116         /// </summary>
117         /// <privilege>http://tizen.org/privilege/network.get</privilege>
118         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
119         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
120         static public Task<ConnectionError> SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
121         {
122             return ConnectionInternalManager.SetDefaultCellularProfile(type, profile);
123         }
124     }
125     
126     /// <summary>
127     /// An extended EventArgs class which contains the state of changed connection profile.
128     /// </summary>
129     public class ConnectionProfileStateEventArgs : EventArgs
130     {
131         private  ConnectionProfileState State;
132
133         internal ConnectionProfileStateEventArgs(ConnectionProfileState state)
134         {
135             State = state;
136         }
137
138         /// <summary>
139         /// The connection profile state.
140         /// </summary>
141         public ConnectionProfileState ConnectionProfileState
142         {
143             get
144             {
145                 return State;
146             }
147         }
148     }
149 }