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.cpp
20 * @brief This is the implementation for the %NetConnection class.
23 #include <unique_ptr.h>
24 #include <FNetNetConnection.h>
25 #include <FBaseSysLog.h>
26 #include <FSec_AccessController.h>
27 #include "FNet_NetConnectionImpl.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Security;
34 namespace Tizen { namespace Net
37 NetConnection::NetConnection()
38 : __pNetConnectionImpl(null)
42 NetConnection::~NetConnection(void)
44 delete __pNetConnectionImpl;
45 __pNetConnectionImpl = null;
49 NetConnection::Construct(NetAccountId netAccountId)
53 SysAssertf(__pNetConnectionImpl == null,
54 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
56 unique_ptr<_NetConnectionImpl> pNetConnectionImpl(new (std::nothrow) _NetConnectionImpl());
57 SysTryReturnResult(NID_NET, pNetConnectionImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
59 r = pNetConnectionImpl->Construct(this, netAccountId);
60 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
62 __pNetConnectionImpl = pNetConnectionImpl.release();
68 NetConnection::AddNetConnectionListener(INetConnectionEventListener& listener)
72 SysAssertf(__pNetConnectionImpl != null, "Not yet constructed. Construct() should be called before use.");
74 r = __pNetConnectionImpl->AddNetConnectionListener(listener);
75 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
81 NetConnection::RemoveNetConnectionListener(INetConnectionEventListener& listener)
85 SysAssertf(__pNetConnectionImpl != null, "Not yet constructed. Construct() should be called before use.");
87 r = __pNetConnectionImpl->RemoveNetConnectionListener(listener);
88 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
94 NetConnection::Start(void)
98 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_CONNECTION);
99 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
100 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application is not permitted to call this method.");
102 SysAssertf(__pNetConnectionImpl != null, "Not yet constructed. Construct() should be called before use.");
104 r = __pNetConnectionImpl->Start();
105 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
111 NetConnection::Stop(void)
113 result r = E_SUCCESS;
115 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_CONNECTION);
116 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
117 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application is not permitted to call this method.");
119 SysAssertf(__pNetConnectionImpl != null, "Not yet constructed. Construct() should be called before use.");
121 r = __pNetConnectionImpl->Stop();
122 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
128 NetConnection::Close(void)
130 result r = E_SUCCESS;
132 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_CONNECTION);
133 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
134 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application is not permitted to call this method.");
136 SysAssertf(__pNetConnectionImpl != null, "Not yet constructed. Construct() should be called before use.");
138 r = __pNetConnectionImpl->Close();
139 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
145 NetConnection::GetNetConnectionInfoN(NetAccountId netAccountId)
147 return _NetConnectionImpl::GetNetConnectionInfoN(netAccountId);
151 NetConnection::GetAllNetConnectionInfoN(void)
153 return _NetConnectionImpl::GetAllNetConnectionInfoN();
157 NetConnection::GetNetAccountId(void) const
159 NetAccountId netAccountId = INVALID_HANDLE;
161 SysAssertf(__pNetConnectionImpl != null, "Not yet constructed. Construct() should be called before use.");
163 netAccountId = __pNetConnectionImpl->GetNetAccountId();
168 const NetConnectionInfo*
169 NetConnection::GetNetConnectionInfo(void) const
171 const NetConnectionInfo* pInfo = null;
173 SysAssertf(__pNetConnectionImpl != null, "Not yet constructed. Construct() should be called before use.");
175 pInfo = __pNetConnectionImpl->GetNetConnectionInfo();
181 NetConnection::GetConnectionState(void) const
183 NetConnectionState state = NET_CONNECTION_STATE_NONE;
185 SysAssertf(__pNetConnectionImpl != null, "Not yet constructed. Construct() should be called before use.");
187 state = __pNetConnectionImpl->GetConnectionState();