summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/app_launch/app_launch_data_json.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/app_launch/app_launch_data_json.cc')
-rw-r--r--src/components/application_manager/src/app_launch/app_launch_data_json.cc86
1 files changed, 50 insertions, 36 deletions
diff --git a/src/components/application_manager/src/app_launch/app_launch_data_json.cc b/src/components/application_manager/src/app_launch/app_launch_data_json.cc
index 984997e424..86d585f215 100644
--- a/src/components/application_manager/src/app_launch/app_launch_data_json.cc
+++ b/src/components/application_manager/src/app_launch/app_launch_data_json.cc
@@ -32,26 +32,27 @@
#include "application_manager/app_launch/app_launch_data_json.h"
#include <algorithm>
#include "application_manager/smart_object_keys.h"
-#include "smart_objects/smart_object.h"
-
#include "json/json.h"
+#include "smart_objects/smart_object.h"
#include "utils/date_time.h"
namespace app_launch {
CREATE_LOGGERPTR_GLOBAL(logger_, "AppLaunch")
-AppLaunchDataJson::AppLaunchDataJson(const AppLaunchSettings& settings,
- resumption::LastState& last_state)
- : AppLaunchDataImpl(settings), last_state_(last_state) {}
+AppLaunchDataJson::AppLaunchDataJson(
+ const AppLaunchSettings& settings,
+ resumption::LastStateWrapperPtr last_state_wrapper)
+ : AppLaunchDataImpl(settings), last_state_wrapper_(last_state_wrapper) {}
AppLaunchDataJson::~AppLaunchDataJson() {}
-Json::Value& AppLaunchDataJson::GetSavedApplicationDataList() const {
+Json::Value& AppLaunchDataJson::GetSavedApplicationDataList(
+ Json::Value& dictionary) const {
using namespace application_manager;
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock autolock(app_launch_json_lock_);
- Json::Value& app_launch = GetApplicationData();
+ Json::Value& app_launch = GetApplicationData(dictionary);
if (!app_launch.isMember(strings::app_launch_list)) {
app_launch[strings::app_launch_list] = Json::Value(Json::arrayValue);
LOG4CXX_WARN(logger_, "app_list section is missed");
@@ -64,11 +65,11 @@ Json::Value& AppLaunchDataJson::GetSavedApplicationDataList() const {
return app_launch_list;
}
-Json::Value& AppLaunchDataJson::GetApplicationData() const {
+Json::Value& AppLaunchDataJson::GetApplicationData(
+ Json::Value& dictionary) const {
using namespace application_manager;
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock autolock(app_launch_json_lock_);
- Json::Value& dictionary = last_state().get_dictionary();
if (!dictionary.isMember(strings::app_launch)) {
dictionary[strings::app_launch] = Json::Value(Json::objectValue);
LOG4CXX_WARN(logger_, "app_launch section is missed");
@@ -82,12 +83,14 @@ Json::Value& AppLaunchDataJson::GetApplicationData() const {
}
Json::Value& AppLaunchDataJson::GetApplicationListAndIndex(
- const ApplicationData& app_data, int32_t& founded_index) const {
+ const ApplicationData& app_data,
+ int32_t& found_index,
+ Json::Value& dictionary) const {
using namespace application_manager;
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock autolock(app_launch_json_lock_);
- Json::Value& apps_list = GetSavedApplicationDataList();
+ Json::Value& apps_list = GetSavedApplicationDataList(dictionary);
const Json::ArrayIndex size = apps_list.size();
for (Json::ArrayIndex idx = 0; idx != size; ++idx) {
@@ -103,7 +106,7 @@ Json::Value& AppLaunchDataJson::GetApplicationListAndIndex(
if (deviceID == app_data.device_mac_ && bundleID == app_data.bundle_id_ &&
appID == app_data.mobile_app_id_) {
- founded_index = idx;
+ found_index = idx;
}
}
}
@@ -116,7 +119,11 @@ bool AppLaunchDataJson::IsAppDataAlreadyExisted(
LOG4CXX_AUTO_TRACE(logger_);
int32_t index = NotFound;
- GetApplicationListAndIndex(app_data, index);
+
+ resumption::LastStateAccessor accessor = last_state_wrapper_->get_accessor();
+ Json::Value dictionary = accessor.GetData().dictionary();
+ GetApplicationListAndIndex(app_data, index, dictionary);
+ accessor.GetMutableData().set_dictionary(dictionary);
return index == NotFound ? false : true;
}
@@ -127,7 +134,10 @@ bool AppLaunchDataJson::RefreshAppSessionTime(const ApplicationData& app_data) {
bool retVal = false;
int32_t index = NotFound;
- Json::Value& json_data_list = GetApplicationListAndIndex(app_data, index);
+ resumption::LastStateAccessor accessor = last_state_wrapper_->get_accessor();
+ Json::Value dictionary = accessor.GetData().dictionary();
+ Json::Value& json_data_list =
+ GetApplicationListAndIndex(app_data, index, dictionary);
if (index != NotFound) {
if (json_data_list.empty() == false) {
json_data_list[index][strings::app_launch_last_session] =
@@ -135,6 +145,7 @@ bool AppLaunchDataJson::RefreshAppSessionTime(const ApplicationData& app_data) {
retVal = true;
}
}
+ accessor.GetMutableData().set_dictionary(dictionary);
return retVal;
}
@@ -144,20 +155,22 @@ bool AppLaunchDataJson::AddNewAppData(const ApplicationData& app_data) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock autolock(app_launch_json_lock_);
+ resumption::LastStateAccessor accessor = last_state_wrapper_->get_accessor();
+ Json::Value dictionary = accessor.GetData().dictionary();
Json::Value& json_app_data =
- GetSavedApplicationDataList().append(Json::Value());
+ GetSavedApplicationDataList(dictionary).append(Json::Value());
json_app_data[strings::device_id] = app_data.device_mac_;
json_app_data[strings::app_id] = app_data.mobile_app_id_;
json_app_data[strings::bundle_id] = app_data.bundle_id_;
json_app_data[strings::app_launch_last_session] =
static_cast<Json::Value::UInt64>(getSecs(getCurrentTime()));
+ accessor.GetMutableData().set_dictionary(dictionary);
LOG4CXX_DEBUG(logger_,
"New application data saved. Detatils device_id: "
<< app_data.device_mac_
<< ", app_id: " << app_data.mobile_app_id_
<< ", bundle_id: " << app_data.bundle_id_ << ".");
-
return true;
}
@@ -167,7 +180,9 @@ std::vector<ApplicationDataPtr> AppLaunchDataJson::GetAppDataByDevMac(
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock autolock(app_launch_json_lock_);
std::vector<ApplicationDataPtr> dev_apps;
- const Json::Value& apps_list = GetSavedApplicationDataList();
+ resumption::LastStateAccessor accessor = last_state_wrapper_->get_accessor();
+ Json::Value dictionary = accessor.GetData().dictionary();
+ const Json::Value& apps_list = GetSavedApplicationDataList(dictionary);
const Json::ArrayIndex size = apps_list.size();
for (Json::ArrayIndex idx = 0; idx != size; ++idx) {
@@ -187,15 +202,16 @@ std::vector<ApplicationDataPtr> AppLaunchDataJson::GetAppDataByDevMac(
}
}
}
-
+ accessor.GetMutableData().set_dictionary(dictionary);
return dev_apps;
}
bool AppLaunchDataJson::Clear() {
LOG4CXX_AUTO_TRACE(logger_);
-
- GetSavedApplicationDataList().clear();
-
+ resumption::LastStateAccessor accessor = last_state_wrapper_->get_accessor();
+ Json::Value dictionary = accessor.GetData().dictionary();
+ GetSavedApplicationDataList(dictionary).clear();
+ accessor.GetMutableData().set_dictionary(dictionary);
LOG4CXX_DEBUG(logger_,
"Application launch JSON section successfully cleared.");
@@ -204,9 +220,10 @@ bool AppLaunchDataJson::Clear() {
uint32_t AppLaunchDataJson::GetCurentNumberOfAppData() const {
LOG4CXX_AUTO_TRACE(logger_);
-
- uint32_t list_size = GetSavedApplicationDataList().size();
-
+ resumption::LastStateAccessor accessor = last_state_wrapper_->get_accessor();
+ Json::Value dictionary = accessor.GetData().dictionary();
+ const uint32_t list_size = GetSavedApplicationDataList(dictionary).size();
+ accessor.GetMutableData().set_dictionary(dictionary);
LOG4CXX_DEBUG(logger_,
"Successfully was gotten app_launch list. Size: " << list_size);
@@ -219,7 +236,9 @@ bool AppLaunchDataJson::DeleteOldestAppData() {
sync_primitives::AutoLock autolock(app_launch_json_lock_);
std::vector<uint64_t> temp_array;
std::vector<Json::Value> temp_json_list;
- Json::Value& apps_list = GetSavedApplicationDataList();
+ resumption::LastStateAccessor accessor = last_state_wrapper_->get_accessor();
+ Json::Value dictionary = accessor.GetData().dictionary();
+ Json::Value& apps_list = GetSavedApplicationDataList(dictionary);
const Json::ArrayIndex size = apps_list.size();
// Search oldest record in Json
@@ -241,9 +260,7 @@ bool AppLaunchDataJson::DeleteOldestAppData() {
// Copy in temporary vector Json list without oldest record
int32_t i = 0;
- for (Json::Value::iterator it = GetSavedApplicationDataList().begin();
- it != GetSavedApplicationDataList().end();
- ++it, i++) {
+ for (auto it = apps_list.begin(); it != apps_list.end(); ++it, i++) {
if ((*it).isMember(strings::device_id) &&
(*it).isMember(strings::bundle_id) && (*it).isMember(strings::app_id) &&
(*it).isMember(strings::app_launch_last_session)) {
@@ -255,15 +272,13 @@ bool AppLaunchDataJson::DeleteOldestAppData() {
}
// Clear Json list
- GetSavedApplicationDataList().clear();
+ GetSavedApplicationDataList(dictionary).clear();
// Copy to Json new list without oldest one
- for (std::vector<Json::Value>::iterator it = temp_json_list.begin();
- it != temp_json_list.end();
- ++it) {
- GetSavedApplicationDataList().append((*it));
+ for (const auto& item : temp_json_list) {
+ GetSavedApplicationDataList(dictionary).append(item);
}
-
+ accessor.GetMutableData().set_dictionary(dictionary);
LOG4CXX_DEBUG(
logger_, "Oldest application launch data had been successfully deleted.");
@@ -272,8 +287,7 @@ bool AppLaunchDataJson::DeleteOldestAppData() {
bool AppLaunchDataJson::Persist() {
LOG4CXX_AUTO_TRACE(logger_);
- sync_primitives::AutoLock autolock(app_launch_json_lock_);
- last_state().SaveStateToFileSystem();
+ last_state_wrapper_->get_accessor().GetMutableData().SaveToFileSystem();
return true;
}