tizen 2.3.1 release
[framework/web/wearable/wrt-security.git] / ace_client / include / ace-client / ace_client_helper.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file        ace_client_helper.h
18  * @author      Tomasz Swierczek (t.swierczek@samsung.com)
19  * @version     1.0
20  * @brief       This file contains definitions of AceClient helper types and
21  *              functions.
22  */
23 #ifndef WRT_ACE_CLIENT_HELPER_H
24 #define WRT_ACE_CLIENT_HELPER_H
25
26 #include <string>
27 #include <vector>
28 #include <dpl/foreach.h>
29
30 #include <ace-dao-ro/IRequest.h>
31 #include <ace-dao-ro/PreferenceTypes.h>
32
33 #include "ace_client_types.h"
34
35 namespace AceClient {
36
37 AcePreference toAcePreference(AceDB::PreferenceTypes preference)
38 {
39     switch (preference) {
40     case AceDB::PreferenceTypes::PREFERENCE_PERMIT: {
41         return PREFERENCE_PERMIT; }
42     case AceDB::PreferenceTypes::PREFERENCE_DENY: {
43         return PREFERENCE_DENY; }
44     case AceDB::PreferenceTypes::PREFERENCE_DEFAULT: {
45         return PREFERENCE_DEFAULT; }
46     case AceDB::PreferenceTypes::PREFERENCE_BLANKET_PROMPT: {
47         return PREFERENCE_BLANKET_PROMPT; }
48     case AceDB::PreferenceTypes::PREFERENCE_SESSION_PROMPT: {
49         return PREFERENCE_SESSION_PROMPT; }
50     case AceDB::PreferenceTypes::PREFERENCE_ONE_SHOT_PROMPT: {
51         return PREFERENCE_ONE_SHOT_PROMPT; }
52     }
53     return PREFERENCE_DEFAULT;
54 }
55
56 typedef std::vector<std::string> AceParamKeys;
57 typedef std::vector<std::string> AceParamValues;
58
59 class AceFunctionParam
60 {
61   public:
62     virtual ~AceFunctionParam()
63     {
64     }
65
66     void addAttribute(const std::string& key,
67                       const std::string& value)
68     {
69         m_paramMap.insert(std::make_pair(key, value));
70     }
71
72     AceParamKeys getKeys() const
73     {
74         AceParamKeys out;
75         FOREACH (it, m_paramMap) {
76             out.push_back(it->first);
77         }
78         return out;
79     }
80
81     AceParamValues getValues() const
82     {
83         AceParamValues out;
84         FOREACH (it, m_paramMap) {
85             out.push_back(it->second);
86         }
87         return out;
88     }
89
90     static std::string aceFunctionParamToken;
91
92   private:
93     typedef std::multimap<std::string, std::string> ParamMap;
94     ParamMap m_paramMap;
95 };
96
97 typedef std::vector <AceFunctionParam> AceFunctionParams;
98
99 class AceBasicRequest : public AceDB::IRequest {
100   public:
101     AceBasicRequest(const AceSubject& subject,
102                     const AceResource& resource) :
103       m_subject(subject),
104       m_resource(resource)
105     {
106     }
107
108     AceBasicRequest(const AceSubject& subject,
109                     const AceResource& resource,
110                     const AceFunctionParam& param) :
111       m_subject(subject),
112       m_resource(resource),
113       m_param(param)
114     {
115     }
116     virtual const std::string& getSubjectId() const
117     {
118         return m_subject;
119     }
120     virtual const std::string& getResourceId() const
121     {
122         return m_resource;
123     }
124     virtual const AceFunctionParam& getFunctionParam() const
125     {
126         return m_param;
127     }
128
129   private:
130     AceSubject m_subject;
131     AceResource m_resource;
132     AceFunctionParam m_param;
133 };
134
135 typedef std::vector <AceBasicRequest> AceBasicRequests;
136
137 } // namespace AceClient
138
139 #endif // WRT_ACE_CLIENT_HELPER_H