Add '-D_SECURE_LOG'
[platform/framework/native/telephony.git] / src / FTelNetworkManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 /**
18  * @file        FTelNetworkManager.cpp
19  * @brief       This is the implementation file for NetworkManager class.
20  */
21
22 #include <FTelNetworkManager.h>
23 #include <FBaseSysLog.h>
24 #include <FTelITelephonyNetworkEventListener.h>
25 #include <FTelITelephonyNetworkSettingListener.h>
26 #include <FSec_AccessController.h>
27 #include <FSys_SystemInfoImpl.h>
28 #include "FTel_NetworkManagerImpl.h"
29
30 using namespace Tizen::Security;
31 using namespace Tizen::System;
32
33 namespace Tizen { namespace Telephony
34 {
35 NetworkManager::NetworkManager(void)
36         : __pNetworkManagerImpl(null)
37 {
38
39 }
40
41 NetworkManager::~NetworkManager(void)
42 {
43         delete __pNetworkManagerImpl;
44 }
45
46 result
47 NetworkManager::Construct(ITelephonyNetworkEventListener* pListener)
48 {
49         static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
50
51         SysAssertf(__pNetworkManagerImpl == null,
52                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
53
54         result r = E_SUCCESS;
55         bool isTelephonySupported = false;
56
57     r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
58     SysTryReturnResult(NID_TEL, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
59
60         __pNetworkManagerImpl = new (std::nothrow) _NetworkManagerImpl();
61         SysTryReturnResult(NID_TEL, __pNetworkManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
62
63         r = __pNetworkManagerImpl->Construct(pListener);
64
65         if (r != E_SUCCESS)
66         {
67                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
68                 delete __pNetworkManagerImpl;
69                 __pNetworkManagerImpl = null;
70         }
71
72         return r;
73 }
74
75 result
76 NetworkManager::GetNetworkStatus(NetworkStatus& networkStatus) const
77 {
78         SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
79
80         result r = E_SUCCESS;
81
82         r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
83         SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
84
85         r = __pNetworkManagerImpl->GetNetworkStatus(networkStatus);
86         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
87
88         return r;
89 }
90
91 result
92 NetworkManager::GetNetworkInfo(NetworkInfo& networkInfo) const
93 {
94         SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
95
96         result r = E_SUCCESS;
97
98         r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
99         SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
100
101
102         r = __pNetworkManagerImpl->GetNetworkInfo(networkInfo);
103         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
104
105         return r;
106 }
107
108
109
110 result
111 NetworkManager::SetNetworkSettingListener(ITelephonyNetworkSettingListener* pListener)
112 {
113     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
114
115     result r = __pNetworkManagerImpl->SetNetworkSettingListener(pListener);
116
117     if (r == E_PRIVILEGE_DENIED)
118     {
119         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
120     }
121     else if( r != E_SUCCESS)
122     {
123         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
124     }
125
126     return r;
127 }
128
129 result
130 NetworkManager::GetNetworkSelectionMode(void)
131 {
132     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
133
134     result r = __pNetworkManagerImpl->GetNetworkSelectionMode();
135
136     if (r == E_PRIVILEGE_DENIED)
137     {
138         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
139     }
140     else if( r != E_SUCCESS)
141     {
142         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
143     }
144
145     return r;
146
147 }
148
149 result
150 NetworkManager::SelectNetwork(const NetworkInfo& networkInfo)
151 {
152     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
153
154     result r = __pNetworkManagerImpl->SelectNetwork(networkInfo);
155
156     if (r == E_PRIVILEGE_DENIED)
157     {
158         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
159     }
160     else if( r != E_SUCCESS)
161     {
162         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
163     }
164
165     return r;
166
167 }
168
169 result
170 NetworkManager::SelectNetwork(void)
171 {
172     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
173
174     result r = __pNetworkManagerImpl->SelectNetwork();
175
176     if (r == E_PRIVILEGE_DENIED)
177     {
178         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
179     }
180     else if( r != E_SUCCESS)
181     {
182         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
183     }
184
185     return r;
186
187 }
188
189 result
190 NetworkManager::SearchNetwork(void)
191 {
192     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
193
194     result r = __pNetworkManagerImpl->SearchNetwork();
195
196     if (r == E_PRIVILEGE_DENIED)
197     {
198         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
199     }
200     else if( r != E_SUCCESS)
201     {
202         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
203     }
204
205     return r;
206 }
207
208 }} // Tizen::Telephony