Refactor Controller & AlarmProvider classes 73/103873/10
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 9 Dec 2016 13:21:37 +0000 (14:21 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Wed, 21 Dec 2016 10:33:01 +0000 (11:33 +0100)
Remove singleton Controller and AlarmProvider classes.
Add new TizenApp class to wrap basic main loop functionality.

Change-Id: If86e46dd7e3b6ccf80dd257c823b9b021ded5780

18 files changed:
clock/inc/Clock.h
clock/inc/Common/Defines.h
clock/inc/Controller/MainController.h
clock/inc/Controller/RingController.h
clock/inc/Internal/AlarmBinaryStorage.h [moved from clock/inc/Internal/AlarmProviderFile.h with 78% similarity]
clock/inc/Model/AlarmProvider.h
clock/inc/Presenter/AlarmPresenter.h
clock/inc/Presenter/EditAlarmPresenter.h
clock/inc/Utils/TizenApp.h [new file with mode: 0644]
clock/src/Clock.cpp
clock/src/Controller/MainController.cpp
clock/src/Controller/RingController.cpp
clock/src/Model/AlarmBinaryStorage.cpp [moved from clock/src/Model/AlarmProviderFile.cpp with 69% similarity]
clock/src/Model/AlarmProvider.cpp
clock/src/Presenter/AlarmPresenter.cpp
clock/src/Presenter/EditAlarmPresenter.cpp
clock/src/Utils/TizenApp.cpp [new file with mode: 0644]
clock/src/View/AlarmView.cpp

index 4812d95..4050cde 100644 (file)
@@ -2,8 +2,7 @@
 * Copyright 2016  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
+* you may not use this file except in compliance with the License.  * You may obtain a copy of the License at
 *
 * http://floralicense.org/license/
 *
 #ifndef __CLOCK_H__
 #define __CLOCK_H__
 
-#include <Elementary.h>
 #include "Controller/MainController.h"
-
-#ifdef  LOG_TAG
-#undef  LOG_TAG
-#endif
-#define LOG_TAG "CLOCK"
-
-#if !defined(PACKAGE)
-#define PACKAGE "org.tizen.clock"
-#endif
-
-#define EDJ_FILE "edje/clock.edj"
-#define GRP_MAIN "main"
+#include "Controller/RingController.h"
+#include "Model/AlarmProvider.h"
+#include "Utils/TizenApp.h"
 
 /**
  * @defgroup Models Models
  */
 
 /**
- * @defgroup main Main
+ * @defgroup Utils Utils
+ */
+
+/**
+ * @defgroup Main Main
  */
+
+/**
+ * @addtogroup Main
+ * @{
+ */
+class ClockApp : public utils::TizenApp {
+       public:
+               /**
+                * @brief Default constructor
+                */
+               ClockApp() {}
+
+               /**
+                * @brief Handles language changes.
+                */
+               void OnLanguageChanged(app_event_info_h event) override;
+
+               /**
+                * @brief Handles terminate request.
+                */
+               void OnTerminate() override;
+
+               /**
+                * @brief Handles resume request.
+                */
+               void OnResume() override;
+
+               /**
+                * @brief Handles pause request.
+                */
+               void OnPause() override;
+
+               /**
+                * @brief Handles service request.
+                */
+               void OnService(app_control_h app) override;
+
+               /**
+                * @brief Handles application create request.
+                */
+               bool OnCreate() override;
+       private:
+               model::AlarmProvider *provider_;
+               controller::MainController *main_ctrl_;
+               controller::RingController *ring_ctrl_;
+};
+
+/**
+ * @}
+ */
+
 #endif /* __CLOCK_H__ */
index 40e57fb..0fea200 100644 (file)
 
 #define SOUND_DEFAULT "settings/ringtone_sdk.mp3"
 
+#if !defined(PACKAGE)
+#define PACKAGE "org.tizen.clock"
+#endif
+
+#define EDJ_FILE "edje/clock.edj"
+#define GRP_MAIN "main"
+
 
 #endif
index 380b7f3..bbec65f 100644 (file)
@@ -67,9 +67,9 @@ namespace controller {
        class MainController {
                public:
                        /**
-                        * @brief Retrieves singleton instance.
+                        * @brief Constructs MainController class object.
                         */
-                       static MainController &GetInstance();
+                       MainController(model::AlarmProvider*);
 
                        /**
                         * @brief Destructor.
@@ -110,11 +110,6 @@ namespace controller {
 
                private:
                        /**
-                        * @brief Constructs MainController class object.
-                        */
-                       MainController();
-
-                       /**
                         * @brief Creates new "Edit/Create" alarm page.
                         */
                        void CreateNewAlarmPage(utils::Event &e);
@@ -136,6 +131,8 @@ namespace controller {
                         */
                        void CreateNewWorldClockReorderPage(utils::Event &e);
 
+                       model::AlarmProvider *provider_;
+
                        model::WorldClock *world_clock_model_;
                        model::StopWatch *stop_watch_model_;
                        model::Timer *timer_model_;
index 9081e56..cc8faf9 100644 (file)
@@ -35,8 +35,7 @@ namespace controller {
 
        class RingController {
        public:
-               static RingController &GetInstance(void);
-
+               RingController(model::AlarmProvider *provider);
                ~RingController();
 
                void operator=(RingController const&) = delete;
@@ -49,12 +48,12 @@ namespace controller {
                presenter::RingPresenter *presenter_;
                model::Ring *model_;
                view::RingView *view_;
+               model::AlarmProvider *provider_;
                utils::Listener listener_;
 
                void RingCreate(void);
                void RingDestroy(utils::Event &e);
 
-               RingController();
        };
 
 } //namespace model
similarity index 78%
rename from clock/inc/Internal/AlarmProviderFile.h
rename to clock/inc/Internal/AlarmBinaryStorage.h
index 9baff56..e1b515b 100644 (file)
 * limitations under the License.
 */
 
-#ifndef _INTERNAL_ALARM_PROVIDER_FILE_H_
-#define _INTERNAL_ALARM_PROVIDER_FILE_H_
+#ifndef _INTERNAL_ALARM_PROVIDER_BINARY_STORAGE_H_
+#define _INTERNAL_ALARM_PROVIDER_BINARY_STORAGE_H_
 
+#include <functional>
 #include <vector>
 #include <list>
 
-#include "Model/AlarmProvider.h"
+#include "Model/Alarm.h"
+#include "Utils/Serialization.h"
 
 namespace internal {
-       class AlarmProviderFile : public model::AlarmProvider
+       class AlarmBinaryStorage : utils::ISerializable
        {
                public:
                        std::vector<std::reference_wrapper<model::Alarm>> GetAlarms();
                        model::Alarm* GetAlarmWithId(model::AlarmId id);
                        void Add(model::Alarm& alarm);
                        void Remove(std::reference_wrapper<model::Alarm> alarm);
-                       AlarmProviderFile(utils::IReader &r);
-                       ~AlarmProviderFile();
+                       AlarmBinaryStorage(utils::IReader &r);
+                       virtual ~AlarmBinaryStorage();
                        void Serialize(utils::IWriter &w) const;
                        int Capacity() const;
                        bool IsFull() const;
index dbe1d1c..e79a87a 100644 (file)
 #ifndef _CLOCK_ALARM_PROVIDER_H_
 #define _CLOCK_ALARM_PROVIDER_H_
 
-#include "Common/Defines.h"
+#include "Internal/AlarmBinaryStorage.h"
 #include "Model/Alarm.h"
-#include "Utils/Serialization.h"
 
 #include <vector>
 #include <functional>
 
 namespace model {
-       class AlarmProvider : public utils::ISerializable {
+       class AlarmProvider {
                public:
-                       static AlarmProvider *GetInstance();
-                       static void Sync();
+                       /**
+                        * @brief Constructs AlarmProvider class
+                        */
+                       AlarmProvider();
 
-                       virtual std::vector<std::reference_wrapper<Alarm>> GetAlarms() = 0;
-                       virtual bool HasActiveAlarms() = 0;
-                       virtual Alarm *GetAlarmWithId(AlarmId id) = 0;
-                       virtual void Add(Alarm& alarm) = 0;
-                       virtual void Remove(std::reference_wrapper<Alarm> alarm) = 0;
+                       /**
+                        * @brief AlarmProvider destructor
+                        */
+                       ~AlarmProvider();
+
+                       /**
+                        * @brief Fetch alarms from provider's internal storage
+                        */
+                       std::vector<std::reference_wrapper<Alarm>> GetAlarms();
+
+                       /**
+                        * @brief Get Alarms with specific id.
+                        */
+                       Alarm *GetAlarmWithId(AlarmId id);
+
+                       /**
+                        * @brief Add alarm to provider database.
+                        */
+                       void Add(Alarm& alarm);
+
+                       /**
+                        * @brief Remove alarm from provider's database.
+                        */
+                       void Remove(std::reference_wrapper<Alarm> alarm);
 
                        /**
                         * @brief Return capactiy of provider's internal storage
                         */
-                       virtual int Capacity() const = 0;
+                       int Capacity() const;
 
                        /**
                         * @brief Check if provider's internal storage is full.
                         */
-                       virtual bool IsFull() const = 0;
-               protected:
-                       AlarmProvider() {}
-                       virtual ~AlarmProvider() {}
+                       bool IsFull() const;
+
+                       /**
+                        * @brief Sync AlarmProviderFile internal storage
+                        */
+                       void Sync();
+
+                       /**
+                        * @brief returns true if container have any active alarms.
+                        */
+                       bool HasActiveAlarms();
+               private:
+                       /**
+                        * Alarm provider private backend implementation
+                        */
+                       internal::AlarmBinaryStorage *impl_;
+
        };
 } /* model */
 
index 540ce84..6cca73c 100644 (file)
@@ -31,8 +31,8 @@ namespace presenter {
                        AlarmPresenter(view::AlarmView *view, model::AlarmProvider *model);
                        ~AlarmPresenter();
                private:
-                       view::AlarmView *view;
-                       model::AlarmProvider *model;
+                       view::AlarmView *view_;
+                       model::AlarmProvider *model_;
                        void ShowAll();
                        void OnItemSelected(int idx);
                        void OnAddButtonClicked();
index 93d948e..6d2dd5b 100644 (file)
@@ -27,8 +27,8 @@ namespace presenter {
                        EditAlarmPresenter(model::AlarmProvider *provider, model::Alarm *alarm, view::EditAlarmView& view);
                        ~EditAlarmPresenter();
                private:
-                       model::Alarm *alarm_;
                        model::AlarmProvider *provider_;
+                       model::Alarm *alarm_;
                        view::EditAlarmView &view_;
                        view::EditAlarmView::AlarmViewInfo info_;
                        void OnEditDone();
diff --git a/clock/inc/Utils/TizenApp.h b/clock/inc/Utils/TizenApp.h
new file mode 100644 (file)
index 0000000..a31cf82
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+* Copyright 2016  Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _CLOCK_UTILS_APP_H_
+#define _CLOCK_UTILS_APP_H_
+
+#include <app.h>
+
+namespace utils {
+
+/**
+ * @addtogroup Utils
+ * @{
+ */
+
+/**
+ * @brief Tizen application main class. Starts application main loop and manages
+ * lifecycle callbacks
+ */
+class TizenApp {
+       public:
+               /*
+                * @brief Default constuctor
+                */
+               TizenApp() {}
+
+               /**
+                * @brief Default destructor
+                */
+               virtual ~TizenApp() {}
+
+               /**
+                * @brief Invoked when system language has changed.
+                */
+               virtual void OnLanguageChanged(app_event_info_h event) {};
+
+               /**
+                * @brief Invoked when application recieved terminate request.
+                */
+               virtual void OnTerminate() {};
+
+               /**
+                * @brief Invoked when application recieved resume request (going
+                * foreground)
+                */
+               virtual void OnResume() {};
+
+               /**
+                * @brief Invoked when application recieved pause request (going
+                * background)
+                */
+               virtual void OnPause() {};
+
+               /**
+                * @brief Invoked when application recieved service request (recieve
+                * app control request from other application)
+                */
+               virtual void OnService(app_control_h app) {};
+
+               /**
+                * @brief Invoked when application recieved service request (recieve
+                * app control request from other application)
+                */
+               virtual bool OnCreate() { return false; };
+
+               /**
+                * @brief Run Tizen application main loop
+                */
+               int Run(int argc, char **argv);
+};
+/**
+ * @}
+ */
+
+}
+
+#endif
index 19d7455..e6907af 100644 (file)
 #include "Utils/Log.h"
 #include "app.h"
 #include "Clock.h"
-#include "Controller/MainController.h"
-#include "Controller/RingController.h"
-#include "Common/Defines.h"
+#include "Utils/TizenApp.h"
 
+bool ClockApp::OnCreate()
+{
+       elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
+       provider_ = new model::AlarmProvider();
+       main_ctrl_ = new controller::MainController(provider_);
+       ring_ctrl_ = new controller::RingController(provider_);
+       return true;
+}
+
+void ClockApp::OnLanguageChanged(app_event_info_h event)
+{
+       int ret;
+       char *language;
 
-using namespace controller;
+       ret = app_event_get_language(event, &language);
+       if (ret != APP_ERROR_NONE) {
+               ERR("app_event_get_language failed[%d]: %s", ret, get_error_message(ret));
+               return;
+       }
 
+       if (language != NULL) {
+               elm_language_set(language);
+               free(language);
+       }
+}
 
-static bool
-app_create(void *data)
+void ClockApp::OnTerminate()
 {
-       /* Hook to take necessary actions before main event loop starts
-          Initialize UI resources and application's data
-          If this function returns true, the main loop of application starts
-          If this function returns false, the application is terminated */
+       main_ctrl_->Deinit();
+       delete provider_;
+       delete main_ctrl_;
+       delete ring_ctrl_;
+}
 
-       DBG("app_create");
+void ClockApp::OnResume()
+{
+       main_ctrl_->Resume();
+}
 
-       return true;
+void ClockApp::OnPause()
+{
+       main_ctrl_->Pause();
 }
 
-static void
-app_control(app_control_h app_control, void *data)
+void ClockApp::OnService(app_control_h app_control)
 {
-       DBG("app_control");
        /* Handle the launch request. */
        char *opData;
 
        int ret = app_control_get_operation(app_control, &opData);
        if (ret != APP_CONTROL_ERROR_NONE || opData == NULL) {
-               ERR("app_control_get_operation failed");
+               ERR("app_control_get_operation failed[%d]: %s", ret, get_error_message(ret));
                return;
        }
        DBG("Operation: %s", opData);
 
-       if (!strcmp(opData, APP_CONTROL_OPERATION_DEFAULT))
-               MainController::GetInstance().Init();
-       else if (!strcmp(opData, APP_CONTROL_OPERATION_ALARM)) {
+       if (!strcmp(opData, APP_CONTROL_OPERATION_DEFAULT)) {
+               main_ctrl_->Init();
+       else if (!strcmp(opData, APP_CONTROL_OPERATION_ALARM)) {
 
                char *alarmID = NULL;
 
@@ -67,107 +90,18 @@ app_control(app_control_h app_control, void *data)
                        return;
                }
 
-               RingController::GetInstance().HandleAlarm(std::atoi(alarmID));
+               ring_ctrl_->HandleAlarm(std::atoi(alarmID));
                free(alarmID);
 
        } else if (!strcmp(opData, APP_CONTROL_OPERATION_TIMEOUT)) {
-               RingController::GetInstance().HandleTimeout();
+               ring_ctrl_->HandleTimeout();
        }
 
        free(opData);
 }
 
-static void
-app_pause(void *data)
-{
-       /* Take necessary actions when application becomes invisible. */
-       MainController::GetInstance().Pause();
-}
-
-static void
-app_resume(void *data)
-{
-       /* Take necessary actions when application becomes visible. */
-       MainController::GetInstance().Resume();
-}
-
-static void
-app_terminate(void *data)
-{
-       /* Release all resources. */
-       MainController::GetInstance().Deinit();
-}
-
-static void
-ui_app_lang_changed(app_event_info_h event_info, void *user_data)
-{
-       /*APP_EVENT_LANGUAGE_CHANGED*/
-
-       int ret;
-       char *language;
-
-       ret = app_event_get_language(event_info, &language);
-       if (ret != APP_ERROR_NONE) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
-               return;
-       }
-
-       if (language != NULL) {
-               elm_language_set(language);
-               free(language);
-       }
-}
-
-static void
-ui_app_orient_changed(app_event_info_h event_info, void *user_data)
-{
-       /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
-       return;
-}
-
-static void
-ui_app_region_changed(app_event_info_h event_info, void *user_data)
+int main(int argc, char **argv)
 {
-       /*APP_EVENT_REGION_FORMAT_CHANGED*/
-}
-
-static void
-ui_app_low_battery(app_event_info_h event_info, void *user_data)
-{
-       /*APP_EVENT_LOW_BATTERY*/
-}
-
-static void
-ui_app_low_memory(app_event_info_h event_info, void *user_data)
-{
-       /*APP_EVENT_LOW_MEMORY*/
-}
-
-int
-main(int argc, char *argv[])
-{
-       int ret = 0;
-
-       ui_app_lifecycle_callback_s event_callback = {0,};
-       app_event_handler_h handlers[5] = {NULL, };
-
-       event_callback.create = app_create;
-       event_callback.terminate = app_terminate;
-       event_callback.pause = app_pause;
-       event_callback.resume = app_resume;
-       event_callback.app_control = app_control;
-
-       elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
-
-       ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, NULL);
-       ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, NULL);
-       ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, NULL);
-       ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
-       ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, NULL);
-
-       ret = ui_app_main(argc, argv, &event_callback, NULL);
-       if (ret != APP_ERROR_NONE)
-               dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
-
-       return ret;
+       ClockApp app;
+       return app.Run(argc, argv);
 }
index 4549af9..075fe92 100644 (file)
@@ -38,13 +38,8 @@ using namespace presenter;
 using namespace model;
 using std::placeholders::_1;
 
-MainController &MainController::GetInstance()
-{
-       static MainController instance;
-       return instance;
-}
-
-MainController::MainController() :
+MainController::MainController(model::AlarmProvider *provider) :
+       provider_(provider),
        world_clock_model_(nullptr), stop_watch_model_(nullptr), timer_model_(nullptr),
 
        alarm_presenter_(nullptr), world_clock_presenter_(nullptr), stop_watch_presenter_(nullptr),
@@ -81,7 +76,7 @@ int MainController::Init()
        stop_watch_model_ = new model::StopWatch();
        timer_model_ = new model::Timer();
 
-       alarm_presenter_ = new AlarmPresenter((AlarmView *)main_view_.GetView(ALARM), AlarmProvider::GetInstance());
+       alarm_presenter_ = new AlarmPresenter((AlarmView *)main_view_.GetView(ALARM), provider_);
        world_clock_presenter_ = new WorldClockPresenter((WorldClockView *)main_view_.GetView(WORLD_CLOCK), world_clock_model_);
        stop_watch_presenter_ = new StopWatchPresenter((StopWatchView *)main_view_.GetView(STOP_WATCH), stop_watch_model_);
        timer_presenter_ = new TimerPresenter((TimerView *)main_view_.GetView(TIMER), timer_model_);
@@ -128,7 +123,7 @@ void MainController::CreateNewAlarmPage(Event &e)
 
        delete edit_presenter_;
 
-       edit_presenter_ = new EditAlarmPresenter(AlarmProvider::GetInstance(), nullptr, edit_page_);
+       edit_presenter_ = new EditAlarmPresenter(provider_, nullptr, edit_page_);
 }
 
 void MainController::CreateEditAlarmPage(Event &e)
@@ -137,15 +132,14 @@ void MainController::CreateEditAlarmPage(Event &e)
 
        delete edit_presenter_;
 
-       edit_presenter_ = new EditAlarmPresenter(AlarmProvider::GetInstance(),
-                                                 &ev.GetAlarm(), edit_page_);
+       edit_presenter_ = new EditAlarmPresenter(provider_, &ev.GetAlarm(), edit_page_);
 }
 
 void MainController::CreateNewDeleteAlarmsPage(Event &e)
 {
        delete delete_presenter_;
 
-       delete_presenter_ = new DeleteAlarmPresenter(&delete_page_, AlarmProvider::GetInstance());
+       delete_presenter_ = new DeleteAlarmPresenter(&delete_page_, provider_);
 }
 
 void MainController::CreateNewWorldClockDeletePage(utils::Event &e)
index a4e1fef..39e3f29 100644 (file)
 
 namespace controller {
 
-RingController &RingController::GetInstance()
-{
-       static RingController instance;
-       return instance;
-}
-
-RingController::RingController()
+RingController::RingController(model::AlarmProvider *provider) :
+       presenter_(nullptr), model_(nullptr), view_(nullptr), provider_(provider)
 {
        listener_ = utils::EventBus::AddListener<model::RingDismissEvent>(std::bind(&RingController::RingDestroy,
                                this, std::placeholders::_1));
@@ -42,8 +37,7 @@ RingController::~RingController()
 
 void RingController::HandleAlarm(int alarmID)
 {
-       model::AlarmProvider *alarmProvider = model::AlarmProvider::GetInstance();
-       model::Alarm *alarm = alarmProvider->GetAlarmWithId(alarmID);
+       model::Alarm *alarm = provider_->GetAlarmWithId(alarmID);
 
        if (!alarm) {
                ERR("Alarm not found");
similarity index 69%
rename from clock/src/Model/AlarmProviderFile.cpp
rename to clock/src/Model/AlarmBinaryStorage.cpp
index 9417a89..8d2cb4e 100644 (file)
@@ -14,7 +14,7 @@
 * limitations under the License.
 */
 
-#include "Internal/AlarmProviderFile.h"
+#include "Internal/AlarmBinaryStorage.h"
 #include "Model/AlarmProviderEvent.h"
 #include "Utils/EventBus.h"
 
@@ -27,11 +27,11 @@ using namespace internal;
 using namespace model;
 using namespace utils;
 
-const int AlarmProviderFile::db_schema_version = 1;
+const int AlarmBinaryStorage::db_schema_version = 1;
 const int AVAILABLE_ALARMS_MAX = 20;
 
 
-void AlarmProviderFile::Add(model::Alarm& alarm)
+void AlarmBinaryStorage::Add(model::Alarm& alarm)
 {
        auto it = std::find(alarms.begin(), alarms.end(), alarm);
 
@@ -43,10 +43,9 @@ void AlarmProviderFile::Add(model::Alarm& alarm)
                AlarmAddedEvent ev(alarms.back());
                EventBus::FireEvent(ev);
        }
-       Sync();
 }
 
-void AlarmProviderFile::Remove(std::reference_wrapper<Alarm> alarm)
+void AlarmBinaryStorage::Remove(std::reference_wrapper<Alarm> alarm)
 {
        auto it = std::find(alarms.begin(), alarms.end(), alarm.get());
 
@@ -56,36 +55,25 @@ void AlarmProviderFile::Remove(std::reference_wrapper<Alarm> alarm)
                alarm.get().Deactivate();
                alarms.erase(it);
        }
-       Sync();
 }
 
-AlarmProviderFile::AlarmProviderFile(IReader &r)
+AlarmBinaryStorage::AlarmBinaryStorage(IReader &r)
 {
        utils::Deserialize(r, alarms);
 }
 
-AlarmProviderFile::~AlarmProviderFile()
+AlarmBinaryStorage::~AlarmBinaryStorage()
 {
 }
 
-std::vector<std::reference_wrapper<model::Alarm>> AlarmProviderFile::GetAlarms()
+std::vector<std::reference_wrapper<model::Alarm>> AlarmBinaryStorage::GetAlarms()
 {
        return std::vector<std::reference_wrapper<model::Alarm>>(
                        alarms.begin(),
                        alarms.end());
 }
 
-bool AlarmProviderFile::HasActiveAlarms()
-{
-       for (auto &alarm: alarms) {
-               if (alarm.IsActivated())
-                       return true;
-       }
-
-       return false;
-}
-
-Alarm* AlarmProviderFile::GetAlarmWithId(AlarmId id)
+Alarm* AlarmBinaryStorage::GetAlarmWithId(AlarmId id)
 {
        auto it = std::find(alarms.begin(), alarms.end(), id);
 
@@ -95,17 +83,17 @@ Alarm* AlarmProviderFile::GetAlarmWithId(AlarmId id)
        return &(*it);
 }
 
-void AlarmProviderFile::Serialize(utils::IWriter &w) const
+void AlarmBinaryStorage::Serialize(utils::IWriter &w) const
 {
        utils::Serialize(w, alarms);
 }
 
-int AlarmProviderFile::Capacity() const
+int AlarmBinaryStorage::Capacity() const
 {
        return AVAILABLE_ALARMS_MAX;
 }
 
-bool AlarmProviderFile::IsFull() const
+bool AlarmBinaryStorage::IsFull() const
 {
        return alarms.size() >= Capacity();
 }
index 333a229..2bc14ca 100644 (file)
@@ -15,7 +15,7 @@
 */
 
 #include "Model/AlarmProvider.h"
-#include "Internal/AlarmProviderFile.h"
+#include "Internal/AlarmBinaryStorage.h"
 #include "Utils/BinaryFileReader.h"
 #include "Utils/BinaryFileWriter.h"
 #include "Utils/Utils.h"
@@ -27,29 +27,70 @@ using namespace model;
 using namespace utils;
 using namespace internal;
 
-AlarmProvider *AlarmProvider::GetInstance()
+AlarmProvider::AlarmProvider()
 {
-       static AlarmProvider *instance;
-       if (!instance) {
-               BinaryFileReader reader(Utils::APP_DIR_DATA, DATABASE_FILE);
-               instance = new AlarmProviderFile(reader);
+       BinaryFileReader reader(Utils::APP_DIR_DATA, DATABASE_FILE);
+       impl_ = new AlarmBinaryStorage(reader);
+       if (HasActiveAlarms())
+               Notifier::GetInstance().AlarmNotiPost();
+}
 
-               if (instance->HasActiveAlarms())
-                       Notifier::GetInstance().AlarmNotiPost();
-       }
-       return instance;
+AlarmProvider::~AlarmProvider()
+{
+       Sync();
+       delete impl_;
 }
 
 void AlarmProvider::Sync()
 {
-       AlarmProvider *instance = GetInstance();
-
        BinaryFileWriter writer(Utils::APP_DIR_DATA, DATABASE_FILE);
-       instance->Serialize(writer);
+       impl_->Serialize(writer);
        writer.Flush();
 
-       if (instance->HasActiveAlarms())
+       if (HasActiveAlarms())
                Notifier::GetInstance().AlarmNotiPost();
        else
                Notifier::GetInstance().AlarmNotiDelete();
 }
+
+std::vector<std::reference_wrapper<Alarm>> AlarmProvider::GetAlarms()
+{
+       return impl_->GetAlarms();
+}
+
+Alarm *AlarmProvider::GetAlarmWithId(AlarmId id)
+{
+       return impl_->GetAlarmWithId(id);
+}
+
+void AlarmProvider::Add(Alarm& alarm)
+{
+       impl_->Add(alarm);
+       Sync();
+}
+
+void AlarmProvider::Remove(std::reference_wrapper<Alarm> alarm)
+{
+       impl_->Remove(alarm);
+       Sync();
+}
+
+int AlarmProvider::Capacity() const
+{
+       return impl_->Capacity();
+}
+
+bool AlarmProvider::IsFull() const
+{
+       return impl_->IsFull();
+}
+
+bool AlarmProvider::HasActiveAlarms()
+{
+       for (auto &a : GetAlarms())
+       {
+               if (a.get().IsActivated())
+                       return true;
+       }
+       return false;
+}
index 423e4f0..a9462a8 100644 (file)
@@ -28,13 +28,13 @@ using namespace utils;
 using std::placeholders::_1;
 
 
-AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view(v), model(m)
+AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view_(v), model_(m)
 {
-       view->SetButtonClickedCallback(std::bind(&AlarmPresenter::OnAddButtonClicked, this));
-       view->SetDeleteItemClickedCallback(std::bind(&AlarmPresenter::OnDeleteItemClicked, this));
-       view->SetItemToggleCallback(std::bind(&AlarmPresenter::OnItemActiveStatusChanged, this, _1));
-       view->SetItemSelectCallback(std::bind(&AlarmPresenter::OnItemSelected, this, _1));
-       view->SetMenuButtonClickedCallback(std::bind(&AlarmPresenter::OnMenuButtonClicked, this));
+       view_->SetButtonClickedCallback(std::bind(&AlarmPresenter::OnAddButtonClicked, this));
+       view_->SetDeleteItemClickedCallback(std::bind(&AlarmPresenter::OnDeleteItemClicked, this));
+       view_->SetItemToggleCallback(std::bind(&AlarmPresenter::OnItemActiveStatusChanged, this, _1));
+       view_->SetItemSelectCallback(std::bind(&AlarmPresenter::OnItemSelected, this, _1));
+       view_->SetMenuButtonClickedCallback(std::bind(&AlarmPresenter::OnMenuButtonClicked, this));
 
        listeners_.push_back(EventBus::AddListener<AlarmAddedEvent>(
                        std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1)));
@@ -52,12 +52,12 @@ AlarmPresenter::~AlarmPresenter()
 
 void AlarmPresenter::ShowAll()
 {
-       std::vector<std::reference_wrapper<Alarm>> alarms = model->GetAlarms();
+       std::vector<std::reference_wrapper<Alarm>> alarms = model_->GetAlarms();
 
-       view->Clear();
+       view_->Clear();
 
        for (auto a: alarms) {
-               int id = view->ItemAppend(
+               int id = view_->ItemAppend(
                                a.get().GetTime(),
                                a.get().GetName().c_str(),
                                a.get().GetWeekFlags(),
@@ -84,11 +84,11 @@ void AlarmPresenter::OnAddButtonClicked()
 {
        AlarmCreateRequestEvent ev;
 
-       if (AlarmProvider::GetInstance()->IsFull()) {
+       if (model_->IsFull()) {
                std::string text = Translate::Sprintf("IDS_CLOCK_TPOP_CANT_ADD_MORE_THAN_PD_ALARMS",
-                               AlarmProvider::GetInstance()->Capacity());
+                               model_->Capacity());
 
-               view->ShowPopup(text);
+               view_->ShowPopup(text);
                return;
        }
        EventBus::FireEvent(ev);
@@ -110,16 +110,16 @@ void AlarmPresenter::OnItemActiveStatusChanged(int idx)
                alarm.Activate();
        }
 
-       view->ItemUpdate(idx, alarm.GetTime(), alarm.GetName().c_str(),
+       view_->ItemUpdate(idx, alarm.GetTime(), alarm.GetName().c_str(),
                        alarm.GetWeekFlags(), alarm.IsActivated());
-       AlarmProvider::Sync();
+       model_->Sync();
 }
 
 void AlarmPresenter::OnAlarmAddedEvent(Event &e)
 {
        AlarmAddedEvent &ev = dynamic_cast<AlarmAddedEvent&>(e);
 
-       int id = view->ItemAppend(
+       int id = view_->ItemAppend(
                        ev.GetAlarm().GetTime(),
                        ev.GetAlarm().GetName().c_str(),
                        ev.GetAlarm().GetWeekFlags(),
@@ -138,7 +138,7 @@ void AlarmPresenter::OnDeleteItemClicked()
 void AlarmPresenter::OnMenuButtonClicked()
 {
        if (alarms_.size() > 0)
-               view->ShowDeletePopup();
+               view_->ShowDeletePopup();
 }
 
 void AlarmPresenter::OnAlarmRemovedEvent(Event &e)
@@ -147,7 +147,7 @@ void AlarmPresenter::OnAlarmRemovedEvent(Event &e)
 
        for (auto it = alarms_.begin(); it != alarms_.end(); ++it) {
                if (ev.GetAlarm() == it->second.get()) {
-                       view->RemoveItem(it->first);
+                       view_->RemoveItem(it->first);
                        alarms_.erase(it);
                        break;
                }
@@ -158,9 +158,9 @@ void AlarmPresenter::OnAlarmRemovedEvent(Event &e)
 void AlarmPresenter::UpdateBackgroundLabel()
 {
        if (alarms_.size() == 0)
-               view->ShowNoAlarmsBackgroundLabel();
+               view_->ShowNoAlarmsBackgroundLabel();
        else
-               view->HideNoAlarmsBackgroundLabel();
+               view_->HideNoAlarmsBackgroundLabel();
 }
 
 void AlarmPresenter::OnAlarmEditedEvent(utils::Event &e)
@@ -171,7 +171,7 @@ void AlarmPresenter::OnAlarmEditedEvent(utils::Event &e)
        for (; it != alarms_.end(); ++it) {
                if (ev.GetAlarm() == it->second.get()) {
                        Alarm &alarm = it->second.get();
-                       view->ItemUpdate(it->first, alarm.GetTime(), alarm.GetName().c_str(),
+                       view_->ItemUpdate(it->first, alarm.GetTime(), alarm.GetName().c_str(),
                                        alarm.GetWeekFlags(), alarm.IsActivated());
                        break;
                }
index d86b045..188cee1 100644 (file)
@@ -32,7 +32,7 @@ using std::placeholders::_1;
 const double time_truncate_factor = 60 * 1000; // 60 seconds
 
 EditAlarmPresenter::EditAlarmPresenter(model::AlarmProvider *provider, model::Alarm *alarm, view::EditAlarmView& view) :
-       provider_(provider), view_(view), alarm_(alarm)
+       provider_(provider), alarm_(alarm), view_(view)
 {
        view_.RegisterEditDoneCallback(std::bind(&EditAlarmPresenter::OnEditDone, this));
        view_.RegisterEditCancelCallback(std::bind(&EditAlarmPresenter::OnEditCancel, this));
@@ -108,7 +108,7 @@ void EditAlarmPresenter::CreateNewAlarm()
 {
        Alarm new_alarm;
 
-       if (AlarmProvider::GetInstance()->IsFull()) {
+       if (provider_->IsFull()) {
                std::string text = Translate::Sprintf("IDS_CLOCK_TPOP_CANT_ADD_MORE_THAN_PD_ALARMS",
                                provider_->Capacity());
                view_.ShowPopup(text);
@@ -118,7 +118,7 @@ void EditAlarmPresenter::CreateNewAlarm()
        SetAlarmProperties(new_alarm, view_.GetData());
        new_alarm.Activate();
 
-       AlarmProvider::GetInstance()->Add(new_alarm);
+       provider_->Add(new_alarm);
 }
 
 void EditAlarmPresenter::ShowAlarmUpdatedPopup(const Time &time)
@@ -150,7 +150,7 @@ void EditAlarmPresenter::OnEditDone()
                if (update_target && (update_target != alarm_)) {
                        UpdateAlarm(*update_target);
                        ShowAlarmUpdatedPopup(update_target->GetTime());
-                       AlarmProvider::GetInstance()->Remove(std::reference_wrapper<Alarm>(*alarm_));
+                       provider_->Remove(std::reference_wrapper<Alarm>(*alarm_));
                } else {
                        UpdateAlarm(*alarm_);
                }
@@ -162,7 +162,7 @@ void EditAlarmPresenter::OnEditDone()
                        CreateNewAlarm();
        }
 
-       AlarmProvider::Sync();
+       provider_->Sync();
        view_.PopPage();
 }
 
diff --git a/clock/src/Utils/TizenApp.cpp b/clock/src/Utils/TizenApp.cpp
new file mode 100644 (file)
index 0000000..b12c829
--- /dev/null
@@ -0,0 +1,70 @@
+#include "Utils/TizenApp.h"
+#include "Utils/Log.h"
+
+using namespace utils;
+
+static bool
+app_create(void *data)
+{
+       TizenApp *app = static_cast<TizenApp*>(data);
+       return app->OnCreate();
+}
+
+static void
+app_control(app_control_h app_control, void *data)
+{
+       TizenApp *app = static_cast<TizenApp*>(data);
+       app->OnService(app_control);
+}
+
+static void
+app_pause(void *data)
+{
+       /* Take necessary actions when application becomes invisible. */
+       TizenApp *app = static_cast<TizenApp*>(data);
+       app->OnPause();
+}
+
+static void
+app_resume(void *data)
+{
+       /* Take necessary actions when application becomes visible. */
+       TizenApp *app = static_cast<TizenApp*>(data);
+       app->OnResume();
+}
+
+static void
+app_terminate(void *data)
+{
+       TizenApp *app = static_cast<TizenApp*>(data);
+       app->OnTerminate();
+}
+
+static void
+ui_app_lang_changed(app_event_info_h event_info, void *data)
+{
+       TizenApp *app = static_cast<TizenApp*>(data);
+       app->OnLanguageChanged(event_info);
+}
+
+int TizenApp::Run(int argc, char **argv)
+{
+       int ret = 0;
+
+       ui_app_lifecycle_callback_s event_callback = {0,};
+       app_event_handler_h handler;
+
+       event_callback.create = app_create;
+       event_callback.terminate = app_terminate;
+       event_callback.pause = app_pause;
+       event_callback.resume = app_resume;
+       event_callback.app_control = app_control;
+
+       ui_app_add_event_handler(&handler, APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, this);
+
+       ret = ui_app_main(argc, argv, &event_callback, this);
+       if (ret != APP_ERROR_NONE)
+               DBG("ui_app_main() is failed. err = %d", ret);
+
+       return ret;
+}
index e11793c..e005faa 100644 (file)
@@ -274,8 +274,9 @@ void AlarmView::ButtonClicked(void *data, Evas_Object *obj, void *event_info)
 
 void AlarmView::DismissPopupCallback(void *data, Evas_Object *obj, void *event_info)
 {
-       Evas_Object *popup = static_cast<Evas_Object*>(data);
-       evas_object_del(popup);
+       AlarmView *view = static_cast<AlarmView*>(data);
+       evas_object_del(view->popup_);
+       view->popup_ = nullptr;
 }
 
 void AlarmView::PopupDeleteItemCallback(void *data, Evas_Object *obj, void *event_info)
@@ -293,8 +294,8 @@ void AlarmView::ShowDeletePopup()
        popup_ = elm_popup_add(elm_object_top_widget_get(content_));
        elm_popup_align_set(popup_, ELM_NOTIFY_ALIGN_FILL, 1.0);
        evas_object_size_hint_weight_set(popup_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       evas_object_smart_callback_add(popup_, "block,clicked", AlarmView::DismissPopupCallback, popup_);
-       eext_object_event_callback_add(popup_, EEXT_CALLBACK_BACK, AlarmView::DismissPopupCallback, popup_);
+       evas_object_smart_callback_add(popup_, "block,clicked", AlarmView::DismissPopupCallback, this);
+       eext_object_event_callback_add(popup_, EEXT_CALLBACK_BACK, AlarmView::DismissPopupCallback, this);
 
        Evas_Object *list = elm_list_add(popup_);
        elm_list_mode_set(list, ELM_LIST_EXPAND);