summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/resumption/resumption_data.cc
blob: 0663237c43ea366fa62c24dbbe9f99257bf91ca7 (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
/*
 * Copyright (c) 2015, 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/resumption/resumption_data.h"
#include "application_manager/application_manager_settings.h"
#include "application_manager/smart_object_keys.h"
#include "utils/logger.h"

namespace resumption {

SDL_CREATE_LOG_VARIABLE("Resumption")

ResumptionData::ResumptionData(
    const application_manager::ApplicationManager& application_manager)
    : application_manager_(application_manager) {}

smart_objects::SmartObject ResumptionData::GetApplicationCommands(
    app_mngr::ApplicationConstSharedPtr application) const {
  using namespace app_mngr;
  SDL_LOG_AUTO_TRACE();
  smart_objects::SmartObject commands_array(smart_objects::SmartType_Array);
  DCHECK_OR_RETURN(application, commands_array);
  if (!application) {
    SDL_LOG_ERROR("NULL Pointer App");
    return commands_array;
  }
  const DataAccessor<CommandsMap> accessor = application->commands_map();
  const CommandsMap& commands = accessor.GetData();
  CommandsMap::const_iterator it = commands.begin();
  for (int i = 0; it != commands.end(); ++it, ++i) {
    commands_array[i] = *(it->second);
  }
  return commands_array;
}

smart_objects::SmartObject ResumptionData::GetApplicationSubMenus(
    app_mngr::ApplicationConstSharedPtr application) const {
  using namespace app_mngr;
  SDL_LOG_AUTO_TRACE();

  DCHECK(application.get());
  smart_objects::SmartObject submenues_array =
      smart_objects::SmartObject(smart_objects::SmartType_Array);

  if (!application) {
    SDL_LOG_ERROR("NULL Pointer App");
    return submenues_array;
  }
  const DataAccessor<SubMenuMap> accessor = application->sub_menu_map();
  const SubMenuMap& sub_menus = accessor.GetData();
  SubMenuMap::const_iterator it = sub_menus.begin();
  for (int i = 0; it != sub_menus.end(); ++it, ++i) {
    submenues_array[i] = *(it->second);
  }
  return submenues_array;
}

smart_objects::SmartObject ResumptionData::GetApplicationInteractionChoiseSets(
    app_mngr::ApplicationConstSharedPtr application) const {
  using namespace app_mngr;
  SDL_LOG_AUTO_TRACE();

  DCHECK(application.get());
  smart_objects::SmartObject interaction_choice_set_array =
      smart_objects::SmartObject(smart_objects::SmartType_Array);
  if (!application) {
    SDL_LOG_ERROR("NULL Pointer App");
    return interaction_choice_set_array;
  }
  const DataAccessor<ChoiceSetMap> accessor = application->choice_set_map();
  const ChoiceSetMap& choices = accessor.GetData();
  ChoiceSetMap::const_iterator it = choices.begin();
  for (int i = 0; it != choices.end(); ++it, ++i) {
    interaction_choice_set_array[i] = *(it->second);
  }
  return interaction_choice_set_array;
}

smart_objects::SmartObject ResumptionData::GetApplicationGlobalProperties(
    app_mngr::ApplicationConstSharedPtr application) const {
  using namespace app_mngr;
  SDL_LOG_AUTO_TRACE();

  DCHECK(application.get());
  smart_objects::SmartObject global_properties =
      smart_objects::SmartObject(smart_objects::SmartType_Map);
  if (!application) {
    SDL_LOG_ERROR("NULL Pointer App");
    return global_properties;
  }

  global_properties[strings::help_prompt] =
      PointerToSmartObj(application->help_prompt());
  global_properties[strings::timeout_prompt] =
      PointerToSmartObj(application->timeout_prompt());
  global_properties[strings::vr_help] =
      PointerToSmartObj(application->vr_help());
  global_properties[strings::vr_help_title] =
      PointerToSmartObj(application->vr_help_title());
  global_properties[strings::keyboard_properties] =
      PointerToSmartObj(application->keyboard_props());
  global_properties[strings::menu_title] =
      PointerToSmartObj(application->menu_title());
  global_properties[strings::menu_icon] =
      PointerToSmartObj(application->menu_icon());
  global_properties[strings::menu_layout] =
      PointerToSmartObj(application->menu_layout());
  return global_properties;
}

smart_objects::SmartObject ResumptionData::GetApplicationSubscriptions(
    app_mngr::ApplicationConstSharedPtr application) const {
  using namespace app_mngr;
  SDL_LOG_AUTO_TRACE();
  DCHECK(application.get());
  smart_objects::SmartObject subscriptions =
      smart_objects::SmartObject(smart_objects::SmartType_Map);
  if (!application) {
    SDL_LOG_ERROR("NULL Pointer App");
    return subscriptions;
  }
  SDL_LOG_DEBUG("app_id:" << application->app_id());

  {
    DataAccessor<ButtonSubscriptions> button_accessor =
        application->SubscribedButtons();

    const ButtonSubscriptions& button_subscriptions = button_accessor.GetData();

    SDL_LOG_DEBUG("SubscribedButtons:" << button_subscriptions.size());
    Append(button_subscriptions.begin(),
           button_subscriptions.end(),
           strings::application_buttons,
           subscriptions);
  }

  auto extensions = application->Extensions();
  for (auto& extension : extensions.GetData()) {
    extension->SaveResumptionData(subscriptions);
  }

  return subscriptions;
}

smart_objects::SmartObject ResumptionData::GetApplicationFiles(
    app_mngr::ApplicationConstSharedPtr application) const {
  using namespace app_mngr;
  SDL_LOG_AUTO_TRACE();
  DCHECK(application.get());
  SDL_LOG_TRACE("ENTER app_id:" << application->app_id());

  smart_objects::SmartObject files =
      smart_objects::SmartObject(smart_objects::SmartType_Array);
  if (!application) {
    SDL_LOG_ERROR("NULL Pointer App");
    return files;
  }

  const AppFilesMap& app_files = application->getAppFiles();
  int i = 0;
  for (AppFilesMap::const_iterator file_it = app_files.begin();
       file_it != app_files.end();
       ++file_it) {
    const AppFile& file = file_it->second;
    if (file.is_persistent) {
      smart_objects::SmartObject file_data =
          smart_objects::SmartObject(smart_objects::SmartType_Map);
      file_data[strings::persistent_file] = file.is_persistent;
      file_data[strings::is_download_complete] = file.is_download_complete;
      file_data[strings::sync_file_name] = file.file_name;
      file_data[strings::file_type] = file.file_type;
      files[i++] = file_data;
    }
  }
  return files;
}

smart_objects::SmartObject ResumptionData::GetApplicationWidgetsInfo(
    app_mngr::ApplicationConstSharedPtr application) const {
  using namespace app_mngr;
  SDL_LOG_AUTO_TRACE();
  smart_objects::SmartObject windows_info =
      smart_objects::SmartObject(smart_objects::SmartType_Array);
  DCHECK_OR_RETURN(application, windows_info);
  const auto window_ids = application->GetWindowIds();
  const auto& window_optional_params_map =
      application->window_optional_params_map().GetData();
  for (const auto& window_id : window_ids) {
    const HmiStatePtr hmi_state = application->CurrentHmiState(window_id);
    if (mobile_apis::WindowType::WIDGET != hmi_state->window_type()) {
      continue;
    }
    auto info = CreateWindowInfoSO(
        window_id, hmi_state->window_type(), window_optional_params_map);

    windows_info[windows_info.length()] = info;
  }
  return windows_info;
}

smart_objects::SmartObject ResumptionData::CreateWindowInfoSO(
    const app_mngr::WindowID window_id,
    const mobile_apis::WindowType::eType window_type,
    const app_mngr::WindowParamsMap& window_optional_params_map) const {
  using namespace app_mngr;
  SDL_LOG_AUTO_TRACE();
  auto window_info = smart_objects::SmartObject(smart_objects::SmartType_Map);

  window_info[strings::window_id] = window_id;
  window_info[strings::window_type] = window_type;

  const auto& it_info = window_optional_params_map.find(window_id);
  if (window_optional_params_map.end() != it_info) {
    const auto keys = it_info->second->enumerate();

    for (const auto& key : keys) {
      window_info[key] = (*it_info->second)[key];
    }
  }

  return window_info;
}

smart_objects::SmartObject ResumptionData::PointerToSmartObj(
    const smart_objects::SmartObjectSPtr ptr) const {
  SDL_LOG_AUTO_TRACE();
  smart_objects::SmartObject temp;
  if (ptr) {
    temp = *ptr;
  }
  return temp;
}
}  // namespace resumption