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 //delete default constructor in order to prevent creation of buckets with no id
53 PolicyBucket() = delete;
54 PolicyBucket(const PolicyBucketId &id,
55 const PolicyResult &defaultPolicy = PredefinedPolicyType::DENY)
56 : m_defaultPolicy(defaultPolicy),
58 PolicyBucket(const PolicyBucketId &id,
59 const PolicyCollection &policies)
60 : m_policyCollection(makePolicyMap(policies)),
61 m_defaultPolicy(PredefinedPolicyType::DENY),
63 PolicyBucket(const PolicyBucketId &id,
64 const PolicyResult &defaultPolicy,
65 const PolicyCollection &policies)
66 : m_policyCollection(makePolicyMap(policies)),
67 m_defaultPolicy(defaultPolicy),
70 PolicyBucket filtered(const PolicyKey &key) const;
71 void insertPolicy(PolicyPtr policy);
72 void deletePolicy(const PolicyKey &key);
74 // TODO: Try to change interface, so this method is not needed
75 void deletePolicy(std::function<bool(PolicyPtr)> predicate);
77 static PolicyMap makePolicyMap(const PolicyCollection &policies);
80 PolicyMap m_policyCollection;
81 PolicyResult m_defaultPolicy;
86 const_policy_iterator begin(void) const {
87 return const_policy_iterator(m_policyCollection.begin());
90 const_policy_iterator end(void) const {
91 return const_policy_iterator(m_policyCollection.end());
94 PolicyMap::size_type size(void) const {
95 return m_policyCollection.size();
98 bool empty(void) const {
99 return m_policyCollection.empty();
102 const PolicyResult &defaultPolicy(void) const {
103 return m_defaultPolicy;
106 const PolicyBucketId &id(void) const {
110 // TODO: Consider StorageBackend to be only one to alter this property
111 void setDefaultPolicy(const PolicyResult &defaultPolicy) {
112 m_defaultPolicy = defaultPolicy;
116 } /* namespace Cynara */
117 #endif /* SRC_COMMON_TYPES_POLICYBUCKET_H_ */