summaryrefslogtreecommitdiff
path: root/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h
blob: ee424aecc44e7f4f76d69924447c2cdbda4dcdc4 (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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
/*
 * Copyright (c) 2016, 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_HMI_CAPABILITIES_IMPL_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HMI_CAPABILITIES_IMPL_H_

#include "application_manager/hmi_capabilities.h"
#include "application_manager/hmi_language_handler.h"
#include "interfaces/HMI_API.h"
#include "interfaces/MOBILE_API.h"
#include "json/json.h"
#include "utils/macro.h"
#include "utils/rwlock.h"

namespace application_manager {
class ApplicationManager;

class HMICapabilitiesImpl : public HMICapabilities {
 public:
  /**
   * @ Class constructor
   * @param app_mngr Application manager pointer
   */
  explicit HMICapabilitiesImpl(ApplicationManager& app_mngr);

  /**
   * @brief Class destructor
   */
  virtual ~HMICapabilitiesImpl();

  bool VerifyImageType(const int32_t image_type) const OVERRIDE;

  bool is_vr_cooperating() const OVERRIDE;
  void set_is_vr_cooperating(const bool value) OVERRIDE;

  bool is_tts_cooperating() const OVERRIDE;
  void set_is_tts_cooperating(const bool value) OVERRIDE;

  bool is_ui_cooperating() const OVERRIDE;
  void set_is_ui_cooperating(const bool value) OVERRIDE;

  bool is_navi_cooperating() const OVERRIDE;
  void set_is_navi_cooperating(const bool value) OVERRIDE;

  bool is_ivi_cooperating() const OVERRIDE;
  void set_is_ivi_cooperating(const bool value) OVERRIDE;

  bool is_rc_cooperating() const OVERRIDE;
  void set_is_rc_cooperating(const bool value) OVERRIDE;

  void set_ccpu_version(const std::string& ccpu_version) OVERRIDE;

  const std::string& ccpu_version() const OVERRIDE;

  void set_hardware_version(const std::string& hardware_version) OVERRIDE;

  const std::string& hardware_version() const OVERRIDE;

  bool attenuated_supported() const OVERRIDE;

  void set_attenuated_supported(const bool state) OVERRIDE;

  const hmi_apis::Common_Language::eType active_ui_language() const OVERRIDE;

  void set_active_ui_language(
      const hmi_apis::Common_Language::eType language) OVERRIDE;

  const smart_objects::SmartObjectSPtr ui_supported_languages() const OVERRIDE;

  void set_ui_supported_languages(
      const smart_objects::SmartObject& supported_languages) OVERRIDE;

  const hmi_apis::Common_Language::eType active_vr_language() const OVERRIDE;

  void set_active_vr_language(
      const hmi_apis::Common_Language::eType language) OVERRIDE;

  const smart_objects::SmartObjectSPtr vr_supported_languages() const OVERRIDE;

  void set_vr_supported_languages(
      const smart_objects::SmartObject& supported_languages) OVERRIDE;

  const hmi_apis::Common_Language::eType active_tts_language() const OVERRIDE;

  void set_active_tts_language(
      const hmi_apis::Common_Language::eType language) OVERRIDE;

  const smart_objects::SmartObjectSPtr tts_supported_languages() const OVERRIDE;

  void set_tts_supported_languages(
      const smart_objects::SmartObject& supported_languages) OVERRIDE;

  const smart_objects::SmartObjectSPtr display_capabilities() const OVERRIDE;

  void set_display_capabilities(
      const smart_objects::SmartObject& display_capabilities) OVERRIDE;

  const smart_objects::SmartObjectSPtr system_display_capabilities()
      const OVERRIDE;

  void set_system_display_capabilities(
      const smart_objects::SmartObject& display_capabilities);

  const smart_objects::SmartObjectSPtr hmi_zone_capabilities() const OVERRIDE;

  void set_hmi_zone_capabilities(
      const smart_objects::SmartObject& hmi_zone_capabilities) OVERRIDE;

  const smart_objects::SmartObjectSPtr ui_hmi_capabilities() const OVERRIDE;

  void set_ui_hmi_capabilities(
      const smart_objects::SmartObject& ui_hmi_capabilities) OVERRIDE;

  const smart_objects::SmartObjectSPtr soft_button_capabilities()
      const OVERRIDE;

  void set_soft_button_capabilities(
      const smart_objects::SmartObject& soft_button_capabilities) OVERRIDE;

  const smart_objects::SmartObjectSPtr button_capabilities() const OVERRIDE;

  void set_button_capabilities(
      const smart_objects::SmartObject& button_capabilities) OVERRIDE;

  void set_speech_capabilities(
      const smart_objects::SmartObject& speech_capabilities) OVERRIDE;

  const smart_objects::SmartObjectSPtr speech_capabilities() const OVERRIDE;

  void set_vr_capabilities(
      const smart_objects::SmartObject& vr_capabilities) OVERRIDE;

  const smart_objects::SmartObjectSPtr vr_capabilities() const OVERRIDE;

  void set_audio_pass_thru_capabilities(
      const smart_objects::SmartObject& audio_pass_thru_capabilities) OVERRIDE;

  const smart_objects::SmartObjectSPtr audio_pass_thru_capabilities()
      const OVERRIDE;

  void set_pcm_stream_capabilities(
      const smart_objects::SmartObject& pcm_stream_capabilities) OVERRIDE;

  const smart_objects::SmartObjectSPtr pcm_stream_capabilities() const OVERRIDE;

  const smart_objects::SmartObjectSPtr preset_bank_capabilities()
      const OVERRIDE;

  void set_preset_bank_capabilities(
      const smart_objects::SmartObject& preset_bank_capabilities) OVERRIDE;

  void set_vehicle_type(
      const smart_objects::SmartObject& vehicle_type) OVERRIDE;

  const smart_objects::SmartObjectSPtr vehicle_type() const OVERRIDE;

  const smart_objects::SmartObjectSPtr prerecorded_speech() const OVERRIDE;

  void set_prerecorded_speech(
      const smart_objects::SmartObject& prerecorded_speech) OVERRIDE;

  void set_navigation_supported(const bool supported) OVERRIDE;

  bool navigation_supported() const OVERRIDE;

  void set_phone_call_supported(const bool supported) OVERRIDE;

  bool phone_call_supported() const OVERRIDE;

  void set_video_streaming_supported(const bool supported) OVERRIDE;

  bool video_streaming_supported() const OVERRIDE;

  void set_rc_supported(const bool supported) OVERRIDE;

  bool rc_supported() const OVERRIDE;

  /*
   * @brief Interface to store whether HMI supports driver distraction menu
   * limits
   *
   * @param supported Indicates whether driver distraction menu limits is
   * supported by HMI
   */
  void set_driver_distraction_supported(const bool supported) OVERRIDE;

  /*
   * @brief Retrieves whether HMI supports driver distraction menu limits
   *
   * @return TRUE if it supported, otherwise FALSE
   */
  bool driver_distraction_supported() const OVERRIDE;

  /*
   * @brief Interface used to store information regarding
   * the navigation "System Capability"
   *
   * @param navigation_capability contains information related
   * to the navigation system capability.
   */
  void set_navigation_capability(
      const smart_objects::SmartObject& navigation_capability) OVERRIDE;

  const smart_objects::SmartObjectSPtr navigation_capability() const OVERRIDE;

  void set_phone_capability(
      const smart_objects::SmartObject& phone_capability) OVERRIDE;

  const smart_objects::SmartObjectSPtr phone_capability() const OVERRIDE;

  void set_video_streaming_capability(
      const smart_objects::SmartObject& video_streaming_capability) OVERRIDE;

  const smart_objects::SmartObjectSPtr video_streaming_capability()
      const OVERRIDE;

  void set_rc_capability(
      const smart_objects::SmartObject& rc_capability) OVERRIDE;

  const smart_objects::SmartObjectSPtr rc_capability() const OVERRIDE;

  void set_driver_distraction_capability(
      const smart_objects::SmartObject& driver_distraction_capability) OVERRIDE;

  const smart_objects::SmartObjectSPtr driver_distraction_capability()
      const OVERRIDE;

  void set_seat_location_capability(
      const smart_objects::SmartObject& seat_location_capability) OVERRIDE;

  const smart_objects::SmartObjectSPtr seat_location_capability()
      const OVERRIDE;

  void Init(resumption::LastStateWrapperPtr last_state_wrapper) OVERRIDE;

  HMILanguageHandler& get_hmi_language_handler() OVERRIDE;

  void set_handle_response_for(
      const smart_objects::SmartObject& request) OVERRIDE;

  bool SaveCachedCapabilitiesToFile(
      const std::string& interface_name,
      const std::vector<std::string>& sections_to_update,
      const smart_objects::CSmartSchema& schema) OVERRIDE;

  bool DeleteCachedCapabilitiesFile() const OVERRIDE;

  bool IsRequestsRequiredForCapabilities(
      hmi_apis::FunctionID::eType function_id) const OVERRIDE;

  void UpdateRequestsRequiredForCapabilities(
      hmi_apis::FunctionID::eType requested_interface) OVERRIDE;

  void OnSoftwareVersionReceived(const std::string& ccpu_version) OVERRIDE;

  void UpdateCachedCapabilities() OVERRIDE;

 protected:
  /**
   * @brief Loads capabilities from local file in case SDL was launched
   * without HMI
   *
   * @return TRUE if capabilities loaded successfully, otherwise FALSE.
   */
  bool LoadCapabilitiesFromFile();

  /**
   * @brief function converts json object "languages" to smart object
   * @param json_languages from file hmi_capabilities.json
   * @param languages - the converted object
   *
   */
  void convert_json_languages_to_obj(
      const Json::Value& json_languages,
      smart_objects::SmartObject& languages) const;

  /**
   * @brief function that converts a single entry of audio pass thru capability
   *        to smart object
   * @param capability json object that represents a single entry of audio pass
   *        thru capability
   * @param output_so the converted object
   */
  void convert_audio_capability_to_obj(
      const Json::Value& capability,
      smart_objects::SmartObject& output_so) const;

 private:
  /**
   * @brief Checks are all updating fields are currently saved in the JSON
   * structure
   * @param root_node reference to root node of JSON structure
   * @param interface_name name of interface to check
   * @param sections_to_check reference to list of fields to check
   * @return true if all fields from the list are saved in the JSON structure,
   * otherwise returns false
   */
  bool AllFieldsSaved(const Json::Value& root_node,
                      const std::string& interface_name,
                      const std::vector<std::string>& sections_to_check) const;

  /**
   * @brief Remove received interface from default initialized capabilities
   * @param requested_interface interface which should be removed
   */
  void RemoveFromRequestsRequiredForCapabilities(
      hmi_apis::FunctionID::eType requested_interface);

  /**
   * @brief Gets the currently active language depending on interface
   * @param interface_name name of interface of currently active language
   * @return active language for specified interface
   *
   */
  hmi_apis::Common_Language::eType GetActiveLanguageForInterface(
      const std::string& interface_name) const;

  /**
   * @brief Prepares specified JSON structure according to sections which
   * should be updated
   * @param interface_name name of interface to prepare
   * @param sections_to_update reference to list of fields to update
   * @param schema reference to schema which should be unapplied before field
   * updating
   * @param out_root_node reference to JSON structure to update
   */
  void PrepareJsonValueForSaving(
      const char* interface_name,
      const std::vector<std::string>& sections_to_update,
      const smart_objects::CSmartSchema& schema,
      Json::Value& out_root_node) const;

  /**
   * @brief Prepares specified JSON structure for UI interface according to
   * sections which should be updated
   * @param sections_to_update reference to list of fields to update
   * @param schema reference to schema which should be unapplied before field
   * updating
   * @param out_node reference to JSON structure to update
   */
  void PrepareUiJsonValueForSaving(
      const std::vector<std::string>& sections_to_update,
      const smart_objects::CSmartSchema& schema,
      Json::Value& out_node) const;

  /**
   * @brief Prepares specified JSON structure for VR interface according to
   * sections which should be updated
   * @param sections_to_update reference to list of fields to update
   * @param schema reference to schema which should be unapplied before field
   * updating
   * @param out_node reference to JSON structure to update
   */
  void PrepareVrJsonValueForSaving(
      const std::vector<std::string>& sections_to_update,
      const smart_objects::CSmartSchema& schema,
      Json::Value& out_node) const;

  /**
   * @brief Prepares specified JSON structure for TTS interface according to
   * sections which should be updated
   * @param sections_to_update reference to list of fields to update
   * @param schema reference to schema which should be unapplied before field
   * updating
   * @param out_node reference to JSON structure to update
   */
  void PrepareTtsJsonValueForSaving(
      const std::vector<std::string>& sections_to_update,
      const smart_objects::CSmartSchema& schema,
      Json::Value& out_node) const;

  /**
   * @brief Prepares specified JSON structure for Buttons interface according to
   * sections which should be updated
   * @param sections_to_update reference to list of fields to update
   * @param schema reference to schema which should be unapplied before field
   * updating
   * @param out_node reference to JSON structure to update
   */
  void PrepareButtonsJsonValueForSaving(
      const std::vector<std::string>& sections_to_update,
      const smart_objects::CSmartSchema& schema,
      Json::Value& out_node) const;

  /**
   * @brief Prepares specified JSON structure for VehicleInfo interface
   * according to sections which should be updated
   * @param sections_to_update reference to list of fields to update
   * @param schema reference to schema which should be unapplied before field
   * updating
   * @param out_node reference to JSON structure to update
   */
  void PrepareVehicleInfoJsonValueForSaving(
      const std::vector<std::string>& sections_to_update,
      const smart_objects::CSmartSchema& schema,
      Json::Value& out_node) const;

  /**
   * @brief Prepares specified JSON structure for RC interface according to
   * sections which should be updated
   * @param sections_to_update reference to list of fields to update
   * @param schema reference to schema which should be unapplied before field
   * updating
   * @param out_node reference to JSON structure to update
   */
  void PrepareRCJsonValueForSaving(
      const std::vector<std::string>& sections_to_update,
      const smart_objects::CSmartSchema& schema,
      Json::Value& out_node) const;

  /**
   * @brief Adds appropriate request IDs to the requested required collection
   * according to an interface name
   * @param interface_name An interface name which requests required to send to
   * the HMI
   */
  void AddRequiredRequestsForCapabilities(const std::string& interface_name);

  bool is_vr_cooperating_;
  bool is_tts_cooperating_;
  bool is_ui_cooperating_;
  bool is_navi_cooperating_;
  bool is_ivi_cooperating_;
  bool is_rc_cooperating_;

  bool attenuated_supported_;
  hmi_apis::Common_Language::eType ui_language_;
  hmi_apis::Common_Language::eType vr_language_;
  hmi_apis::Common_Language::eType tts_language_;
  smart_objects::SmartObjectSPtr vehicle_type_;
  smart_objects::SmartObjectSPtr ui_supported_languages_;
  smart_objects::SmartObjectSPtr tts_supported_languages_;
  smart_objects::SmartObjectSPtr vr_supported_languages_;
  /*
   * display_capabilities_ is deprecated and replaced by
   * system_display_capabilities_. For backward compatibility
   * display_capabilities_ is not removed.
   */
  smart_objects::SmartObjectSPtr display_capabilities_;
  smart_objects::SmartObjectSPtr system_display_capabilities_;
  smart_objects::SmartObjectSPtr hmi_zone_capabilities_;
  smart_objects::SmartObjectSPtr ui_hmi_capabilities_;
  smart_objects::SmartObjectSPtr soft_buttons_capabilities_;
  smart_objects::SmartObjectSPtr button_capabilities_;
  smart_objects::SmartObjectSPtr preset_bank_capabilities_;
  smart_objects::SmartObjectSPtr vr_capabilities_;
  smart_objects::SmartObjectSPtr speech_capabilities_;
  smart_objects::SmartObjectSPtr audio_pass_thru_capabilities_;
  smart_objects::SmartObjectSPtr pcm_stream_capabilities_;
  smart_objects::SmartObjectSPtr prerecorded_speech_;
  bool is_navigation_supported_;
  bool is_phone_call_supported_;
  bool is_video_streaming_supported_;
  bool is_rc_supported_;
  bool is_driver_distraction_supported_;
  std::string ccpu_version_;
  std::string hardware_version_;
  smart_objects::SmartObjectSPtr navigation_capability_;
  smart_objects::SmartObjectSPtr phone_capability_;
  smart_objects::SmartObjectSPtr video_streaming_capability_;
  smart_objects::SmartObjectSPtr rc_capability_;
  smart_objects::SmartObjectSPtr driver_distraction_capability_;
  smart_objects::SmartObjectSPtr seat_location_capability_;

  ApplicationManager& app_mngr_;
  HMILanguageHandler hmi_language_handler_;

  mutable sync_primitives::RWLock hmi_capabilities_lock_;
  std::set<hmi_apis::FunctionID::eType> requests_required_for_capabilities_;

  DISALLOW_COPY_AND_ASSIGN(HMICapabilitiesImpl);
};

}  //  namespace application_manager

#endif  //  SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HMI_CAPABILITIES_IMPL_H_