summaryrefslogtreecommitdiff
path: root/SDL_Core/src/components/application_manager/include/application_manager/message_helper.h
blob: a6532169042b1012604e30e65f44c1ca982dcf65 (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
/*
 Copyright (c) 2013, 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_MESSAGE_HELPER_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_MESSAGE_HELPER_H_

#include <map>
#include <string>
#include "interfaces/MOBILE_API.h"
#include "utils/macro.h"
#include "connection_handler/device.h"
#include "application_manager/application.h"

namespace NsSmartDeviceLink {
namespace NsSmartObjects {
class SmartObject;
}
}

namespace application_manager {
namespace mobile_api = mobile_apis;
namespace smart_objects = NsSmartDeviceLink::NsSmartObjects;

/*
 * @brief Typedef for HMI TextFieldName type
 */
typedef enum {
  MAIN_FILED1 = 0,
  MAIN_FILED2,
  MAIN_FILED3,
  MAIN_FILED4,
  STATUS_BAR,
  MEDIA_CLOCK,
  MEDIA_TRACK,
  ALERT_TEXT1,
  ALERT_TEXT2,
  ALERT_TEXT3,
  SCROLLABLE_MSG_BODY,
  INITIAL_INTERACTION_TEXT,
  NAVI_TEXT1,
  NAVI_TEXT2,
  ETA,
  TOTAL_DISTANCE,
  NAVI_TEXT,
  AUDIO_DISPLAY_TEXT1,
  AUDIO_DISPLAY_TEXT2,
  SLIDER_HADER,
  SLIDER_FOOTEER
} TextFieldName;

/*
 * @brief Typedef for the vehicle data types that can
 * be published and subscribed to
 */
typedef enum {
  GPS = 0,
  SPEED,
  RPM,
  FUELLEVEL,
  FUELLEVEL_STATE,
  FUELCONSUMPTION,
  EXTERNTEMP,
  VIN,
  PRNDL,
  TIREPRESSURE,
  ODOMETER,
  BELTSTATUS,
  BODYINFO,
  DEVICESTATUS,
  ECALLINFO,
  AIRBAGSTATUS,
  EMERGENCYEVENT,
  CLUSTERMODESTATUS,
  MYKEY,
  BRAKING,
  WIPERSTATUS,
  HEADLAMPSTATUS,
  BATTVOLTAGE,
  ENGINETORQUE,
  ACCPEDAL,
  STEERINGWHEEL
} VehicleDataType;

/*
 * @brief Typedef for VehicleData
 *
 * @param const char* Name of the parameter in mobile request
 * @param VehicleDataType Enum for vehicle data
 */
typedef std::map<const char*, VehicleDataType> VehicleData;

/**
 * @brief MessageHelper class
 **/
class MessageHelper {
  public:

    typedef std::vector<smart_objects::SmartObject*> SmartObjectList;

    /**
     * @brief Sends HMI status notification to mobile
     *
     *@param application_impl application with changed HMI status
     *
     **/
    static void SendHMIStatusNotification(const Application& application_impl);

    /**
     * @brief Sends OnAppRegistered notification to HMI
     *
     *@param application_impl application with changed HMI status
     *
     **/
    static void SendOnAppRegisteredNotificationToHMI(
      const Application& application_impl);

    /**
     * @brief Sendss Vr Command 'Help'
     */
    static void SendHelpVrCommand();

    /**
     * @brief Create mobile HashUpdateNotification
     */
    static smart_objects::SmartObject* GetHashUpdateNotification(const uint32_t app_id);

    /**
     * @brief Sends to mobile HashUpdateNotification
     */
    static void SendHashUpdateNotification(const uint32_t app_id);

    /**
     * @brief Removes Vr Synonyms of application name from HMI
     * when unregistering application.
     */
    static void SendRemoveVrCommandsOnUnregisterApp(ApplicationConstSharedPtr app);

    /**
     * @brief Sends OnAppInterfaceUnregistered notification to mobile
     *
     *@param connection_key Connection key
     *@param reason Reason
     *
     **/
    static void SendOnAppInterfaceUnregisteredNotificationToMobile(
      int32_t connection_key,
      mobile_apis::AppInterfaceUnregisteredReason::eType reason);

    /*
     * @brief Retrieve vehicle data map for param name in mobile request
     * to VehicleDataType
     *
     * @return VehicleData reference
     */
    static const VehicleData& vehicle_data();

    static smart_objects::SmartObject* CreateBlockedByPoliciesResponse(
      mobile_apis::FunctionID::eType function_id,
      mobile_apis::Result::eType result, uint32_t correlation_id,
      uint32_t connection_key);

    /*
     * @brief Prepare GetDeviceListResponse
     *
     *
     * @param devices Devices list
     *
     */
    static smart_objects::SmartObject* CreateDeviceListSO(
      const connection_handler::DeviceList& devices);

    static smart_objects::SmartObject* CreateModuleInfoSO(
      uint32_t function_id);

    static smart_objects::SmartObject* CreateSetAppIcon(
      const std::string& path_to_icon, uint32_t app_id);

    /**
     * @brief Sends IVI subscriptions
     */
    static bool SendIVISubscribtions(const uint32_t app_id);

    /**
     * @brief Sends IVI subscriptions
     */
    static SmartObjectList GetIVISubscribtionRequests(const uint32_t app_id);

    static void SendAppDataToHMI(ApplicationConstSharedPtr app);
    static void SendGlobalPropertiesToHMI(ApplicationConstSharedPtr app);
    static SmartObjectList CreateGlobalPropertiesRequestsToHMI(ApplicationConstSharedPtr app);

    static smart_objects::SmartObject* CreateAppVrHelp(ApplicationConstSharedPtr app);

    static void SendShowRequestToHMI(ApplicationConstSharedPtr app);
    static void SendShowConstantTBTRequestToHMI(ApplicationConstSharedPtr app);
    static void SendAddCommandRequestToHMI(ApplicationConstSharedPtr app);
    static SmartObjectList CreateAddCommandRequestToHMI(ApplicationConstSharedPtr app);

    static void SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app);
    static void SendAddVRCommandToHMI(
      uint32_t cmd_id, const smart_objects::SmartObject& vr_commands,
      uint32_t app_id);

    static smart_objects::SmartObject* CreateAddVRCommandToHMI(
      uint32_t cmd_id, const smart_objects::SmartObject& vr_commands,
      uint32_t app_id);

    static void SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app);
    static SmartObjectList CreateAddSubMenuRequestToHMI(ApplicationConstSharedPtr app);

    static void RemoveAppDataFromHMI(ApplicationSharedPtr app);
    static void SendOnSdlCloseNotificationToHMI();
    static void SendOnAppUnregNotificationToHMI(ApplicationConstSharedPtr app);
    static void SendDeleteCommandRequestToHMI(ApplicationConstSharedPtr app);
    static void SendDeleteSubMenuRequestToHMI(ApplicationConstSharedPtr app);
    static void ResetGlobalproperties(ApplicationSharedPtr app);

    static void SendActivateAppToHMI(uint32_t const app_id);


    /*
     * @brief Sends notification to HMI to start video streaming
     *
     * @param url             URL for video streamng
     * @param connection_key  Application connection key
     *
     */
    static void SendNaviStartStream(const std::string& url, int32_t connection_key);

    /*
     * @brief Sends notification to HMI to stop video streaming
     *
     * @param connection_key  Application connection key
     *
     */
    static void SendNaviStopStream(int32_t connection_key);

    /*
     * @brief Sends notification to HMI to start audio streaming
     *
     * @param url             URL for video streamng
     * @param connection_key  Application connection key
     *
     */
    static void SendAudioStartStream(const std::string& url, int32_t connection_key);

    /*
     * @brief Sends notification to HMI to stop audio streaming
     *
     * @param connection_key  Application connection key
     *
     */
    static void SendAudioStopStream(int32_t connection_key);

    /*
     * @brief Sends notification to HMI to stop audioPathThru
     *
     * @param connection_key  Application connection key
     *
     * @return TRUE on SUCCES otherwise return FALSE
     */
    static bool SendStopAudioPathThru();

    static smart_objects::SmartObject* CreateNegativeResponse(
      uint32_t connection_key, int32_t function_id, uint32_t correlation_id,
      int32_t result_code);

    /*
     * @brief Verify image and add image file full path
     *
     * @param SmartObject with image
     *
     * @param app current application
     *
     * @return verification result
     *
     */
    static mobile_apis::Result::eType VerifyImage(smart_objects::SmartObject& image,
                            ApplicationConstSharedPtr app);

    /*
     * @brief Finds "Image" structure in request and verify image file presence
     *                      in Core.
     *
     * @param message SmartObject with request
     *
     * @param app current application
     *
     * @return verification result
     *
     */
    static mobile_apis::Result::eType VerifyImageFiles(
      smart_objects::SmartObject& message, ApplicationConstSharedPtr app);

    static bool VerifySoftButtonText(smart_objects::SmartObject& soft_button);

    static mobile_apis::Result::eType ProcessSoftButtons(
                                  smart_objects::SmartObject& message_params,
                                  ApplicationConstSharedPtr app);

    static bool PrintSmartObject(const smart_objects::SmartObject& object);

    template<typename From, typename To>
    static To ConvertEnumAPINoCheck(const From& input) {
      return static_cast<To>(input);
    }

  private:
    static smart_objects::SmartObject* CreateChangeRegistration(
      int32_t function_id, int32_t language, uint32_t app_id);
    static smart_objects::SmartObject* CreateGeneralVrCommand();
    static void SendRemoveCommandToHMI(int32_t function_id, int32_t command_id,
                                       uint32_t app_id);
    MessageHelper();

    static const VehicleData vehicle_data_;
    DISALLOW_COPY_AND_ASSIGN(MessageHelper);
};

}  // namespace application_manager

#endif  // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_MESSAGE_HELPER_H_