2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file src/common/types/PolicyBucket.h
18 * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
19 * @author Aleksander Zdyb <a.zdyb@samsung.com>
21 * @brief This file defines PolicyBucket type - a policy aggregation
25 #ifndef SRC_COMMON_TYPES_POLICYBUCKET_H_
26 #define SRC_COMMON_TYPES_POLICYBUCKET_H_
32 #include <exceptions/NotImplementedException.h>
33 #include <types/pointers.h>
34 #include <types/Policy.h>
35 #include <types/PolicyBucketId.h>
36 #include <types/PolicyCollection.h>
37 #include <types/PolicyKey.h>
38 #include <types/PolicyType.h>
42 // TODO: Move this const somewhere else
43 const PolicyBucketId defaultPolicyBucketId("");
48 typedef PolicyCollection::value_type value_type;
49 typedef const_policy_iterator const_iterator;
51 // TODO: Review usefulness of ctors
52 PolicyBucket() : m_defaultPolicy(PredefinedPolicyType::DENY) {}
53 PolicyBucket(const PolicyBucketId &id, const PolicyResult &defaultPolicy)
54 : m_defaultPolicy(defaultPolicy), m_id(id) {}
55 PolicyBucket(const PolicyCollection &policies)
56 : m_policyCollection(makePolicyMap(policies)),
57 m_defaultPolicy(PredefinedPolicyType::DENY) {}
58 PolicyBucket(const PolicyBucketId &id,
59 const PolicyResult &defaultPolicy,
60 const PolicyCollection &policies)
61 : m_policyCollection(makePolicyMap(policies)),
62 m_defaultPolicy(defaultPolicy),
65 PolicyBucket filtered(const PolicyKey &key) const;
66 void insertPolicy(PolicyPtr policy);
67 void deletePolicy(const PolicyKey &key);
69 // TODO: Try to change interface, so this method is not needed
70 void deletePolicy(std::function<bool(PolicyPtr)> predicate);
72 static PolicyMap makePolicyMap(const PolicyCollection &policies);
75 PolicyMap m_policyCollection;
76 PolicyResult m_defaultPolicy;
81 const_policy_iterator begin(void) const {
82 return const_policy_iterator(m_policyCollection.begin());
85 const_policy_iterator end(void) const {
86 return const_policy_iterator(m_policyCollection.end());
89 PolicyMap::size_type size(void) const {
90 return m_policyCollection.size();
93 bool empty(void) const {
94 return m_policyCollection.empty();
97 const PolicyResult &defaultPolicy(void) const {
98 return m_defaultPolicy;
101 const PolicyBucketId &id(void) const {
105 // TODO: Consider StorageBackend to be only one to alter this property
106 void setDefaultPolicy(const PolicyResult &defaultPolicy) {
107 m_defaultPolicy = defaultPolicy;
111 } /* namespace Cynara */
112 #endif /* SRC_COMMON_TYPES_POLICYBUCKET_H_ */