pull in new policy updates
[profile/ivi/smartdevicelink.git] / src / components / policy / src / policy / include / policy / sql_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_SQL_PT_REPRESENTATION_H_
34 #define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_SQL_PT_REPRESENTATION_H_
35
36 #include <string>
37 #include <vector>
38 #include "policy/pt_representation.h"
39 #include "rpc_base/rpc_base.h"
40 #include "./types.h"
41
42 namespace policy_table = rpc::policy_table_interface_base;
43
44 namespace policy {
45
46 namespace dbms {
47 class SQLDatabase;
48 }  // namespace dbms
49
50 class SQLPTRepresentation : public virtual PTRepresentation {
51   public:
52     SQLPTRepresentation();
53     ~SQLPTRepresentation();
54     virtual CheckPermissionResult CheckPermissions(const PTString& app_id,
55         const PTString& hmi_level,
56         const PTString& rpc);
57
58     virtual bool IsPTPreloaded();
59     virtual int IgnitionCyclesBeforeExchange();
60     virtual int KilometersBeforeExchange(int current);
61     virtual bool SetCountersPassedForSuccessfulUpdate(int kilometers,
62         int days_after_epoch);
63     virtual int DaysBeforeExchange(int current);
64     virtual void IncrementIgnitionCycles();
65     virtual void ResetIgnitionCycles();
66     virtual int TimeoutResponse();
67     virtual bool SecondsBetweenRetries(std::vector<int>* seconds);
68
69     virtual VehicleData GetVehicleData();
70
71     virtual std::vector<UserFriendlyMessage> GetUserFriendlyMsg(
72       const std::vector<std::string>& msg_codes, const std::string& language);
73
74     virtual EndpointUrls GetUpdateUrls(int service_type);
75
76     virtual int GetNotificationsNumber(policy_table::Priority priority);
77     InitResult Init();
78     bool Close();
79     bool Clear();
80     bool Drop();
81     virtual utils::SharedPtr<policy_table::Table> GenerateSnapshot() const;
82     bool Save(const policy_table::Table& table);
83     bool GetInitialAppData(const std::string& app_id, StringArray* nicknames =
84                              NULL,
85                            StringArray* app_hmi_types = NULL);
86     bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups);
87
88   protected:
89     virtual void GatherModuleMeta(policy_table::ModuleMeta* meta) const;
90     virtual void GatherModuleConfig(policy_table::ModuleConfig* config) const;
91     virtual bool GatherUsageAndErrorCounts(
92       policy_table::UsageAndErrorCounts* counts) const;
93     virtual void GatherDeviceData(policy_table::DeviceData* data) const;
94     virtual bool GatherFunctionalGroupings(
95       policy_table::FunctionalGroupings* groups) const;
96     virtual bool GatherConsumerFriendlyMessages(
97       policy_table::ConsumerFriendlyMessages* messages) const;
98     virtual bool GatherApplicationPolicies(
99       policy_table::ApplicationPolicies* apps) const;
100
101     bool GatherAppGroup(const std::string& app_id,
102                         policy_table::Strings* app_groups) const;
103     bool GatherAppType(const std::string& app_id,
104                        policy_table::AppHMITypes* app_types) const;
105     bool GatherNickName(const std::string& app_id,
106                         policy_table::Strings* nicknames) const;
107
108     virtual bool SaveModuleMeta(const policy_table::ModuleMeta& meta);
109     virtual bool SaveModuleConfig(const policy_table::ModuleConfig& config);
110     virtual bool SaveUsageAndErrorCounts(
111       const policy_table::UsageAndErrorCounts& counts);
112     virtual bool SaveDeviceData(const policy_table::DeviceData& devices);
113     virtual bool SaveFunctionalGroupings(
114       const policy_table::FunctionalGroupings& groups);
115     virtual bool SaveConsumerFriendlyMessages(
116       const policy_table::ConsumerFriendlyMessages& messages);
117     virtual bool SaveApplicationPolicies(
118       const policy_table::ApplicationPolicies& apps);
119
120     virtual bool SaveMessageString(const std::string& type,
121                                    const std::string& lang,
122                                    const policy_table::MessageString& strings);
123
124     bool SaveAppGroup(const std::string& app_id,
125                       const policy_table::Strings& app_groups);
126     bool SaveNickname(const std::string& app_id,
127                       const policy_table::Strings& nicknames);
128     bool SaveAppType(const std::string& app_id,
129                      const policy_table::AppHMITypes& types);
130
131     bool UpdateRequired() const;
132     void SaveUpdateRequired(bool value);
133
134     bool IsApplicationRevoked(const std::string& app_id) const;
135     bool IsApplicationRepresented(const std::string& app_id) const;
136     virtual bool IsDefaultPolicy(const std::string& app_id) const;
137     virtual bool IsPredataPolicy(const std::string& app_id) const;
138     virtual bool SetDefaultPolicy(const std::string& app_id);
139
140     dbms::SQLDatabase* db() const;
141     virtual bool SetIsDefault(const std::string& app_id, bool is_default) const;
142
143   private:
144     static const std::string kDatabaseName;
145     dbms::SQLDatabase* db_;
146
147     bool SaveRpcs(int64_t group_id, const policy_table::Rpc& rpcs);
148     bool SaveServiceEndpoints(const policy_table::ServiceEndpoints& endpoints);
149     bool SaveSecondsBetweenRetries(
150       const policy_table::SecondsBetweenRetries& seconds);
151     bool SaveNumberOfNotificationsPerMinute(
152       const policy_table::NumberOfNotificationsPerMinute& notifications);
153     bool SaveMessageType(const std::string& type);
154     bool SaveLanguage(const std::string& code);
155 };
156 }  //  namespace policy
157
158 #endif  // SRC_COMPONENTS_POLICY_INCLUDE_POLICY_SQL_PT_REPRESENTATION_H_