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.
19 * @file FTel_NetIpcProxy.cpp
20 * @brief This is the implementation file for the %_NetIpcProxy class.
22 * This file contains the implementation of the %_NetIpcProxy class.
27 #include <FBaseSysLog.h>
28 #include <FBaseString.h>
29 #include <FNetNetTypes.h>
30 #include <FIo_IpcClient.h>
31 #include <FNet_ConnectivityIpcMessages.h>
32 #include "FNet_NetAccountDatabase.h"
33 #include "FNet_NetIpcProxy.h"
34 #include "FNet_NetAccountInfoImpl.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Io;
40 namespace Tizen { namespace Net
43 _NetIpcProxy* _NetIpcProxy::__pInstance = null;
45 _NetIpcProxy::_NetIpcProxy(void)
50 _NetIpcProxy::~_NetIpcProxy(void)
55 _NetIpcProxy::Construct(void)
59 unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient());
60 SysTryReturnResult(NID_NET, pIpcClient != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
62 r = pIpcClient->Construct(NET_CONNECTIVITY_IPC_SERVER_NAME, null);
63 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
65 __pIpcClient = move(pIpcClient);
71 _NetIpcProxy::GetInstance(void)
73 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
75 if (__pInstance == null)
78 pthread_once(&onceBlock, InitSingleton);
79 result r = GetLastResult();
82 onceBlock = PTHREAD_ONCE_INIT;
90 _NetIpcProxy::InitSingleton(void)
93 static _NetIpcProxy instance;
95 r = instance.Construct();
96 SysTryReturnVoidResult(NID_NET, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
98 __pInstance = &instance;
102 _NetIpcProxy::UpdateSystemNetAccount(const String& profileName, const NetAccountInfo& netAccountInfo, NetBearerType bearerType)
104 result r = E_SUCCESS;
105 unsigned long ret = 0;
107 unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_updateSystemNetAccount(profileName, netAccountInfo, bearerType, &ret));
108 SysTryReturnResult(NID_NET, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
110 r = __pIpcClient->SendRequest(*pMessage);
111 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
112 SysTryReturnResult(NID_NET, ret == E_SUCCESS, ret, "Propagating.");
117 _NetIpcProxy::GetAppNetAccountId(const String& netProfileName, NetAccountId& netAccountId) const
119 SysLog(NID_NET, "GetAppNetAccountId() has been called with profileName:%ls", netProfileName.GetPointer());
121 result r = E_SUCCESS;
122 int accountId = INVALID_HANDLE;
123 unsigned long ret = 0;
125 unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_getAppNetAccountId(netProfileName, &accountId, &ret));
126 SysTryReturnResult(NID_NET, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
128 r = __pIpcClient->SendRequest(*pMessage);
129 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
130 SysTryReturnResult(NID_NET, ret == E_SUCCESS, ret, "Propagating.");
131 netAccountId = static_cast<NetAccountId>(accountId);
133 SysLog(NID_NET, "GetAppNetAccountId() has done with accountId:%d", netAccountId);
139 _NetIpcProxy::SetNetAccountId(NetAccountId netAccountId, NetAccountId& netAccountId2)
141 SysLog(NID_NET, "SetNetAccountId() has been called with accountId:%d", netAccountId);
143 result r = E_SUCCESS;
144 int accountId = INVALID_HANDLE;
145 unsigned long ret = 0;
147 unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_setNetAccountId(netAccountId, &accountId, &ret));
148 SysTryReturnResult(NID_NET, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
150 r = __pIpcClient->SendRequest(*pMessage);
151 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
152 SysTryReturnResult(NID_NET, ret == E_SUCCESS, ret, "Propagating.");
154 netAccountId2 = static_cast<NetAccountId>(accountId);
156 SysLog(NID_NET, "SetNetAccountId() has done with accountId:%d", netAccountId2);
162 _NetIpcProxy::ResetNetStatistics(NetBearerType bearerType, NetStatisticsInfoType statType)
164 result r = E_SUCCESS;
165 unsigned long ret = 0;
167 SysLog(NID_NET, "ResetNetStatistics() has been called with bearer:%d stat:%d", bearerType, statType);
169 unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_resetNetStatistics(bearerType, statType, &ret));
170 SysTryReturnResult(NID_NET, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
172 r = __pIpcClient->SendRequest(*pMessage);
173 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
174 SysTryReturnResult(NID_NET, ret == E_SUCCESS, ret, "Propagating.");
180 _NetIpcProxy::ResetAllNetStatistics(NetBearerType bearerType)
182 result r = E_SUCCESS;
183 unsigned long ret = 0;
185 SysLog(NID_NET, "ResetAllNetStatistics() has been called with bearer:%d", bearerType);
187 unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_resetAllNetStatistics(bearerType, &ret));
188 SysTryReturnResult(NID_NET, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
190 r = __pIpcClient->SendRequest(*pMessage);
191 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
192 SysTryReturnResult(NID_NET, ret == E_SUCCESS, ret, "Propagating.");