summaryrefslogtreecommitdiff
path: root/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_request.h
blob: ce95617b6cc062534493b1db4ab1318afcc1d177 (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
/*
 Copyright (c) 2018, 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_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_RC_COMMAND_REQUEST_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_RC_COMMAND_REQUEST_H_

#include "rc_rpc_plugin/resource_allocation_manager.h"
#include "rc_rpc_plugin/rc_app_extension.h"
#include "application_manager/commands/command_request_impl.h"
#include "rc_rpc_plugin/interior_data_cache.h"
#include "rc_rpc_plugin/commands/rc_command_params.h"

namespace rc_rpc_plugin {
namespace app_mngr = application_manager;

enum TypeAccess { kDisallowed, kAllowed };

namespace commands {

class RCCommandRequest : public app_mngr::commands::CommandRequestImpl {
 public:
  /**
   * @brief RCCommandRequest class constructor
   * @param message MessageSharedPtr
   * @param application_manager ApplicationManager
   * @param rpc_service RPCService
   * @param hmi_capabilities HMICapabilities
   * @param policy_handle PolicyHandlerInterface
   * @param resource_allocation_manager ResourceAllocationManager
   **/
  RCCommandRequest(
      const application_manager::commands::MessageSharedPtr& message,
      const RCCommandParams& params);

  virtual ~RCCommandRequest();

  void onTimeOut() OVERRIDE;

  void Run() OVERRIDE;

  virtual void on_event(const app_mngr::event_engine::Event& event) OVERRIDE;

 protected:
  bool is_subscribed;
  bool auto_allowed_;

  ResourceAllocationManager& resource_allocation_manager_;
  InteriorDataCache& interior_data_cache_;
  InteriorDataManager& interior_data_manager_;
  /**
   * @brief AcquireResource try to allocate resource for application
   * In case if allocation of resource is not required, return ALLOWED by
   * default.
   * This method should be overrided in RPCs that requires resource allocation
   * @return result of resource allocation, in case if allocation os not
   * required, return ALLOWED
   */
  virtual AcquireResult::eType AcquireResource(
      const app_mngr::commands::MessageSharedPtr& message) {
    return AcquireResult::ALLOWED;
  }

  /**
   * @brief IsResourceFree check resource state
   * This is default implementation which has to be redefined for RPCs which
   * need to manage the resources
   * @param module_type Resource name
   * @return True if free, otherwise - false
   */
  virtual bool IsResourceFree(const std::string& module_type) const {
    UNUSED(module_type);
    return true;
  }
  /**
   * @brief SetResourceState changes state of resource
   * This is default implementation which has to be redefined for RPCs which
   * need to manage the resources
   * @param module_type Resource name
   * @param State to set for resource
   */
  virtual void SetResourceState(const std::string& module_type,
                                const ResourceState::eType) {}

  /**
   * Checks if module for application is present in policy table
   * @param app_id id of application
   * @param module type Resource name
   * @return kAllowed if module is present, otherwise - kDisallowed
   */
  TypeAccess CheckModule(const std::string& module_type,
                         application_manager::ApplicationSharedPtr app);

  bool auto_allowed() const {
    return auto_allowed_;
  }

  void set_auto_allowed(const bool value) {
    auto_allowed_ = value;
  }

  /**
   * @brief executes specific logic of children classes
   */
  void virtual Execute() = 0;

  void set_disallowed_info(const std::string& info) {
    disallowed_info_ = info;
  }

  virtual std::string ModuleType() = 0;

 private:
  /**
   * @brief CheckDriverConsent checks driver consent defined in policy table
   * @return True if no consent is required, otherwise - false
   */
  bool CheckDriverConsent();

  /**
   * @brief AcquireResources checks whether resource status is busy or not and
   * then tries to acquire this resource. In case driver consent is required -
   * sends consent request to HMI.
   * @return True in case of resource is free and successfully acquired,
   * otherwise false
   */
  bool AcquireResources();
  void SendDisallowed(TypeAccess access);

  /**
   * @brief SendGetUserConsent sends consent request to HMI
   * @param module_type Resource name
   */
  void SendGetUserConsent(const std::string& module_type);
  void ProcessAccessResponse(const app_mngr::event_engine::Event& event);
  bool IsInterfaceAvailable(
      const app_mngr::HmiInterfaces::InterfaceID interface) const;

  std::string disallowed_info_;
};
}
}

#endif  // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_RC_COMMAND_REQUEST_H_