summaryrefslogtreecommitdiff
path: root/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h
blob: a4f83fff44482d64bbd8d66201d901af9f027473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 * Copyright (c) 2015, Ford Motor Company
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided with the
 * distribution.
 *
 * Neither the name of the Ford Motor Company nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_JSON_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_JSON_H_

#include "application_manager/resumption/resumption_data.h"
#include "json/json.h"
#include "resumption/last_state_wrapper.h"

namespace resumption {

/**
 * @brief class contains logic for representation application data in
 * json file
 */
class ResumptionDataJson : public ResumptionData {
 public:
  /**
   * @brief Constructor of ResumptionDataJson
   */
  ResumptionDataJson(
      resumption::LastStateWrapperPtr last_state_wrapper,
      const application_manager::ApplicationManager& application_manager);

  /**
   * @brief allows to destroy ResumptionDataJson object
   */
  virtual ~ResumptionDataJson();

  /**
   * @brief Save application persistent info for future resuming on json format
   * @param application is application witch need to be saved
   */
  virtual void SaveApplication(
      app_mngr::ApplicationSharedPtr application) OVERRIDE;

  /**
   * @brief Checks if saved data of applications have hmi app id
   * @param hmi_app_id - hmi application id
   * @return true if exist, false otherwise
   */
  virtual bool IsHMIApplicationIdExist(uint32_t hmi_app_id) const;

  /**
   * @brief Retrieves HMI app ID for the given mobile app ID
   * and device ID from stored information.
   * @param policy_app_id - mobile application id
   * @param device_id - contains id of device on which is running application
   * @return HMI app ID
   */
  virtual uint32_t GetHMIApplicationID(const std::string& policy_app_id,
                                       const std::string& device_id) const;
  /**
   * @brief Increments ignition counter for all registered applications
   * and remember ign_off time stamp
   */
  void IncrementIgnOffCount() FINAL;

  /**
   * @brief Decrements ignition counter for all registered applications
   */
  void DecrementIgnOffCount() FINAL;

  /**
   * @brief Retrieves hash ID for the given mobile app ID
   * and device ID from stored information.
   * @param policy_app_id - mobile application id
   * @param device_id - contains id of device on which is running application
   * @param hash_id - parameter which will contain HASH id from saved
   * application
   * @return TRUE if application will be found in saved data otherwise
   * returns FALSE
   */
  virtual bool GetHashId(const std::string& policy_app_id,
                         const std::string& device_id,
                         std::string& hash_id) const;

  /**
   * @brief Retrieves data of saved application for the given mobile app ID
   * and device ID
   * @param policy_app_id - mobile application id
   * @param device_id - contains id of device on which is running application
   * @param saved_app - parameter which will contain data of saved application
   * @return TRUE if application will be found in saved data otherwise
   * returns FALSE
   */
  virtual bool GetSavedApplication(const std::string& policy_app_id,
                                   const std::string& device_id,
                                   smart_objects::SmartObject& saved_app) const;

  /**
   * @brief Remove application from list of saved applications
   * @param policy_app_id application witch need to be removed
   * @param device_id - contains id of device on which is running application
   * @return return true, if success, otherwise return false
   */
  virtual bool RemoveApplicationFromSaved(const std::string& policy_app_id,
                                          const std::string& device_id);

  /**
   * @brief Get the last ignition off time from LastState
   * @return the last ignition off time from LastState
   */
  virtual int64_t GetIgnOffTime() const;

  void IncrementGlobalIgnOnCounter() OVERRIDE;

  uint32_t GetGlobalIgnOnCounter() const OVERRIDE;

  void ResetGlobalIgnOnCount() OVERRIDE;

  /**
   * @brief Checks if saved data have application
   * @param policy_app_id - mobile application id
   * @param device_id - contains id of device on which is running application
   * @return index if data of application exists, otherwise returns -1
   */
  virtual ssize_t IsApplicationSaved(const std::string& policy_app_id,
                                     const std::string& device_id) const;

  /**
   * @brief Retrieves data from saved application
   * @param  will be contain data for resume_ctrl
   */
  virtual void GetDataForLoadResumeData(
      smart_objects::SmartObject& saved_data) const;

  /**
   * @brief Updates HMI level of saved application
   * @param policy_app_id - mobile application id
   * @param device_id - contains id of device on which is running application
   * @param hmi_level - contains hmi level for saved application
   */
  virtual void UpdateHmiLevel(const std::string& policy_app_id,
                              const std::string& device_id,
                              mobile_apis::HMILevel::eType hmi_level);

  virtual bool Init();

  bool DropAppDataResumption(const std::string& device_id,
                             const std::string& app_id) OVERRIDE;

  /**
   * @brief Write json resumption info to file system
   */
  void Persist() OVERRIDE;

 private:
  /**
   * @brief GetFromSavedOrAppend allows to get existed record about application
   * or adds the new one.
   * @param policy_app_id application id.
   * @param device_id unique id of device.
   * @param dictionary - data dictionary where all necessary info stored
   * @return the reference to the record in applications array.
   */
  Json::Value& GetFromSavedOrAppend(const std::string& policy_app_id,
                                    const std::string& device_id,
                                    Json::Value& dictionary) const;

  /**
   * @brief Get applications for resumption of LastState
   * @param dictionary - data dictionary where all necessary info stored
   * @return applications for resumption of LastState
   */
  Json::Value& GetSavedApplications(Json::Value& dictionary) const;

  /**
   * @brief Get Resumption section of LastState
   * @param dictionary - data dictionary where all necessary info stored
   * @return Resumption section of LastState in Json
   */
  Json::Value& GetResumptionData(Json::Value& dictionary) const;

  /**
   * @brief GetObjectIndex allows to obtain specified object index from
   * applications arrays.
   * @param policy_app_id application id that should be found.
   * @param device_id unique id of device.
   * @return application's index of or -1 if it doesn't exists
   */
  ssize_t GetObjectIndex(const std::string& policy_app_id,
                         const std::string& device_id) const;

  /**
   * @brief Set applications for resumption to LastState
   * @param dictionary - data dictionary where all necessary info stored
   * @parems apps_json applications to write in LastState
   */
  void SetSavedApplication(Json::Value& apps_json, Json::Value& dictionary);

  /**
   * @brief Setup IgnOff time to LastState
   * @param dictionary - data dictionary where all necessary info stored
   * @param ign_off_time - igition off time
   */
  void SetLastIgnOffTime(time_t ign_off_time, Json::Value& dictionary);

  /*
   * @brief Return true if application resumption data is valid,
   * otherwise false
   * @param index application index in the resumption list
   */
  bool IsResumptionDataValid(uint32_t index) const;

  resumption::LastStateWrapperPtr last_state_wrapper_;
  DISALLOW_COPY_AND_ASSIGN(ResumptionDataJson);
};
}  // namespace resumption

#endif  // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_JSON_H_