2 Copyright (c) 2013, Ford Motor Company
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following
13 disclaimer in the documentation and/or other materials provided with the
16 Neither the name of the Ford Motor Company nor the names of its contributors
17 may be used to endorse or promote products derived from this software
18 without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
33 #ifndef SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_HELPER_H_
34 #define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_HELPER_H_
36 #include "./functions.h"
37 #include "utils/shared_ptr.h"
38 #include "policy/policy_types.h"
41 class PolicyManagerImpl;
43 const std::string kAllowedKey = "allowed";
44 const std::string kUserDisallowedKey = "userDisallowed";
46 namespace policy_table = rpc::policy_table_interface_base;
48 typedef policy_table::Strings::const_iterator StringsConstItr;
49 typedef policy_table::ApplicationPolicies::const_iterator AppPoliciesConstItr;
50 typedef policy_table::HmiLevels::const_iterator HMILevelsConstItr;
51 typedef policy_table::Parameters::const_iterator ParametersConstItr;
52 typedef policy_table::FunctionalGroupings::const_iterator FuncGroupConstItr;
54 typedef policy_table::ApplicationPolicies::value_type AppPoliciesValueType;
55 typedef policy_table::Rpc::value_type RpcValueType;
56 typedef policy_table::Strings::value_type StringsValueType;
59 * @brief Helper struct to compare functional group names
61 struct CompareGroupName {
62 explicit CompareGroupName(const StringsValueType& group_name);
63 bool operator()(const StringsValueType& group_name_to_compare) const;
65 const StringsValueType& group_name_;
69 * @brief Used for compare of policies parameters mapped with specific
72 bool operator!=(const policy_table::ApplicationParams& first,
73 const policy_table::ApplicationParams& second);
76 * @brief Helper struct for checking changes of application policies, which
77 * come with update along with current data snapshot
78 * In case of policies changed for some application, current data will be
79 * updated and notification will be sent to application
81 struct CheckAppPolicy {
82 CheckAppPolicy(PolicyManagerImpl* pm,
83 const utils::SharedPtr<policy_table::Table> update);
84 bool HasSameGroups(const AppPoliciesValueType& app_policy,
85 AppPermissions* perms) const;
86 bool IsNewAppication(const std::string& application_id) const;
87 void SendNotification(const AppPoliciesValueType& app_policy) const;
88 void SendOnPendingPermissions(const AppPoliciesValueType& app_policy,
89 AppPermissions permissions) const;
90 bool IsAppRevoked(const AppPoliciesValueType& app_policy) const;
91 bool NicknamesMatch(const std::string app_id,
92 const AppPoliciesValueType& app_policy) const;
93 bool operator()(const AppPoliciesValueType& app_policy);
95 PolicyManagerImpl* pm_;
96 const utils::SharedPtr<policy_table::Table> update_;
100 * @brief Fill notification data with merged rpc permissions for hmi levels and
103 struct FillNotificationData {
104 FillNotificationData(Permissions& data, GroupConsent group_state);
105 bool operator()(const RpcValueType& rpc);
106 void UpdateHMILevels(const policy_table::HmiLevels& in_hmi,
107 std::set<HMILevel>& out_hmi);
108 void UpdateParameters(const policy_table::Parameters& in_parameters,
109 std::set<Parameter>& out_parameter);
111 void ExcludeDisAllowed();
112 std::string current_key_;
117 * @brief Check for functional group presence and pass it to helper struct,
118 * which gather data for notification sending
120 struct ProcessFunctionalGroup {
121 ProcessFunctionalGroup(
122 const policy_table::FunctionalGroupings& fg,
123 const std::vector<FunctionalGroupPermission>& group_permissions,
125 bool operator()(const StringsValueType& group_name);
127 GroupConsent GetGroupState(const std::string& group_name);
128 const policy_table::FunctionalGroupings& fg_;
130 const std::vector<FunctionalGroupPermission>& group_permissions_;
133 struct FunctionalGroupInserter {
134 FunctionalGroupInserter(const policy_table::Strings& preconsented_groups,
135 PermissionsList& list);
136 void operator()(const StringsValueType& group_name);
138 PermissionsList& list_;
139 const policy_table::Strings& preconsented_;
143 * @brief Fills FunctionalGroupPermissions with provided params
144 * @param ids Functional group ids from DB
145 * @param names Group names and user_consent_prompt
146 * @param state User consent for group
147 * @param permissions Struct to be filled with provided params
149 void FillFunctionalGroupPermissions(
150 FunctionalGroupIDs& ids,
151 FunctionalGroupNames& names,
153 std::vector<FunctionalGroupPermission>& permissions);
157 #endif // SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_HELPER_H_