09af74ec9d252a56a3d94f024dee855b505e2a2b
[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 "FTel_NetworkManagerImpl.h"
28
29 using namespace Tizen::Security;
30
31 namespace Tizen { namespace Telephony
32 {
33 NetworkManager::NetworkManager(void)
34         : __pNetworkManagerImpl(null)
35 {
36
37 }
38
39 NetworkManager::~NetworkManager(void)
40 {
41         delete __pNetworkManagerImpl;
42 }
43
44 result
45 NetworkManager::Construct(ITelephonyNetworkEventListener* pListener)
46 {
47         SysAssertf(__pNetworkManagerImpl == null,
48                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
49
50         result r = E_SUCCESS;
51
52         __pNetworkManagerImpl = new (std::nothrow) _NetworkManagerImpl();
53         SysTryReturnResult(NID_TEL, __pNetworkManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
54
55         r = __pNetworkManagerImpl->Construct(pListener);
56
57         if (r != E_SUCCESS)
58         {
59                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
60                 delete __pNetworkManagerImpl;
61                 __pNetworkManagerImpl = null;
62         }
63
64         return r;
65 }
66
67 result
68 NetworkManager::GetNetworkStatus(NetworkStatus& networkStatus) const
69 {
70         SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
71
72         result r = E_SUCCESS;
73
74         r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
75         SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
76
77         r = __pNetworkManagerImpl->GetNetworkStatus(networkStatus);
78         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
79
80         return r;
81 }
82
83 result
84 NetworkManager::GetNetworkInfo(NetworkInfo& networkInfo) const
85 {
86         SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
87
88         result r = E_SUCCESS;
89
90         r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
91         SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
92
93
94         r = __pNetworkManagerImpl->GetNetworkInfo(networkInfo);
95         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
96
97         return r;
98 }
99
100
101
102 result
103 NetworkManager::SetNetworkSettingListener(ITelephonyNetworkSettingListener* pListener)
104 {
105     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
106
107     result r = __pNetworkManagerImpl->SetNetworkSettingListener(pListener);
108
109     if (r == E_PRIVILEGE_DENIED)
110     {
111         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
112     }
113     else if( r != E_SUCCESS)
114     {
115         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
116     }
117
118     return r;
119 }
120
121 result
122 NetworkManager::GetNetworkSelectionMode(void)
123 {
124     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
125
126     result r = __pNetworkManagerImpl->GetNetworkSelectionMode();
127
128     if (r == E_PRIVILEGE_DENIED)
129     {
130         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
131     }
132     else if( r != E_SUCCESS)
133     {
134         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
135     }
136
137     return r;
138
139 }
140
141 result
142 NetworkManager::SelectNetwork(const NetworkInfo& networkInfo)
143 {
144     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
145
146     result r = __pNetworkManagerImpl->SelectNetwork(networkInfo);
147
148     if (r == E_PRIVILEGE_DENIED)
149     {
150         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
151     }
152     else if( r != E_SUCCESS)
153     {
154         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
155     }
156
157     return r;
158
159 }
160
161 result
162 NetworkManager::SelectNetwork(void)
163 {
164     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
165
166     result r = __pNetworkManagerImpl->SelectNetwork();
167
168     if (r == E_PRIVILEGE_DENIED)
169     {
170         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
171     }
172     else if( r != E_SUCCESS)
173     {
174         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
175     }
176
177     return r;
178
179 }
180
181 result
182 NetworkManager::SearchNetwork(void)
183 {
184     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
185
186     result r = __pNetworkManagerImpl->SearchNetwork();
187
188     if (r == E_PRIVILEGE_DENIED)
189     {
190         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
191     }
192     else if( r != E_SUCCESS)
193     {
194         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
195     }
196
197     return r;
198 }
199
200 }} // Tizen::Telephony