alarm: remove AlarmProvidedEvent.h 49/110049/4
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 10 Jan 2017 15:03:12 +0000 (16:03 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Wed, 18 Jan 2017 12:35:15 +0000 (13:35 +0100)
Move alarm provided from global scope (EventBus) into AlarmProvider
class.

Change-Id: I1c2264926a39123522be40f76034651b39a5baca

clock/inc/Model/AlarmProvider.h
clock/inc/Model/AlarmProviderEvent.h [deleted file]
clock/inc/Presenter/AlarmPresenter.h
clock/src/Model/AlarmBinaryStorage.cpp
clock/src/Model/AlarmProvider.cpp
clock/src/Presenter/AlarmPresenter.cpp

index af4346f..06e1528 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "Internal/AlarmBinaryStorage.h"
 #include "Model/Alarm.h"
+#include "Utils/Signal.h"
 
 #include <vector>
 #include <functional>
@@ -86,6 +87,16 @@ namespace model {
                         * false otherwise.
                         */
                        bool HasActiveAlarms();
+
+                       /**
+                        * @brief Signal emitted when new alarm has been added.
+                        */
+                       utils::Signal<void(Alarm&)> OnAlarmRemoved;
+
+                       /**
+                        * @brief Signal emitted when alarm has been removed.
+                        */
+                       utils::Signal<void(Alarm&)> OnAlarmAdded;
                private:
                        /**
                         * Alarm provider private backend implementation
diff --git a/clock/inc/Model/AlarmProviderEvent.h b/clock/inc/Model/AlarmProviderEvent.h
deleted file mode 100644 (file)
index 7539150..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-* 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_ALARM_PROVIDER_EVENT_H_
-#define _CLOCK_ALARM_PROVIDER_EVENT_H_
-
-#include "Utils/EventBus.h"
-#include "Model/Alarm.h"
-
-namespace model {
-       /**
-        * @brief Global event that is announce that alarm was added to Provider
-        */
-       class AlarmAddedEvent : public utils::Event {
-               public:
-                       /**
-                        * @brief Creates AlarmAddedEvent instance
-                        * @param alarm added alarm.
-                        */
-                       AlarmAddedEvent(Alarm &alarm) : alarm_(alarm) {}
-                       /**
-                        * @brief Gets event target 
-                        * @return added alarm.
-                        */
-                       Alarm& GetAlarm() { return alarm_; }
-               private:
-                       Alarm &alarm_;
-       };
-
-       /**
-        * @brief Global event that is announce that alarm was removed from Provider
-        */
-       class AlarmRemovedEvent : public utils::Event {
-               public:
-                       /**
-                        * @brief Creates AlarmRemovedEvent instance
-                        * @param alarm removed alarm reference.
-                        */
-                       AlarmRemovedEvent(Alarm &alarm) : alarm_(alarm) {}
-                       /**
-                        * @brief Gets event target
-                        * @return removed alarm reference.
-                        */
-                       Alarm& GetAlarm() { return alarm_; }
-               private:
-                       Alarm &alarm_;
-       };
-} /* model */
-
-#endif
index 8bf3900..c1eac40 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "View/AlarmView.h"
 #include "Model/AlarmProvider.h"
-#include "Model/AlarmProviderEvent.h"
 #include "Utils/EventBus.h"
 
 #include <map>
@@ -46,8 +45,8 @@ namespace presenter {
                        void OnItemSelected(int idx);
                        void OnAddButtonClicked();
                        void OnItemActiveStatusChanged(int idx);
-                       void OnAlarmAddedEvent(utils::Event &e);
-                       void OnAlarmRemovedEvent(utils::Event &e);
+                       void OnAlarmAddedEvent(model::Alarm &e);
+                       void OnAlarmRemovedEvent(model::Alarm &e);
                        void OnAlarmEditedEvent(utils::Event &e);
                        void OnDeleteItemClicked();
                        void UpdateBackgroundLabel();
index 4511487..dd83496 100644 (file)
@@ -15,7 +15,6 @@
 */
 
 #include "Internal/AlarmBinaryStorage.h"
-#include "Model/AlarmProviderEvent.h"
 #include "Utils/EventBus.h"
 
 #include <cstdlib>
@@ -39,8 +38,6 @@ void AlarmBinaryStorage::Add(model::Alarm& alarm)
 
        if (it == alarms.end()) {
                alarms.push_back(alarm);
-               AlarmAddedEvent ev(alarms.back());
-               EventBus::FireEvent(ev);
        }
 }
 
@@ -49,8 +46,6 @@ void AlarmBinaryStorage::Remove(std::reference_wrapper<Alarm> alarm)
        auto it = std::find(alarms.begin(), alarms.end(), alarm.get());
 
        if (it != alarms.end()) {
-               AlarmRemovedEvent ev(alarm);
-               EventBus::FireEvent(ev);
                alarm.get().Deactivate();
                alarms.erase(it);
        }
index 29d1093..40b211d 100644 (file)
@@ -66,11 +66,13 @@ Alarm *AlarmProvider::GetAlarmWithId(AlarmId id)
 void AlarmProvider::Add(Alarm& alarm)
 {
        impl_->Add(alarm);
+       OnAlarmAdded(impl_->GetAlarms().back().get());
        Sync();
 }
 
 void AlarmProvider::Remove(std::reference_wrapper<Alarm> alarm)
 {
+       OnAlarmRemoved(alarm);
        impl_->Remove(alarm);
        Sync();
 }
index c935e81..c98d711 100644 (file)
@@ -15,7 +15,6 @@
 */
 
 #include "Presenter/AlarmPresenter.h"
-#include "Model/AlarmProviderEvent.h"
 #include "Model/AlarmEvent.h"
 #include "Utils/EventBus.h"
 #include "Utils/Log.h"
@@ -41,9 +40,9 @@ AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view_(v), model
        connections_.push_back(
                        view_->OnMenuButtonClicked.Connect(std::bind(&AlarmPresenter::OnMenuButtonClicked, this)));
 
-       connections_.push_back(EventBus::AddListener<AlarmAddedEvent>(
+       connections_.push_back(m->OnAlarmAdded.Connect(
                        std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1)));
-       connections_.push_back(EventBus::AddListener<AlarmRemovedEvent>(
+       connections_.push_back(m->OnAlarmRemoved.Connect(
                        std::bind(&AlarmPresenter::OnAlarmRemovedEvent, this, _1)));
        connections_.push_back(EventBus::AddListener<AlarmEditedEvent>(
                        std::bind(&AlarmPresenter::OnAlarmEditedEvent, this, _1)));
@@ -120,16 +119,14 @@ void AlarmPresenter::OnItemActiveStatusChanged(int idx)
        model_->Sync();
 }
 
-void AlarmPresenter::OnAlarmAddedEvent(Event &e)
+void AlarmPresenter::OnAlarmAddedEvent(Alarm &alarm)
 {
-       AlarmAddedEvent &ev = dynamic_cast<AlarmAddedEvent&>(e);
-
        int id = view_->ItemAppend(
-                       ev.GetAlarm().GetTime(),
-                       ev.GetAlarm().GetName().c_str(),
-                       ev.GetAlarm().GetWeekFlags(),
-                       ev.GetAlarm().IsActivated());
-       alarms_.insert(std::map<int, std::reference_wrapper<Alarm>>::value_type (id, std::reference_wrapper<Alarm>(ev.GetAlarm())));
+                       alarm.GetTime(),
+                       alarm.GetName().c_str(),
+                       alarm.GetWeekFlags(),
+                       alarm.IsActivated());
+       alarms_.insert(std::map<int, std::reference_wrapper<Alarm>>::value_type (id, std::reference_wrapper<Alarm>(alarm)));
 
        UpdateBackgroundLabel();
 }
@@ -146,12 +143,10 @@ void AlarmPresenter::OnMenuButtonClicked()
                view_->ShowDeletePopup();
 }
 
-void AlarmPresenter::OnAlarmRemovedEvent(Event &e)
+void AlarmPresenter::OnAlarmRemovedEvent(Alarm &alarm)
 {
-       AlarmRemovedEvent &ev = dynamic_cast<AlarmRemovedEvent&>(e);
-
        for (auto it = alarms_.begin(); it != alarms_.end(); ++it) {
-               if (ev.GetAlarm() == it->second.get()) {
+               if (alarm == it->second.get()) {
                        view_->RemoveItem(it->first);
                        alarms_.erase(it);
                        break;