pull in new policy updates
[profile/ivi/smartdevicelink.git] / src / components / policy / src / policy / include / policy / pt_representation.h
1 /*
2  Copyright (c) 2013, Ford Motor Company
3  All rights reserved.
4
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7
8  Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10
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
14  distribution.
15
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.
19
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.
31  */
32
33 #ifndef SRC_COMPONENTS_POLICY_INCLUDE_POLICY_PT_REPRESENTATION_H_
34 #define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_PT_REPRESENTATION_H_
35
36 #include <vector>
37 #include <string>
38 #include "policy/policy_types.h"
39 #include "./types.h"
40
41 namespace policy_table = rpc::policy_table_interface_base;
42
43 namespace policy {
44
45 /**
46  * @struct Data about vehicle
47  */
48 struct VehicleData {
49   const std::string vehicle_make;
50   const std::string vehicle_model;
51   int vehicle_year;
52 };
53
54 enum InitResult {
55   NONE = 0,
56   EXISTS,
57   SUCCESS,
58   FAIL
59 };
60
61 class PTRepresentation {
62   public:
63     virtual ~PTRepresentation() {
64     }
65
66     /**
67      * @brief Check if specified RPC for specified application
68      * has permission to be executed in specified HMI Level
69      * and also its permitted params.
70      * @param app_id Id of application provided during registration
71      * @param hmi_level Current HMI Level of application
72      * @param rpc Name of RPC
73      * @return CheckPermissionResult containing flag if HMI Level is allowed
74      * and list of allowed params.
75      */
76     virtual CheckPermissionResult CheckPermissions(const PTString& app_id,
77         const PTString& hmi_level,
78         const PTString& rpc) = 0;
79
80     /**
81      * @brief Returns true if Policy Table was not updated yet
82      * from preloaded pt file.
83      */
84     virtual bool IsPTPreloaded() = 0;
85
86     /**
87      * Gets number of ignition cycles before next update policy table
88      * @return number of ignition cycles
89      */
90     virtual int IgnitionCyclesBeforeExchange() = 0;
91
92     /**
93      * Gets value in kilometers before next update policy table
94      * @param current value in kilometers from the odometers
95      * @return value in kilometers
96      */
97     virtual int KilometersBeforeExchange(int current) = 0;
98
99     /**
100      * @brief Sets kilometers and days after epoch, that passed for recieved
101      * successful PT UPdate
102      */
103     virtual bool SetCountersPassedForSuccessfulUpdate(int kilometers,
104         int days_after_epoch) = 0;
105
106     /**
107      * Gets value in days before next update policy table
108      * @param current value in days after epoch
109      * @return value in days
110      */
111     virtual int DaysBeforeExchange(int current) = 0;
112
113     /**
114      * @brief Increment number of ignition cycles since last exchange by 1
115      */
116     virtual void IncrementIgnitionCycles() = 0;
117
118     /**
119      * @brief Reset number of ignition cycles since last exchange to 0
120      */
121     virtual void ResetIgnitionCycles() = 0;
122
123     /**
124      * @brief Returns timeout to wait for a response of PT update
125      * @return value in seconds
126      */
127     virtual int TimeoutResponse() = 0;
128
129     /**
130      * @brief Returns number of seconds between each try of sending PTS
131      * @param seconds Return value: array of 5 elements
132      * @return bool Success of operation
133      */
134     virtual bool SecondsBetweenRetries(std::vector<int>* seconds) = 0;
135
136     /**
137      * @brief Get information about vehicle
138      */
139     virtual VehicleData GetVehicleData() = 0;
140
141     /**
142      * @brief Get message text for displaying/pronouncing for user
143      * dependent on language and context.
144      * @param msg_codes Context of message (Driver distraction, Grant permission etc)
145      * @param language Language of the message
146      * @return Array of appropriate messages parameters
147      */
148     virtual std::vector<UserFriendlyMessage> GetUserFriendlyMsg(
149       const std::vector<std::string>& msg_codes, const std::string& language) = 0;
150
151     /**
152      * @brief Get list of URL to send PTS to
153      * @param service_type If URLs for specific service are preset,
154      * return them otherwise default URLs.
155      */
156     virtual EndpointUrls GetUpdateUrls(int service_type) = 0;
157
158     /**
159      * @brief Get allowed number of notifications
160      * depending on application priority.
161      * @param priority Priority of application
162      */
163     virtual int GetNotificationsNumber(policy_table::Priority priority) = 0;
164
165     /**
166      * @brief Initialized Policy Table (load)
167      * @return bool Success of operation
168      */
169     virtual InitResult Init() = 0;
170
171     /**
172      * @brief Close policy table
173      * @return bool Success of operation
174      */
175     virtual bool Close() = 0;
176
177     /**
178      * @brief Removes policy table content.
179      * @return bool Success of operation
180      */
181     virtual bool Clear() = 0;
182
183     /**
184      * Drops policy table (schema and content)
185      * @return true if successfully
186      */
187     virtual bool Drop() = 0;
188
189     /**
190      * @brief Get snapshot of Policy Table
191      * including app_policies, functional_groups,
192      * device_info, statistics, excluding user messages
193      * @return Generated structure for obtaining Json string.
194      */
195     virtual utils::SharedPtr<policy_table::Table> GenerateSnapshot() const = 0;
196
197     /**
198      * Saves policy table in storage
199      * @param table policy table
200      * @return true if successfully
201      */
202     virtual bool Save(const policy_table::Table& table) = 0;
203
204     /**
205      * Gets flag updateRequired
206      * @return true if update is required
207      */
208     virtual bool UpdateRequired() const = 0;
209
210     /**
211      * Saves flag updateRequired
212      */
213     virtual void SaveUpdateRequired(bool value) = 0;
214
215     /*
216      Retrieves data from app_policies about app on its registration:
217      app_id - id of registered app; all outputs are filled in only if not null
218      output: nicknames Synonyms for application
219      output: app_types Section on HMI where app can appear (Navigation, Phone etc)
220      */
221     virtual bool GetInitialAppData(const std::string& app_id,
222                                    StringArray* nicknames = NULL,
223                                    StringArray* app_types = NULL) = 0;
224
225     /**
226      * Checks if the application is revoked
227      * @param app_id application id
228      * @return true if application is revoked
229      */
230     virtual bool IsApplicationRevoked(const std::string& app_id) const = 0;
231
232     /**
233      * @brief Get functional groupings from DB
234      * @param groups Known functional groupings
235      * @return true, if succeeded, otherwise - false
236      */
237     virtual bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups) = 0;
238
239     /**
240      * Checks if the application is represented in policy table
241      * @param app_id application id
242      * @return true if application is represented in policy table
243      */
244     virtual bool IsApplicationRepresented(const std::string& app_id) const = 0;
245
246     /**
247      * Checks if the application has default policy
248      * @param app_id application id
249      * @return true if application has default policy
250      */
251     virtual bool IsDefaultPolicy(const std::string& app_id) const = 0;
252
253     /**
254          * Checks if the application has pre_data policy
255          * @param app_id application id
256          * @return true if application has pre_data policy
257          */
258     virtual bool IsPredataPolicy(const std::string& app_id) const = 0;
259
260     /**
261      * Sets default policy for application
262      * @param app_id application id
263      * @return true if success
264      */
265     virtual bool SetDefaultPolicy(const std::string& app_id) = 0;
266 };
267
268 }  //  namespace policy
269
270 #endif  //  SRC_COMPONENTS_POLICY_INCLUDE_POLICY_PT_REPRESENTATION_H_