2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FNetNetConnection.h
20 * @brief This is the header file for the %NetConnection class.
22 * This header file contains the declarations of the %NetConnection class.
24 #ifndef _FNET_NET_CONNECTION_H_
25 #define _FNET_NET_CONNECTION_H_
28 #include <FNetNetTypes.h>
29 #include <FNetNetConnectionInfo.h>
30 #include <FNetINetConnectionEventListener.h>
32 namespace Tizen { namespace Net
34 class _NetConnectionImpl;
37 * @class NetConnection
38 * @brief This class provides methods for all the network connections.
42 * The %NetConnection class provides methods for managing the connections for data communication.
44 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/net/managing_network_connections.htm">Managing Network Connections</a>.
46 * The following example demonstrates how to use the %NetConnection class.
53 * using namespace Tizen::Base;
54 * using namespace Tizen::Net;
58 * , public INetConnectionEventListener
64 * void OnNetConnectionStarted(NetConnection& netConnection, result r)
66 * AppLog("OnStarted result=[%s]\n", GetErrorMessage(r));
69 * void OnNetConnectionStopped(NetConnection& netConnection, result r)
71 * AppLog("OnStopped\n");
74 * void OnNetConnectionSuspended(NetConnection& netConnection)
76 * AppLog("OnSuspended\n");
79 * void OnNetConnectionResumed(NetConnection& netConnection)
81 * AppLog("OnResumed\n");
84 * void StartNetConnection(void);
88 * MyClass::StartNetConnection(void)
90 * NetAccountManager netAccountManager;
91 * result r = netAccountManager.Construct();
97 * NetAccountId accountId = netAccountManager.GetNetAccountId(NET_BEARER_PS);
99 * NetConnection* pNetConnection = new NetConnection();
100 * r = pNetConnection->Construct(accountId);
103 * delete pNetConnection;
107 * r = pNetConnection->AddNetConnectionListener(*this);
108 * r = pNetConnection->Start();
110 * // Wait OnNetConnectionStarted() event
112 * delete pNetConnection;
117 class _OSP_EXPORT_ NetConnection
118 : public Tizen::Base::Object
122 * The object is not fully constructed after this constructor is called. @n
123 * For full construction, the Construct() method must be called right after calling this constructor.
130 * This destructor overrides Tizen::Base::Object::~Object().
134 virtual ~NetConnection(void);
137 * Initializes this instance of %NetConnection with the specified parameter. @n
138 * It automatically binds @c netAccountId with %NetConnection. This method registers an application for receiving the network connection events. @n
139 * A network connection is based on a configured network account for starting the connection. In order to start the network connection, create a new
140 * network account or obtain the information of an existing network account, and call the Start() method.
144 * @return An error code
145 * @param[in] netAccountId The index of the network account to which this %NetConnection is bound
146 * @exception E_SUCCESS The method is successful.
147 * @exception E_MAX_EXCEEDED Unable to setup a new connection due to too many existing connections.
148 * @exception E_OUT_OF_MEMORY The memory is insufficient.
149 * @exception E_INVALID_ARG The specified input parameter is invalid.
150 * @exception E_INVALID_ACCOUNT The specified network account ID is invalid.
151 * @exception E_SYSTEM An internal error has occurred.
152 * @exception E_INVALID_PROXY The proxy address is invalid.
153 * @remarks If the application gets the last result by @c E_INVALID_PROXY, it must use a warning pop-up to notify the user.
155 result Construct(NetAccountId netAccountId);
159 * Adds a listener to %NetConnection. @n
160 * The added listener can listen to events when they are fired.
164 * @param[in] listener A reference to INetConnectionEventListener
165 * @return An error code
166 * @exception E_SUCCESS The method is successful.
167 * @exception E_INVALID_STATE This instance may be closed.
168 * @exception E_OUT_OF_MEMORY The memory is insufficient.
169 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
170 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, @n
171 * because the caller thread is a worker thread.
173 result AddNetConnectionListener(INetConnectionEventListener& listener);
176 * Removes the specified INetConnectionEventListener instance.
180 * @param[in] listener A reference to INetConnectionEventListener
181 * @return An error code
182 * @exception E_SUCCESS The method is successful.
183 * @exception E_INVALID_STATE This instance may be closed.
184 * @exception E_OBJ_NOT_FOUND The eventListener is not found.
186 result RemoveNetConnectionListener(INetConnectionEventListener& listener);
189 * Starts the network connection.
194 * @privilege %http://tizen.org/privilege/network.connection
196 * @return An error code
197 * @exception E_SUCCESS The method is successful.
198 * @exception E_INVALID_STATE This instance may be closed.
199 * @exception E_INVALID_ACCOUNT The specified network account ID is invalid.
200 * @exception E_INVALID_CONNECTION The network connection is invalid.
201 * @exception E_ILLEGAL_ACCESS Access is denied to the resources bound to this %NetConnection.
202 * @exception E_INVALID_CONTEXT The context information associated with the network connection account is invalid.
203 * @exception E_SERVICE_LIMITED A connection is already active. Therefore, cannot setup a co-existing network connection.
204 * @exception E_SYSTEM An internal error has occurred.
205 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
206 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
207 * @remarks When the network is available, after calling this method, the INetConnectionEventListener::OnNetConnectionStarted() method of the registered
208 * INetConnectionEventListener instance is called.
214 * Stops the network connection.
219 * @privilege %http://tizen.org/privilege/network.connection
221 * @return An error code
222 * @exception E_SUCCESS The method is successful.
223 * @exception E_INVALID_STATE This instance may be closed.
224 * @exception E_INVALID_CONNECTION The network connection is invalid.
225 * @exception E_ILLEGAL_ACCESS Access is denied to the resources bound to this %NetConnection.
226 * @exception E_INVALID_CONTEXT The context information associated with the network connection account is invalid.
227 * @exception E_SYSTEM An internal error has occurred.
228 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
229 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
230 * @remarks This method stops the network connection of an application. Additionally, it does not ensure immediate disconnection of the network
231 * service (for example, 3G data service or Wi-Fi). The network service remains active till all the applications stop using the network
232 * connection. Once stopped, the network connection can be restarted using the Start() method.
239 * Closes the network connection. @n
240 * All the resources associated with the network connection are freed. This is a forced operation. The Close() method disconnects the network connection
241 * with a remote server or gateway.
246 * @privilege %http://tizen.org/privilege/network.connection
248 * @return An error code
249 * @exception E_SUCCESS The method is successful.
250 * @exception E_INVALID_STATE This instance may be closed.
251 * @exception E_INVALID_CONNECTION The network connection is invalid.
252 * @exception E_ILLEGAL_ACCESS Access is denied to the resources bound to this %NetConnection.
253 * @exception E_INVALID_CONTEXT The context information associated with the network connection account is invalid.
254 * @exception E_SYSTEM An internal error has occurred.
255 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
256 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
257 * @remarks This method stops the network connection of an application. Additionally, it does not ensure immediate disconnection of the network
258 * service (for example, 3G data service or Wi-Fi). The network service remains active till all the applications stop using the network
265 * Gets the network account ID of this instance. @n
266 * This ID is used to establish a network connection with a remote server or gateway.
270 * @return The NetAccountId of this %NetConnection which is bound at Construct(), @n
271 * else @c INVALID_HANDLE if %NetConnection is invalid or not constructed
272 * @exception E_SUCCESS The method is successful.
273 * @exception E_INVALID_STATE This instance may be closed.
274 * @remarks The specific error code can be accessed using the GetLastResult() method.
276 NetAccountId GetNetAccountId(void) const;
279 * Gets the network connection information.
283 * @return A NetConnectionInfo instance specifying information on this network connection
284 * @exception E_SUCCESS The method is successful.
285 * @exception E_INVALID_STATE This instance may be closed.
286 * @exception E_INVALID_CONNECTION The network connection is invalid.
287 * @exception E_ILLEGAL_ACCESS The access is denied.
288 * @exception E_INVALID_CONTEXT The context information associated with the network connection account is invalid.
289 * @exception E_OUT_OF_MEMORY The memory is insufficient.
290 * @exception E_SYSTEM An internal error has occurred.
292 * - The specific error code can be accessed using the GetLastResult() method.
293 * - This method requires a NetConnectionInfo instance reference. The network connection information is only available when the network
294 * connection is "Active". For other states, this method returns @c null.
295 * @warning Do not delete the returned NetConnectionInfo instance. This instance directly references the internal connection information of
298 const NetConnectionInfo* GetNetConnectionInfo(void) const;
302 * Gets the connection information for the specified account.
304 * @brief <i> [Deprecated] </i>
305 * @deprecated This method is deprecated because it is moved to the NetConnectionManager class.
308 * @return A NetConnectionInfo instance specifying information on this network connection, @n
309 * else @c null in case of an error or if an active connection is not found
310 * @param[in] netAccountId The network account
311 * @exception E_SUCCESS The method is successful.
312 * @exception E_INVALID_ACCOUNT The specified network account ID is invalid.
313 * @exception E_OUT_OF_MEMORY The memory is insufficient.
314 * @exception E_SYSTEM An internal error has occurred.
315 * @remarks The specific error code can be accessed using the GetLastResult() method.
318 static NetConnectionInfo* GetNetConnectionInfoN(NetAccountId netAccountId);
322 * Gets a list of all the connection information used by the system.
324 * @brief <i> [Deprecated] </i>
325 * @deprecated This method is deprecated because it is moved to the NetConnectionManager class.
328 * @return A Tizen::Base::Collection::IList containing indexes to NetConnectionInfo in the network, @n
329 * else @c null in case of an error or if an active connection is not found
330 * @exception E_SUCCESS The method is successful.
331 * @exception E_OUT_OF_MEMORY The memory is insufficient.
332 * @exception E_SYSTEM An internal error has occurred (baseband or system).
333 * @remarks The specific error code can be accessed using the GetLastResult() method.
336 static Tizen::Base::Collection::IList* GetAllNetConnectionInfoN(void);
340 * Gets the state of the network connection.
344 * @return The state of the network connection
345 * @exception E_SUCCESS The method is successful.
346 * @exception E_INVALID_STATE This instance may be closed.
347 * @remarks The specific error code can be accessed using the GetLastResult() method.
349 NetConnectionState GetConnectionState(void) const;
353 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
355 * @param[in] value An instance of %NetConnection
357 NetConnection(const NetConnection& rhs);
360 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
362 * @param[in] rhs An instance of %NetConnection
364 NetConnection& operator =(const NetConnection& rhs);
367 _NetConnectionImpl* __pNetConnectionImpl;
369 friend class _NetConnectionImpl;
374 #endif // _FNET_NET_CONNECTION_H_