summaryrefslogtreecommitdiff
path: root/src/components/include/application_manager/request_controller.h
blob: e892762312618b1f2cde48416c42ec4c644c5597 (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
/*
 * Copyright (c) 2020, 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_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_
#define SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_

#include "application_manager/commands/command.h"

#include <memory>

namespace application_manager {
namespace request_controller {

typedef std::shared_ptr<commands::Command> RequestPtr;
/**
 * @brief RequestController class is used to control currently active mobile
 * requests.
 */
class RequestController {
 public:
  /**
   * @brief Result code for addRequest
   */
  enum class TResult {
    SUCCESS = 0,
    TOO_MANY_REQUESTS,
    TOO_MANY_PENDING_REQUESTS,
    NONE_HMI_LEVEL_MANY_REQUESTS,
    INVALID_DATA
  };

  /**
   * @brief Thread pool state
   */
  enum class TPoolState {
    UNDEFINED = 0,
    STARTED,
    STOPPED,
  };

  /**
   * @brief Class destructor
   */
  virtual ~RequestController() {}

  /**
   * @brief Stop request controller internal activities
   */
  virtual void Stop() = 0;

  /**
   * @brief Initialize thread pool
   */
  virtual void InitializeThreadpool() = 0;

  /**
   * @brief Destroy thread pool
   */
  virtual void DestroyThreadpool() = 0;

  /**
   * @brief Check if max request amount wasn't exceed and adds request to queue.
   * @param request Active request to mobile
   * @param hmi_level Current application hmi_level
   * @return Result code
   */
  virtual TResult AddMobileRequest(
      const RequestPtr request,
      const mobile_apis::HMILevel::eType& hmi_level) = 0;

  /**
   * @brief Store HMI request until response or timeout won't remove it
   * @param request Active request to hmi
   * @return Result code
   */
  virtual TResult AddHMIRequest(const RequestPtr request) = 0;

  /**
   * @brief Add notification to collection
   * @param ptr Reference to shared pointer that point on hmi notification
   */
  virtual void AddNotification(const RequestPtr ptr) = 0;

  /**
   * @brief RetainRequestInstance retains request instance by its
   * connection+correlation key
   * @param connection_key connection key of application
   * @param correlation_id correlation id of request
   * @return true if request was rerained. false if the request with such
   * connection+correlation key was not found
   */
  virtual bool RetainRequestInstance(const uint32_t connection_key,
                                     const uint32_t correlation_id) = 0;

  /**
   * @brief RemoveRetainedRequest removes request instance retained before
   * @param connection_key connection key of application
   * @param correlation_id correlation id of request
   */
  virtual bool RemoveRetainedRequest(const uint32_t connection_key,
                                     const uint32_t correlation_id) = 0;

  /**
   * @brief IsStillWaitingForResponse check if request is still waiting for
   * response
   * @param connection_key connection key of application
   * @param correlation_id correlation id of request
   * @return true if request is still waiting for response, otherwise returns
   * false
   */
  virtual bool IsStillWaitingForResponse(
      const uint32_t connection_key, const uint32_t correlation_id) const = 0;

  /**
   * @brief Removes request from queue
   * @param correlation_id Active request correlation ID,
   * @param connection_key Active request connection key (0 for HMI requests)
   * @param function_id Active request function id
   * @param force_terminate if true, request controller will terminate
   * even if not allowed by request
   */
  virtual void TerminateRequest(const uint32_t correlation_id,
                                const uint32_t connection_key,
                                const int32_t function_id,
                                const bool force_terminate = false) = 0;

  /**
   * @brief Removes request from queue
   * @param mobile_correlation_id Active mobile request correlation ID
   * @param connection_key Active request connection key (0 for HMI requests)
   * @param function_id Active request function ID
   */
  virtual void OnMobileResponse(const uint32_t mobile_correlation_id,
                                const uint32_t connection_key,
                                const int32_t function_id) = 0;

  /**
   * @brief Removes request from queue
   * @param mobile_correlation_id Active mobile request correlation ID
   * @param function_id Active request function ID
   */
  virtual void OnHMIResponse(const uint32_t correlation_id,
                             const int32_t function_id) = 0;

  /**
   * @ Add notification to collection
   * @param notification Pointer that points to hmi notification
   */
  virtual void RemoveNotification(const commands::Command* notification) = 0;

  /**
   * @brief Removes all requests from queue for specified application
   * @param app_id Mobile application ID (app_id)
   */
  virtual void TerminateAppRequests(const uint32_t app_id) = 0;

  /**
   * @brief Terminates all requests from HMI
   */
  virtual void TerminateAllHMIRequests() = 0;

  /**
   * @brief Terminates all requests from Mobile
   */
  virtual void TerminateAllMobileRequests() = 0;

  /**
   * @brief Updates request timeout
   * @param app_id Connection key of application
   * @param mobile_correlation_id Correlation ID of the mobile request
   * @param new_timeout_value New timeout to be set in milliseconds
   */
  virtual void UpdateRequestTimeout(const uint32_t app_id,
                                    const uint32_t mobile_correlation_id,
                                    const uint32_t new_timeout) = 0;
  /**
   * @brief Function Should be called when Low Voltage is occured
   */
  virtual void OnLowVoltage() = 0;

  /**
   * @brief Function Should be called when WakeUp occures after Low Voltage
   */
  virtual void OnWakeUp() = 0;

  /**
   * @return true if low voltage state is active
   */
  virtual bool IsLowVoltage() = 0;
};

}  // namespace request_controller
}  // namespace application_manager

#endif  // SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_