summaryrefslogtreecommitdiff
path: root/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h
blob: 41ffefc3cde5ce32186b17dd1a98cfad4c0e51ec (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
#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_VEHICLE_DATA_VALIDATION_MANAGER_IMPL_H
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_VEHICLE_DATA_VALIDATION_MANAGER_IMPL_H

#include <boost/optional.hpp>

#include "smart_objects/smart_object.h"
#include "vehicle_info_plugin/custom_vehicle_data_manager.h"

namespace rpc {
namespace policy_table_interface_base {
class VehicleDataItem;
}
}  // namespace rpc

namespace policy {
class VehicleDataItemProvider;
}

namespace vehicle_info_plugin {
namespace policy_table = rpc::policy_table_interface_base;

typedef boost::optional<const policy_table::VehicleDataItem> OptionalDataItem;
typedef std::set<std::string> VehicleInfoSubscriptions;

class CustomVehicleDataManagerImpl : public CustomVehicleDataManager {
 public:
  CustomVehicleDataManagerImpl(
      policy::VehicleDataItemProvider& vehicle_data_provider);
  bool ValidateVehicleDataItems(
      const smart_objects::SmartObject& msg_params) OVERRIDE;

  virtual smart_objects::SmartObject CreateHMIMessageParams(
      const std::set<std::string>& item_names) OVERRIDE;

  std::string GetVehicleDataItemType(
      const std::string& vehicle_data_item_name) const OVERRIDE;

  virtual void CreateMobileMessageParams(
      smart_objects::SmartObject& msg_params) OVERRIDE;

  bool IsVehicleDataName(const std::string& name) OVERRIDE;

  bool IsVehicleDataKey(const std::string& key) OVERRIDE;

 private:
  bool ValidateVehicleDataItem(
      const smart_objects::SmartObject& item,
      const policy_table::VehicleDataItem& item_schema);

  /**
   * @brief ValidateRPCSpecEnumVehicleDataItem validate custom item in case it
   * `type` of the item is enum from RPCspec
   * @param item item to validate
   * @param item_schema schema for item validation
   * @return true if item is valid according schema, false if not
   */
  bool ValidateRPCSpecEnumVehicleDataItem(
      const smart_objects::SmartObject& item,
      const policy_table::VehicleDataItem& item_schema);

  /**
   * @brief ValidatePODTypeItem validate custom item in case it
   * `type` of the item Plain Old Data (POD)
   * @param item item to validate
   * @param item_schema schema for item validation
   * @return true if item is valid according schema, false if not
   */
  bool ValidatePODTypeItem(const smart_objects::SmartObject& item,
                           const policy_table::VehicleDataItem& item_schema);

  bool ValidateStructTypeItem(
      const ns_smart_device_link::ns_smart_objects::SmartObject& item,
      const policy_table::VehicleDataItem& item_schema);

  const OptionalDataItem FindSchemaByNameNonRecursive(
      const std::string& name) const;
  const OptionalDataItem FindSchemaByKeyNonRecursive(
      const std::string& key) const;
  const OptionalDataItem FindSchemaByNameRecursive(
      const std::string& name) const;
  const OptionalDataItem FindSchemaByKeyRecursive(
      const std::string& name) const;

  policy::VehicleDataItemProvider& vehicle_data_provider_;
};

}  // namespace vehicle_info_plugin

#endif  // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_VEHICLE_DATA_VALIDATION_MANAGER_IMPL_H