summaryrefslogtreecommitdiff
path: root/src/components/resumption/src/last_state.cc
diff options
context:
space:
mode:
authorKozoriz <kozorizandriy@gmail.com>2016-03-24 08:27:20 +0200
committerKozoriz <kozorizandriy@gmail.com>2016-03-31 17:54:09 +0300
commit530e5cc597806056e7a837a009d6aa84bf8a3b2c (patch)
tree7dcae10809e232ab217b8a777e2a642ba4c9861b /src/components/resumption/src/last_state.cc
parentb94f45a387066e50307102e53352ccb6e3857f4e (diff)
downloadsdl_core-530e5cc597806056e7a837a009d6aa84bf8a3b2c.tar.gz
Refactor LastState to avoid singletons usage
Removed singletones from LastState
Diffstat (limited to 'src/components/resumption/src/last_state.cc')
-rw-r--r--src/components/resumption/src/last_state.cc40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/components/resumption/src/last_state.cc b/src/components/resumption/src/last_state.cc
index 4c1bc440b4..07bcc0d2a5 100644
--- a/src/components/resumption/src/last_state.cc
+++ b/src/components/resumption/src/last_state.cc
@@ -31,7 +31,6 @@
*/
#include "resumption/last_state.h"
-#include "config_profile/profile.h"
#include "utils/file_system.h"
#include "utils/logger.h"
@@ -39,29 +38,35 @@ namespace resumption {
CREATE_LOGGERPTR_GLOBAL(logger_, "Resumption")
+LastState::LastState(const std::string& app_storage_folder,
+ const std::string& app_info_storage)
+ : app_storage_folder_(app_storage_folder),
+ app_info_storage_(app_info_storage) {
+ LoadFromFileSystem();
+ LOG4CXX_AUTO_TRACE(logger_);
+}
+
+LastState::~LastState() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ SaveToFileSystem();
+}
+
void LastState::SaveToFileSystem() {
LOG4CXX_AUTO_TRACE(logger_);
- const std::string file =
- profile::Profile::instance()->app_info_storage();
const std::string& str = dictionary.toStyledString();
const std::vector<uint8_t> char_vector_pdata(
str.begin(), str.end());
- DCHECK(file_system::CreateDirectoryRecursively(
- profile::Profile::instance()->app_storage_folder()));
-
- LOG4CXX_INFO(logger_, "LastState::SaveToFileSystem " << file
- << str);
-
- DCHECK(file_system::Write(file, char_vector_pdata));
+ DCHECK(file_system::CreateDirectoryRecursively(app_storage_folder_));
+ LOG4CXX_INFO(logger_, "LastState::SaveToFileSystem "
+ << app_info_storage_ << str);
+ DCHECK(file_system::Write(app_info_storage_, char_vector_pdata));
}
void LastState::LoadFromFileSystem() {
- const std::string file =
- profile::Profile::instance()->app_info_storage();
std::string buffer;
- bool result = file_system::ReadFile(file, buffer);
+ bool result = file_system::ReadFile(app_info_storage_, buffer);
Json::Reader m_reader;
if (result && m_reader.parse(buffer, dictionary)) {
LOG4CXX_INFO(logger_, "Valid last state was found."
@@ -71,12 +76,5 @@ void LastState::LoadFromFileSystem() {
LOG4CXX_WARN(logger_, "No valid last state was found.");
}
-LastState::LastState() {
- LoadFromFileSystem();
-}
-
-LastState::~LastState() {
-
-}
-}
+} // resumption