summaryrefslogtreecommitdiff
path: root/src/components/application_manager/include/application_manager/resumption
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/include/application_manager/resumption')
-rw-r--r--src/components/application_manager/include/application_manager/resumption/pending_resumption_handler.h91
-rw-r--r--src/components/application_manager/include/application_manager/resumption/resume_ctrl.h53
-rw-r--r--src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h127
-rw-r--r--src/components/application_manager/include/application_manager/resumption/resumption_data_processor.h104
-rw-r--r--src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h384
5 files changed, 629 insertions, 130 deletions
diff --git a/src/components/application_manager/include/application_manager/resumption/pending_resumption_handler.h b/src/components/application_manager/include/application_manager/resumption/pending_resumption_handler.h
new file mode 100644
index 0000000000..8d21c1f34f
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/resumption/pending_resumption_handler.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2020, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_PENDING_RESUMPTION_HANDLER_H
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_PENDING_RESUMPTION_HANDLER_H
+#include "application_manager/app_extension.h"
+#include "application_manager/application_manager.h"
+#include "application_manager/event_engine/event_observer.h"
+
+namespace resumption {
+
+namespace app_mngr = application_manager;
+
+/**
+ * @brief The PendingResumptionHandler class responsibility to avoid
+ * duplication of subscription requests to HMI if multiple applications
+ * are registering
+ */
+class PendingResumptionHandler
+ : public application_manager::event_engine::EventObserver {
+ public:
+ PendingResumptionHandler(app_mngr::ApplicationManager& application_manager);
+
+ virtual ~PendingResumptionHandler() {}
+
+ /**
+ * @brief HandleResumptionSubscriptionRequest handles all subscriptions
+ * requests, which might be send to HMI under certain conditions
+ * @param extension reference to corresponding application extension
+ * @param subscriber callback for subscribing
+ * @param app reference to application owner
+ */
+ virtual void HandleResumptionSubscriptionRequest(
+ app_mngr::AppExtension& extension,
+ application_manager::Application& app) = 0;
+
+ /**
+ * @brief OnResumptionRevert is a callback to be called in the case, when
+ * resumption is failed for current application.
+ */
+ virtual void OnResumptionRevert() = 0;
+
+ resumption::ResumptionDataProcessor& resumption_data_processor();
+
+ protected:
+ /**
+ * @brief MakeResumptionRequest creates resumption request
+ * @param corr_id correlation ID
+ * @param function_id function ID
+ * @param message Message to HMI
+ * @return instance of ResumptionRequest class
+ */
+ ResumptionRequest MakeResumptionRequest(
+ const uint32_t corr_id,
+ const hmi_apis::FunctionID::eType function_id,
+ const smart_objects::SmartObject& message);
+
+ app_mngr::ApplicationManager& application_manager_;
+};
+} // namespace resumption
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_PENDING_RESUMPTION_HANDLER_H
diff --git a/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h b/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h
index e572eaec39..d945df6154 100644
--- a/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h
+++ b/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h
@@ -46,6 +46,7 @@ typedef std::shared_ptr<const Application> ApplicationConstSharedPtr;
namespace app_mngr = application_manager;
namespace resumption {
+class ResumptionDataProcessor;
/**
* @brief Contains logic for storage/restore data of applications.
@@ -59,6 +60,16 @@ class ResumeCtrl {
virtual ~ResumeCtrl() {}
/**
+ * @brief ResumptionCallBack Function signature to be called when
+ * data resumption will be finished
+ * @param result_code result code for sending to mobile
+ * @param info additional info for sending to mobile
+ */
+ typedef std::function<void(mobile_apis::Result::eType result_code,
+ const std::string& info)>
+ ResumptionCallBack;
+
+ /**
* @brief Save all applications info to the file system
*/
virtual void SaveAllApplications() = 0;
@@ -79,13 +90,6 @@ class ResumeCtrl {
application_manager::ApplicationSharedPtr application) = 0;
/**
- * @brief Restore widgets HMI level on the resumption response from HMI
- * @param response_message smart_object with HMI message
- */
- virtual void RestoreWidgetsHMIState(
- const smart_objects::SmartObject& response_message) = 0;
-
- /**
* @brief Set application HMI Level as stored in policy
* @param application is application witch HMI Level is need to setup
* @return true if success, otherwise return false
@@ -108,16 +112,6 @@ class ResumeCtrl {
bool check_policy = true) = 0;
/**
- * @brief RestoreAppWidgets add widgets for the application
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- * @return the number of widget windows to be resumed
- */
- virtual size_t RestoreAppWidgets(
- application_manager::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app) = 0;
-
- /**
* @brief Remove application from list of saved applications
* @param application is application which need to be removed
* @return return true, if success, otherwise return false
@@ -175,10 +169,13 @@ class ResumeCtrl {
* @brief Start timer for resumption applications
* Restore D1-D5 data
* @param application that is need to be restored
+ * @param hash stored hash value for this app
+ * @param callback Function to be called when data resumption will be finished
* @return true if it was saved, otherwise return false
*/
virtual bool StartResumption(app_mngr::ApplicationSharedPtr application,
- const std::string& hash) = 0;
+ const std::string& hash,
+ ResumptionCallBack callback) = 0;
/**
* @brief Start timer for resumption applications
* Does not restore D1-D5 data
@@ -196,6 +193,15 @@ class ResumeCtrl {
virtual void RetryResumption(const uint32_t app_id) = 0;
/**
+ * @brief Handle restored data when timeout appeared
+ * @param correlation_id - const int32_t
+ * @param function id hmi_apis::FunctionID::eType
+ */
+
+ virtual void HandleOnTimeOut(const uint32_t correlation_id,
+ const hmi_apis::FunctionID::eType) = 0;
+
+ /**
* @brief Check if there are all files need for resumption
* @param application that is need to be restored
* @return true if it all files exist, otherwise return false
@@ -206,6 +212,7 @@ class ResumeCtrl {
/**
* @brief Check application hash
* @param application that is need to be restored
+ * @param hash stored hash value to be checked for restoring application
* @return true if it was saved, otherwise return false
*/
virtual bool CheckApplicationHash(app_mngr::ApplicationSharedPtr application,
@@ -300,11 +307,19 @@ class ResumeCtrl {
virtual int32_t GetSavedAppHmiLevel(const std::string& app_id,
const std::string& device_id) const = 0;
+ /**
+ * @brief StartWaitingForDisplayCapabilitiesUpdate add application to
+ * capabilities builder waitlist
+ * @param application application to add
+ * @param is_resume_app flag to check whether app data should be resumed or
+ * not
+ */
virtual void StartWaitingForDisplayCapabilitiesUpdate(
- app_mngr::ApplicationSharedPtr application) = 0;
+ app_mngr::ApplicationSharedPtr application, const bool is_resume_app) = 0;
virtual time_t LaunchTime() const = 0;
+ virtual ResumptionDataProcessor& resumption_data_processor() = 0;
#ifdef BUILD_TESTS
virtual void set_resumption_storage(
std::shared_ptr<ResumptionData> mock_storage) = 0;
diff --git a/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h b/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h
index 3ac59b9f88..379b25d8d4 100644
--- a/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h
+++ b/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h
@@ -44,6 +44,7 @@
#include "application_manager/application.h"
#include "application_manager/event_engine/event_observer.h"
#include "application_manager/resumption/resumption_data.h"
+#include "application_manager/resumption/resumption_data_processor.h"
#include "interfaces/HMI_API.h"
#include "interfaces/HMI_API_schema.h"
#include "interfaces/MOBILE_API_schema.h"
@@ -56,8 +57,7 @@ namespace resumption {
* @brief Contains logic for storage/restore data of applications.
*/
-class ResumeCtrlImpl : public ResumeCtrl,
- public app_mngr::event_engine::EventObserver {
+class ResumeCtrlImpl : public ResumeCtrl {
public:
/**
* @brief allows to create ResumeCtrlImpl object
@@ -70,12 +70,6 @@ class ResumeCtrlImpl : public ResumeCtrl,
~ResumeCtrlImpl();
/**
- * @brief Event, that raised if application get resumption response from HMI
- * @param event : event object, that contains smart_object with HMI message
- */
- void on_event(const app_mngr::event_engine::Event& event) OVERRIDE;
-
- /**
* @brief Save all applications info to the file system
*/
void SaveAllApplications() OVERRIDE;
@@ -93,9 +87,6 @@ class ResumeCtrlImpl : public ResumeCtrl,
*/
bool RestoreAppHMIState(app_mngr::ApplicationSharedPtr application) OVERRIDE;
- void RestoreWidgetsHMIState(
- const smart_objects::SmartObject& response_message) OVERRIDE;
-
/**
* @brief Set application HMI Level as stored in policy
* @param application is application witch HMI Level is need to setup
@@ -118,15 +109,6 @@ class ResumeCtrlImpl : public ResumeCtrl,
bool check_policy = true) OVERRIDE;
/**
- * @brief RestoreAppWidgets add widgets for the application
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- */
- size_t RestoreAppWidgets(
- application_manager::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app) OVERRIDE;
-
- /**
* @brief Remove application from list of saved applications
* @param application is application which need to be removed
* @return return true, if success, otherwise return false
@@ -181,21 +163,13 @@ class ResumeCtrlImpl : public ResumeCtrl,
*/
void StopRestoreHmiLevelTimer();
- /**
- * @brief Start timer for resumption applications
- * Restore D1-D5 data
- * @param application that is need to be restored
- * @return true if it was saved, otherwise return false
- */
bool StartResumption(app_mngr::ApplicationSharedPtr application,
- const std::string& hash) OVERRIDE;
+ const std::string& hash,
+ ResumptionCallBack callback) OVERRIDE;
+
+ void HandleOnTimeOut(const uint32_t correlation_id,
+ const hmi_apis::FunctionID::eType) OVERRIDE;
- /**
- * @brief Start timer for resumption applications
- * Does not restore D1-D5 data
- * @param application that is need to be restored
- * @return true if it was saved, otherwise return false
- */
bool StartResumptionOnlyHMILevel(
app_mngr::ApplicationSharedPtr application) OVERRIDE;
@@ -310,7 +284,8 @@ class ResumeCtrlImpl : public ResumeCtrl,
const std::string& device_id) const OVERRIDE;
void StartWaitingForDisplayCapabilitiesUpdate(
- app_mngr::ApplicationSharedPtr application) OVERRIDE;
+ app_mngr::ApplicationSharedPtr application,
+ const bool is_resume_app) OVERRIDE;
/**
* @brief geter for launch_time_
@@ -330,6 +305,8 @@ class ResumeCtrlImpl : public ResumeCtrl,
*/
void StartSavePersistentDataTimer() OVERRIDE;
+ ResumptionDataProcessor& resumption_data_processor();
+
#ifdef BUILD_TESTS
void set_resumption_storage(
std::shared_ptr<ResumptionData> mock_storage) OVERRIDE;
@@ -354,9 +331,12 @@ class ResumeCtrlImpl : public ResumeCtrl,
/**
* @brief restores saved data of application
* @param application contains application for which restores data
+ * @param callback callback, which contains logic for sending response
+ * to mobile and updating hash
* @return true if success, otherwise return false
*/
- bool RestoreApplicationData(app_mngr::ApplicationSharedPtr application);
+ bool RestoreApplicationData(app_mngr::ApplicationSharedPtr application,
+ ResumptionCallBack callback);
/**
* @brief SaveDataOnTimer :
@@ -372,67 +352,6 @@ class ResumeCtrlImpl : public ResumeCtrl,
void FinalPersistData();
/**
- * @brief AddFiles allows to add files for the application
- * which should be resumed
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- */
- void AddFiles(app_mngr::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app);
-
- /**
- * @brief AddSubmenues allows to add sub menues for the application
- * which should be resumed
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- */
- void AddSubmenues(app_mngr::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app);
-
- /**
- * @brief AddCommands allows to add commands for the application
- * which should be resumed
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- */
- void AddCommands(app_mngr::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app);
-
- /**
- * @brief AddChoicesets allows to add choice sets for the application
- * which should be resumed
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- */
- void AddChoicesets(app_mngr::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app);
-
- /**
- * @brief SetGlobalProperties allows to restore global properties.
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- */
- void SetGlobalProperties(app_mngr::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app);
-
- /**
- * @brief AddSubscriptions allows to restore subscriptions
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- */
- void AddSubscriptions(app_mngr::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app);
-
- /**
- * @brief AddWayPointsSubscription allows to restore subscription
- * for WayPoints
- * @param application application which will be resumed
- * @param saved_app application specific section from backup file
- */
- void AddWayPointsSubscription(app_mngr::ApplicationSharedPtr application,
- const smart_objects::SmartObject& saved_app);
-
- /**
* @brief Checks if saved HMI level is allowed for resumption
* by Ignition Cycle restrictions
* @param saved_app application specific section from backup file
@@ -541,21 +460,6 @@ class ResumeCtrlImpl : public ResumeCtrl,
*/
void SetLastIgnOffTime(time_t ign_off_time);
- /**
- * @brief Process specified HMI request
- * @param request Request to process
- * @param use_events Process request events or not flag
- * @return TRUE on success, otherwise FALSE
- */
- bool ProcessHMIRequest(smart_objects::SmartObjectSPtr request = NULL,
- bool use_events = false);
-
- /**
- * @brief Process list of HMI requests using ProcessHMIRequest method
- * @param requests List of requests to process
- */
- void ProcessHMIRequests(const smart_objects::SmartObjectList& requests);
-
void InsertToTimerQueue(uint32_t app_id, uint32_t time_stamp);
/**
@@ -635,6 +539,7 @@ class ResumeCtrlImpl : public ResumeCtrl,
time_t wake_up_time_;
std::shared_ptr<ResumptionData> resumption_storage_;
application_manager::ApplicationManager& application_manager_;
+ std::unique_ptr<ResumptionDataProcessor> resumption_data_processor_;
/**
*@brief Mapping correlation id to request
*wait for on event response from HMI to resume HMI Level
diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_processor.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor.h
new file mode 100644
index 0000000000..943022295b
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor.h
@@ -0,0 +1,104 @@
+/*
+ Copyright (c) 2020, Ford Motor Company
+ All rights reserved.
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided with the
+ distribution.
+ Neither the name of the Ford Motor Company nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_PROCESSOR_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_PROCESSOR_H_
+
+#include "application_manager/application.h"
+#include "application_manager/resumption/resume_ctrl.h"
+#include "smart_objects/smart_object.h"
+
+namespace resumption {
+
+/**
+ * @brief Determines whether response is successful
+ * judging from type of response received from HMI
+ * @param response from HMI
+ */
+bool IsResponseSuccessful(const smart_objects::SmartObject& response);
+
+/**
+ * @brief The ResumptionRequestID struct contains fields, needed during
+ * processing events, related to responses from HMI to each resumption request
+ */
+struct ResumptionRequestID {
+ hmi_apis::FunctionID::eType function_id;
+ int32_t correlation_id;
+
+ /**
+ * @brief This operator is needed for correct iteration through map, which
+ * contains keys with type ResumptionRequestID
+ */
+ bool operator<(const ResumptionRequestID& other) const;
+};
+
+/**
+ * @brief The ResumptionRequest struct contains information, needed for
+ * processing event, and request message
+ */
+struct ResumptionRequest {
+ ResumptionRequestID request_id;
+ smart_objects::SmartObject message;
+};
+
+/**
+ * @brief Contains logic for the resumption and revert resumption data of
+ * applications.
+ */
+class ResumptionDataProcessor {
+ public:
+ /**
+ * @brief Running resumption data process from saved_app to application.
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ * @param callback function signature to be called when
+ * data resumption will be finished
+ */
+ virtual void Restore(application_manager::ApplicationSharedPtr application,
+ smart_objects::SmartObject& saved_app,
+ ResumeCtrl::ResumptionCallBack callback) = 0;
+
+ /**
+ * @brief Handle restored data when timeout appeared
+ * @param correlation_id Correlation ID from event
+ * @param function_id Function ID from event
+ */
+ virtual void HandleOnTimeOut(
+ const uint32_t correlation_id,
+ const hmi_apis::FunctionID::eType function_id) = 0;
+
+ /**
+ * @brief subscribe to events for the application and save request
+ * @param app_id application id
+ * @param request for saving
+ */
+ virtual void SubscribeToResponse(const int32_t app_id,
+ const ResumptionRequest& request) = 0;
+};
+
+} // namespace resumption
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_PROCESSOR_H_
diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h
new file mode 100644
index 0000000000..0b3c84432b
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h
@@ -0,0 +1,384 @@
+/*
+ Copyright (c) 2020, Ford Motor Company
+ All rights reserved.
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided with the
+ distribution.
+ Neither the name of the Ford Motor Company nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_PROCESSOR_IMPL_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_PROCESSOR_IMPL_H_
+
+#include <functional>
+#include <map>
+#include <vector>
+
+#include "application_manager/application.h"
+#include "application_manager/event_engine/event_observer.h"
+#include "application_manager/resumption/resume_ctrl.h"
+#include "application_manager/resumption/resumption_data_processor.h"
+#include "smart_objects/smart_object.h"
+#include "utils/rwlock.h"
+
+namespace resumption {
+
+namespace app_mngr = application_manager;
+
+/**
+ * @brief ApplicationResumptionStatus contains information about all requests,
+ * which was sent, and results of this operation
+ */
+struct ApplicationResumptionStatus {
+ std::vector<ResumptionRequest> list_of_sent_requests;
+ std::vector<ResumptionRequest> error_requests;
+ std::vector<ResumptionRequest> successful_requests;
+ std::vector<std::string> unsuccessful_vehicle_data_subscriptions_;
+ std::vector<std::string> successful_vehicle_data_subscriptions_;
+};
+
+/**
+ * @brief Contains logic for the resumption and revert resumption data of
+ * applications.
+ */
+class ResumptionDataProcessorImpl
+ : public ResumptionDataProcessor,
+ public app_mngr::event_engine::EventObserver {
+ public:
+ /**
+ * @brief allows to create ResumptionDataProcessor object
+ */
+ explicit ResumptionDataProcessorImpl(
+ application_manager::ApplicationManager& application_manager);
+
+ /**
+ * @brief allows to destroy ResumptionDataProcessor object
+ */
+ ~ResumptionDataProcessorImpl();
+
+ void Restore(app_mngr::ApplicationSharedPtr application,
+ smart_objects::SmartObject& saved_app,
+ ResumeCtrl::ResumptionCallBack callback) override;
+
+ void on_event(const app_mngr::event_engine::Event& event) override;
+
+ void HandleOnTimeOut(const uint32_t correlation_id,
+ const hmi_apis::FunctionID::eType function_id) override;
+
+ void SubscribeToResponse(const int32_t app_id,
+ const ResumptionRequest& request) override;
+
+ private:
+ /**
+ * @brief GetAppIdWaitingForResponse returns application ID, which corresponds
+ * to function ID and correlation ID from event
+ * @param function_id Function ID
+ * @param corr_id Correlation ID
+ * @return optional object, which contains application ID, or empty optional,
+ * if such ID wasn't found
+ */
+ utils::Optional<uint32_t> GetAppIdWaitingForResponse(
+ const hmi_apis::FunctionID::eType function_id, const int32_t corr_id);
+
+ /**
+ * @brief GetRequest returns ResumptionRequest, which corresponds to
+ * function ID and correlation ID from event
+ * @param app_id ID of application, related to event
+ * @param function_id Function ID
+ * @param corr_id Correlation ID
+ * @return optional object, which contains resumption request, or empty
+ * optional, if such request wasn't found
+ */
+ utils::Optional<ResumptionRequest> GetRequest(
+ const uint32_t app_id,
+ const hmi_apis::FunctionID::eType function_id,
+ const int32_t corr_id);
+
+ /**
+ * @brief ProcessResumptionStatus processes received response to determine
+ * whether it is successful or not
+ * @param app_id ID of application, related to event
+ * @param response reference to response message
+ * @param found_request reference to found request
+ */
+ void ProcessResumptionStatus(const uint32_t app_id,
+ const smart_objects::SmartObject& response,
+ const ResumptionRequest& found_request);
+
+ /**
+ * @brief IsResumptionFinished checks whether some responses are still waiting
+ * @param app_id ID of application, related to event
+ * @param found_request reference to found request
+ * @return true, if resumption for this application is finished, or false, if
+ * some requests aren't processed yet
+ */
+ bool IsResumptionFinished(const uint32_t app_id,
+ const ResumptionRequest& found_request);
+
+ /**
+ * @brief IsResumptionSuccessful checks whether overall resumption status
+ * is successful or not
+ * @param app_id ID of application, related to event
+ * @return true, if resumption is successful, false otherwise
+ */
+ bool IsResumptionSuccessful(const uint32_t app_id);
+
+ /**
+ * @brief GetResumptionCallback returns ResumptionCallBack, which was stored
+ * for application, related to event
+ * @param app_id ID of application, related to event
+ * @return optional object, which contains callback, or empty optional,
+ * if callback wasn't found for such application ID
+ */
+ utils::Optional<ResumeCtrl::ResumptionCallBack> GetResumptionCallback(
+ const uint32_t app_id);
+
+ /**
+ * @brief EraseAppResumptionData erases data, needed for resumption, for
+ * given application
+ * @param app_id ID of application, related to event
+ * @param function_id Function ID
+ * @param corr_id Correlation ID
+ */
+ void EraseAppResumptionData(const uint32_t app_id,
+ const hmi_apis::FunctionID::eType function_id,
+ const int32_t corr_id);
+
+ /**
+ * @brief Processes response message from HMI
+ * @param response reference to response message
+ * @param function_id function id of response
+ * @param corr_id correlation id of response
+ */
+ void ProcessResponseFromHMI(const smart_objects::SmartObject& response,
+ const hmi_apis::FunctionID::eType function_id,
+ const int32_t corr_id);
+
+ /**
+ * @brief Revert the data to the state before Resumption
+ * @param shared ptr to application
+ */
+ void RevertRestoredData(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief Process specified HMI message
+ * @param request Message to process
+ * @param subscribe_on_response flag to specify should message events be
+ * processed or not
+ * @return TRUE on success, otherwise FALSE
+ */
+ void ProcessMessageToHMI(smart_objects::SmartObjectSPtr request,
+ bool subscribe_on_response);
+
+ /**
+ * @brief Process list of HMI messages using ProcessHMIRequest method
+ * @param messages List of messages to process
+ */
+ void ProcessMessagesToHMI(const smart_objects::SmartObjectList& messages);
+
+ /**
+ * @brief AddFiles allows to add files for the application
+ * which should be resumed
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void AddFiles(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief AddWindows allows to add widget windows for the application
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void AddWindows(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief AddSubmenus allows to add sub-menus for the application
+ * which should be resumed
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void AddSubmenus(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief Deleting sub-menus that have been resumed
+ * @param shared ptr to application
+ */
+ void DeleteSubmenus(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief AddCommands allows to add commands for the application
+ * which should be resumed
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void AddCommands(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief Deleting all commands that have been resumed
+ * @param shared ptr to application
+ */
+ void DeleteCommands(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief AddChoicesets allows to add choice sets for the application
+ * which should be resumed
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void AddChoicesets(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief Deleting choice sets that have been resumed
+ * @param shared ptr to application
+ */
+ void DeleteChoicesets(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief SetGlobalProperties allows to restore global properties.
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void SetGlobalProperties(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief Reset global properties that have been resumed
+ * @param shared ptr to application
+ */
+ void DeleteGlobalProperties(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief AddSubscriptions allows to restore subscriptions
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void AddSubscriptions(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief AddSubscriptions allows to restore subscriptions
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void AddButtonsSubscriptions(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief AddSubscriptions allows to restore subscriptions
+ * @param application application which will be resumed
+ * @param saved_app application specific section from backup file
+ */
+ void AddPluginsSubscriptions(app_mngr::ApplicationSharedPtr application,
+ const smart_objects::SmartObject& saved_app);
+
+ /**
+ * @brief Deleting subscriptions have been resumed
+ * @param shared ptr to application
+ */
+ void DeleteSubscriptions(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief Deleting buttons subscriptions have been resumed
+ * @param shared ptr to application
+ */
+ void DeleteButtonsSubscriptions(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief Deleting plugins subscriptions have been resumed
+ * @param app_id application id
+ */
+ void DeletePluginsSubscriptions(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief Deletting subscription for CreateWindow have been resumed
+ * @param shared ptr to application
+ */
+ void DeleteWindowsSubscriptions(app_mngr::ApplicationSharedPtr application);
+
+ /**
+ * @brief Get button subscriptions that need to be resumed.
+ * Since some subscriptions can be set by default during
+ * app registration, this function is needed to discard subscriptions
+ * that do not need to be resumed
+ * @param application which subscriptions to resume
+ */
+ app_mngr::ButtonSubscriptions GetButtonSubscriptionsToResume(
+ app_mngr::ApplicationSharedPtr application) const;
+
+ /**
+ * @brief Checks whether SubscribeVehicleData response successful or not and
+ * handles it
+ * @param request reference to request SO
+ * @param response reference to response SO
+ * @param status reference to struct, which stores informaion about
+ * successful and unsuccessful subscriptions to vehicle data
+ */
+ void CheckVehicleDataResponse(const smart_objects::SmartObject& request,
+ const smart_objects::SmartObject& response,
+ ApplicationResumptionStatus& status);
+
+ /**
+ * @brief Checks whether CreateWindow response successful or not and handles
+ * it
+ * @param request reference to request SO
+ * @param response reference to response SO
+ */
+ void CheckCreateWindowResponse(
+ const smart_objects::SmartObject& request,
+ const smart_objects::SmartObject& response) const;
+
+ /**
+ * @brief Determines whether application has saved data, including
+ * submenus, commands, choice sets, global properties, subscriptions to
+ * restore.
+ * @param saved_app smart object containing saved app data
+ * @return bool value stating whether app has mentioned data to restore
+ */
+ bool HasDataToRestore(const smart_objects::SmartObject& saved_app) const;
+
+ app_mngr::ApplicationManager& application_manager_;
+
+ /**
+ * @brief A map of the IDs and Application Resumption Status for these ID
+ **/
+ std::map<std::int32_t, ApplicationResumptionStatus> resumption_status_;
+ sync_primitives::RWLock resumption_status_lock_;
+
+ /**
+ * @brief A map of callbacks used when resumption is finished
+ */
+ std::map<std::int32_t, ResumeCtrl::ResumptionCallBack> register_callbacks_;
+ sync_primitives::RWLock register_callbacks_lock_;
+
+ /**
+ * @brief A map of sent requests and corresponding app_id
+ */
+ std::map<ResumptionRequestID, std::uint32_t> request_app_ids_;
+ sync_primitives::RWLock request_app_ids_lock_;
+};
+
+} // namespace resumption
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUMPTION_DATA_PROCESSOR_IMPL_H_