Fixed NID in macro.
[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 <FSys_SystemInfoImpl.h>
26 #include "FTel_SimStateManagerImpl.h"
27
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Security;
31 using namespace Tizen::System;
32
33
34 namespace Tizen { namespace Telephony
35 {
36 SimStateManager::SimStateManager(void)
37         : __pSimStateManagerImpl(null)
38 {
39 }
40
41 SimStateManager::~SimStateManager(void)
42 {
43         delete __pSimStateManagerImpl;
44 }
45
46 result
47 SimStateManager::Construct(void)
48 {
49         static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
50
51         SysAssertf(__pSimStateManagerImpl == 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         __pSimStateManagerImpl = new (std::nothrow)_SimStateManagerImpl();
61         SysTryReturnResult(NID_TEL, __pSimStateManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
62
63         r = __pSimStateManagerImpl->Construct();
64
65         if (r != E_SUCCESS)
66         {
67                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
68                 delete __pSimStateManagerImpl;
69                 __pSimStateManagerImpl = null;
70         }
71
72         return r;
73 }
74
75 result
76 SimStateManager::SetSimEventListener(ITelephonySimEventListener* pListener)
77 {
78         SysAssertf(__pSimStateManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
79
80         result r = E_SUCCESS;
81
82         r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
83         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "The application does not have the privilege to call this method.");
84
85         r = __pSimStateManagerImpl->SetSimEventListener(pListener);
86         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
87
88         return r;
89 }
90
91 result
92 SimStateManager::GetPinLockSetting(ISimStateManagerGetPinLockSettingResultListener* pListener)
93 {
94         SysAssertf(__pSimStateManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
95
96         result r = E_SUCCESS;
97
98         r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
99         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "The application does not have the privilege to call this method.");
100
101         r = __pSimStateManagerImpl->GetPinLockSetting(pListener);
102         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
103
104         return r;
105 }
106
107 SimState
108 SimStateManager::GetSimState(void) const
109 {
110         SysAssertf(__pSimStateManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
111
112         result r = E_SUCCESS;
113
114         r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
115         SysTryReturn(NID_TEL, r == E_SUCCESS, SIM_STATE_UNKNOWN, r,
116                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
117
118         return __pSimStateManagerImpl->GetSimState();
119 }
120
121 result
122 SimStateManager::GetSimInfo(SimInfo& simInfo) const
123 {
124         SysAssertf(__pSimStateManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
125
126         result r = E_SUCCESS;
127
128         r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
129         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "The application does not have the privilege to call this method.");
130
131         r = __pSimStateManagerImpl->GetSimInfo(simInfo);
132         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
133
134         return r;
135 }
136
137 } } // Tizen::Telephony