2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FNet_WifiSystemNetConnection.cpp
19 * @brief This is the implementation file for _WifiSystemNetConnection class.
22 * This file contains the implementation of _WifiSystemNetConnection class.
25 #include <FNetNetConnectionInfo.h>
26 #include <FBaseRtMutexGuard.h>
27 #include <FBaseSysLog.h>
28 #include <FBase_StringConverter.h>
29 #include "FNet_NetTypes.h"
30 #include "FNet_WifiSystemNetConnection.h"
31 #include "FNet_NetConnectionInfoImpl.h"
32 #include "FNet_NetConnectionEvent.h"
33 #include "FNet_NetConnectionEventArg.h"
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Base::Runtime;
41 namespace Tizen { namespace Net {
43 _WifiSystemNetConnection::_WifiSystemNetConnection(void)
48 _WifiSystemNetConnection::~_WifiSystemNetConnection(void)
53 _WifiSystemNetConnection::Construct(void)
56 _NetConnectionInfoImpl* pConnectionInfoImpl = null;
58 r = _SystemNetConnection::Initialize(L"WIFI");
59 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
61 __proxyAddress.Clear();
63 __pIpcProxy = _NetIpcProxy::GetInstance();
64 SysTryCatch(NID_NET, __pIpcProxy != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to initialize IPC client.");
66 r = __pIpcProxy->AddWifiConnectionListener(this, _connectionState, __connectionInfo);
67 SysTryCatch(NID_NET, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
69 _bearerType = __connectionInfo.GetBearerType();
70 pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(__connectionInfo);
71 if (pConnectionInfoImpl != null)
73 __proxyAddress = pConnectionInfoImpl->GetProxyAddress();
76 SysLog(NID_NET, "Wi-Fi connection state[%d] proxy[%ls]", _connectionState, __proxyAddress.GetPointer());
82 _SystemNetConnection::Deinitialize();
88 _WifiSystemNetConnection::Start(_NetConnectionEvent& event)
90 SysLog(NID_NET, "Starting WIFI connection.");
94 MutexGuard locked(*_pLock);
96 if (_connectionState == NET_CONNECTION_STATE_STARTED)
99 SysLog(NID_NET, "WIFI connection is already started.");
101 if (event.GetConnectionState() != NET_CONNECTION_STATE_STARTED)
103 unique_ptr<_NetConnectionEventArg> pEventArg(new (std::nothrow) _NetConnectionEventArg(_NET_CONNECTION_EVENT_TYPE_STARTED, E_SUCCESS));
104 SysTryReturnResult(NID_NET, pEventArg != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
106 event.SetConnectionState(NET_CONNECTION_STATE_STARTED);
107 r = event.FireAsync(*pEventArg);
108 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
114 else if ((_connectionState == NET_CONNECTION_STATE_STARTING) || (_connectionState == NET_CONNECTION_STATE_STOPPING))
117 SysLog(NID_NET, "WIFI connection is waiting response.");
119 if (event.GetConnectionState() != NET_CONNECTION_STATE_STARTING)
121 event.SetConnectionState(NET_CONNECTION_STATE_STARTING);
128 SysLog(NID_NET, "WIFI connection is not active.");
130 SysTryReturnResult(NID_NET, !event.IsManagedSystemConnection(), E_INVALID_CONNECTION, "Wi-Fi activation is not allowed for a managed network connection.");
132 r = __pIpcProxy->StartWifiConnection();
133 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
135 _connectionState = NET_CONNECTION_STATE_STARTING;
136 event.SetConnectionState(NET_CONNECTION_STATE_STARTING);
142 SysLog(NID_NET, "Exit with result[%s].", GetErrorMessage(r));
148 _WifiSystemNetConnection::GetConnectionInfo(NetConnectionInfo& netConnectionInfo)
150 MutexGuard locked(*_pLock);
152 netConnectionInfo = __connectionInfo;
156 _WifiSystemNetConnection::GetProxyAddress(void) const
158 SysLog(NID_NET, "GetProxyAddress() has done with proxy[%ls]", __proxyAddress.GetPointer());
160 return __proxyAddress;
164 _WifiSystemNetConnection::ProcessEvent(result error, _NetConnectionEventType type, NetConnectionState state, const NetConnectionInfo& connectionInfo)
166 _NetConnectionEvent* pEvent = null;
167 _NetConnectionEventArg* pEventArg = null;
168 _NetConnectionInfoImpl* pConnectionInfoImpl = null;
170 SysLog(NID_NET, "Notify wifi connection changed event. type[%d] state[%d]", type, state);
172 MutexGuard locked(*_pLock);
174 _connectionState = state;
175 _bearerType = connectionInfo.GetBearerType();
176 __connectionInfo = connectionInfo;
178 pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(__connectionInfo);
179 if (pConnectionInfoImpl != null)
181 __proxyAddress = pConnectionInfoImpl->GetProxyAddress();
184 unique_ptr<IEnumerator> pEnum(_pEventList->GetEnumeratorN());
187 while (pEnum->MoveNext() == E_SUCCESS)
189 pEvent = dynamic_cast<_NetConnectionEvent*>(pEnum->GetCurrent());
192 if (type == _NET_CONNECTION_EVENT_TYPE_STARTED)
194 if (pEvent->GetConnectionState() == NET_CONNECTION_STATE_STARTING)
196 pEvent->SetConnectionState(NET_CONNECTION_STATE_STARTED);
197 pEventArg = new (std::nothrow) _NetConnectionEventArg(_NET_CONNECTION_EVENT_TYPE_STARTED, E_SUCCESS);
200 else if (type == _NET_CONNECTION_EVENT_TYPE_STOPPED)
202 if (pEvent->GetConnectionState() == NET_CONNECTION_STATE_STARTING)
204 pEvent->SetConnectionState(NET_CONNECTION_STATE_STOPPED);
205 pEventArg = new (std::nothrow) _NetConnectionEventArg(_NET_CONNECTION_EVENT_TYPE_STARTED, error);
207 else if ((pEvent->GetConnectionState() != NET_CONNECTION_STATE_NONE) &&
208 (pEvent->GetConnectionState() != NET_CONNECTION_STATE_STOPPED))
210 pEvent->SetConnectionState(NET_CONNECTION_STATE_STOPPED);
211 pEventArg = new (std::nothrow) _NetConnectionEventArg(_NET_CONNECTION_EVENT_TYPE_STOPPED, error);
219 if (pEventArg != null)
221 pEvent->FireAsync(*pEventArg);
229 _WifiSystemNetConnection::ProcessProxyChangedEvent(const String& proxy)
231 if (_connectionState == NET_CONNECTION_STATE_STARTED)
233 __proxyAddress = proxy;