diff options
author | Kozoriz <kozorizandriy@gmail.com> | 2016-03-24 08:27:20 +0200 |
---|---|---|
committer | Kozoriz <kozorizandriy@gmail.com> | 2016-03-31 17:54:09 +0300 |
commit | 530e5cc597806056e7a837a009d6aa84bf8a3b2c (patch) | |
tree | 7dcae10809e232ab217b8a777e2a642ba4c9861b | |
parent | b94f45a387066e50307102e53352ccb6e3857f4e (diff) | |
download | sdl_core-530e5cc597806056e7a837a009d6aa84bf8a3b2c.tar.gz |
Refactor LastState to avoid singletons usage
Removed singletones from LastState
-rw-r--r-- | src/components/resumption/include/resumption/last_state.h | 30 | ||||
-rw-r--r-- | src/components/resumption/src/last_state.cc | 40 |
2 files changed, 34 insertions, 36 deletions
diff --git a/src/components/resumption/include/resumption/last_state.h b/src/components/resumption/include/resumption/last_state.h index 5183f1a1da..a331d9291c 100644 --- a/src/components/resumption/include/resumption/last_state.h +++ b/src/components/resumption/include/resumption/last_state.h @@ -36,14 +36,24 @@ #include <string> #include "utils/macro.h" -#include "utils/singleton.h" #include "json/json.h" namespace resumption { -class LastState : public utils::Singleton<LastState> { +class LastState { public: /** + * @brief Constructor + */ + LastState(const std::string& app_storage_folder, + const std::string& app_info_storage); + + /** + * @brief Destructor + */ + ~LastState(); + + /** * @brief Saving dictionary to filesystem */ void SaveToFileSystem(); @@ -54,25 +64,15 @@ class LastState : public utils::Singleton<LastState> { Json::Value dictionary; private: + DISALLOW_COPY_AND_ASSIGN(LastState); /** * @brief Load dictionary from filesystem */ void LoadFromFileSystem(); - /** - * @brief Private default constructor - */ - LastState(); - - /** - * @brief Private destructor - */ - ~LastState(); - - DISALLOW_COPY_AND_ASSIGN(LastState); - - FRIEND_BASE_SINGLETON_CLASS(LastState); + std::string app_storage_folder_; + std::string app_info_storage_; }; } // namespace resumption 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 |