Tizen 2.1 base
[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);
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);
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
122 result
123 NetworkManager::GetNetworkSelectionMode(void)
124 {
125     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
126
127     result r = __pNetworkManagerImpl->GetNetworkSelectionMode();
128
129     if (r == E_PRIVILEGE_DENIED)
130     {
131         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
132     }
133     else if( r != E_SUCCESS)
134     {
135         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
136     }
137
138     return r;
139
140 }
141
142 result
143 NetworkManager::SelectNetwork(const NetworkInfo& networkInfo)
144 {
145     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
146
147     result r = __pNetworkManagerImpl->SelectNetwork(networkInfo);
148
149     if (r == E_PRIVILEGE_DENIED)
150     {
151         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
152     }
153     else if( r != E_SUCCESS)
154     {
155         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
156     }
157
158     return r;
159
160 }
161
162 result
163 NetworkManager::SelectNetwork(void)
164 {
165     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
166
167     result r = __pNetworkManagerImpl->SelectNetwork();
168
169     if (r == E_PRIVILEGE_DENIED)
170     {
171         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
172     }
173     else if( r != E_SUCCESS)
174     {
175         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
176     }
177
178     return r;
179
180 }
181
182 result
183 NetworkManager::SearchNetwork(void)
184 {
185     SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
186
187     result r = __pNetworkManagerImpl->SearchNetwork();
188
189     if (r == E_PRIVILEGE_DENIED)
190     {
191         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
192     }
193     else if( r != E_SUCCESS)
194     {
195         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
196     }
197
198     return r;
199 }
200
201 }} // Tizen::Telephony