summaryrefslogtreecommitdiff
path: root/src/components/application_manager/include/application_manager/resumption/resumption_data.h
blob: ee9972b98cc0edffaaa1b9f88768e0c57a08d79f (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
 * Copyright (c) 2019, 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_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_H_

#include "application_manager/application.h"
#include "application_manager/application_manager.h"
#include "smart_objects/smart_object.h"
#include "utils/macro.h"

namespace application_manager {
class ApplicationManagerSettings;
}

namespace resumption {

namespace app_mngr = application_manager;

/**
 * @brief Abstract class which provides an interface for storage/restore
 * application data. Contains methods for receiving application data
 * from application.
 */

class ResumptionData {
 public:
  /**
   * @brief Constructor of ResumptionData
   */
  ResumptionData(
      const application_manager::ApplicationManager& application_manager);

  /**
   * @brief Destructor of ResumptionData
   */
  virtual ~ResumptionData() {}

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

  /**
   * @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 = 0;

  /**
   * @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 = 0;

  /**
   * @brief Increments ignition counter for all registered applications
   * and remember ign_off time stamp
   */
  virtual void IncrementIgnOffCount() = 0;

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

  /**
   * @brief Increments global ignition on counter
   * by 1
   */
  virtual void IncrementGlobalIgnOnCounter() = 0;

  /**
   * @brief Get the global ignition on counter
   * @return the global ignition on counter
   */
  virtual uint32_t GetGlobalIgnOnCounter() const = 0;

  /**
   * @brief Resets global ignition on counter
   */
  virtual void ResetGlobalIgnOnCount() = 0;

  /**
   * @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 = 0;

  /**
   * @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 = 0;

  /**
   * @brief Remove application from list of saved applications
   * @param policy_app_id application which 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) = 0;

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

  /**
   * @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 = 0;

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

  /**
   * @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) = 0;

  /**
   * @brief Init storage
   */
  virtual bool Init() = 0;

  /**
   * @brief Drops data related to applicaton data resumption
   * @param device_id Device ID
   * @param app_id Application ID
   * @return true, if dropped successfully, otherwise - false
   */
  virtual bool DropAppDataResumption(const std::string& device_id,
                                     const std::string& app_id) = 0;

  /**
   * @brief Persist saves resumption data on file system
   */
  virtual void Persist() = 0;

 protected:
  /**
   * @brief Retrieves of commands from application
   * @param application contains application of which selection commands
   * @return list of commands
   */
  smart_objects::SmartObject GetApplicationCommands(
      app_mngr::ApplicationConstSharedPtr application) const;

  /**
   * @brief Retrieves of submenues from application
   * @param application contains application of which selection submenues
   * @return list of submenues
   */
  smart_objects::SmartObject GetApplicationSubMenus(
      app_mngr::ApplicationConstSharedPtr application) const;

  /**
   * @brief Retrieves of interactionChoiceSet from application
   * @param application contains application of which selection
   * interactionChoiceSet
   * @return list of interaction choice set
   */
  smart_objects::SmartObject GetApplicationInteractionChoiseSets(
      app_mngr::ApplicationConstSharedPtr application) const;

  /**
   * @brief Retrieves of global properties from application
   * @param application contains application of which selection global
   * properties
   * @return global properties of application
   */
  smart_objects::SmartObject GetApplicationGlobalProperties(
      app_mngr::ApplicationConstSharedPtr application) const;

  /**
   * @brief Retrieves of subscriptions from application
   * @param application contains application of which selection subscriptions
   * @return subscriptions of application
   */
  smart_objects::SmartObject GetApplicationSubscriptions(
      app_mngr::ApplicationConstSharedPtr application) const;

  /**
   * @brief Retrieves of files from application
   * @param application contains application of which selection files
   * @return files of application
   */
  smart_objects::SmartObject GetApplicationFiles(
      app_mngr::ApplicationConstSharedPtr application) const;

  /**
   * @brief Retrieves of windows info from list of available window
   * @param application contains list of available windows
   * @return windows info from list of available window
   */
  smart_objects::SmartObject GetApplicationWidgetsInfo(
      app_mngr::ApplicationConstSharedPtr application) const;

  /**
   * @brief checks pointer that it is not equal NULL
   * @param ptr - contains pointer which need to check
   * @return smartObject from pointer
   */
  smart_objects::SmartObject PointerToSmartObj(
      const smart_objects::SmartObjectSPtr ptr) const;

  /**
   * @brief creates smart object containing window info
   * @param window_id window id
   * @param window_type window type
   * @param window_name window name
   * @param window_optional_params_map collection containing optional params for
   * creating window
   * @return smart object with window data
   */
  smart_objects::SmartObject CreateWindowInfoSO(
      const application_manager::WindowID window_id,
      const mobile_apis::WindowType::eType window_type,
      const application_manager::WindowParamsMap& window_optional_params_map)
      const;

  /**
   * @brief Creates smart array from received data
   * @param first - iterator points to beginning of the data
   * @param last - iterator points to ending of the data
   * @param key - contains smart array's name
   * @param result - will contain created array
   */
  template <typename Iterator>
  void Append(Iterator first,
              Iterator last,
              const std::string& key,
              smart_objects::SmartObject& result) const {
    int i = 0;
    result[key] = smart_objects::SmartObject(smart_objects::SmartType_Array);
    while (first != last) {
      result[key][i++] = *first;
      ++first;
    }
  }
  const application_manager::ApplicationManager& application_manager_;
};
}  // namespace resumption

#endif  // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_H_