merge with master
[platform/framework/native/telephony.git] / src / FTelSimStateManager.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        FTelSimStateManager.cpp
19  * @brief       This is the implementation file for SimStateManager class.
20  */
21
22 #include <FBaseSysLog.h>
23 #include <FSec_AccessController.h>
24 #include <FTelSimStateManager.h>
25 #include "FTel_SimStateManagerImpl.h"
26
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Security;
30
31
32 namespace Tizen { namespace Telephony
33 {
34 SimStateManager::SimStateManager(void)
35         : __pSimStateManagerImpl(null)
36 {
37 }
38
39 SimStateManager::~SimStateManager(void)
40 {
41         delete __pSimStateManagerImpl;
42 }
43
44 result
45 SimStateManager::Construct(void)
46 {
47         SysAssertf(__pSimStateManagerImpl == 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         __pSimStateManagerImpl = new (std::nothrow)_SimStateManagerImpl();
53         SysTryReturnResult(NID_TEL, __pSimStateManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
54
55         r = __pSimStateManagerImpl->Construct();
56
57         if (r != E_SUCCESS)
58         {
59                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
60                 delete __pSimStateManagerImpl;
61                 __pSimStateManagerImpl = null;
62         }
63
64         return r;
65 }
66
67 result
68 SimStateManager::SetSimEventListener(ITelephonySimEventListener* pListener)
69 {
70         SysAssertf(__pSimStateManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
71
72         result r = E_SUCCESS;
73
74         r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
75         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application does not have the privilege to call this method.");
76
77         r = __pSimStateManagerImpl->SetSimEventListener(pListener);
78         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
79
80         return r;
81 }
82
83 result
84 SimStateManager::GetPinLockSetting(ISimStateManagerGetPinLockSettingResultListener* pListener)
85 {
86         SysAssertf(__pSimStateManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
87
88         result r = E_SUCCESS;
89
90         r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
91         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application does not have the privilege to call this method.");
92
93         r = __pSimStateManagerImpl->GetPinLockSetting(pListener);
94         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
95
96         return r;
97 }
98
99 SimState
100 SimStateManager::GetSimState(void) const
101 {
102         SysAssertf(__pSimStateManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
103
104         result r = E_SUCCESS;
105
106         r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
107         SysTryReturn(NID_NET, r == E_SUCCESS, SIM_STATE_UNKNOWN, r,
108                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
109
110         return __pSimStateManagerImpl->GetSimState();
111 }
112
113 result
114 SimStateManager::GetSimInfo(SimInfo& simInfo) const
115 {
116         SysAssertf(__pSimStateManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
117
118         result r = E_SUCCESS;
119
120         r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
121         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application does not have the privilege to call this method.");
122
123         r = __pSimStateManagerImpl->GetSimInfo(simInfo);
124         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
125
126         return r;
127 }
128
129 } } // Tizen::Telephony