summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/message_helper.cc
blob: bbe5bad19bdfad25b7ef7375c576369d8d38dd89 (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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
/*
 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.
 */

#include "application_manager/message_helper.h"

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#undef __STDC_FORMAT_MACROS

#include <set>
#include <string>
#include <algorithm>
#include <utility>
#include <map>

#include "application_manager/application.h"
#include "application_manager/application_manager_impl.h"
#include "application_manager/commands/command_impl.h"
#include "application_manager/policies/policy_handler.h"
#include "config_profile/profile.h"
#include "connection_handler/connection_handler_impl.h"
#include "interfaces/MOBILE_API.h"
#include "smart_objects/enum_schema_item.h"
#include "utils/file_system.h"
#include "utils/macro.h"
#include "utils/make_shared.h"
#include "utils/logger.h"
#include "utils/make_shared.h"

#include "formatters/formatter_json_rpc.h"
#include "formatters/CFormatterJsonSDLRPCv2.hpp"
#include "formatters/CFormatterJsonSDLRPCv1.hpp"

namespace application_manager {

CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager")

namespace {

typedef
std::map<std::string, hmi_apis::Common_AppPriority::eType> CommonAppPriorityMap;

CommonAppPriorityMap app_priority_values = {
  {"NORMAL", hmi_apis::Common_AppPriority::NORMAL},
  {"COMMUNICATION", hmi_apis::Common_AppPriority::COMMUNICATION},
  {"EMERGENCY", hmi_apis::Common_AppPriority::EMERGENCY},
  {"NAVIGATION", hmi_apis::Common_AppPriority::NAVIGATION},
  {"NONE", hmi_apis::Common_AppPriority::NONE},
  {"VOICECOM", hmi_apis::Common_AppPriority::VOICE_COMMUNICATION},
  {"INVALID_ENUM", hmi_apis::Common_AppPriority::INVALID_ENUM}
};

const uint32_t GetPriorityCode(const std::string& priority) {
  CommonAppPriorityMap::const_iterator it = app_priority_values.find(priority);
  if (app_priority_values.end() != it) {
    return static_cast<uint32_t>((*it).second);
  }
  return static_cast<uint32_t>(hmi_apis::Common_AppPriority::INVALID_ENUM);
}

bool ValidateSoftButtons(smart_objects::SmartObject& soft_buttons) {
  using namespace smart_objects;
  for (size_t i = 0; i < soft_buttons.length(); ++i) {
    SmartObject& button = soft_buttons[i];

    // Check if image parameter is valid
    if (button.keyExists(strings::image)) {
      SmartObject& buttonImage = button[strings::image];

      // Image name must not be empty and must not contain incorrect
      //character
      if (false == MessageHelper::VerifySoftButtonString(
          buttonImage[strings::value].asString())) {
        return false;
      }
    }
  }
  return true;
}  // namespace

}
std::pair<std::string, VehicleDataType> kVehicleDataInitializer[] = {
  std::make_pair(strings::gps, VehicleDataType::GPS), std::make_pair(
    strings::speed, VehicleDataType::SPEED), std::make_pair(
      strings::rpm, VehicleDataType::RPM), std::make_pair(
        strings::fuel_level, VehicleDataType::FUELLEVEL), std::make_pair(
          strings::fuel_level_state, VehicleDataType::FUELLEVEL_STATE),
  std::make_pair(strings::instant_fuel_consumption,
  VehicleDataType::FUELCONSUMPTION), std::make_pair(
    strings::external_temp, VehicleDataType::EXTERNTEMP), std::make_pair(
      strings::vin, VehicleDataType::VIN), std::make_pair(
        strings::prndl, VehicleDataType::PRNDL), std::make_pair(
          strings::tire_pressure, VehicleDataType::TIREPRESSURE), std::make_pair(
            strings::odometer, VehicleDataType::ODOMETER), std::make_pair(
              strings::belt_status, VehicleDataType::BELTSTATUS), std::make_pair(
                strings::body_information, VehicleDataType::BODYINFO), std::make_pair(
                  strings::device_status, VehicleDataType::DEVICESTATUS), std::make_pair(
                    strings::driver_braking, VehicleDataType::BRAKING), std::make_pair(
                      strings::wiper_status, VehicleDataType::WIPERSTATUS), std::make_pair(
                        strings::head_lamp_status, VehicleDataType::HEADLAMPSTATUS),
  std::make_pair(strings::e_call_info, VehicleDataType::ECALLINFO),
  std::make_pair(strings::airbag_status, VehicleDataType::AIRBAGSTATUS),
  std::make_pair(strings::emergency_event, VehicleDataType::EMERGENCYEVENT),
  std::make_pair(strings::cluster_mode_status,
  VehicleDataType::CLUSTERMODESTATUS), std::make_pair(
    strings::my_key, VehicleDataType::MYKEY),
  /*
   NOT DEFINED in mobile API
   std::make_pair(strings::gps,                      VehicleDataType::BATTVOLTAGE),
   */
  std::make_pair(strings::engine_torque, VehicleDataType::ENGINETORQUE),
  std::make_pair(strings::acc_pedal_pos, VehicleDataType::ACCPEDAL),
  std::make_pair(strings::steering_wheel_angle,
  VehicleDataType::STEERINGWHEEL),
};

const VehicleData MessageHelper::vehicle_data_(
  kVehicleDataInitializer, kVehicleDataInitializer +
  ARRAYSIZE(kVehicleDataInitializer));

#ifdef HMI_DBUS_API
namespace {
struct VehicleInfo_Requests {
  hmi_apis::FunctionID::eType func_id;
  const char* str;
};
static VehicleInfo_Requests ivi_subrequests[] = {
  { hmi_apis::FunctionID::VehicleInfo_SubscribeGps, strings::gps},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeSpeed, strings::speed},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeRpm, strings::rpm},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeFuelLevel, strings::fuel_level},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeFuelLevel_State, strings::fuel_level_state},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeInstantFuelConsumption, strings::instant_fuel_consumption},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeExternalTemperature, strings::external_temp},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeVin, strings::vin},
  { hmi_apis::FunctionID::VehicleInfo_SubscribePrndl, strings::prndl},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeTirePressure, strings::tire_pressure},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeOdometer, strings::odometer},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeBeltStatus, strings::belt_status},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeBodyInformation, strings::body_information},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeDeviceStatus, strings::device_status},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeDriverBraking, strings::driver_braking},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeWiperStatus, strings::wiper_status},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeHeadLampStatus, strings::head_lamp_status},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeEngineTorque, strings::engine_torque},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeAccPedalPosition, strings::acc_pedal_pos},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeSteeringWheelAngle, strings::steering_wheel_angle},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeECallInfo, strings::e_call_info},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeAirbagStatus, strings::airbag_status},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeEmergencyEvent, strings::emergency_event},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeClusterModeStatus, strings::cluster_mode_status},
  { hmi_apis::FunctionID::VehicleInfo_SubscribeMyKey, strings::my_key},
};
}
#endif // #ifdef HMI_DBUS_API

std::string MessageHelper::CommonLanguageToString(
  hmi_apis::Common_Language::eType language) {
  using namespace NsSmartDeviceLink::NsSmartObjects;
  const char* str = 0;
  if (EnumConversionHelper<hmi_apis::Common_Language::eType>::EnumToCString(
        language, &str)) {
    return str ? str : "";
  }
  return std::string();
}

hmi_apis::Common_Language::eType MessageHelper::CommonLanguageFromString(
    const std::string& language) {
  using namespace NsSmartDeviceLink::NsSmartObjects;
  hmi_apis::Common_Language::eType value;
  if (EnumConversionHelper<hmi_apis::Common_Language::eType>::StringToEnum(
        language, &value)) {
    return value;
  }
  return hmi_apis::Common_Language::INVALID_ENUM;
}

uint32_t MessageHelper::GetAppCommandLimit(const std::string& policy_app_id) {

  std::string priority;
  policy::PolicyHandler::instance()->GetPriority(policy_app_id, &priority);
  return policy::PolicyHandler::instance()->GetNotificationsNumber(priority);
}

void MessageHelper::SendHMIStatusNotification(
  const Application& application_impl) {
  LOG4CXX_AUTO_TRACE(logger_);
  smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject;
  if (!notification) {
    // TODO(VS): please add logger.
    return;
  }
  smart_objects::SmartObject& message = *notification;

  message[strings::params][strings::function_id] =
    static_cast<int32_t>(mobile_api::FunctionID::OnHMIStatusID);

  message[strings::params][strings::message_type] =
    static_cast<int32_t>(application_manager::MessageType::kNotification);

  message[strings::params][strings::connection_key] =
    static_cast<int32_t>(application_impl.app_id());

  message[strings::msg_params][strings::hmi_level] =
    static_cast<int32_t>(application_impl.hmi_level());

  message[strings::msg_params][strings::audio_streaming_state] =
    static_cast<int32_t>(application_impl.audio_streaming_state());

  message[strings::msg_params][strings::system_context] =
    static_cast<int32_t>(application_impl.system_context());

  ApplicationManagerImpl::instance()->ManageMobileCommand(notification);
}

void MessageHelper::SendOnAppRegisteredNotificationToHMI(
  const Application& application_impl, bool resumption, bool need_restore_vr) {
  using namespace smart_objects;

  SmartObjectSPtr notification = utils::MakeShared<SmartObject>(SmartType_Map);
  if (!notification) {
    LOG4CXX_ERROR(logger_, "Failed to create smart object");
    return;
  }

  (*notification)[strings::params] = SmartObject(SmartType_Map);
  smart_objects::SmartObject& params = (*notification)[strings::params];
  params[strings::function_id] =
      static_cast<int32_t>(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered);
  params[strings::message_type] = static_cast<int32_t>(kNotification);
  params[strings::protocol_version] = commands::CommandImpl::protocol_version_;
  params[strings::protocol_type] = commands::CommandImpl::hmi_protocol_type_;

  (*notification)[strings::msg_params] = SmartObject(SmartType_Map);
  smart_objects::SmartObject& msg_params = (*notification)[strings::msg_params];
  // Due to current requirements in case when we're in resumption mode
  // we have to always send resumeVRGrammar field.
  if (resumption) {
    msg_params[strings::resume_vr_grammars] = need_restore_vr;
  }

  if (application_impl.vr_synonyms()) {
    msg_params[strings::vr_synonyms] = *(application_impl.vr_synonyms());
  }

  if (application_impl.tts_name()) {
    msg_params[strings::tts_name] = *(application_impl.tts_name());
  }

  std::string priority;
  policy::PolicyHandler::instance()->GetPriority(
        application_impl.mobile_app_id(), &priority);
  if (!priority.empty()) {
    msg_params[strings::priority] = GetPriorityCode(priority);
  }

  smart_objects::SmartObject& application = msg_params[strings::application];
  application[strings::app_name] = application_impl.name();
  application[strings::app_id] = application_impl.app_id();
  application[hmi_response::policy_app_id] = application_impl.mobile_app_id();
  application[strings::icon] = application_impl.app_icon_path();

  const smart_objects::SmartObject* ngn_media_screen_name =
      application_impl.ngn_media_screen_name();
  if (ngn_media_screen_name) {
    application[strings::ngn_media_screen_app_name] = *ngn_media_screen_name;
  }

  application[strings::hmi_display_language_desired] =
      static_cast<int32_t>(application_impl.ui_language());

  application[strings::is_media_application] = application_impl.is_media_application();

  const smart_objects::SmartObject* app_type = application_impl.app_types();

  if (app_type) {
    application[strings::app_type] = *app_type;
  }
  if (application_impl.IsRegistered()) {
    std::vector<std::string> request_types =
        policy::PolicyHandler::instance()->GetAppRequestTypes(
            application_impl.mobile_app_id());

    application[strings::request_type] = SmartObject(SmartType_Array);
    smart_objects::SmartObject& request_array = application[strings::request_type];

    uint32_t index = 0;
    std::vector<std::string>::const_iterator it = request_types.begin();
    for (; request_types.end() != it; ++it) {
      request_array[index] = *it;
      ++index;
    }
  }

  application[strings::device_info] = SmartObject(SmartType_Map);
  smart_objects::SmartObject& device_info = application[strings::device_info];
  std::string device_name;
  std::string mac_address;
  std::string transport_type;
  if (-1 == connection_handler::ConnectionHandlerImpl::instance()->
      GetDataOnDeviceID(application_impl.device(), &device_name,
                        NULL, &mac_address, &transport_type)) {
    LOG4CXX_ERROR(logger_, "Failed to extract information for device "
                  << application_impl.device());
  }
  device_info[strings::name] = device_name;
  device_info[strings::id] = mac_address;

  const policy::DeviceConsent device_consent =
      policy::PolicyHandler::instance()->GetUserConsentForDevice(mac_address);
  device_info[strings::isSDLAllowed] =
      policy::DeviceConsent::kDeviceAllowed == device_consent;

  device_info[strings::transport_type] =
      ApplicationManagerImpl::instance()->GetDeviceTransportType(transport_type);

  DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(notification));
}

smart_objects::SmartObjectSPtr MessageHelper::GetHashUpdateNotification(
  const uint32_t app_id) {

  LOG4CXX_INFO(logger_, "GetHashUpdateNotification" << app_id);
  ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(
                               app_id);

  if (!app) {
    return NULL;
  }

  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  (*message)[strings::params][strings::function_id] =
      mobile_apis::FunctionID::OnHashChangeID;
  (*message)[strings::params][strings::connection_key] = app_id;
  (*message)[strings::params][strings::message_type] =
      static_cast<int32_t>(kNotification);

  return message;
}

smart_objects::SmartObject* MessageHelper::GetLockScreenIconUrlNotification(const uint32_t connection_key) {
  ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(connection_key);
  DCHECK(app.get());

  smart_objects::SmartObject* message = new smart_objects::SmartObject(smart_objects::SmartType_Map);
  (*message)[strings::params][strings::function_id] = mobile_apis::FunctionID::OnSystemRequestID;
  (*message)[strings::params][strings::connection_key] = connection_key;
  (*message)[strings::params][strings::message_type] = mobile_apis::messageType::notification;
  (*message)[strings::params][strings::protocol_type] = commands::CommandImpl::mobile_protocol_type_;
  (*message)[strings::params][strings::protocol_version] = commands::CommandImpl::protocol_version_;

  (*message)[strings::msg_params][strings::request_type] = mobile_apis::RequestType::LOCK_SCREEN_ICON_URL;

  (*message)[strings::msg_params][strings::url] = policy::PolicyHandler::instance()->GetLockScreenIconUrl();


  return message;
}

void MessageHelper::SendLockScreenIconUrlNotification(const uint32_t connection_key) {
  LOG4CXX_INFO(logger_, "SendLockScreenIconUrlNotification");

  smart_objects::SmartObject* so = GetLockScreenIconUrlNotification(connection_key);
  PrintSmartObject(*so);
  DCHECK(ApplicationManagerImpl::instance()->ManageMobileCommand(so));
}

void MessageHelper::SendHashUpdateNotification(const uint32_t app_id) {
  LOG4CXX_AUTO_TRACE(logger_);

  smart_objects::SmartObjectSPtr so = GetHashUpdateNotification(app_id);
  if (so) {
    PrintSmartObject(*so);
    if (!ApplicationManagerImpl::instance()->ManageMobileCommand(so)) {
      LOG4CXX_ERROR_EXT(logger_, "Failed to send HashUpdate notification.");
    } else {
      ApplicationManagerImpl::instance()->resume_controller().ApplicationsDataUpdated();
    }
  }
}

void MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
  int32_t connection_key,
  mobile_api::AppInterfaceUnregisteredReason::eType reason) {

  LOG4CXX_AUTO_TRACE(logger_);

  smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject;
  DCHECK(notification);
  smart_objects::SmartObject& message = *notification;

  message[strings::params][strings::function_id] =
    static_cast<int32_t>(mobile_api::FunctionID::OnAppInterfaceUnregisteredID);

  message[strings::params][strings::message_type] =
    static_cast<int32_t>(kNotification);

  message[strings::params][strings::connection_key] = connection_key;

  message[strings::msg_params][strings::reason] = static_cast<int32_t>(reason);

  if (ApplicationManagerImpl::instance()->ManageMobileCommand(notification)) {
    LOG4CXX_DEBUG(logger_, "Mobile command sent");
  }
  else {
    LOG4CXX_WARN(logger_, "Cannot send mobile command");
  }
}

const VehicleData& MessageHelper::vehicle_data() {
  return vehicle_data_;
}

mobile_apis::HMILevel::eType MessageHelper::StringToHMILevel(
  const std::string& hmi_level) {
  using namespace NsSmartDeviceLink::NsSmartObjects;
  mobile_apis::HMILevel::eType value;
  if (EnumConversionHelper<mobile_apis::HMILevel::eType>::StringToEnum(
        hmi_level, &value)) {
    return value;
  }
  return mobile_apis::HMILevel::INVALID_ENUM;
}

std::string MessageHelper::StringifiedHMILevel(
  mobile_apis::HMILevel::eType hmi_level) {
  using namespace NsSmartDeviceLink::NsSmartObjects;
  const char* str = 0;
  if (EnumConversionHelper<mobile_apis::HMILevel::eType>::EnumToCString(
        hmi_level, &str)) {
    return str;
  }
  return std::string();
}

std::string MessageHelper::StringifiedFunctionID(
  mobile_apis::FunctionID::eType function_id) {
  LOG4CXX_AUTO_TRACE(logger_);
  using namespace NsSmartDeviceLink::NsSmartObjects;
  const char* str = 0;
  if (EnumConversionHelper<mobile_apis::FunctionID::eType>::EnumToCString(
        function_id, &str)) {
    const std::string enum_name = str;
    // Strip 'ID' suffix from value name
    DCHECK(enum_name.length() > 2
           && enum_name.substr(enum_name.length() - 2) == "ID");
    return enum_name.substr(0, enum_name.length() - 2);
  }
  return std::string();
}

#ifdef HMI_DBUS_API
namespace {
const std::map<std::string, uint16_t> create_get_vehicle_data_args() {
  std::map<std::string, uint16_t> rc;
  rc.insert(std::make_pair(strings::gps, hmi_apis::FunctionID::VehicleInfo_GetGpsData));
  rc.insert(std::make_pair(strings::speed, hmi_apis::FunctionID::VehicleInfo_GetSpeed));
  rc.insert(std::make_pair(strings::rpm, hmi_apis::FunctionID::VehicleInfo_GetRpm));
  rc.insert(std::make_pair(strings::fuel_level, hmi_apis::FunctionID::VehicleInfo_GetFuelLevel));
  rc.insert(std::make_pair(strings::fuel_level_state, hmi_apis::FunctionID::VehicleInfo_GetFuelLevelState));
  rc.insert(std::make_pair(strings::instant_fuel_consumption, hmi_apis::FunctionID::VehicleInfo_GetInstantFuelConsumption));
  rc.insert(std::make_pair(strings::external_temp, hmi_apis::FunctionID::VehicleInfo_GetExternalTemperature));
  rc.insert(std::make_pair(strings::vin, hmi_apis::FunctionID::VehicleInfo_GetVin));
  rc.insert(std::make_pair(strings::prndl, hmi_apis::FunctionID::VehicleInfo_GetPrndl));
  rc.insert(std::make_pair(strings::tire_pressure, hmi_apis::FunctionID::VehicleInfo_GetTirePressure));
  rc.insert(std::make_pair(strings::odometer, hmi_apis::FunctionID::VehicleInfo_GetOdometer));
  rc.insert(std::make_pair(strings::belt_status, hmi_apis::FunctionID::VehicleInfo_GetBeltStatus));
  rc.insert(std::make_pair(strings::body_information, hmi_apis::FunctionID::VehicleInfo_GetBodyInformation));
  rc.insert(std::make_pair(strings::device_status, hmi_apis::FunctionID::VehicleInfo_GetDeviceStatus));
  rc.insert(std::make_pair(strings::driver_braking, hmi_apis::FunctionID::VehicleInfo_GetDriverBraking));
  rc.insert(std::make_pair(strings::wiper_status, hmi_apis::FunctionID::VehicleInfo_GetWiperStatus));
  rc.insert(std::make_pair(strings::head_lamp_status, hmi_apis::FunctionID::VehicleInfo_GetHeadLampStatus));
  rc.insert(std::make_pair(strings::engine_torque, hmi_apis::FunctionID::VehicleInfo_GetEngineTorque));
  rc.insert(std::make_pair(strings::acc_pedal_pos, hmi_apis::FunctionID::VehicleInfo_GetAccPedalPosition));
  rc.insert(std::make_pair(strings::steering_wheel_angle, hmi_apis::FunctionID::VehicleInfo_GetSteeringWheelAngle));
  rc.insert(std::make_pair(strings::e_call_info, hmi_apis::FunctionID::VehicleInfo_GetECallInfo));
  rc.insert(std::make_pair(strings::airbag_status, hmi_apis::FunctionID::VehicleInfo_GetAirbagStatus));
  rc.insert(std::make_pair(strings::emergency_event, hmi_apis::FunctionID::VehicleInfo_GetEmergencyEvent));
  rc.insert(std::make_pair(strings::cluster_mode_status, hmi_apis::FunctionID::VehicleInfo_GetClusterModeStatus));
  rc.insert(std::make_pair(strings::my_key, hmi_apis::FunctionID::VehicleInfo_GetMyKey));
  return rc;
}
static std::map<std::string, uint16_t> vehicle_data_args = create_get_vehicle_data_args();
}
#endif

void MessageHelper::CreateGetVehicleDataRequest(
    uint32_t correlation_id, const std::vector<std::string>& params) {
  LOG4CXX_AUTO_TRACE(logger_);
#ifdef HMI_DBUS_API
  for (std::vector<std::string>::const_iterator it = params.begin();
       it != params.end(); it++) {
    smart_objects::SmartObjectSPtr request = new smart_objects::SmartObject;

    (*request)[strings::params][strings::message_type] = static_cast<int>(kRequest);
    (*request)[strings::params][strings::correlation_id] = correlation_id;
    (*request)[strings::params][strings::protocol_version] =
      commands::CommandImpl::protocol_version_;
    (*request)[strings::params][strings::protocol_type] =
      commands::CommandImpl::hmi_protocol_type_;
    (*request)[strings::params][strings::function_id] =
      static_cast<int>(vehicle_data_args[*it]);
    ApplicationManagerImpl::instance()->ManageHMICommand(request);
  }
#else
  smart_objects::SmartObjectSPtr request = new smart_objects::SmartObject;

  (*request)[strings::params][strings::message_type] = static_cast<int>(kRequest);
  (*request)[strings::params][strings::function_id] =
    static_cast<int>(hmi_apis::FunctionID::VehicleInfo_GetVehicleData);
  (*request)[strings::params][strings::correlation_id] = correlation_id;
  (*request)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*request)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;
  (*request)[strings::msg_params] = smart_objects::SmartObject(smart_objects::SmartType_Map);
  for (std::vector<std::string>::const_iterator it = params.begin();
       it != params.end(); it++) {
    (*request)[strings::msg_params][*it] = true;
  }
  ApplicationManagerImpl::instance()->ManageHMICommand(request);
#endif
}

smart_objects::SmartObjectSPtr MessageHelper::CreateBlockedByPoliciesResponse(
    mobile_apis::FunctionID::eType function_id,
    mobile_apis::Result::eType result, uint32_t correlation_id,
    uint32_t connection_key) {
  LOG4CXX_AUTO_TRACE(logger_);
  smart_objects::SmartObjectSPtr response = new smart_objects::SmartObject;

  (*response)[strings::params][strings::function_id] =
    static_cast<int>(function_id);
  (*response)[strings::params][strings::message_type] =
    static_cast<int>(kResponse);
  (*response)[strings::msg_params][strings::success] = false;
  (*response)[strings::msg_params][strings::result_code] =
    static_cast<int>(result);
  (*response)[strings::params][strings::correlation_id] = correlation_id;
  (*response)[strings::params][strings::connection_key] = connection_key;
  (*response)[strings::params][strings::protocol_type] =
    commands::CommandImpl::mobile_protocol_type_;
  (*response)[strings::params][strings::protocol_version] =
    static_cast<int>(kV2);
  return response;
}

smart_objects::SmartObjectSPtr MessageHelper::CreateDeviceListSO(
  const connection_handler::DeviceMap& devices) {
  LOG4CXX_AUTO_TRACE(logger_);
  smart_objects::SmartObjectSPtr device_list_so =
      new smart_objects::SmartObject(smart_objects::SmartType_Map);

  (*device_list_so)[strings::device_list] = smart_objects::SmartObject(
        smart_objects::SmartType_Array);
  smart_objects::SmartObject& list_so = (*device_list_so)[strings::device_list];

  int32_t index = 0;
  for (connection_handler::DeviceMap::const_iterator it = devices.begin();
       devices.end() != it; ++it) {
    const connection_handler::Device& d =
      static_cast<connection_handler::Device>(it->second);
    list_so[index][strings::name] = d.user_friendly_name();
    list_so[index][strings::id] = it->second.mac_address();

    const policy::DeviceConsent device_consent =
        policy::PolicyHandler::instance()->GetUserConsentForDevice(it->second.mac_address());
    list_so[index][strings::isSDLAllowed] =
        policy::DeviceConsent::kDeviceAllowed == device_consent;
    list_so[index][strings::transport_type] =
      ApplicationManagerImpl::instance()->GetDeviceTransportType(d.connection_type());
    ++index;
  }
  return device_list_so;
}

smart_objects::SmartObjectSPtr MessageHelper::CreateModuleInfoSO(
    uint32_t function_id) {
  LOG4CXX_AUTO_TRACE(logger_);
  smart_objects::SmartObjectSPtr module_info = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  smart_objects::SmartObject& object = *module_info;
  object[strings::params][strings::message_type] = static_cast<int>(kRequest);
  object[strings::params][strings::function_id] = static_cast<int>(function_id);
  object[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();
  object[strings::msg_params] = smart_objects::SmartObject(
                                  smart_objects::SmartType_Map);
  return module_info;
}

smart_objects::SmartObjectSPtr MessageHelper::CreateSetAppIcon(
  const std::string& path_to_icon, uint32_t app_id) {
  LOG4CXX_AUTO_TRACE(logger_);
  smart_objects::SmartObjectSPtr set_icon = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  if (!set_icon) {
    return NULL;
  }

  smart_objects::SmartObject& object = *set_icon;
  object[strings::sync_file_name][strings::value] = path_to_icon;
  // TODO(PV): need to store actual image type
  object[strings::sync_file_name][strings::image_type] =
    static_cast<int>(mobile_api::ImageType::DYNAMIC);
  object[strings::app_id] = app_id;

  return set_icon;
}

bool MessageHelper::SendIVISubscribtions(const uint32_t app_id) {
  LOG4CXX_AUTO_TRACE(logger_);

  bool result = true;
  ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(
                               app_id);

  if (!app.valid()) {
    LOG4CXX_ERROR(logger_, "Invalid application " << app_id);
    return result;
  }

  smart_objects::SmartObjectList requests = GetIVISubscriptionRequests(app);
  for (smart_objects::SmartObjectList::const_iterator it = requests.begin();
       it != requests.end(); ++it) {
    if (!ApplicationManagerImpl::instance()->ManageHMICommand(*it)) {
      result = false;
    }
  }
  return result;
}

smart_objects::SmartObjectList MessageHelper::GetIVISubscriptionRequests(
  ApplicationSharedPtr app) {
  LOG4CXX_AUTO_TRACE(logger_);

  smart_objects::SmartObjectList hmi_requests;
  if (!app.valid()) {
    LOG4CXX_ERROR(logger_, "Invalid application pointer ");
    return hmi_requests;
  }

  smart_objects::SmartObject msg_params = smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  msg_params[strings::app_id] = app->app_id();
  const VehicleData& vehicle_data = MessageHelper::vehicle_data_;
  VehicleData::const_iterator ivi_it = vehicle_data.begin();
  const std::set<uint32_t>& subscribes = app->SubscribesIVI();

  for (; vehicle_data.end() != ivi_it; ++ivi_it) {
    uint32_t type_id = static_cast<int>(ivi_it->second);
    if (subscribes.end() != subscribes.find(type_id)) {
      std::string key_name = ivi_it->first;
      msg_params[key_name] = true;
    }
  }

#ifdef HMI_JSON_API
  smart_objects::SmartObjectSPtr request = MessageHelper::CreateModuleInfoSO(
      hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData);
  (*request)[strings::msg_params] = msg_params;
  hmi_requests.push_back(request);
#endif // #ifdef HMI_JSON_API
#ifdef HMI_DBUS_API
  //Generate list of ivi_subrequests
  for (size_t i = 0; i < sizeof(ivi_subrequests) / sizeof(ivi_subrequests[0]); ++i) {
    const VehicleInfo_Requests& sr = ivi_subrequests[i];
    if (true == msg_params.keyExists(sr.str)
        && true == msg_params[sr.str].asBool()) {
      smart_objects::SmartObjectSPtr request = MessageHelper::CreateModuleInfoSO(
                                              sr.func_id);
      (*request)[strings::msg_params] = msg_params;
      hmi_requests.push_back(request);
    }
  }
#endif // #ifdef HMI_DBUS_API
  return hmi_requests;
}

void MessageHelper::SendOnButtonSubscriptionNotification(
    uint32_t app_id, hmi_apis::Common_ButtonName::eType button, bool is_subscribed) {
  using namespace smart_objects;
  using namespace hmi_apis;
  LOG4CXX_AUTO_TRACE(logger_);

  SmartObjectSPtr notification_ptr = utils::MakeShared<SmartObject>(SmartType_Map);
  if (!notification_ptr) {
    LOG4CXX_ERROR(logger_, "Memory allocation failed.");
    return;
  }
  SmartObject& notification = *notification_ptr;

  SmartObject msg_params = SmartObject(SmartType_Map);
  msg_params[strings::app_id] = app_id;
  msg_params[strings::name] = button;
  msg_params[strings::is_suscribed] = is_subscribed;

  notification[strings::params][strings::message_type] =
      static_cast<int32_t>(application_manager::MessageType::kNotification);
  notification[strings::params][strings::protocol_version] =
      commands::CommandImpl::protocol_version_;
  notification[strings::params][strings::protocol_type] =
      commands::CommandImpl::hmi_protocol_type_;
  notification[strings::params][strings::function_id] =
      hmi_apis::FunctionID::Buttons_OnButtonSubscription;
  notification[strings::msg_params] = msg_params;

  if (!ApplicationManagerImpl::instance()->ManageHMICommand(notification_ptr)) {
    LOG4CXX_ERROR(logger_, "Unable to send HMI notification");
  }
}

void MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp(
    ApplicationConstSharedPtr app) {
  using namespace smart_objects;
  using namespace hmi_apis;
  using namespace mobile_apis;
  LOG4CXX_AUTO_TRACE(logger_);

  if (!app.valid()) {
    LOG4CXX_ERROR(logger_, "Invalid application pointer ");
    return;
  }

  std::set<ButtonName::eType> subscriptions = app->SubscribedButtons();
  std::set<ButtonName::eType>::iterator it = subscriptions.begin();
  for (; subscriptions.end() != it; ++it) {
    SendOnButtonSubscriptionNotification(
        app->hmi_app_id(), static_cast<Common_ButtonName::eType>(*it), true);
  }
}

void MessageHelper::SendSetAppIcon(uint32_t app_id,
                                   const std::string& icon_path) {
  using namespace smart_objects;
  SmartObjectSPtr set_app_icon(new smart_objects::SmartObject);
  if (set_app_icon) {
    SmartObject& so_to_send = *set_app_icon;
    so_to_send[strings::params][strings::function_id] =
      static_cast<int>(hmi_apis::FunctionID::UI_SetAppIcon);
    so_to_send[strings::params][strings::message_type] =
      static_cast<int>(hmi_apis::messageType::request);
    so_to_send[strings::params][strings::protocol_version] =
      commands::CommandImpl::protocol_version_;
    so_to_send[strings::params][strings::protocol_type] =
      commands::CommandImpl::hmi_protocol_type_;
    so_to_send[strings::params][strings::correlation_id] =
      ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

    so_to_send[strings::msg_params] = smart_objects::SmartObject(
                                        smart_objects::SmartType_Map);
    SmartObjectSPtr msg_params(MessageHelper::CreateSetAppIcon(icon_path, app_id));

    if (msg_params) {
      so_to_send[strings::msg_params] = *msg_params;
    }
    ApplicationManagerImpl::instance()->ManageHMICommand(set_app_icon);
  }
}

void MessageHelper::SendAppDataToHMI(ApplicationConstSharedPtr app) {
  LOG4CXX_AUTO_TRACE(logger_);
  if (app) {
    SendSetAppIcon(app, app->app_icon_path());
    SendGlobalPropertiesToHMI(app);
    SendShowRequestToHMI(app);
  }
}

void MessageHelper::SendGlobalPropertiesToHMI(ApplicationConstSharedPtr app) {
  if (!app.valid()) {
    LOG4CXX_ERROR(logger_, "Invalid application");
    return;
  }

  smart_objects::SmartObjectList requests = CreateGlobalPropertiesRequestsToHMI(app);
  for (smart_objects::SmartObjectList::const_iterator it = requests.begin();
       it != requests.end(); ++it) {
    DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it))
  }
}

smart_objects::SmartObjectList MessageHelper::CreateGlobalPropertiesRequestsToHMI(
  ApplicationConstSharedPtr app) {
  LOG4CXX_AUTO_TRACE(logger_);

  smart_objects::SmartObjectList requests;
  if (!app.valid()) {
    LOG4CXX_ERROR(logger_, "Invalid application");
    return requests;
  }

  // UI global properties

  if (app->vr_help_title() || app->vr_help()) {
    smart_objects::SmartObjectSPtr ui_global_properties =
        new smart_objects::SmartObject(smart_objects::SmartType_Map);

    if (!ui_global_properties) {
      return requests;
    }

    (*ui_global_properties)[strings::params][strings::function_id] =
      static_cast<int>(hmi_apis::FunctionID::UI_SetGlobalProperties);
    (*ui_global_properties)[strings::params][strings::message_type] =
      static_cast<int>(hmi_apis::messageType::request);
    (*ui_global_properties)[strings::params][strings::protocol_version] =
      commands::CommandImpl::protocol_version_;
    (*ui_global_properties)[strings::params][strings::protocol_type] =
      commands::CommandImpl::hmi_protocol_type_;
    (*ui_global_properties)[strings::params][strings::correlation_id] =
      ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

    smart_objects::SmartObject ui_msg_params = smart_objects::SmartObject(
          smart_objects::SmartType_Map);
    if (app->vr_help_title()) {
      ui_msg_params[strings::vr_help_title] = (*app->vr_help_title());
    }
    if (app->vr_help()) {
      ui_msg_params[strings::vr_help] = (*app->vr_help());
    }
    if (app->keyboard_props()) {
      ui_msg_params[strings::keyboard_properties] = (*app->keyboard_props());
    }
    if (app->menu_title()) {
      ui_msg_params[strings::menu_title] = (*app->menu_title());
    }
    if (app->menu_icon()) {
      ui_msg_params[strings::menu_icon] = (*app->menu_icon());
    }
    ui_msg_params[strings::app_id] = app->app_id();

    (*ui_global_properties)[strings::msg_params] = ui_msg_params;

    requests.push_back(ui_global_properties);
  }

  // TTS global properties
  if (app->help_prompt() || app->timeout_prompt()) {
    smart_objects::SmartObjectSPtr tts_global_properties =
        new smart_objects::SmartObject(smart_objects::SmartType_Map);

    if (!tts_global_properties) {
      return requests;
    }

    (*tts_global_properties)[strings::params][strings::function_id] =
      static_cast<int>(hmi_apis::FunctionID::TTS_SetGlobalProperties);
    (*tts_global_properties)[strings::params][strings::message_type] =
      static_cast<int>(hmi_apis::messageType::request);
    (*tts_global_properties)[strings::params][strings::protocol_version] =
      commands::CommandImpl::protocol_version_;
    (*tts_global_properties)[strings::params][strings::protocol_type] =
      commands::CommandImpl::hmi_protocol_type_;
    (*tts_global_properties)[strings::params][strings::correlation_id] =
      ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

    smart_objects::SmartObject tts_msg_params = smart_objects::SmartObject(
          smart_objects::SmartType_Map);
    if (app->help_prompt()) {
      tts_msg_params[strings::help_prompt] = (*app->help_prompt());
    }
    if (app->timeout_prompt()) {
      tts_msg_params[strings::timeout_prompt] = (*app->timeout_prompt());
    }
    tts_msg_params[strings::app_id] = app->app_id();

    (*tts_global_properties)[strings::msg_params] = tts_msg_params;

    requests.push_back(tts_global_properties);
  }
  return requests;
}

void MessageHelper::SendTTSGlobalProperties(
    ApplicationSharedPtr app, bool default_help_prompt) {
  LOG4CXX_AUTO_TRACE(logger_);
  if (!app) {
    return;
  }
  smart_objects::SmartObjectSPtr tts_global_properties(
      new smart_objects::SmartObject);
  if (tts_global_properties) {
    smart_objects::SmartObject& so_to_send = *tts_global_properties;
    so_to_send[strings::params][strings::function_id] =
        static_cast<int>(hmi_apis::FunctionID::TTS_SetGlobalProperties);
    so_to_send[strings::params][strings::message_type] =
        static_cast<int>(hmi_apis::messageType::request);
    so_to_send[strings::params][strings::protocol_version] =
        commands::CommandImpl::protocol_version_;
    so_to_send[strings::params][strings::protocol_type] =
        commands::CommandImpl::hmi_protocol_type_;
    so_to_send[strings::params][strings::correlation_id] =
        ApplicationManagerImpl::instance()->GetNextHMICorrelationID();
    smart_objects::SmartObject msg_params = smart_objects::SmartObject(
        smart_objects::SmartType_Map);
    msg_params[strings::help_prompt] = smart_objects::SmartObject(
        smart_objects::SmartType_Array);
    if (default_help_prompt) {
      const DataAccessor<CommandsMap> accessor = app->commands_map();
      const CommandsMap& commands = accessor.GetData();
      CommandsMap::const_iterator it = commands.begin();
      uint32_t index = 0;
      for (; commands.end() != it; ++it) {
        smart_objects::SmartObject item(smart_objects::SmartType_Map);
        if ((*it->second).keyExists(strings::menu_params)){
          item[strings::text] = (*it->second)[strings::menu_params][strings::menu_name].asString();
          item[strings::type] = mobile_apis::SpeechCapabilities::SC_TEXT;
        } else {
          continue;
        }
        msg_params[strings::help_prompt][index++] = item;
      }
    }
    app->set_help_prompt(msg_params[strings::help_prompt]);
    msg_params[strings::app_id] = app->app_id();
    so_to_send[strings::msg_params] = msg_params;
    ApplicationManagerImpl::instance()->ManageHMICommand(tts_global_properties);
  }
}

smart_objects::SmartObjectSPtr MessageHelper::CreateAppVrHelp(
  ApplicationConstSharedPtr app) {
  smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!result) {
    return NULL;
  }
  smart_objects::SmartObject& vr_help = *result;
  vr_help[strings::vr_help_title] = app->name();

  int32_t index = 0;
  if (app->vr_synonyms()) {
    smart_objects::SmartObject item(smart_objects::SmartType_Map);
    item[strings::text] = (*(app->vr_synonyms())).getElement(0);
    item[strings::position] = index + 1;
    vr_help[strings::vr_help][index++] = item;
  }

  // copy all app VR commands
  const DataAccessor<CommandsMap> cmd_accessor = app->commands_map();
  const CommandsMap& commands = cmd_accessor.GetData();
  CommandsMap::const_iterator it = commands.begin();

  for (; commands.end() != it; ++it) {
    smart_objects::SmartObject item(smart_objects::SmartType_Map);
    item[strings::text] = (*it->second)[strings::vr_commands][0].asString();
    item[strings::position] = index + 1;
    vr_help[strings::vr_help][index++] = item;
  }
  return result;
}

smart_objects::SmartObjectList MessageHelper::CreateShowRequestToHMI(
    ApplicationConstSharedPtr app) {

  smart_objects::SmartObjectList requests;
  if (!app) {
    LOG4CXX_ERROR(logger_, "Invalid application");
    return requests;
  }

  if (app->show_command()) {
    smart_objects::SmartObjectSPtr ui_show = new smart_objects::SmartObject(
        smart_objects::SmartType_Map);
    (*ui_show)[strings::params][strings::function_id] =
      static_cast<int>(hmi_apis::FunctionID::UI_Show);
    (*ui_show)[strings::params][strings::message_type] =
      static_cast<int>(hmi_apis::messageType::request);
    (*ui_show)[strings::params][strings::protocol_version] =
      commands::CommandImpl::protocol_version_;
    (*ui_show)[strings::params][strings::protocol_type] =
      commands::CommandImpl::hmi_protocol_type_;
    (*ui_show)[strings::params][strings::correlation_id] =
      ApplicationManagerImpl::instance()->GetNextHMICorrelationID();
    (*ui_show)[strings::msg_params] = (*app->show_command());
    requests.push_back(ui_show);
  }
  return requests;
}

void MessageHelper::SendShowRequestToHMI(ApplicationConstSharedPtr app) {
  if (!app) {
    return;
  }
  smart_objects::SmartObjectList shows = CreateShowRequestToHMI(app);

  for (smart_objects::SmartObjectList::const_iterator it = shows.begin();
      it != shows.end(); ++it) {
    DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it));
  }

}

void MessageHelper::SendShowConstantTBTRequestToHMI(
  ApplicationConstSharedPtr app) {
  if (!app) {
    return;
  }

  if (app->tbt_show_command()) {
    utils::SharedPtr<smart_objects::SmartObject> navi_show_tbt =
        new smart_objects::SmartObject(smart_objects::SmartType_Map);
    if (!navi_show_tbt) {
      return;
    }
    (*navi_show_tbt)[strings::params][strings::function_id] =
      static_cast<int>(hmi_apis::FunctionID::Navigation_ShowConstantTBT);
    (*navi_show_tbt)[strings::params][strings::message_type] =
      static_cast<int>(hmi_apis::messageType::request);
    (*navi_show_tbt)[strings::params][strings::protocol_version] =
      commands::CommandImpl::protocol_version_;
    (*navi_show_tbt)[strings::params][strings::protocol_type] =
      commands::CommandImpl::hmi_protocol_type_;
    (*navi_show_tbt)[strings::params][strings::correlation_id] =
      ApplicationManagerImpl::instance()->GetNextHMICorrelationID();
    (*navi_show_tbt)[strings::msg_params] = (*app->tbt_show_command());
    DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(navi_show_tbt));
  }
}

void MessageHelper::SendAddCommandRequestToHMI(ApplicationConstSharedPtr app) {
  if (!app) {
    return;
  }
  smart_objects::SmartObjectList requests = CreateAddCommandRequestToHMI(app);
  for (smart_objects::SmartObjectList::iterator it = requests.begin(); it != requests.end();
       ++it) {
    DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it));
  }
}

smart_objects::SmartObjectList MessageHelper::CreateAddCommandRequestToHMI(
  ApplicationConstSharedPtr app) {

  smart_objects::SmartObjectList requests;
  if (!app) {
    LOG4CXX_ERROR(logger_, "Invalid application");
    return requests;
  }

  const DataAccessor<CommandsMap> accessor = app->commands_map();
  const CommandsMap& commands = accessor.GetData();
  CommandsMap::const_iterator i = commands.begin();
  for (; commands.end() != i; ++i) {
    // UI Interface
    if ((*i->second).keyExists(strings::menu_params)) {
      smart_objects::SmartObjectSPtr ui_command = new smart_objects::SmartObject(
          smart_objects::SmartType_Map);

      if (!ui_command) {
        return requests;
      }

      (*ui_command)[strings::params][strings::function_id] =
        static_cast<int>(hmi_apis::FunctionID::UI_AddCommand);
      (*ui_command)[strings::params][strings::message_type] =
        static_cast<int>(hmi_apis::messageType::request);
      (*ui_command)[strings::params][strings::protocol_version] =
        commands::CommandImpl::protocol_version_;
      (*ui_command)[strings::params][strings::protocol_type] =
        commands::CommandImpl::hmi_protocol_type_;
      (*ui_command)[strings::params][strings::correlation_id] =
        ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

      smart_objects::SmartObject msg_params = smart_objects::SmartObject(
          smart_objects::SmartType_Map);
      msg_params[strings::cmd_id] = i->first;
      msg_params[strings::menu_params] = (*i->second)[strings::menu_params];
      msg_params[strings::app_id] = app->app_id();

      if (((*i->second).keyExists(strings::cmd_icon))
          && (0 < (*i->second)[strings::cmd_icon][strings::value].length())) {
        msg_params[strings::cmd_icon] = (*i->second)[strings::cmd_icon];
        msg_params[strings::cmd_icon][strings::value] =
            (*i->second)[strings::cmd_icon][strings::value].asString();
      }
      (*ui_command)[strings::msg_params] = msg_params;
      requests.push_back(ui_command);
    }

    // VR Interface
    if ((*i->second).keyExists(strings::vr_commands)) {
      SendAddVRCommandToHMI(i->first, (*i->second)[strings::vr_commands],
                            app->app_id());
    }
  }
  return requests;
}

smart_objects::SmartObjectSPtr MessageHelper::CreateChangeRegistration(
    int32_t function_id, int32_t language, uint32_t app_id,
    const smart_objects::SmartObject* app_types) {
  smart_objects::SmartObjectSPtr command = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!command) {
    return NULL;
  }
  smart_objects::SmartObject& params = *command;

  params[strings::params][strings::message_type] =
    static_cast<int>(hmi_apis::messageType::request);
  params[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  params[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;

  params[strings::params][strings::function_id] = function_id;

  params[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

  smart_objects::SmartObject msg_params = smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  msg_params[strings::language] = language;
  msg_params[strings::app_id] = app_id;

  if (app_types != NULL) {
    msg_params[strings::app_hmi_type] = *app_types;
  }

  params[strings::msg_params] = msg_params;
  return command;
}

void MessageHelper::SendUIChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app) {
  if (!app.valid()) {
    LOG4CXX_ERROR(logger_, "Application is not valid");
    return;
  }

  if (NULL != app->app_types()) {
    smart_objects::SmartObjectSPtr ui_command = CreateChangeRegistration(
        hmi_apis::FunctionID::UI_ChangeRegistration, app->ui_language(),
        app->app_id(), app->app_types());

    if (ui_command) {
      ApplicationManagerImpl::instance()->ManageHMICommand(ui_command);
    }
  }
}

void MessageHelper::SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app) {
  if (!app.valid()) {
    return;
  }
  if (mobile_apis::Language::INVALID_ENUM != app->language()) {
    smart_objects::SmartObjectSPtr vr_command = CreateChangeRegistration(
          hmi_apis::FunctionID::VR_ChangeRegistration, app->language(),
          app->app_id());

    if (vr_command) {
      ApplicationManagerImpl::instance()->ManageHMICommand(vr_command);
    }
  }

  if (mobile_apis::Language::INVALID_ENUM != app->language()) {
    smart_objects::SmartObjectSPtr tts_command = CreateChangeRegistration(
          hmi_apis::FunctionID::TTS_ChangeRegistration, app->language(),
          app->app_id());

    if (tts_command) {
      ApplicationManagerImpl::instance()->ManageHMICommand(tts_command);
    }
  }

  if (mobile_apis::Language::INVALID_ENUM != app->ui_language()) {
    smart_objects::SmartObjectSPtr ui_command = CreateChangeRegistration(
          hmi_apis::FunctionID::UI_ChangeRegistration, app->ui_language(),
          app->app_id());

    if (ui_command) {
      ApplicationManagerImpl::instance()->ManageHMICommand(ui_command);
    }

  }
}

void MessageHelper::SendAddVRCommandToHMI(
  uint32_t cmd_id, const smart_objects::SmartObject& vr_commands,
  uint32_t app_id) {
  smart_objects::SmartObjectSPtr request = CreateAddVRCommandToHMI(cmd_id,
                                        vr_commands,
                                        app_id);
  DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(request));
}

smart_objects::SmartObjectSPtr MessageHelper::CreateAddVRCommandToHMI(
    uint32_t cmd_id, const smart_objects::SmartObject& vr_commands,
    uint32_t app_id) {
  smart_objects::SmartObjectSPtr vr_command = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  if (!vr_command) {
    return NULL;
  }

  (*vr_command)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::VR_AddCommand;
  (*vr_command)[strings::params][strings::message_type] =
    hmi_apis::messageType::request;
  (*vr_command)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*vr_command)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;
  (*vr_command)[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

  smart_objects::SmartObject msg_params = smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (0 != cmd_id) {
    msg_params[strings::cmd_id] = cmd_id;
  }
  msg_params[strings::vr_commands] = vr_commands;
  if (0 < app_id) {
    msg_params[strings::app_id] = app_id;
  }
  msg_params[strings::grammar_id] =
    ApplicationManagerImpl::instance()->application(app_id)->get_grammar_id();
  msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command;

  (*vr_command)[strings::msg_params] = msg_params;

  return vr_command;
}

bool MessageHelper::CreateHMIApplicationStruct(ApplicationConstSharedPtr app,
    smart_objects::SmartObject& output) {
  using namespace smart_objects;
  LOG4CXX_AUTO_TRACE(logger_);

  if (!app) {
    LOG4CXX_WARN(logger_, "Application is not valid");
    return false;
  }

  const SmartObject* app_types = app->app_types();
  const SmartObject* ngn_media_screen_name = app->ngn_media_screen_name();
  const connection_handler::DeviceHandle handle = app->device();
  std::string device_name = ApplicationManagerImpl::instance()->GetDeviceName(handle);

  std::string mac_address;
  std::string transport_type;
  if (-1 == connection_handler::ConnectionHandlerImpl::instance()->
      GetDataOnDeviceID(app->device(), &device_name,
                        NULL, &mac_address, &transport_type)) {
    LOG4CXX_ERROR(logger_, "Failed to extract information for device "
                  << app->device());
  }

  output = SmartObject(SmartType_Map);
  output[strings::app_name] = app->name();
  output[strings::icon] = app->app_icon_path();
  output[strings::app_id] = app->hmi_app_id();

  if (app->IsRegistered()) {
    output[strings::hmi_display_language_desired] = app->ui_language();
    output[strings::is_media_application] = app->is_media_application();
  }

  if (!app->IsRegistered()) {
    output[strings::greyOut] = app->is_greyed_out();
    const SmartObject* app_tts_name = app->tts_name();
    DCHECK_OR_RETURN(app_tts_name, false);
    if (!app_tts_name->empty()) {
      SmartObject output_tts_name = SmartObject(SmartType_Array);
      output_tts_name[0][strings::text] = *(app->tts_name());
      output_tts_name[0][strings::type] = hmi_apis::Common_SpeechCapabilities::SC_TEXT;
      output[json::ttsName] = output_tts_name;
    }
    if (!app->vr_synonyms()->empty()) {
      output[json::vrSynonyms] = *(app->vr_synonyms());
    }
  }

  if (ngn_media_screen_name) {
    output[strings::ngn_media_screen_app_name] = ngn_media_screen_name->asString();
  }
  if (app_types) {
    output[strings::app_type] = *app_types;
  }

  output[strings::device_info] = smart_objects::SmartObject(smart_objects::SmartType_Map);
  output[strings::device_info][strings::name] = device_name;
  output[strings::device_info][strings::id] = mac_address;
  const policy::DeviceConsent device_consent =
      policy::PolicyHandler::instance()->GetUserConsentForDevice(mac_address);
  output[strings::device_info][strings::isSDLAllowed] =
      policy::DeviceConsent::kDeviceAllowed == device_consent;

  output[strings::device_info][strings::transport_type] =
      ApplicationManagerImpl::instance()->GetDeviceTransportType(transport_type);
  return true;
}

void MessageHelper::SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app) {
  if (!app.valid()) {
    LOG4CXX_ERROR(logger_, "Invalid application");
    return;
  }

  smart_objects::SmartObjectList requests = CreateAddSubMenuRequestToHMI(app);
  for (smart_objects::SmartObjectList::iterator it = requests.begin();
      it != requests.end(); ++it) {
    DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it));
  }
}

smart_objects::SmartObjectList MessageHelper::CreateAddSubMenuRequestToHMI(
  ApplicationConstSharedPtr app) {
  smart_objects::SmartObjectList requsets;
  const DataAccessor<SubMenuMap> accessor = app->sub_menu_map();
  const SubMenuMap& sub_menu = accessor.GetData();
  SubMenuMap::const_iterator i = sub_menu.begin();
  for (; sub_menu.end() != i; ++i) {
    smart_objects::SmartObjectSPtr ui_sub_menu = new smart_objects::SmartObject(
        smart_objects::SmartType_Map);

    if (!ui_sub_menu) {
      return requsets;
    }

    (*ui_sub_menu)[strings::params][strings::function_id] =
      hmi_apis::FunctionID::UI_AddSubMenu;
    (*ui_sub_menu)[strings::params][strings::message_type] =
      hmi_apis::messageType::request;
    (*ui_sub_menu)[strings::params][strings::protocol_version] =
      commands::CommandImpl::protocol_version_;
    (*ui_sub_menu)[strings::params][strings::protocol_type] =
      commands::CommandImpl::hmi_protocol_type_;
    (*ui_sub_menu)[strings::params][strings::correlation_id] =
      ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

    smart_objects::SmartObject msg_params = smart_objects::SmartObject(
        smart_objects::SmartType_Map);

    msg_params[strings::menu_id] = i->first;
    msg_params[strings::menu_params][strings::position] =
      (*i->second)[strings::position];
    msg_params[strings::menu_params][strings::menu_name] =
      (*i->second)[strings::menu_name];
    msg_params[strings::app_id] = app->app_id();
    (*ui_sub_menu)[strings::msg_params] = msg_params;
    requsets.push_back(ui_sub_menu);
  }
  return requsets;
}

void MessageHelper::SendOnAppUnregNotificationToHMI(
  ApplicationConstSharedPtr app, bool is_unexpected_disconnect) {
  smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!notification) {
    return;
  }

  smart_objects::SmartObject& message = *notification;

  message[strings::params][strings::function_id] =
    hmi_apis::FunctionID::BasicCommunication_OnAppUnregistered;

  message[strings::params][strings::message_type] = MessageType::kNotification;
  // we put hmi_app_id because applicaton list does not contain application on this momment
  // and ReplaceHMIByMobileAppId function will be unable to replace app_id to hmi_app_id
  message[strings::msg_params][strings::app_id] = app->hmi_app_id();
  message[strings::msg_params][strings::unexpected_disconnect] =
    is_unexpected_disconnect;
  ApplicationManagerImpl::instance()->ManageHMICommand(notification);
}

uint32_t MessageHelper::SendActivateAppToHMI(uint32_t const app_id,
    hmi_apis::Common_HMILevel::eType level,
    bool send_policy_priority) {
  uint32_t correlation_id = 0;
  application_manager::ApplicationConstSharedPtr app =
    application_manager::ApplicationManagerImpl::instance()
    ->application(app_id);
  if (!app) {
    LOG4CXX_WARN(logger_, "Invalid app_id: " << app_id);
    return correlation_id;
  }

  correlation_id =
      ApplicationManagerImpl::instance()->GetNextHMICorrelationID();
  utils::SharedPtr<smart_objects::SmartObject> message = new smart_objects::SmartObject(
    smart_objects::SmartType_Map);
  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::BasicCommunication_ActivateApp;
  (*message)[strings::params][strings::message_type] = MessageType::kRequest;
  (*message)[strings::params][strings::correlation_id] = correlation_id;
  (*message)[strings::msg_params][strings::app_id] = app_id;

  if (send_policy_priority) {
    std::string priority;
    // TODO(KKolodiy): need remove method policy_manager

    policy::PolicyHandler::instance()->GetPriority(
        app->mobile_app_id(), &priority);
    // According SDLAQ-CRS-2794
    // SDL have to send ActivateApp without "proirity" parameter to HMI.
    // in case of unconsented device
    std::string mac_adress;
    connection_handler::DeviceHandle device_handle = app->device();
    connection_handler::ConnectionHandlerImpl::instance()->
        GetDataOnDeviceID(device_handle, NULL, NULL, &mac_adress, NULL);

    policy::DeviceConsent consent =
        policy::PolicyHandler::instance()->GetUserConsentForDevice(mac_adress);
    if (!priority.empty() && (policy::DeviceConsent::kDeviceAllowed == consent)) {
      (*message)[strings::msg_params][strings::priority] = GetPriorityCode(priority);
    }
  }

  // We haven't send HMI level to HMI in case it FULL.
  if (hmi_apis::Common_HMILevel::INVALID_ENUM != level &&
      hmi_apis::Common_HMILevel::FULL != level) {
    (*message)[strings::msg_params][strings::activate_app_hmi_level] = level;
  }

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
  return correlation_id;
}

void MessageHelper::SendOnResumeAudioSourceToHMI(const uint32_t app_id) {
  LOG4CXX_WARN(logger_, "SendOnResumeAudioSourceToHMI app_id: " << app_id);
  application_manager::ApplicationConstSharedPtr app =
    application_manager::ApplicationManagerImpl::instance()
    ->application(app_id);
  if (!app) {
    LOG4CXX_WARN(logger_, "Invalid app_id: " << app_id);
    return;
  }

  utils::SharedPtr<smart_objects::SmartObject> message = new smart_objects::SmartObject(
    smart_objects::SmartType_Map);

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::BasicCommunication_OnResumeAudioSource;
  (*message)[strings::params][strings::message_type] = MessageType::kNotification;
  (*message)[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();
  (*message)[strings::msg_params][strings::app_id] = app_id;

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

std::string MessageHelper::GetDeviceMacAddressForHandle(
  const uint32_t device_handle) {

  std::string device_mac_address = "";
  connection_handler::ConnectionHandlerImpl::instance()->GetDataOnDeviceID(
    device_handle, NULL, NULL, &device_mac_address);
  LOG4CXX_DEBUG(logger_, "result : " << device_handle);
  return device_mac_address;
}

void MessageHelper::GetDeviceInfoForHandle(const uint32_t device_handle,
    policy::DeviceParams* device_info) {
  if (!device_info) {
    return;
  }
  connection_handler::ConnectionHandlerImpl::instance()->GetDataOnDeviceID(
    device_handle, &device_info->device_name, NULL,
    &device_info->device_mac_address, &device_info->device_connection_type);
}

void MessageHelper::GetDeviceInfoForApp(uint32_t connection_key,
                                        policy::DeviceParams* device_info) {
  if (!device_info) {
    return;
  }

  device_info->device_handle = ApplicationManagerImpl::instance()->application(
                                 connection_key)->device();

  GetDeviceInfoForHandle(device_info->device_handle, device_info);
}

void MessageHelper::SendSDLActivateAppResponse(policy::AppPermissions& permissions,
    uint32_t correlation_id) {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!message) {
    return;
  }

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::SDL_ActivateApp;
  (*message)[strings::params][strings::message_type] = MessageType::kResponse;
  (*message)[strings::params][strings::correlation_id] = correlation_id;
  (*message)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;
  (*message)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*message)[strings::params][hmi_response::code] = 0;

  (*message)[strings::msg_params]["isSDLAllowed"] = permissions.isSDLAllowed;
  if (!permissions.isSDLAllowed) {
    (*message)[strings::msg_params]["device"]["name"] = permissions.deviceInfo
        .device_name;
    (*message)[strings::msg_params]["device"]["id"] = permissions.deviceInfo
        .device_mac_address;
  }

  (*message)[strings::msg_params]["isAppRevoked"] = permissions.appRevoked;
  (*message)[strings::msg_params]["isAppPermissionsRevoked"] = permissions
      .isAppPermissionsRevoked;

  if (permissions.isAppPermissionsRevoked) {
    FillAppRevokedPermissions(permissions, *message);
  }

  (*message)[strings::msg_params]["isPermissionsConsentNeeded"] = permissions
      .appPermissionsConsentNeeded;

  if (!permissions.priority.empty()) {
    (*message)[strings::msg_params]["priority"] = GetPriorityCode(
          permissions.priority);
  }

  ApplicationManagerImpl::instance()->ManageHMICommand(message);

  // If application is revoked it should not be activated
  if (permissions.appRevoked || !permissions.isSDLAllowed) {
    return;
  }
}

void MessageHelper::SendOnSDLConsentNeeded(
  const policy::DeviceParams& device_info) {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!message) {
    return;
  }

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::SDL_OnSDLConsentNeeded;
  (*message)[strings::params][strings::message_type] =
    MessageType::kNotification;

  (*message)[strings::msg_params]["device"]["id"] = device_info.device_mac_address;
  (*message)[strings::msg_params]["device"]["name"] = device_info.device_name;

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

void MessageHelper::SendPolicyUpdate(
  const std::string& file_path,
  int timeout,
  const std::vector<int>& retries) {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  smart_objects::SmartObject& object = *message;
  object[strings::params][strings::function_id] =
    hmi_apis::FunctionID::BasicCommunication_PolicyUpdate;
  object[strings::params][strings::message_type] = MessageType::kRequest;
  object[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();
  object[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  object[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;

  object[strings::msg_params][hmi_request::file] = file_path;
  object[strings::msg_params][strings::timeout] = timeout;
  object[strings::msg_params][hmi_request::retry] = smart_objects::SmartObject(
        smart_objects::SmartType_Array);
  for (size_t i = 0; i < retries.size(); ++i) {
    object[strings::msg_params][hmi_request::retry][i] = retries[i];
  }
  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

void MessageHelper::SendGetUserFriendlyMessageResponse(
  const std::vector<policy::UserFriendlyMessage>& msg,
  uint32_t correlation_id) {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!message) {
    return;
  }

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::SDL_GetUserFriendlyMessage;
  (*message)[strings::params][strings::message_type] =
    MessageType::kResponse;
  (*message)[strings::params][strings::correlation_id] = correlation_id;
  (*message)[strings::params][hmi_response::code] = 0;

  // If no any messages found - skip sending of "messages" param
  if (msg.empty()) {
    ApplicationManagerImpl::instance()->ManageHMICommand(message);
  }

  const std::string messages = "messages";
  (*message)[strings::msg_params][messages] =
    smart_objects::SmartObject(smart_objects::SmartType_Array);

  smart_objects::SmartObject& user_friendly_messages =
    (*message)[strings::msg_params][messages];

  const std::string message_code = "messageCode";

  std::vector<policy::UserFriendlyMessage>::const_iterator it = msg.begin();
  std::vector<policy::UserFriendlyMessage>::const_iterator it_end = msg.end();
  for (uint32_t index = 0; it != it_end; ++it, ++index) {
    user_friendly_messages[index] = smart_objects::SmartObject(
                                      smart_objects::SmartType_Map);

    smart_objects::SmartObject& obj = user_friendly_messages[index];
    obj[message_code] = it->message_code;
  }

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

void MessageHelper::SendGetListOfPermissionsResponse(
    const std::vector<policy::FunctionalGroupPermission>& permissions,
    uint32_t correlation_id) {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!message) {
    return;
  }

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::SDL_GetListOfPermissions;
  (*message)[strings::params][strings::message_type] =
    MessageType::kResponse;
  (*message)[strings::params][strings::correlation_id] = correlation_id;
  (*message)[strings::params][hmi_response::code] = 0;

  const std::string allowed_functions = "allowedFunctions";
  (*message)[strings::msg_params][allowed_functions] =
    smart_objects::SmartObject(smart_objects::SmartType_Array);

  smart_objects::SmartObject& allowed_functions_array =
    (*message)[strings::msg_params][allowed_functions];

  std::vector<policy::FunctionalGroupPermission>::const_iterator it =
    permissions.begin();
  std::vector<policy::FunctionalGroupPermission>::const_iterator it_end =
    permissions.end();
  for (uint32_t index = 0; it != it_end; ++it, ++index) {
    allowed_functions_array[index] = smart_objects::SmartObject(
                                       smart_objects::SmartType_Map);

    smart_objects::SmartObject& item = allowed_functions_array[index];
    item[strings::name] = (*it).group_alias;
    item[strings::id] = (*it).group_id;
    policy::GroupConsent permission_state = (*it).state;
    // If state undefined, 'allowed' parameter should be absent
    if (policy::kGroupUndefined != permission_state) {
      item["allowed"] = policy::kGroupAllowed == permission_state;
    }
  }

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

smart_objects::SmartObjectSPtr MessageHelper::CreateNegativeResponse(
    uint32_t connection_key, int32_t function_id, uint32_t correlation_id,
    int32_t result_code) {
  smart_objects::SmartObjectSPtr response = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  smart_objects::SmartObject& response_data = *response;
  response_data[strings::params][strings::function_id] = function_id;
  response_data[strings::params][strings::message_type] =
    mobile_apis::messageType::response;
  response_data[strings::params][strings::correlation_id] = correlation_id;
  response_data[strings::params][strings::protocol_type] =
    commands::CommandImpl::mobile_protocol_type_;
  response_data[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  response_data[strings::msg_params][strings::result_code] = result_code;
  response_data[strings::msg_params][strings::success] = false;
  response_data[strings::params][strings::connection_key] = connection_key;

  return response;
}

void MessageHelper::SendNaviStartStream(int32_t connection_key) {
  LOG4CXX_AUTO_TRACE(logger_);
  smart_objects::SmartObjectSPtr start_stream = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  if (!start_stream) {
    return;
  }

  (*start_stream)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::Navigation_StartStream;
  (*start_stream)[strings::params][strings::message_type] =
    hmi_apis::messageType::request;
  (*start_stream)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*start_stream)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;
  (*start_stream)[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

  smart_objects::SmartObject msg_params = smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  uint32_t app_id = 0;
  connection_handler::ConnectionHandlerImpl::instance()->GetDataOnSessionKey(
    connection_key, &app_id);

  char url[100] = {'\0'};
  if ("socket" == profile::Profile::instance()->video_server_type()) {
    snprintf(url, sizeof(url) / sizeof(url[0]), "http://%s:%d",
             profile::Profile::instance()->server_address().c_str(),
             profile::Profile::instance()->video_streaming_port());
  } else if ("pipe" == profile::Profile::instance()->video_server_type()) {
    snprintf(url, sizeof(url) / sizeof(url[0]), "%s",
             profile::Profile::instance()->named_video_pipe_path().c_str());
  } else {
    int snprintf_result;
    snprintf_result = snprintf(url, sizeof(url) / sizeof(url[0]), "%s",
        profile::Profile::instance()->video_stream_file().c_str());
    DCHECK(snprintf_result);
  }
  msg_params[strings::app_id] = app_id;
  msg_params[strings::url] = url;

  (*start_stream)[strings::msg_params] = msg_params;

  ApplicationManagerImpl::instance()->ManageHMICommand(start_stream);
}

void MessageHelper::SendNaviStopStream(int32_t connection_key) {
  smart_objects::SmartObjectSPtr stop_stream = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  if (!stop_stream) {
    return;
  }

  (*stop_stream)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::Navigation_StopStream;
  (*stop_stream)[strings::params][strings::message_type] =
    hmi_apis::messageType::request;
  (*stop_stream)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*stop_stream)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;
  (*stop_stream)[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

  smart_objects::SmartObject msg_params = smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  uint32_t app_id = 0;
  connection_handler::ConnectionHandlerImpl::instance()->GetDataOnSessionKey(
    connection_key, &app_id);

  msg_params[strings::app_id] = app_id;

  (*stop_stream)[strings::msg_params] = msg_params;

  ApplicationManagerImpl::instance()->ManageHMICommand(stop_stream);
}

void MessageHelper::SendAudioStartStream(int32_t connection_key) {

  smart_objects::SmartObjectSPtr start_stream = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  if (!start_stream) {
    return;
  }

  (*start_stream)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::Navigation_StartAudioStream;
  (*start_stream)[strings::params][strings::message_type] =
    hmi_apis::messageType::request;
  (*start_stream)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*start_stream)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;
  (*start_stream)[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

  smart_objects::SmartObject msg_params = smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  uint32_t app_id = 0;
  connection_handler::ConnectionHandlerImpl::instance()->GetDataOnSessionKey(
    connection_key, &app_id);

  char url[100] = {'\0'};
  if ("socket" == profile::Profile::instance()->audio_server_type()) {
    snprintf(url, sizeof(url) / sizeof(url[0]), "http://%s:%d",
           profile::Profile::instance()->server_address().c_str(),
           profile::Profile::instance()->audio_streaming_port());
  } else if ("pipe" == profile::Profile::instance()->audio_server_type()) {
    snprintf(url, sizeof(url) / sizeof(url[0]), "%s",
             profile::Profile::instance()->named_audio_pipe_path().c_str());
  } else {
    int snprintf_result;
    snprintf_result = snprintf(url, sizeof(url) / sizeof(url[0]), "%s",
         profile::Profile::instance()->audio_stream_file().c_str());
    DCHECK(snprintf_result);
  }

  msg_params[strings::app_id] = app_id;
  msg_params[strings::url] = url;

  (*start_stream)[strings::msg_params] = msg_params;

  DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(start_stream));
}

void MessageHelper::SendAudioStopStream(int32_t connection_key) {
  smart_objects::SmartObjectSPtr stop_stream = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  if (!stop_stream) {
    return;
  }

  (*stop_stream)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::Navigation_StopAudioStream;
  (*stop_stream)[strings::params][strings::message_type] =
    hmi_apis::messageType::request;
  (*stop_stream)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*stop_stream)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;
  (*stop_stream)[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();

  smart_objects::SmartObject msg_params = smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  uint32_t app_id = 0;
  connection_handler::ConnectionHandlerImpl::instance()->GetDataOnSessionKey(
    connection_key, &app_id);

  msg_params[strings::app_id] = app_id;

  (*stop_stream)[strings::msg_params] = msg_params;

  ApplicationManagerImpl::instance()->ManageHMICommand(stop_stream);
}

void MessageHelper::SendOnDataStreaming(protocol_handler::ServiceType service,
                                        bool available) {
  using namespace protocol_handler;
  smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);

  if (!notification) {
    return;
  }

  if (ServiceType::kAudio != service && ServiceType::kMobileNav != service) {
    return;
  }

  (*notification)[strings::params][strings::function_id] =
      ServiceType::kAudio == service
      ? hmi_apis::FunctionID::Navigation_OnAudioDataStreaming
      : hmi_apis::FunctionID::Navigation_OnVideoDataStreaming;
  (*notification)[strings::params][strings::message_type] =
    hmi_apis::messageType::notification;
  (*notification)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*notification)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;

  (*notification)[strings::msg_params]["available"] = available;

  ApplicationManagerImpl::instance()->ManageHMICommand(notification);
}

bool MessageHelper::SendStopAudioPathThru() {
  LOG4CXX_INFO(logger_, "MessageHelper::SendAudioStopAudioPathThru");

  smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject;
  const uint32_t hmi_correlation_id = ApplicationManagerImpl::instance()
                                      ->GetNextHMICorrelationID();
  smart_objects::SmartObject& request = *result;
  request[strings::params][strings::message_type] = MessageType::kRequest;
  request[strings::params][strings::function_id] =
    hmi_apis::FunctionID::UI_EndAudioPassThru;
  request[strings::params][strings::correlation_id] = hmi_correlation_id;
  request[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  request[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;
  return ApplicationManagerImpl::instance()->ManageHMICommand(result);
}

void MessageHelper::SendPolicySnapshotNotification(
  unsigned int connection_key, const std::vector<uint8_t>& policy_data,
  const std::string& url, int timeout) {

  using namespace mobile_apis;
  using namespace smart_objects;

  SmartObject content (SmartType_Map);
  if (!url.empty()) {
    content[strings::msg_params][mobile_notification::syncp_url] = url;
  }

  content[strings::msg_params][strings::request_type] = RequestType::HTTP;
  content[strings::params][strings::binary_data] = SmartObject(policy_data);
  content[strings::msg_params][strings::file_type] = FileType::BINARY;

  SendSystemRequestNotification(connection_key, content);
}

void MessageHelper::SendSystemRequestNotification (uint32_t connection_key,
    smart_objects::SmartObject& content) {

  using namespace mobile_apis;
  using namespace commands;
  using namespace smart_objects;

  content[strings::params][strings::function_id] = FunctionID::OnSystemRequestID;
  content[strings::params][strings::message_type] = messageType::notification;
  content[strings::params][strings::protocol_type] = CommandImpl::mobile_protocol_type_;
  content[strings::params][strings::protocol_version] = CommandImpl::protocol_version_;

  content[strings::params][strings::connection_key] = connection_key;

  ApplicationManagerImpl::instance()->ManageMobileCommand(new SmartObject(content));
}

void MessageHelper::SendLaunchApp(uint32_t connection_key,
                                  const std::string& urlSchema,
                                  const std::string& packageName) {

  using namespace mobile_apis;
  using namespace smart_objects;

  SmartObject content (SmartType_Map);
  content[strings::msg_params][strings::request_type] = RequestType::LAUNCH_APP;
  content[strings::msg_params][strings::app_id] = connection_key;
  if (!urlSchema.empty()) {
    content[strings::msg_params][strings::url] = urlSchema;
  } else if (!packageName.empty()) {
    content[strings::msg_params][strings::url] = packageName;
  }

  SendSystemRequestNotification(connection_key, content);
}

void application_manager::MessageHelper::SendQueryApps(
    uint32_t connection_key) {
  using namespace mobile_apis;
  using namespace smart_objects;

  policy::PolicyHandler* policy_handler = policy::PolicyHandler::instance();

  SmartObject content (SmartType_Map);
  content[strings::msg_params][strings::request_type] = RequestType::QUERY_APPS;
  content[strings::msg_params][strings::url] = policy_handler->RemoteAppsUrl();
  content[strings::msg_params][strings::timeout] =
      policy_handler->TimeoutExchange();

  Json::Value http;
  Json::Value& http_header = http[http_request::httpRequest][http_request::headers];

  const int timeout = policy_handler->TimeoutExchange();

  http_header[http_request::content_type] = "application/json";
  http_header[http_request::connect_timeout] = timeout;
  http_header[http_request::do_output] = true;
  http_header[http_request::do_input] = true;
  http_header[http_request::use_caches] = false;
  http_header[http_request::request_method] = http_request::GET;
  http_header[http_request::read_timeout] = timeout;
  http_header[http_request::instance_follow_redirect] = false;
  http_header[http_request::charset] = "utf-8";
  http_header[http_request::content_lenght] = 0;

  std::string data = http_header.toStyledString();
  std::vector<uint8_t> binary_data(data.begin(), data.end());

  content[strings::params][strings::binary_data] = SmartObject(binary_data);
  content[strings::msg_params][strings::file_type] = FileType::BINARY;

  SendSystemRequestNotification(connection_key, content);
}

void MessageHelper::SendOnPermissionsChangeNotification(
  uint32_t connection_key, const policy::Permissions& permissions) {
  utils::SharedPtr<smart_objects::SmartObject> notification = new smart_objects::SmartObject(
    smart_objects::SmartType_Map);
  smart_objects::SmartObject& content = *notification;

  content[strings::params][strings::function_id] =
    mobile_apis::FunctionID::OnPermissionsChangeID;
  content[strings::params][strings::message_type] =
    mobile_apis::messageType::notification;
  content[strings::params][strings::protocol_type] =
    commands::CommandImpl::mobile_protocol_type_;
  content[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  content[strings::params][strings::connection_key] = connection_key;

  utils::SharedPtr<smart_objects::SmartObject> p_msg_params = new smart_objects::SmartObject(
    smart_objects::SmartType_Map);

  smart_objects::SmartObject& msg_params = *p_msg_params;

  content[strings::msg_params] = msg_params;

  //content[strings::msg_params][strings::app_id] = connection_key;

  content[strings::msg_params]["permissionItem"] = smart_objects::SmartObject(
        smart_objects::SmartType_Array);

  smart_objects::SmartObject& permissions_item_array =
    content[strings::msg_params]["permissionItem"];

  policy::Permissions::const_iterator it_permissions = permissions.begin();
  policy::Permissions::const_iterator it_permissions_end = permissions.end();

  for (size_t index_pi = 0; it_permissions != it_permissions_end;
       ++it_permissions, ++index_pi) {

    permissions_item_array[index_pi] = smart_objects::SmartObject(
                                         smart_objects::SmartType_Map);

    smart_objects::SmartObject& permission_item =
      permissions_item_array[index_pi];

    // Filling the rpcName of PermissionItem
    permission_item["rpcName"] = (*it_permissions).first;
    const policy::RpcPermissions& rpc_permissions = (*it_permissions).second;

    // Creating SO for hmiPermissions
    permission_item["hmiPermissions"] = smart_objects::SmartObject(
                                          smart_objects::SmartType_Map);

    smart_objects::SmartObject& hmi_permissions =
      permission_item["hmiPermissions"];

    policy::HMIPermissions::const_iterator it_hmi_permissions = rpc_permissions
        .hmi_permissions.begin();
    policy::HMIPermissions::const_iterator it_hmi_permissions_end =
      rpc_permissions.hmi_permissions.end();

    // Filling the hmiPermissions of PermissionItem
    for (; it_hmi_permissions != it_hmi_permissions_end; ++it_hmi_permissions) {
      // Possible key names are "allowed", "userDisallowed"
      hmi_permissions[(*it_hmi_permissions).first] = smart_objects::SmartObject(
            smart_objects::SmartType_Array);

      smart_objects::SmartObject& hmi_levels =
        hmi_permissions[(*it_hmi_permissions).first];

      std::set<policy::HMILevel>::const_iterator it_hmi_levels =
        (*it_hmi_permissions).second.begin();
      std::set<policy::HMILevel>::const_iterator it_hmi_levels_end =
        (*it_hmi_permissions).second.end();

      for (size_t index_hmi_levels = 0; it_hmi_levels != it_hmi_levels_end;
           ++it_hmi_levels, ++index_hmi_levels) {
        hmi_levels[index_hmi_levels] = *it_hmi_levels;
      }
    }

    // Creating SO for parameterPermissions
    permission_item["parameterPermissions"] = smart_objects::SmartObject(
          smart_objects::SmartType_Map);

    smart_objects::SmartObject& parameter_permissions =
      permission_item["parameterPermissions"];

    policy::ParameterPermissions::const_iterator it_parameter_permissions =
      rpc_permissions.parameter_permissions.begin();
    policy::ParameterPermissions::const_iterator it_parameter_permissions_end =
      rpc_permissions.parameter_permissions.end();

    // Filling the parameterPermissions of PermissionItem
    for (; it_parameter_permissions != it_parameter_permissions_end;
         ++it_parameter_permissions) {
      // Possible key names are "allowed", "userDisallowed"
      parameter_permissions[(*it_parameter_permissions).first] =
        smart_objects::SmartObject(smart_objects::SmartType_Array);

      smart_objects::SmartObject& parameters =
        parameter_permissions[(*it_parameter_permissions).first];

      std::set<policy::Parameter>::const_iterator it_parameters =
        (*it_parameter_permissions).second.begin();
      std::set<policy::Parameter>::const_iterator it_parameters_end =
        (*it_parameter_permissions).second.end();

      for (size_t index_parameters = 0; it_parameters != it_parameters_end;
           ++it_parameters, ++index_parameters) {
        parameters[index_parameters] = *it_parameters;
      }
    }
  }

  ApplicationManagerImpl::instance()->ManageMobileCommand(notification);
}

void MessageHelper::FillAppRevokedPermissions(
    const policy::AppPermissions& permissions,
    smart_objects::SmartObject& message) {

  message[strings::msg_params]["appRevokedPermissions"] =
    smart_objects::SmartObject(smart_objects::SmartType_Array);
  smart_objects::SmartObject& revoked_permission_items =
      message[strings::msg_params]["appRevokedPermissions"];
  for (size_t i = 0; i < permissions.appRevokedPermissions.size(); ++i) {
    revoked_permission_items[i] = smart_objects::SmartObject(
                                    smart_objects::SmartType_Map);
    smart_objects::SmartObject& permission_item = revoked_permission_items[i];
    permission_item["name"] = permissions.appRevokedPermissions[i].
                              group_alias;

    permission_item["id"] = permissions.appRevokedPermissions[i].group_id;

    if (policy::kGroupUndefined !=
        permissions.appRevokedPermissions[i].state) {
      permission_item["allowed"] =
          policy::kGroupAllowed == permissions.appRevokedPermissions[i].state
          ? true : false;
    }
  }
}

void MessageHelper::SendOnAppPermissionsChangedNotification(
  uint32_t connection_key, const policy::AppPermissions& permissions) {
  using namespace smart_objects;
  SmartObjectSPtr notification = new SmartObject(SmartType_Map);
  if (!notification) {
    return;
  }

  SmartObject& message = *notification;

  message[strings::params][strings::function_id] =
    hmi_apis::FunctionID::SDL_OnAppPermissionChanged;

  message[strings::params][strings::message_type] = MessageType::kNotification;
  message[strings::msg_params][strings::app_id] = connection_key;

  // TODO(AOleynik): Add other parameters processing from incoming struct
  if (permissions.appRevoked) {
    message[strings::msg_params]["appRevoked"] = permissions.appRevoked;
  }
  if (permissions.isAppPermissionsRevoked) {
    message[strings::msg_params]["isAppPermissionsRevoked"] = permissions
        .isAppPermissionsRevoked;

    FillAppRevokedPermissions(permissions, message);
  }

  if (permissions.appPermissionsConsentNeeded) {
    message[strings::msg_params]["appPermissionsConsentNeeded"] = permissions
        .appPermissionsConsentNeeded;
  }
  if (permissions.appUnauthorized) {
    message[strings::msg_params]["appUnauthorized"] = permissions
        .appUnauthorized;
  }
  if (!permissions.priority.empty()) {
    message[strings::msg_params]["priority"] = GetPriorityCode(
          permissions.priority);
  }
  if (permissions.requestTypeChanged) {
    SmartObject request_types_array = SmartObject(SmartType_Array);
    for (uint16_t index = 0; index < permissions.requestType.size(); ++index) {
      request_types_array[index] = permissions.requestType[index];
    }
    message[strings::msg_params][strings::request_type] =
        request_types_array;
  }

  ApplicationManagerImpl::instance()->ManageHMICommand(notification);
}

void MessageHelper::SendGetStatusUpdateResponse(const std::string& status,
    uint32_t correlation_id) {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!message) {
    return;
  }

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::SDL_GetStatusUpdate;
  (*message)[strings::params][strings::message_type] =
    MessageType::kResponse;
  (*message)[strings::params][strings::correlation_id] = correlation_id;
  (*message)[strings::params][hmi_response::code] = 0;

  (*message)[strings::msg_params]["status"] = status;

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

void MessageHelper::SendUpdateSDLResponse(const std::string& result,
                                          uint32_t correlation_id) {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!message) {
    return;
  }

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::SDL_UpdateSDL;
  (*message)[strings::params][strings::message_type] =
    MessageType::kResponse;
  (*message)[strings::params][strings::correlation_id] = correlation_id;
  (*message)[strings::params][hmi_response::code] = 0;

  (*message)[strings::msg_params]["result"] = result;

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

void MessageHelper::SendOnStatusUpdate(const std::string& status) {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!message) {
    return;
  }

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::SDL_OnStatusUpdate;
  (*message)[strings::params][strings::message_type] =
    MessageType::kNotification;

  (*message)[strings::msg_params]["status"] = status;

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

void MessageHelper::SendGetSystemInfoRequest() {
  smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject(
      smart_objects::SmartType_Map);
  if (!message) {
    return;
  }

  (*message)[strings::params][strings::function_id] =
    hmi_apis::FunctionID::BasicCommunication_GetSystemInfo;
  (*message)[strings::params][strings::message_type] =
    MessageType::kRequest;
  (*message)[strings::params][strings::correlation_id] =
    ApplicationManagerImpl::instance()->GetNextHMICorrelationID();
  (*message)[strings::params][strings::protocol_version] =
    commands::CommandImpl::protocol_version_;
  (*message)[strings::params][strings::protocol_type] =
    commands::CommandImpl::hmi_protocol_type_;

  ApplicationManagerImpl::instance()->ManageHMICommand(message);
}

mobile_apis::Result::eType MessageHelper::VerifyImageFiles(
  smart_objects::SmartObject& message, ApplicationConstSharedPtr app) {
  if (NsSmartDeviceLink::NsSmartObjects::SmartType_Array == message.getType()) {
    for (uint32_t i = 0; i < message.length(); ++i) {
      mobile_apis::Result::eType res = VerifyImageFiles(message[i], app);
      if (mobile_apis::Result::SUCCESS != res) {
        LOG4CXX_DEBUG(logger_, "VerifyImageFiles result:" << res);
        return res;
      }
    }
  } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Map
             == message.getType()) {
    if (message.keyExists(strings::image_type)) {
      mobile_apis::Result::eType verification_result = VerifyImage(message,
          app);

      if (mobile_apis::Result::SUCCESS != verification_result) {
        LOG4CXX_DEBUG(logger_, "VerifyImageFiles result:" << verification_result);
        return verification_result;  // exit point
      }
    } else {
      std::set<std::string> keys = message.enumerate();

      for (std::set<std::string>::const_iterator key = keys.begin();
           key != keys.end(); ++key) {
        if (strings::soft_buttons != (*key)) {
          mobile_apis::Result::eType res = VerifyImageFiles(message[*key], app);
          if (mobile_apis::Result::SUCCESS != res) {
            LOG4CXX_DEBUG(logger_, "VerifyImageFiles result:" << res);
            return res;
          }
        }
      }
    }
  }  // all other types shoudn't be processed

  return mobile_apis::Result::SUCCESS;
}

mobile_apis::Result::eType MessageHelper::VerifyImage(
  smart_objects::SmartObject& image, ApplicationConstSharedPtr app) {
  // Checking image type first: if STATIC - skip existence check, since it is
  // HMI related file and it should know it location
  const uint32_t image_type = image[strings::image_type].asUInt();
  mobile_apis::ImageType::eType type =
    static_cast<mobile_apis::ImageType::eType>(image_type);
  if (mobile_apis::ImageType::STATIC == type) {
    return mobile_apis::Result::SUCCESS;
  }

  const std::string& file_name = image[strings::value].asString();

  std::string str = file_name;
  str.erase(remove(str.begin(), str.end(), ' '), str.end());
  if (0 == str.size()) {
    return mobile_apis::Result::INVALID_DATA;
  }

  std::string full_file_path;
  if (file_name.size() > 0 && file_name[0] == '/') {
    full_file_path = file_name;
  } else {
    const std::string& app_storage_folder =
            profile::Profile::instance()->app_storage_folder();
    if (!app_storage_folder.empty()) {
// TODO(nvaganov@luxoft.com): APPLINK-11293
      if (app_storage_folder[0] == '/') { // absolute path
        full_file_path = app_storage_folder + "/";
      }
      else { // relative path
        full_file_path = file_system::CurrentWorkingDirectory() + "/" +
                         app_storage_folder + "/";
      }
    }
    else { // empty app storage folder
      full_file_path = file_system::CurrentWorkingDirectory() + "/";
    }

    full_file_path += app->folder_name();
    full_file_path += "/";
    full_file_path += file_name;
  }

  if (!file_system::FileExists(full_file_path)) {
    return mobile_apis::Result::INVALID_DATA;
  }

  image[strings::value] = full_file_path;

  return mobile_apis::Result::SUCCESS;
}

mobile_apis::Result::eType MessageHelper::VerifyImageVrHelpItems(
  smart_objects::SmartObject& message, ApplicationConstSharedPtr app) {
  mobile_apis::Result::eType verification_result_image =
    mobile_apis::Result::SUCCESS;
  for (uint32_t i = 0; i < message.length(); ++i) {
    if (message[i].keyExists(strings::image)) {
      verification_result_image =  VerifyImage(message[i][strings::image], app);
      if (mobile_apis::Result::SUCCESS != verification_result_image) {
        return verification_result_image;
      }
    }
  }
  return mobile_apis::Result::SUCCESS;
}

bool MessageHelper::VerifySoftButtonString(const std::string& str) {

  if ((std::string::npos != str.find_first_of("\t\n")) ||
      (std::string::npos != str.find("\\n")) ||
      (std::string::npos != str.find("\\t")) ||
      (std::string::npos == str.find_first_not_of(' '))) {
    LOG4CXX_ERROR(logger_, "MessageHelper::VerifySoftButtonString"
                  "string contains incorrect character");
    return false;
  }
  return true;
}

bool MessageHelper::CheckWithPolicy(
    mobile_api::SystemAction::eType system_action,
    const std::string& app_mobile_id) {
  using namespace mobile_apis;
  bool result = true;
  policy::PolicyHandler* policy_handler = policy::PolicyHandler::instance();
  if (NULL != policy_handler && policy_handler->PolicyEnabled()) {
    result = policy_handler->CheckSystemAction(system_action, app_mobile_id);
  }

  return result;
}

mobile_apis::Result::eType MessageHelper::ProcessSoftButtons(
  smart_objects::SmartObject& message_params, ApplicationConstSharedPtr app) {
  using namespace mobile_apis;
  using namespace smart_objects;

  if (!message_params.keyExists(strings::soft_buttons)) {
    return mobile_apis::Result::SUCCESS;
  }

  const HMICapabilities& hmi_capabilities = ApplicationManagerImpl::instance()
      ->hmi_capabilities();
  const SmartObject* soft_button_capabilities = hmi_capabilities
      .soft_button_capabilities();
  bool image_supported = false;
  if (soft_button_capabilities) {
    image_supported = (*soft_button_capabilities)[hmi_response::image_supported]
                      .asBool();
  }

  SmartObject& request_soft_buttons = message_params[strings::soft_buttons];

  // Check whether soft buttons request is well-formed
  if (!ValidateSoftButtons(request_soft_buttons)) {
    return Result::INVALID_DATA;
  }

  SmartObject soft_buttons(SmartType_Array);

  uint32_t j = 0;
  size_t size = request_soft_buttons.length();
  for (uint32_t i = 0; i < size; ++i) {
    const int system_action = request_soft_buttons[i][strings::system_action].asInt();

    if (!CheckWithPolicy(static_cast<SystemAction::eType>(system_action),
                         app->mobile_app_id())) {
      return Result::DISALLOWED;
    }

    switch (request_soft_buttons[i][strings::type].asInt()) {
      case SoftButtonType::SBT_IMAGE: {
        if (!image_supported) {
          continue;
        }
        //Any text value for type "IMAGE" should be ignored.
        if (request_soft_buttons[i].keyExists(strings::text)) {
          request_soft_buttons[i].erase(strings::text);
        }
        if (request_soft_buttons[i].keyExists(strings::image)) {
          Result::eType verification_result = VerifyImage(
                request_soft_buttons[i][strings::image], app);
          if (Result::SUCCESS != verification_result) {
            return Result::INVALID_DATA;
          }
        } else {
          return Result::INVALID_DATA;
        }
        break;
      }
      case SoftButtonType::SBT_TEXT: {
        if ((!request_soft_buttons[i].keyExists(strings::text)) ||
            (!VerifySoftButtonString(
                request_soft_buttons[i][strings::text].asString()))) {
          return Result::INVALID_DATA;
        }
        break;
      }
      case SoftButtonType::SBT_BOTH: {

        if ((!request_soft_buttons[i].keyExists(strings::text)) ||
            ((request_soft_buttons[i][strings::text].length())
                && (!VerifySoftButtonString(
                request_soft_buttons[i][strings::text].asString())))) {
          return Result::INVALID_DATA;
        }

        bool image_exist = false;
        if (image_supported) {
          image_exist = request_soft_buttons[i].keyExists(strings::image);
          if (!image_exist) {
            return Result::INVALID_DATA;
          }
        }
        if (image_exist) {
          Result::eType verification_result = VerifyImage(
                request_soft_buttons[i][strings::image], app);

          if (Result::SUCCESS != verification_result) {
            return Result::INVALID_DATA;

          }
        }
        break;
      }
      default: {
        continue;
        break;
      }
    }

    soft_buttons[j] = request_soft_buttons[i];
    ++j;
  }

  request_soft_buttons = soft_buttons;

  if (0 == request_soft_buttons.length()) {
    message_params.erase(strings::soft_buttons);
  }
  return Result::SUCCESS;
}

void MessageHelper::SubscribeApplicationToSoftButton(
    smart_objects::SmartObject& message_params, ApplicationSharedPtr app,
    int32_t function_id) {
  SoftButtonID softbuttons_id;
  smart_objects::SmartObject& soft_buttons = message_params[strings::soft_buttons];
  unsigned int length = soft_buttons.length();
  for(unsigned int i = 0; i < length; ++i) {
    softbuttons_id.insert(soft_buttons[i][strings::soft_button_id].asUInt());
  }
  app->SubscribeToSoftButtons(function_id, softbuttons_id);
}

// TODO(AK): change printf to logger
bool MessageHelper::PrintSmartObject(const smart_objects::SmartObject& object) {
  return true;
#ifdef ENABLE_LOG
  static uint32_t tab = 0;
  std::string tab_buffer;

  if (tab == 0) {
    printf("\n-------------------------------------------------------------");
  }

  for (uint32_t i = 0; i < tab; ++i) {
    tab_buffer += "\t";
  }

  switch (object.getType()) {
    case NsSmartDeviceLink::NsSmartObjects::SmartType_Array: {
      for (size_t i = 0; i < object.length(); i++) {
        ++tab;

        printf("\n%s%zu: ", tab_buffer.c_str(), i);
        if (!PrintSmartObject(object.getElement(i))) {
          printf("\n");
          return false;
        }
      }
      break;
    }
    case NsSmartDeviceLink::NsSmartObjects::SmartType_Map: {
      std::set<std::string> keys = object.enumerate();

      for (std::set<std::string>::const_iterator key = keys.begin();
           key != keys.end(); key++) {
        ++tab;

        printf("\n%s%s: ", tab_buffer.c_str(), (*key).c_str());
        if (!PrintSmartObject(object[(*key).c_str()])) {
          printf("\n");
          return false;
        }
      }
      break;
    }
    case NsSmartDeviceLink::NsSmartObjects::SmartType_Boolean:
      object.asBool() ? printf("true\n") : printf("false\n");
      break;
    case NsSmartDeviceLink::NsSmartObjects::SmartType_Double: {
      printf("%f", object.asDouble());
      break;
    }
    case NsSmartDeviceLink::NsSmartObjects::SmartType_Integer:
      printf("%" PRId64 "\n", object.asInt64());
      break;
    case NsSmartDeviceLink::NsSmartObjects::SmartType_String:
      printf("%s", object.asString().c_str());
      break;
    case NsSmartDeviceLink::NsSmartObjects::SmartType_Character:
      printf("%c", object.asChar());
      break;
    default:
      printf("PrintSmartObject - default case\n");
      break;
  }

  if (0 != tab) {
    --tab;
  } else {
    printf("\n-------------------------------------------------------------\n");
  }
#endif
  return true;
}

}  //  namespace application_manager