sync with master
[platform/framework/native/appfw.git] / src / security / FSecPrivilegeInfo.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 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 /**
19  * @file        FSecPrivilegeInfo.cpp
20  * @brief       This is the implementation for the PrivilegeInfo class.
21  */
22
23 #include <new>
24
25 #include <FSecPrivilegeInfo.h>
26
27 #include <FBaseSysLog.h>
28 #include <FSec_AccessController.h>
29 #include "FSec_PrivilegeInfoImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace Security
36 {
37
38 _PrivilegeInfoImpl* PrivilegeInfo::__pPrivilegeInfoImpl = null;
39
40 PrivilegeInfo::PrivilegeInfo(void)
41         : __pImpl(null)
42 {
43
44 }
45
46 PrivilegeInfo::~PrivilegeInfo(void)
47 {
48
49 }
50
51 result
52 PrivilegeInfo::Construct(const Tizen::Base::String& privilegeId)
53 {
54         result r = E_SUCCESS;
55
56         SysAssertf(__pImpl == null,
57                     "Already constructed. Calling Construct() twice or more on a same in stance is not allowed for this class.");
58
59         __pImpl = new (std::nothrow) _PrivilegeInfoImpl;
60     SysTryReturnResult(NID_SEC, __pImpl != null, E_OUT_OF_MEMORY, "");
61
62     r = __pImpl->Construct(privilegeId);
63     SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
64
65     return r;
66
67 CATCH:
68     delete __pImpl;
69     __pImpl = null;
70
71     return r;
72
73 }
74
75 String
76 PrivilegeInfo::GetId(void) const
77 {
78         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
79
80         return __pImpl->GetId();
81 }
82
83
84 String
85 PrivilegeInfo::GetDisplayName(void) const
86 {
87         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
88
89         return __pImpl->GetDisplayName();
90 }
91
92 String
93 PrivilegeInfo::GetDescription(void) const
94 {
95         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
96
97         return __pImpl->GetDescription();
98 }
99
100
101
102 String
103 PrivilegeInfo::GetName(const String& privilege)
104 {
105         String name;
106
107         if (__pPrivilegeInfoImpl == null)
108         {
109                 __pPrivilegeInfoImpl = _PrivilegeInfoImpl::GetInstance();
110         }
111         SysTryReturn(NID_SEC, __pPrivilegeInfoImpl != null, name, E_SYSTEM, "An unexpected system error occurred.");
112
113         name = __pPrivilegeInfoImpl->GetName(privilege);
114
115         return name;
116 }
117
118 String
119 PrivilegeInfo::GetDescription(const String& privilege)
120 {
121         String description;
122
123         if (__pPrivilegeInfoImpl == null)
124         {
125                 __pPrivilegeInfoImpl = _PrivilegeInfoImpl::GetInstance();
126         }
127         SysTryReturn(NID_SEC, __pPrivilegeInfoImpl != null, description, E_SYSTEM, "An unexpected system error occurred.");
128
129         description = __pPrivilegeInfoImpl->GetDescription(privilege);
130
131         return description;
132 }
133
134 }} // Tizen::Security