MainController: add initialization check 25/92625/2
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Mon, 17 Oct 2016 15:32:42 +0000 (17:32 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 20 Oct 2016 08:26:01 +0000 (01:26 -0700)
Add initialization flag to avoid multiple initialization problem.

Change-Id: I80e796301999e06cd18d50dcee46deb6dd620e49

clock/inc/Controller/MainController.h
clock/src/Controller/MainController.cpp

index fa11c51..a0a83f2 100644 (file)
@@ -146,6 +146,11 @@ namespace controller {
                         * @brief global events subscriptions vector
                         */
                        std::vector<utils::Listener> listeners_;
+
+                       /**
+                        * @brief intiialized flag
+                        */
+                       bool initialized_;
        };
 }
 
index 16e7a22..3aeba55 100644 (file)
@@ -39,7 +39,8 @@ MainController &MainController::GetInstance()
 
 MainController::MainController() :
        edit_page_(main_view_), delete_page_(main_view_),
-       delete_presenter_(nullptr), edit_presenter_(nullptr)
+       delete_presenter_(nullptr), edit_presenter_(nullptr),
+       initialized_(false)
 {
 }
 
@@ -60,6 +61,8 @@ void MainController::Resume()
 
 int MainController::Init()
 {
+       if (initialized_) return 0;
+
        world_clock_model_ = new model::WorldClock();
        stop_watch_model_ = new model::StopWatch();
        timer_model_ = new model::Timer();
@@ -76,11 +79,14 @@ int MainController::Init()
        listeners_.push_back(utils::EventBus::AddListener<AlarmEditRequestEvent>(
                        std::bind(&MainController::CreateEditAlarmPage, this, _1)));
 
+       initialized_ = true;
        return 0;
 }
 
 void MainController::Deinit()
 {
+       if (!initialized_) return;
+
        delete alarm_presenter_;
 
        delete world_clock_presenter_;
@@ -93,6 +99,7 @@ void MainController::Deinit()
        delete timer_model_;
 
        listeners_.clear();
+       initialized_ = false;
 }
 
 void MainController::CreateNewAlarmPage(Event &e)