signal/slot implementation 74/107374/17
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 27 Dec 2016 17:12:46 +0000 (18:12 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 17 Jan 2017 14:02:18 +0000 (15:02 +0100)
Change-Id: Iec1f3a6f90688c320c7e60a76b44b071df382aaf

54 files changed:
clock-tests/.cproject
clock-tests/src/EventBusTest.cpp
clock-tests/src/SignalTest.cpp [new file with mode: 0644]
clock-tests/unittest.xml
clock/inc/Common/CounterAnimator.h
clock/inc/Controller/MainController.h
clock/inc/Controller/RingController.h
clock/inc/Model/WorldClock.h
clock/inc/Presenter/AlarmPresenter.h
clock/inc/Presenter/DeleteAlarmPresenter.h
clock/inc/Presenter/EditAlarmPresenter.h
clock/inc/Presenter/RingPresenter.h
clock/inc/Presenter/StopWatchPresenter.h
clock/inc/Presenter/TimerPresenter.h
clock/inc/Presenter/WorldClockDeletePresenter.h
clock/inc/Presenter/WorldClockPresenter.h
clock/inc/Presenter/WorldClockReorderPresenter.h
clock/inc/Utils/EventBus.h
clock/inc/Utils/RingtonePicker.h
clock/inc/Utils/Signal.h [new file with mode: 0644]
clock/inc/View/AlarmView.h
clock/inc/View/DeleteAlarmView.h
clock/inc/View/EditAlarmView.h
clock/inc/View/PageView.h
clock/inc/View/RingView.h
clock/inc/View/StopWatchView.h
clock/inc/View/TimerView.h
clock/inc/View/WorldClockDeleteItemsView.h
clock/inc/View/WorldClockReorderView.h
clock/inc/View/WorldClockView.h
clock/src/Common/CounterAnimator.cpp
clock/src/Controller/MainController.cpp
clock/src/Model/WorldClock.cpp
clock/src/Presenter/AlarmPresenter.cpp
clock/src/Presenter/DeleteAlarmPresenter.cpp
clock/src/Presenter/EditAlarmPresenter.cpp
clock/src/Presenter/RingPresenter.cpp
clock/src/Presenter/StopWatchPresenter.cpp
clock/src/Presenter/TimerPresenter.cpp
clock/src/Presenter/WorldClockDeletePresenter.cpp
clock/src/Presenter/WorldClockPresenter.cpp
clock/src/Presenter/WorldClockReorderPresenter.cpp
clock/src/Utils/EventBus.cpp
clock/src/Utils/RingtonePicker.cpp
clock/src/View/AlarmView.cpp
clock/src/View/DeleteAlarmView.cpp
clock/src/View/EditAlarmView.cpp
clock/src/View/PageView.cpp
clock/src/View/RingView.cpp
clock/src/View/StopWatchView.cpp
clock/src/View/TimerView.cpp
clock/src/View/WorldClockDeleteItemsView.cpp
clock/src/View/WorldClockReorderView.cpp
clock/src/View/WorldClockView.cpp

index 1eeccd2..979bf05 100644 (file)
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/PopupManager.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/RingtonePicker.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Serialization.o&quot;"/>
-                                                                       <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Signal.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/SoundManager.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/ThemeExtension.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Time.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/TizenApp.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Translate.o&quot;"/>
-                                                                       <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Utils.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/WorldClock.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/View/AlarmView.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/View/CounterView.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/View/WorldClockMap.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/View/WorldClockReorderView.o&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/View/WorldClockView.o&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/TizenAppUtils.o&quot;"/>
                                                                </option>
                                                                <option id="gnu.cpp.link.option.libs.2071152623" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
                                                                        <listOptionValue builtIn="false" value="gtest"/>
index 19157a3..7531746 100644 (file)
@@ -50,8 +50,8 @@ TEST(EventBusTestSuite, listener)
        Subscriber s1, s2;
        TestEvent event;
 
-       Listener l1 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s1, _1));
-       Listener l2 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s2, _1));
+       Connection l1 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s1, _1));
+       Connection l2 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s2, _1));
 
        EXPECT_EQ(s1.times_, 0);
        EXPECT_EQ(s2.times_, 0);
@@ -65,8 +65,8 @@ TEST(EventBusTestSuite, listener2)
        Subscriber s1, s2;
        TestEvent event;
 
-       Listener l1 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s1, _1));
-       Listener l2 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s2, _1));
+       Connection l1 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s1, _1));
+       Connection l2 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s2, _1));
 
        EXPECT_EQ(s1.times_, 0);
        EXPECT_EQ(s2.times_, 0);
@@ -74,59 +74,22 @@ TEST(EventBusTestSuite, listener2)
        EXPECT_EQ(s1.times_, 1);
        EXPECT_EQ(s2.times_, 1);
 
-       l1.Unregister();
+       l1->Disconnect();
        EventBus::FireEvent(event);
        EXPECT_EQ(s1.times_, 1);
        EXPECT_EQ(s2.times_, 2);
 
-       l2.Unregister();
+       l2->Disconnect();
        EventBus::FireEvent(event);
        EXPECT_EQ(s1.times_, 1);
        EXPECT_EQ(s2.times_, 2);
 }
 
-TEST(EventBusTestSuite, listener_copy)
-{
-       Subscriber s1, s2;
-       TestEvent event;
-
-       Listener l1 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s1, _1));
-       Listener l2 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s2, _1));
-
-       EXPECT_EQ(s1.times_, 0);
-       EXPECT_EQ(s2.times_, 0);
-
-       EventBus::FireEvent(event);
-       EXPECT_EQ(s1.times_, 1);
-       EXPECT_EQ(s2.times_, 1);
-
-       Listener l3 = l1;
-       EventBus::FireEvent(event);
-       EXPECT_EQ(s1.times_, 3);
-       EXPECT_EQ(s2.times_, 2);
-
-       l1.Unregister();
-       EventBus::FireEvent(event);
-       EXPECT_EQ(s1.times_, 4);
-       EXPECT_EQ(s2.times_, 3);
-
-       l3.Unregister();
-       EventBus::FireEvent(event);
-       EXPECT_EQ(s1.times_, 4);
-       EXPECT_EQ(s2.times_, 4);
-
-       l2.Unregister();
-       EventBus::FireEvent(event);
-       EXPECT_EQ(s1.times_, 4);
-       EXPECT_EQ(s2.times_, 4);
-}
-
 TEST(EventBusTestSuite, listener_in_vector)
 {
-       DBG("Last test start");
        Subscriber s1, s2;
        TestEvent event;
-       std::vector<Listener> listeners;
+       std::vector<Connection> listeners;
 
        listeners.push_back(EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s1, _1)));
        listeners.push_back(EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s2, _1)));
@@ -138,42 +101,3 @@ TEST(EventBusTestSuite, listener_in_vector)
        EXPECT_EQ(s1.times_, 1);
        EXPECT_EQ(s2.times_, 1);
 }
-
-TEST(EventBusTestSuite, listener_copy2)
-{
-       Subscriber s1, s2;
-       TestEvent event;
-
-       Listener l1 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s1, _1));
-       Listener l2 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s2, _1));
-
-       EXPECT_EQ(s1.times_, 0);
-       EXPECT_EQ(s2.times_, 0);
-
-       /* Unregister l1 subscription and make new subscription like l2 */
-       l1 = l2;
-
-       EventBus::FireEvent(event);
-       EXPECT_EQ(s1.times_, 0);
-       EXPECT_EQ(s2.times_, 2);
-}
-
-TEST(EventBusTestSuite, listener_copy3)
-{
-       Subscriber s1, s2;
-       Listener l3;
-       TestEvent event;
-
-       Listener l1 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s1, _1));
-       Listener l2 = EventBus::AddListener<TestEvent>(std::bind(&Subscriber::OnEvent2, &s2, _1));
-
-       EXPECT_EQ(s1.times_, 0);
-       EXPECT_EQ(s2.times_, 0);
-
-       /* Unregister l1 subscription and make new subscription like empty subscription l3 */
-       l1 = l3;
-
-       EventBus::FireEvent(event);
-       EXPECT_EQ(s1.times_, 0);
-       EXPECT_EQ(s2.times_, 1);
-}
diff --git a/clock-tests/src/SignalTest.cpp b/clock-tests/src/SignalTest.cpp
new file mode 100644 (file)
index 0000000..d293978
--- /dev/null
@@ -0,0 +1,257 @@
+#include "Utils/Signal.h"
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include <vector>
+#include <iostream>
+#include <cstdlib>
+
+using namespace testing;
+using namespace utils;
+using std::placeholders::_1;
+
+
+class SignalTestSuite : public testing::Test
+{
+       protected:
+       // virtual void SetUp() will be called before each test is run.
+       // You should define it if you need to initialize the variables.
+       // Otherwise, you don't have to provide it.
+       virtual void SetUp()
+       {
+
+       }
+       // virtual void TearDown() will be called after each test is run.
+       // You should define it if there is cleanup work to do.
+       // Otherwise, you don't have to provide it.
+       virtual void TearDown()
+       {
+
+       }
+};
+
+class Subscriber
+{
+       public:
+               Subscriber() : times_(0) {}
+               int times_;
+               void OnEvent(int e);
+};
+
+void Subscriber::OnEvent(int event)
+{
+       times_ += event;
+}
+
+TEST(SignalTestSuite, connection)
+{
+       Subscriber s1, s2;
+       Signal<void(int)> event;
+
+       Connection c1 = event.Connect(std::bind(&Subscriber::OnEvent, &s1, _1));
+       Connection c2 = event.Connect(std::bind(&Subscriber::OnEvent, &s2, _1));
+
+       EXPECT_EQ(s1.times_, 0);
+       EXPECT_EQ(s2.times_, 0);
+       event(1);
+       EXPECT_EQ(s1.times_, 1);
+       EXPECT_EQ(s2.times_, 1);
+}
+
+TEST(SignalTestSuite, connection2)
+{
+       Subscriber s1, s2;
+       Signal<void(int)> event;
+
+       Connection c1 = event.Connect(std::bind(&Subscriber::OnEvent, &s1, _1));
+       Connection c2 = event.Connect(std::bind(&Subscriber::OnEvent, &s2, _1));
+
+       EXPECT_EQ(s1.times_, 0);
+       EXPECT_EQ(s2.times_, 0);
+       event(1);
+       EXPECT_EQ(s1.times_, 1);
+       EXPECT_EQ(s2.times_, 1);
+
+       c1->Disconnect();
+       event(1);
+       EXPECT_EQ(s1.times_, 1);
+       EXPECT_EQ(s2.times_, 2);
+
+       c2->Disconnect();
+       event(1);
+       EXPECT_EQ(s1.times_, 1);
+       EXPECT_EQ(s2.times_, 2);
+}
+
+TEST(SignalTestSuite, listener_in_vector)
+{
+       Subscriber s1, s2;
+       Signal<void(int)> event;
+
+       std::vector<Connection> listeners;
+
+       listeners.push_back(event.Connect(std::bind(&Subscriber::OnEvent, &s1, _1)));
+       listeners.push_back(event.Connect(std::bind(&Subscriber::OnEvent, &s2, _1)));
+
+       EXPECT_EQ(s1.times_, 0);
+       EXPECT_EQ(s2.times_, 0);
+
+       event(1);
+
+       EXPECT_EQ(s1.times_, 1);
+       EXPECT_EQ(s2.times_, 1);
+}
+
+TEST(SignalTestSuite, listener_in_vector2)
+{
+       Subscriber s1, s2;
+       Signal<void(int)> event;
+
+       std::vector<Connection> *listeners = new std::vector<Connection>(2);
+
+       listeners->push_back(event.Connect(std::bind(&Subscriber::OnEvent, &s1, _1)));
+       listeners->push_back(event.Connect(std::bind(&Subscriber::OnEvent, &s2, _1)));
+
+       EXPECT_EQ(s1.times_, 0);
+       EXPECT_EQ(s2.times_, 0);
+
+       event(1);
+
+       EXPECT_EQ(s1.times_, 1);
+       EXPECT_EQ(s2.times_, 1);
+
+       delete listeners;
+
+       event(1);
+
+       EXPECT_EQ(s1.times_, 1);
+       EXPECT_EQ(s2.times_, 1);
+}
+
+TEST(SignalTestSuite, signals_auto_unsubsribe_on_destroy)
+{
+       Subscriber s1, s2;
+       Signal<void(int)> *event = new Signal<void(int)>();
+
+       std::vector<Connection> listeners;
+
+       listeners.push_back(event->Connect(std::bind(&Subscriber::OnEvent, &s1, _1)));
+       listeners.push_back(event->Connect(std::bind(&Subscriber::OnEvent, &s2, _1)));
+
+       EXPECT_EQ(s1.times_, 0);
+       EXPECT_EQ(s2.times_, 0);
+
+       (*event)(1);
+
+       EXPECT_EQ(s1.times_, 1);
+       EXPECT_EQ(s2.times_, 1);
+
+       delete event;
+
+       // listeners goes out-of scope (Disconnect called implicite)
+}
+
+class SubscriberWithConnection
+{
+       public:
+               void OnEvent(int e);
+               Connection conn;
+};
+
+void SubscriberWithConnection::OnEvent(int event)
+{
+       conn->Disconnect();
+}
+
+TEST(SignalTestSuite, signals_disconnect_in_invoke)
+{
+       SubscriberWithConnection s1;
+       Signal<void(int)> event;
+
+       s1.conn = event.Connect(std::bind(&SubscriberWithConnection::OnEvent, &s1, _1));
+
+       event(1);
+}
+
+class SubscriberWithSignalObject
+{
+       public:
+               void OnEvent(int e);
+               Connection conn;
+               Signal<void(int)> *event;
+};
+
+void SubscriberWithSignalObject::OnEvent(int id)
+{
+       delete event;
+}
+
+TEST(SignalTestSuite, signals_destruct_signal)
+{
+       SubscriberWithSignalObject s2;
+       s2.event = new Signal<void(int)>();
+       s2.conn = s2.event->Connect(std::bind(&SubscriberWithSignalObject::OnEvent, &s2, _1));
+       s2.event->operator()(1);
+}
+
+class SubscriberWithSignalObjectReentrant
+{
+       public:
+               void OnEvent(int e);
+               Connection conn;
+               int counter;
+               Signal<void(int)> *event;
+};
+
+void SubscriberWithSignalObjectReentrant::OnEvent(int id)
+{
+       if (++counter < 5)
+               event->operator()(1);
+
+       conn->Disconnect();
+}
+
+TEST(SignalTestSuite, signals_reentrancy)
+{
+       SubscriberWithSignalObjectReentrant s2;
+       s2.event = new Signal<void(int)>();
+       s2.conn = s2.event->Connect(std::bind(&SubscriberWithSignalObjectReentrant::OnEvent, &s2, _1));
+
+       s2.counter = 0;
+       s2.event->operator()(1);
+       EXPECT_EQ(s2.counter, 5);
+}
+
+class SubscriberWithSignalObjectReentrant2
+{
+       public:
+               void OnEvent(int e);
+               std::vector<Connection> conn;
+               int counter;
+               Signal<void(int)> event;
+};
+
+void SubscriberWithSignalObjectReentrant2::OnEvent(int id)
+{
+       ++counter;
+
+       if (counter % 2 == 0) {
+               int idx = std::rand() % (conn.size());
+               conn[idx]->Disconnect();
+       }
+       else
+               conn.push_back(event.Connect(std::bind(&SubscriberWithSignalObjectReentrant2::OnEvent, this, _1)));
+
+       if (counter < 30)
+               event(1);
+}
+
+TEST(SignalTestSuite, signals_reentrancy2)
+{
+       std::srand(0);
+       SubscriberWithSignalObjectReentrant2 s2;
+       s2.conn.push_back(s2.event.Connect(std::bind(&SubscriberWithSignalObjectReentrant2::OnEvent, &s2, _1)));
+
+       s2.counter = 0;
+       s2.event(1);
+}
index 9a40f93..80e7b7a 100644 (file)
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/PopupManager.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/RingtonePicker.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Serialization.o</targetObjectFile>
-<targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Signal.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/SoundManager.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/ThemeExtension.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Time.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/TizenApp.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Translate.o</targetObjectFile>
-<targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/Utils.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/WorldClock.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/View/AlarmView.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/View/CounterView.o</targetObjectFile>
@@ -53,4 +51,5 @@
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/View/WorldClockMap.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/View/WorldClockReorderView.o</targetObjectFile>
 <targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/View/WorldClockView.o</targetObjectFile>
+<targetObjectFile>/home/l.stanislaws/Projects/clock/clock/Debug/src/Utils/TizenAppUtils.o</targetObjectFile>
 </tizen_unittest>
index 3cbb426..7ff9c43 100644 (file)
@@ -21,6 +21,8 @@
 #include <vector>
 #include <functional>
 
+#include "Utils/Signal.h"
+
 namespace common {
 
        /**
@@ -82,22 +84,12 @@ namespace common {
                void SetFrametime(double time);
 
                /**
-                * @brief Registers animators callback
-                *
-                * This function registers callback to be called on
-                * every animator tick.
-                *
-                * @param[in] func Callback function to be registered
+                * @brief Signal emitted on each animator tick.
                 */
-               void RegisterSignal(std::function<void(void)>func);
+               utils::Signal<void(void)> OnTick;
 
        private:
                Ecore_Animator *animator_;
-
-
-               std::vector<std::function<void(void)>> signals_;
-
-               void EmitSignal(void);
                static Eina_Bool Task(void *data);
        };
 }
index 2d71f8c..f60eac1 100644 (file)
@@ -161,7 +161,7 @@ namespace controller {
                        /**
                         * @brief global events subscriptions vector
                         */
-                       std::vector<utils::Listener> listeners_;
+                       std::vector<utils::Connection> connections_;
 
                        /**
                         * @brief intiialized flag
index b2bfd99..3da2cfe 100644 (file)
@@ -85,7 +85,7 @@ namespace controller {
                model::Ring *model_;
                view::RingView *view_;
                model::AlarmProvider *provider_;
-               utils::Listener listener_;
+               utils::Connection listener_;
 
                void RingCreate(void);
                void RingDestroy(utils::Event &e);
index abef133..2a8d171 100644 (file)
@@ -21,6 +21,7 @@
 #include <functional>
 
 #include "Model/Location.h"
+#include "Utils/Signal.h"
 
 namespace model {
 
@@ -44,24 +45,6 @@ namespace model {
                public:
 
                        /**
-                        * @brief Enumeration for signals that passes parameter
-                        *
-                        * @details Only const model::Location & parameter type is allowed
-                        */
-                       enum class ParameterSignalType {
-                               USER_LOCATION_REMOVED,
-                               MAX
-                       };
-
-                       /**
-                        * @brief Model signals
-                        */
-                       enum class SignalType {
-                               CUSTOM_LIST_CHANGED,
-                               MAX
-                       };
-
-                       /**
                         * @brief Enumeration for direction of time zone shift.
                         */
                        enum Direction {
@@ -183,21 +166,17 @@ namespace model {
                        void MoveCurrentTimezone(Direction direction);
 
                        /**
-                        * @brief Registers signal handler
-                        * @details func must have one parameter. For now only const model::Location & type is supported
-                        *
-                        * @param signal signal type
-                        * @param func function to be called when registered signal is emitted.
+                        * @brief Signal emitted when custom locations list has been
+                        * changed.
                         */
-                       void RegisterSignalHandler(ParameterSignalType signal, std::function<void(const model::Location &)> func);
+                       utils::Signal<void(void)> OnCustomListChanged;
 
                        /**
-                        * @brief Registers signal handler
-                        *
-                        * @param signal signal type
-                        * @param func function to be called when registered signal is emitted.
+                        * @brief Signal emitted when user location list has been
+                        * removed.
                         */
-                       void RegisterSignalHandler(SignalType signal, std::function<void(void)> func);
+                       utils::Signal<void(const model::Location&)> OnUserLocationRemoved;
+
                private:
 
                        enum ItemKeyType {
@@ -223,10 +202,6 @@ namespace model {
                         */
                        static std::vector<Timezone> time_zones_;
 
-                       std::vector<std::function<void(const model::Location &)>> parameter_signals_;
-
-                       std::vector<std::function<void(void)>> signals_;
-
                        /**
                         * @brief Saves items list state using app_preferences API
                         *
@@ -271,22 +246,6 @@ namespace model {
                         * @brief Gets time zone by its no in time_zone_ list
                         */
                        const Timezone *GetTimezone(int no) const;
-
-                       /**
-                        * @brief Emits signal s
-                        *
-                        * @param s signal
-                        * @param location location to pass to function registered for given signal
-                        */
-                       void EmitSignal(ParameterSignalType s, const model::Location &location);
-
-                       /**
-                        * @brief Emits signal s
-                        *
-                        * @param s signal
-                        * @param location location to pass to function registered for given signal
-                        */
-                       void EmitSignal(SignalType s);
        };
 } /* model */
 
index 4d19ade..8bf3900 100644 (file)
@@ -52,7 +52,7 @@ namespace presenter {
                        void OnDeleteItemClicked();
                        void UpdateBackgroundLabel();
                        std::map<int, std::reference_wrapper<model::Alarm>> alarms_;
-                       std::vector<utils::Listener> listeners_;
+                       std::vector<utils::Connection> connections_;
                        bool CheckModelSizeLimit();
                        void OnMenuButtonClicked();
        };
index a15fbb9..80d40d8 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "Model/AlarmProvider.h"
 #include "View/DeleteAlarmView.h"
+#include "Utils/Signal.h"
 
 #include <map>
 
@@ -41,6 +42,7 @@ namespace presenter {
                        model::AlarmProvider *model_;
                        void OnDeleteButtonClicked();
                        void OnCancelButtonClicked();
+                       std::vector<utils::Connection> connections_;
                        std::map<int, std::reference_wrapper<model::Alarm>> alarms_;
        };
 } /* presenter */
index eb09955..5dcd8ee 100644 (file)
@@ -20,6 +20,9 @@
 #include "View/EditAlarmView.h"
 #include "Model/Alarm.h"
 #include "Model/AlarmProvider.h"
+#include "Utils/Signal.h"
+
+#include <vector>
 
 namespace presenter {
        /**
@@ -53,6 +56,7 @@ namespace presenter {
                        void ShowAlarmUpdatedPopup(const utils::Time &time);
                        void OnBackButton();
                        void OnDiscardPopupOptionClicked(view::EditAlarmView::DiscardPopupOption option);
+                       std::vector<utils::Connection> connections_;
        };
 } /* presenter */
 
index 87d2eb8..7e564f7 100644 (file)
@@ -47,7 +47,7 @@ namespace presenter {
                model::Ring *model_;
                model::Alarm *alarm_;
 
-               std::vector<utils::Listener> listeners_;
+               std::vector<utils::Connection> connections_;
 
                common::CounterAnimator animator_;
 
index 6aa9b6e..b648f80 100644 (file)
@@ -23,6 +23,7 @@
 #include "View/StopWatchView.h"
 #include "View/CounterView.h"
 #include "View/View.h"
+#include "Utils/Signal.h"
 #include "Model/StopWatch.h"
 #include "Common/CounterAnimator.h"
 
@@ -63,6 +64,8 @@ namespace presenter {
 
                std::string GetTimeString(std::chrono::milliseconds time);
                Time GetTimeStructure(std::chrono::milliseconds time);
+
+               std::vector<utils::Connection> connections_;
        };
 }
 
index bddc815..e7829c4 100644 (file)
@@ -21,6 +21,7 @@
 #include "View/CounterView.h"
 #include "Model/Timer.h"
 #include "Common/CounterAnimator.h"
+#include "Utils/Signal.h"
 
 namespace presenter {
 
@@ -55,6 +56,7 @@ namespace presenter {
                void TimeIsUp();
 
                void TimeUpdateRequest();
+               std::vector<utils::Connection> connections_;
        };
 
 }
index 45ee374..a165789 100644 (file)
@@ -78,6 +78,11 @@ namespace presenter {
                         * @brief Updates page title and "Select All" item state.
                         */
                        void OnListItemClicked();
+
+                       /**
+                        * @brief Presenter connections
+                        */
+                       std::vector<utils::Connection> connections_;
        };
 }
 
index 1e9d42b..299b265 100644 (file)
@@ -58,8 +58,6 @@ namespace presenter {
                        view::WorldClockView *view_;
                        model::WorldClock *model_;
 
-                       std::vector<utils::Listener> listeners_;
-
                        /**
                         * @brief Updates background of locations list. If list is empty proper message is displayed
                         */
@@ -130,6 +128,10 @@ namespace presenter {
                         */
                        void OnCustomListChanged();
 
+                       /**
+                        * @brief Connections
+                        */
+                       std::vector<utils::Connection> connections_;
        };
 }
 
index c35af1c..b587181 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "View/WorldClockReorderView.h"
 #include "Model/WorldClock.h"
+#include "Utils/Signal.h"
 
 namespace presenter {
        /**
@@ -67,6 +68,11 @@ namespace presenter {
                         * @details Pops Reorder View page
                         */
                        void OnBackClicked();
+
+                       /**
+                        * @brief Presenter connections.
+                        */
+                       std::vector<utils::Connection> connections_;
        };
 }
 
index 667376a..9fc0cfb 100644 (file)
@@ -23,6 +23,8 @@
 #include <list>
 #include <typeindex>
 
+#include "Utils/Signal.h"
+
 namespace utils {
        /**
         * @brief Base event class.
@@ -34,75 +36,6 @@ namespace utils {
        };
 
        /**
-        * @brief Listener class represents event subscription.
-        *
-        * Listeners are created with EventBus::AddListener function.
-        */
-       class Listener {
-               public:
-                       /**
-                        * @brief default constructor
-                        *
-                        * Creates listener without any subscription.
-                        */
-                       Listener() : owner_(nullptr) {}
-
-                       /**
-                        * @brief Copy constructor. Creates new event subscription.
-                        */
-                       Listener(const Listener&);
-
-                       /**
-                        * @brief Stealing constructor
-                        */
-                       Listener(Listener&& obj);
-
-                       /**
-                        * @brief Destructor
-                        *
-                        * Destructor Unregisters event subscription.
-                        */
-                       ~Listener();
-
-                       /**
-                        * @brief Unregister current event subscription.
-                        */
-                       void Unregister();
-
-                       /**
-                        * @brief Assignment operator.
-                        *
-                        * Assignment make two thins:
-                        * 1. Unregisters current event subscription.
-                        * 2. Creates new subscription identical to right value.
-                        *
-                        * example:
-                        * Listener l1 = EventBus::AllListner(std::bind(&MyClass::MyMethod,
-                        * obj1, _1));
-                        * Listener l2 = EventBus::AllListner(std::bind(&MyClass::MyMethod,
-                        * obj2, _1));
-                        *
-                        * // subscription on obj1 get unregistered, new registration on obj2
-                        * // has been set in l1.
-                        *
-                        * l1 = l2;
-                        *
-                        * EventBus::FireEvent(...) // MyMethod on obj2 will be called 2 times.
-                        */
-                       Listener& operator=(const Listener&);
-
-                       /**
-                        * @brief Constructor used to create listener subscribed to event.
-                        */
-                       Listener(std::list<std::function<void(Event&)>> &owner,
-                               std::list<std::function<void(Event&)>>::iterator it);
-
-               private:
-                       std::list<std::function<void(Event&)>> *owner_;
-                       std::list<std::function<void(Event&)>>::iterator it_;
-       };
-
-       /**
         * @brief Global events dispatcher.
         *
         * How to use Event bus:
@@ -131,7 +64,7 @@ namespace utils {
                         * @brief Registers handler for given event type
                         */
                        template <typename T>
-                       static Listener AddListener(std::function<void(Event&)> func)
+                       static utils::Connection AddListener(std::function<void(Event&)> func)
                        {
                                return AddListenerInternal(typeid(T), func);
                        }
@@ -155,11 +88,11 @@ namespace utils {
                        void operator=(const EventBus &bus) = delete;
 
                private:
-                       static Listener AddListenerInternal(const std::type_index,
+                       static utils::Connection AddListenerInternal(const std::type_index,
                                        std::function<void(Event&)>);
                        static EventBus& GetInstance();
                        EventBus() {}
-                       std::map<std::type_index, std::list<std::function<void(Event&)>>> callbacks_;
+                       std::map<std::type_index, utils::Signal<void(Event&)>> callbacks_;
        };
 } /* utils */
 
index b37ba56..80a0da7 100644 (file)
@@ -20,6 +20,8 @@
 #include <app_control.h>
 #include <functional>
 
+#include "Utils/Signal.h"
+
 namespace utils {
 
 /**
@@ -44,18 +46,16 @@ class RingtonePicker {
                 *
                 * @return return absolute file path to ringtone. Value remains valid
                 * until class is destructed or function subscribed with
-                * RegisterPathUpdateSignalHandler is called.
+                * OnPathUpdated is called.
                 */
                const std::string& GetRingtonePath() const { return ringtone_; }
 
                /**
-                * @brief Register callback called when ringtone path changes.
-                * New path will be returned by GetRingtonePath method.
+                * @brief Signal emitted when ringtone path has been updated.
                 */
-               void RegisterPathUpdateSignalHandler(std::function<void(void)> cb);
+               utils::Signal<void(void)> OnPathUpdated;
        private:
                std::string ringtone_;
-               std::function<void(void)> update_cb_;
                bool initialized_;
                static void AppControlCb(app_control_h request, app_control_h reply, app_control_result_e result, void *priv);
 };
diff --git a/clock/inc/Utils/Signal.h b/clock/inc/Utils/Signal.h
new file mode 100644 (file)
index 0000000..bbfd8d6
--- /dev/null
@@ -0,0 +1,268 @@
+/*
+* 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_SIGNAL_H_
+#define _CLOCK_SIGNAL_H_
+
+#include <functional>
+#include <list>
+#include <memory>
+
+namespace utils {
+       /**
+        * @brief Implementation of Signal/Slot infrastructure.
+        *
+        * @details Signals and Slots are widely used technique of connecting
+        * event emission objects with multiple recievers.
+        *
+        * Event emission objects are called signals and are presented by Signal class.
+        * The reciever object is called Slot and is represented by a functor object.
+        *
+        * To connect function object to signal, we use 'Connect' method of signal
+        * object. The method 'Connect' returns object representing connection
+        * between signal and a Slot. As long as connection object is valid,
+        * the emission of events in signal will invoke Slot objects.
+        *
+        * Example:
+        *
+        * void f(int a) {
+        * }
+        *
+        * Signal<void(int)> onClicked; // declare new signal of void(int) type
+        *
+        * auto conn = onClicked.Connect(std::bind(&f); //connect function f to signal
+        *
+        * onClicked(1); // emit signal
+        *
+        * conn.Disconnect(); // disconnect function 'f' from signal
+        *
+        * @note Unlike many other signal-Slot libraries the connection returned by
+        * 'Connect' method follows RAII pattern, so when connection object is being
+        * destructed the target object will be disconnected from signal.
+        */
+       template <typename... T_arg>
+       class Signal;
+
+       /**
+        * @brief Slot structure
+        */
+       template <typename... T_arg>
+       struct Slot;
+
+       /**
+        * @brief Class representing signal connection
+        */
+       template <typename... T_arg>
+       class SignalConnection;
+
+       /**
+        * @brief Base class for all signal connections.
+        */
+       class SignalBaseConnection;
+
+       typedef std::unique_ptr<SignalBaseConnection> Connection;
+
+       /**
+        * @brief Call context
+        */
+       template <typename... T_arg>
+       struct Slot<void(T_arg...)>
+       {
+               Slot(std::function<void(T_arg...)> f) : func(f), delete_me(false) {}
+               /** @brief Function to call */
+               std::function<void(T_arg...)> func;
+               /** @brief slot has been marked for deletion */
+               bool delete_me : 1;
+       };
+
+       /**
+        * @brief Specialized template for signals with functions of type
+        * void (*)(A...)
+        */
+       template <typename... T_arg>
+       class Signal<void(T_arg...)>
+       {
+               public:
+
+                       /**
+                        * @brief Default constructor
+                        */
+                       Signal() : on_delete_(false) , recursive_count_(0) {}
+
+                       /**
+                        * @brief Delete copy constructor
+                        *
+                        * @param[in] ref reference to Signal
+                        *
+                        * @details Copying signals should not be possible in order
+                        * to avoid unexpected behaviour on object connected to copyied
+                        * signal.
+                        */
+                       Signal(const Signal<void(T_arg...)> &ref) = delete;
+
+                       /**
+                        * @brief Delete assignment operator
+                        *
+                        * @param[in] ref reference to Signal
+                        */
+                       Signal<void(T_arg...)>& operator=(const Signal<void(T_arg...)> &ref) = delete;
+
+                       /**
+                        * @brief Move constructor
+                        *
+                        * @param[in] ref r-value reference to Signal
+                        */
+                       Signal(Signal<void(T_arg...)> &&ref)
+                       {
+                               this->slots_ = std::move(ref.slots_);
+                       }
+
+                       /**
+                        * @brief Emit signal
+                        *
+                        * @param[in] a variadic paramenter list
+                        *
+                        * @details This function will call all connected listeners
+                        * (slots) for given signal.
+                        */
+                       void operator()(T_arg... a)
+                       {
+                               recursive_count_++;
+                               auto it = slots_.begin();
+                               while (it != slots_.end()) {
+                                       if (!it->delete_me) it->func(a...);
+                                       if (on_delete_) return;
+                                       ++it;
+                               }
+                               recursive_count_--;
+                               if (!recursive_count_)
+                                       clean_slots();
+                       }
+
+                       /**
+                        * @brief Connect function f to signal.
+                        *
+                        * @details This means that every time the signal will be emitted
+                        * (with () operator) the function f will be called.
+                        */
+                       Connection Connect(std::function<void(T_arg...)> f)
+                       {
+                               Slot<void(T_arg...)> slot(f);
+                               slots_.push_back(slot);
+                               auto ptr = new SignalConnection<void(T_arg...)>(&slots_.back());
+                               return std::unique_ptr<SignalBaseConnection>(ptr);
+                       }
+
+                       /**
+                        * @brief Destructor
+                        *
+                        * @details Disconnects automatically all conntected Slots
+                        */
+                       ~Signal()
+                       {
+                               on_delete_ = true;
+                               slots_.clear();
+                       }
+               protected:
+                       /**
+                        * @brief Clear-up deleted slots
+                        */
+                       void clean_slots()
+                       {
+                               auto it = slots_.begin();
+                               while (it != slots_.end()) {
+                                       if (it->delete_me)
+                                               it = slots_.erase(it);
+                                       else
+                                               ++it;
+                               }
+                       }
+
+                       /** @brief generic storage for slots */
+                       std::list<Slot<void(T_arg...)>> slots_;
+                       bool on_delete_;
+                       int recursive_count_;
+       };
+
+       /**
+        * @brief Purpose of this class is to allow connections to be stored
+        * in generic containers.
+        */
+       class SignalBaseConnection
+       {
+               public:
+                       SignalBaseConnection() {}
+                       /** @brief Disconnects registered function from signal. */
+                       virtual void Disconnect() {}
+                       virtual ~SignalBaseConnection() {}
+       };
+
+       /**
+        * @brief Specialized template for signal connections with functions of type
+        * void (*)(T_arg...)
+        */
+       template <typename... T_arg>
+       class SignalConnection<void(T_arg...)> : public SignalBaseConnection
+       {
+               public:
+               /**
+                * @brief Constructor
+                *
+                * @param[in] it iterator to list element
+                */
+               SignalConnection(Slot<void(T_arg...)> *slot) : slot_(slot) {}
+
+               ~SignalConnection() { Disconnect(); }
+
+               void Disconnect() override
+               {
+                       if (slot_) {
+                               slot_->delete_me = true;
+                               slot_ = nullptr;
+                       }
+               }
+
+               bool IsConnected() const
+               {
+                       return slot_ != nullptr;
+               }
+
+               /**
+                * @brief R-Value constructor
+                */
+               SignalConnection(SignalConnection&& ref)
+               {
+                       slot_ = ref.slot_;
+                       ref.slot_ = nullptr;
+               }
+
+               /**
+                * @brief Delete copy constructor
+                */
+               SignalConnection(const SignalConnection& ln) = delete;
+
+               /**
+                * @brief Delete assign operator
+                */
+               SignalConnection<T_arg...> operator=(const SignalConnection& ln) = delete;
+
+               private:
+                       Slot<void(T_arg...)> *slot_;
+       };
+
+}; /* utils */
+
+#endif
index 4bb8e0d..3b6e1e9 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "View/View.h"
 #include "Model/WeekFlags.h"
-#include "Utils/EventBus.h"
+#include "Utils/Signal.h"
 #include "Utils/Time.h"
 
 #include <functional>
@@ -32,19 +32,6 @@ namespace view {
         */
        class AlarmView : public ui::IView {
                public:
-                       /** @brief Generic event function */
-                       typedef std::function<void(int)> SelectCallback;
-                       /** @brief Selected event. Selected item identifier is passed in parameter. */
-                       typedef std::function<void(int)> ToggleCallback;
-                       /** @brief Generic event function */
-                       typedef std::function<void(void)> ButtonClickedCallback;
-                       /** @brief Generic event function */
-                       typedef std::function<void(void)> MenuButtonClickedCallback;
-
-                       /**
-                        * @brief Creates AlarmView instance
-                        * @param main MainView instance
-                        */
                        AlarmView(ui::IView &main);
 
                        /**
@@ -84,41 +71,30 @@ namespace view {
                                        const model::WeekFlags flags, bool active);
 
                        /**
-                        * @brief Registers callback emitted when user has cancelled edit
-                        * operation.
-                        *
-                        * @param[in] func callback to register.
+                        * @brief Signal emitted when user clicked "delete" item on Delete popup
                         */
-                       void SetItemToggleCallback(ToggleCallback func) { onToggled_ = func; }
+                       utils::Signal<void(void)> OnDeleteItemClicked;
 
                        /**
-                        * @brief Registers callback emitted when user has selected item on
-                        * list.
-                        *
-                        * @param[in] func callback to register.
+                        * @brief Signal emitted when user clicked "+" button
                         */
-                       void SetItemSelectCallback(SelectCallback func) { onSelected_ = func; }
+                       utils::Signal<void(void)> OnAddButtonClicked;
 
                        /**
-                        * @brief Registers callback emitted when user has clicked "+" floating button
-                        *
-                        * @param[in] func callback to register.
+                        * @brief Signal emitted when user clicked "menu" hardware button
                         */
-                       void SetButtonClickedCallback(ButtonClickedCallback func) { onClicked_ = func; }
+                       utils::Signal<void(void)> OnMenuButtonClicked;
 
                        /**
-                        * @brief Registers callback emitted when user clicked Delete Item
-                        * on Delete popup
-                        *
-                        * @param[in] func callback to register.
+                        * @brief Signal emitted when user selected item on alarm list
                         */
-                       void SetDeleteItemClickedCallback(ButtonClickedCallback func) { onDeleteClicked_ = func;}
+                       utils::Signal<void(int)> OnItemSelected;
+
                        /**
-                        * @brief Registers callback emitted when user clicked "Menu" hardware button
-                        *
-                        * @param[in] func callback to register.
+                        * @brief Signal emitted when user toggled checkbox on alarm list item
                         */
-                       void SetMenuButtonClickedCallback(MenuButtonClickedCallback func) { onMenuClicked_ = func;}
+                       utils::Signal<void(int)> OnItemToggled;
+
                        Evas_Object *GetEvasObject();
 
                        /**
@@ -160,12 +136,7 @@ namespace view {
                        Evas_Object *content_;
                        Evas_Object *popup_;
                        Evas_Object *label_;
-                       SelectCallback onSelected_;
-                       ToggleCallback onToggled_;
-                       ButtonClickedCallback onClicked_;
-                       ButtonClickedCallback onDeleteClicked_;
-                       MenuButtonClickedCallback onMenuClicked_;
-                       utils::Listener time_format_change_listener_;
+                       utils::Connection time_format_change_listener_;
                        void TimeFormatChanged();
        };
 }
index 7323e70..b1533b2 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "View/PageView.h"
 #include "Model/WeekFlags.h"
-#include "Utils/EventBus.h"
+#include "Utils/Signal.h"
 #include "Utils/Time.h"
 
 #include <vector>
@@ -30,9 +30,6 @@ namespace view {
         */
        class DeleteAlarmView : public PageView {
                public:
-                       /** @brief Generic event function */
-                       typedef std::function<void(void)> ButtonClickedCallback;
-
                        /**
                         * @brief Creates DeleteAlarmView instance
                         *
@@ -46,18 +43,15 @@ namespace view {
                        ~DeleteAlarmView();
 
                        /**
-                        * @brief Registers callback emitted when cancel button is clicked
-                        *
-                        * @param[in] cb callback to register.
+                        * @brief Signal emitted when cancel button is clicked
                         */
-                       void RegisterCancelButtonClickedCallback(ButtonClickedCallback cb) { onCancelButtonClicked_ = cb; }
+                       utils::Signal<void(void)> OnCancelButtonClicked;
 
                        /**
-                        * @brief Registers callback emitted when delete button is clicked
-                        *
-                        * @param[in] cb callback to register.
+                        * @brief Signal emitted when delete button is clicked
                         */
-                       void RegisterDeleteButtonClickedCallback(ButtonClickedCallback cb) { onDeleteButtonClicked_ = cb; }
+                       utils::Signal<void(void)> OnDeleteButtonClicked;
+
                        Evas_Object *GetEvasObject() { return content_; }
 
                        /**
@@ -87,9 +81,6 @@ namespace view {
                        Evas_Object *left_btn_;
                        Evas_Object *right_btn_;
 
-                       ButtonClickedCallback onDeleteButtonClicked_;
-                       ButtonClickedCallback onCancelButtonClicked_;
-
                        void SelectAllStateSet(bool value);
                        void UpdateTitle(void);
 
@@ -106,7 +97,7 @@ namespace view {
 
                        void CreateSelectAllItem();
 
-                       utils::Listener time_format_change_listener_;
+                       utils::Connection time_format_change_listener_;
                        void TimeFormatChanged();
        };
 } /* view */
index def5a7f..bf3421d 100644 (file)
@@ -24,7 +24,7 @@
 #include "Model/WeekFlags.h"
 #include "Model/Alarm.h"
 #include "View/WeekFlagsView.h"
-#include "Utils/EventBus.h"
+#include "Utils/Signal.h"
 #include "Utils/RingtonePicker.h"
 
 namespace view {
@@ -68,45 +68,28 @@ namespace view {
                                CONFIRM /** User has requested to confirmed discard operation */
                        };
 
-                       /** @brief Generic event function */
-                       typedef std::function<void(void)> EditDoneCallback;
-                       /** @brief Generic event function */
-                       typedef std::function<void(void)> EditCancelCallback;
-                       /** @brief Generic event function */
-                       typedef std::function<void(void)> BackButtonCallback;
-                       /** @brief Event with operation result */
-                       typedef std::function<void(DiscardPopupOption)> DiscardPopupCallback;
-
                        /**
-                        * @brief Registers callback emitted when user has finished edit
+                        * @brief Signal emitted when user has finished edit
                         * operation.
-                        *
-                        * @param[in] cb callback to register.
                         */
-                       void RegisterEditDoneCallback(EditDoneCallback cb) { onEditDone_ = cb; }
+                       utils::Signal<void(void)> OnEditDone;
 
                        /**
-                        * @brief Registers callback emitted when user has cancelled edit
+                        * @brief Signal emitted when user has cancelled edit
                         * operation.
-                        *
-                        * @param[in] cb callback to register.
                         */
-                       void RegisterEditCancelCallback(EditCancelCallback cb) { onEditCancel_ = cb; }
+                       utils::Signal<void(void)> OnEditCancel;
 
                        /**
-                        * @brief Registers callback emitted when back button is clicked
-                        *
-                        * @param[in] cb callback to register.
+                        * @brief Signal emitted when back button is clicked
                         */
-                       void RegisterBackButtonCallback(BackButtonCallback cb) { onBackButton = cb; }
+                       utils::Signal<void(void)> OnBackButtonClicked;
 
                        /**
-                        * @brief Registers callback emitted when option has been chosen on
+                        * @brief Signal emitted when option has been chosen on
                         * discard popup
-                        *
-                        * @param[in] cb callback to register.
                         */
-                       void RegisterDiscardPopupCallback(DiscardPopupCallback cb) { onDiscardPopupCallback = cb; }
+                       utils::Signal<void(DiscardPopupOption)> OnDiscardPopupOptionSelected;
 
                        /**
                         * @brief Constructor
@@ -187,11 +170,6 @@ namespace view {
                        /* child view of EditAlarmView */
                        WeekFlagsView week_flags_view_;
 
-                       EditDoneCallback onEditDone_;
-                       EditCancelCallback onEditCancel_;
-                       BackButtonCallback onBackButton;;
-                       DiscardPopupCallback onDiscardPopupCallback;
-
                        Elm_Object_Item *type_it_;
                        Elm_Object_Item *repeat_it_;
                        Elm_Object_Item *volume_it_;
@@ -229,8 +207,11 @@ namespace view {
                        void RingtonePathUpdateCallback();
                        const char *GetTitle();
 
-                       utils::Listener time_format_change_listener_;
+                       utils::Connection time_format_change_listener_;
                        void TimeFormatChanged();
+
+                       utils::Connection week_flags_popped_conn_;
+                       utils::Connection picker_conn_;
        };
 } /* view */
 
index 290bdb1..c1a4921 100644 (file)
@@ -20,6 +20,7 @@
 #include <Elementary.h>
 #include "View/MainView.h"
 #include "View/View.h"
+#include "Utils/Signal.h"
 
 #include <vector>
 #include <functional>
@@ -82,9 +83,9 @@ namespace view {
                        void PopPage();
 
                        /**
-                        * @brief Registers page popped callback
+                        * @brief Signal emitted when page is popped.
                         */
-                       void RegisterPoppedCallback(std::function<void(void)>);
+                       utils::Signal<void(void)> OnPagePopped;
 
                protected:
                        /**
@@ -100,8 +101,6 @@ namespace view {
                        Evas_Object *naviframe_;
 
                        static void ItemDeletedCallback(void*, Evas_Object*, void *);
-                       std::vector<std::function<void(void)>> onPopped_;
-                       void EmitPoppedEvent();
        };
 };
 
index ed0e652..0b96bdb 100644 (file)
 #include <functional>
 
 #include "View/CounterView.h"
+#include "Utils/Signal.h"
 
 namespace view {
 
        /**
-        * @brief Ring view signal type
-        */
-       enum class RingSignal {
-               BUTTON_DISMISS_CLICKED,
-               BUTTON_SNOOZE_CLICKED,
-
-               MAX,
-       };
-
-       /**
         * @brief Ring's view class
         *
         * Class creates and displays ring alarm view that shows incoming alarm's
@@ -84,19 +75,14 @@ namespace view {
                void DisplayTime(int hour, int min, int sec);
 
                /**
-                * @brief Registers signal with the RingSignal type.
-                *
-                * @param[in] func The function to be called on passed type signal
-                * @param[in] type The signal type on which callback should be called
+                * @brief Signal emitted when snooze button is clicked.
                 */
-               void RegisterSignal(std::function<void(void)>func, RingSignal type);
+               utils::Signal<void(void)> OnSnoozeButtonClicked;
 
                /**
-                * @brief Emits signal with the assigned type.
-                *
-                * @param[in] type The type of the signal whose callback must be called
+                * @brief Signal emitted when dismiss button is clicked.
                 */
-               void EmitSignal(RingSignal type);
+               utils::Signal<void(void)> OnDismissButtonClicked;
 
                /**
                 * @brief Shows or hides snooze swipe button.
@@ -170,9 +156,6 @@ namespace view {
 
                view::CounterView *counter_ = NULL;
 
-               std::vector<std::function<void(void)>> signals_
-                       = std::vector<std::function<void(void)>>((int)RingSignal::MAX, nullptr);
-
                static const char *GROUP;
                static const char *EDJE_FILE;
 
index 1e8bca4..a592fa1 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "View/CounterView.h"
 #include "View/View.h"
+#include "Utils/Signal.h"
 
 #define PART_LAP_NO "txt.lap.no"
 #define PART_LAP_SPLIT "txt.lap.split"
 namespace view {
 
        /**
-        * @brief StopWatch signal type
-        */
-       enum class Signal {
-               BUTTON_START_CLICKED,
-               BUTTON_STOP_CLICKED,
-               BUTTON_LAP_CLICKED,
-               BUTTON_RESUME_CLICKED,
-               BUTTON_RESET_CLICKED,
-               MAX
-       };
-
-       /**
         * @brief Lap class
         *
         * Class helper for StopWatch view that stores displayed information
@@ -119,12 +108,29 @@ namespace view {
                Evas_Object *GetEvasObject(void);
 
                /**
-                * @brief Registers StopWatchView callbacks
-                *
-                * @param[in] func The callback
-                * @param[in] type The type of the signal
+                * @brief Signal emitted when start button was clicked.
+                */
+               utils::Signal<void(void)> OnStartButtonClicked;
+
+               /**
+                * @brief Signal emitted when stop button was clicked.
+                */
+               utils::Signal<void(void)> OnStopButtonClicked;
+
+               /**
+                * @brief Signal emitted when lap button was clicked.
+                */
+               utils::Signal<void(void)> OnLapButtonClicked;
+
+               /**
+                * @brief Signal emitted when resume button was clicked.
                 */
-               void RegisterSignal(std::function<void(void)>func, Signal type);
+               utils::Signal<void(void)> OnResumeButtonClicked;
+
+               /**
+                * @brief Signal emitted when reset button was clicked.
+                */
+               utils::Signal<void(void)> OnResetButtonClicked;
 
                /**
                 * @brief Shows running menu
@@ -216,13 +222,9 @@ namespace view {
                void CreateMenuButtons(void);
                Evas_Object *CreateList(void);
                void FreeListItemsData(Evas_Object *list);
-               void EmitSignal(Signal type);
 
                const char *GetEdjeFilePath(void);
 
-               std::vector<std::function<void(void)>> signals
-                       = std::vector<std::function<void(void)>> ((int)Signal::MAX, nullptr);
-
                static const char *EDJE_FILE;
                static const char *GROUP;
 
index ae18534..20fc70d 100644 (file)
 #include "View/View.h"
 #include "View/PageView.h"
 #include "View/CounterView.h"
+#include "Utils/Signal.h"
 
 namespace view {
 
        /**
-        * @brief Timer's signal type
-        */
-       enum class TimerSignal {
-               BUTTON_HOUR_INCREASE_CLICKED,
-               BUTTON_MINUTE_INCREASE_CLICKED,
-               BUTTON_SECOND_INCREASE_CLICKED,
-
-               BUTTON_HOUR_DECREASE_CLICKED,
-               BUTTON_MINUTE_DECREASE_CLICKED,
-               BUTTON_SECOND_DECREASE_CLICKED,
-
-               BUTTON_START_CLICKED,
-               BUTTON_PAUSE_CLICKED,
-               BUTTON_CANCEL_CLICKED,
-               BUTTON_RESUME_CLICKED,
-               BUTTON_RESET_CLICKED,
-
-               ON_COUNTER_FOCUS,
-               ON_COUNTER_UNFOCUS,
-
-               MAX,
-       };
-
-       /**
         * @brief Timer's view class
         *
         * Class displays timer's view for user interaction with backend.
@@ -79,12 +56,39 @@ namespace view {
                Evas_Object *GetEvasObject();
 
                /**
-                * @brief Registers TimerView callback
-                *
-                * @param[in] func The function to be called
-                * @param[in] type The type of the signal on which callback is called
+                * @brief Signal emitted when start button has been clicked.
+                */
+               utils::Signal<void(void)> OnStartButtonClicked;
+
+               /**
+                * @brief Signal emitted when start button has been clicked.
+                */
+               utils::Signal<void(void)> OnPauseButtonClicked;
+
+               /**
+                * @brief Signal emitted when cancel button has been clicked.
                 */
-               void RegisterSignal(std::function<void(void)>func, TimerSignal type);
+               utils::Signal<void(void)> OnCancelButtonClicked;
+
+               /**
+                * @brief Signal emitted when resume button has been clicked.
+                */
+               utils::Signal<void(void)> OnResumeButtonClicked;
+
+               /**
+                * @brief Signal emitted when reset button has been clicked.
+                */
+               utils::Signal<void(void)> OnResetButtonClicked;
+
+               /**
+                * @brief Signal emitted when counter has been focused.
+                */
+               utils::Signal<void(void)> OnCounterFocus;
+
+               /**
+                * @brief Signal emitted when counter has been unfocued.
+                */
+               utils::Signal<void(void)> OnCounterUnfocused;
 
                /**
                 * @brief Enables Start button
@@ -179,9 +183,6 @@ namespace view {
                };
                Time set_time_;
 
-               std::vector<std::function<void(void)>> signals
-                       = std::vector<std::function<void(void)>>((int)TimerSignal::MAX, nullptr);
-
                void CreateButton(Evas_Object *parent, const char *name,
                                const char *part, Evas_Smart_Cb cb);
 
@@ -197,8 +198,6 @@ namespace view {
 
                void UnfocusEntries();
 
-               void EmitSignal(TimerSignal type);
-
                static const char *EDJE_FILE;
                static const char *GROUP;
                static const char *GetEdjeFilePath(void);
index f50ab7e..33b284f 100644 (file)
@@ -20,6 +20,7 @@
 #include "View/PageView.h"
 #include "Model/Location.h"
 #include "Utils/Time.h"
+#include "Utils/Signal.h"
 
 namespace view {
        /**
@@ -35,18 +36,6 @@ namespace view {
                public:
 
                        /**
-                        * @brief Enumeration for callbacks signals
-                        */
-                       enum class SignalType {
-                               BUTTON_CANCEL_CLICKED,      //!< BUTTON_CANCEL_CLICKED
-                               BUTTON_DELETE_CLICKED,      //!< BUTTON_DELETE_CLICKED
-                               BUTTON_BACK_CLICKED,        //!< BUTTON_BACK_CLICKED
-                               CHECKBOX_SELECT_ALL_CLICKED,//!< CHECKBOX_SELECT_ALL_CLICKED
-                               LIST_ITEM_CLICKED,          //!< LIST_ITEM_CLICKED
-                               MAX                         //!< MAX
-                       };
-
-                       /**
                         * @brief Creates Class object, push new page and invokes CreateContent().
                         * @param main MainView reference.
                         */
@@ -65,12 +54,29 @@ namespace view {
                        Evas_Object *GetEvasObject() override;
 
                        /**
-                        * @brief Registers signals
-                        *
-                        * @param s signal enumerator
-                        * @param func function invoked when the signal will be emitted
+                        * @brief Signal emitted when cancel button has been clicked.
+                        */
+                       utils::Signal<void(void)> OnCancelButtonClicked;
+
+                       /**
+                        * @brief Signal emitted when delete button has been clicked.
+                        */
+                       utils::Signal<void(void)> OnDeleteButtonClicked;
+
+                       /**
+                        * @brief Signal emitted when back button has been clicked.
+                        */
+                       utils::Signal<void(void)> OnBackButtonClicked;
+
+                       /**
+                        * @brief Signal emitted when select all checkbox has been clicked.
+                        */
+                       utils::Signal<void(void)> OnSelectAllCheckboxClicked;
+
+                       /**
+                        * @brief Signal emitted when list item has been clicked.
                         */
-                       void RegisterSignal(SignalType s, std::function<void(void)>func);
+                       utils::Signal<void(void)> OnListItemClicked;
 
                        /**
                         * @brief Appends items(Locations) from given list to delete View genlist
@@ -164,12 +170,6 @@ namespace view {
                        bool all_selected_;
 
                        /**
-                        * @brief list of signals
-                        */
-                       std::vector<std::function<void(void)>> signals_
-                                       = std::vector<std::function<void(void)>>((int)SignalType::MAX, nullptr);
-
-                       /**
                         * @brief Callback invoked when any item of list is clicked
                         *
                         * @param data user data
@@ -241,34 +241,25 @@ namespace view {
                        void CreateSelectAll();
 
                        /**
-                        * @brief emits signal
-                        *
-                        * @details it cause invocation of registered function
-                        *
-                        * @param s signal enumerator
-                        */
-                       void EmitSignal(SignalType s);
-
-                       /**
                         * @brief Emits BUTTON_CANCEL_CLICKED signal.
                         *
                         * @details Invoked when "Cancel" button is clicked
                         */
-                       static void OnCancelButtonClicked(void *data, Evas_Object *obj, void *event_info);
+                       static void CancelButtonClicked(void *data, Evas_Object *obj, void *event_info);
 
                        /**
                         * @brief Emits BUTTON_DELETE_CLICKED signal.
                         *
                         * @details Invoked when "Delete" button is clicked
                         */
-                       static void OnDeleteButtonClicked(void *data, Evas_Object *obj, void *event_info);
+                       static void DeleteButtonClicked(void *data, Evas_Object *obj, void *event_info);
 
                        /**
                         * @brief Emits CHECKBOX_SELECT_ALL_CLICKED signal and toggle "Select all" checkbox state.
                         *
                         * @details Invoked when "Select all" item or checkbox is clicked
                         */
-                       static void OnSelectAllClicked(void *data, Evas_Object *obj, void *event_info);
+                       static void SelectAllClicked(void *data, Evas_Object *obj, void *event_info);
 
                        /**
                         * @brief Emits LIST_ITEM_CLICKED signal and toggle checkbox state.
@@ -284,7 +275,7 @@ namespace view {
                         */
                        static Eina_Bool TimeUpdateCb(void *data);
 
-                       utils::Listener time_format_change_listener_;
+                       utils::Connection time_format_change_listener_;
 
                        /**
                         * @brief Invoke when platform time format changes.
index f108f87..e1573d2 100644 (file)
@@ -20,6 +20,7 @@
 #include "View/PageView.h"
 #include "Model/Location.h"
 #include "Utils/Time.h"
+#include "Utils/Signal.h"
 
 namespace view {
 
@@ -36,15 +37,6 @@ namespace view {
                public:
 
                        /**
-                        * @brief Enumeration for callbacks signals
-                        */
-                       enum class Signals {
-                               LIST_REORDERED,      //!< LIST_REORDERED
-                               BUTTON_BACK_CLICKED, //!< BUTTON_BACK_CLICKED
-                               MAX                  //!< MAX
-                       };
-
-                       /**
                         * @brief Creates Class object.
                         */
                        WorldClockReorderView(view::MainView &main);
@@ -62,14 +54,15 @@ namespace view {
                        Evas_Object *GetEvasObject() override;
 
                        /**
-                        * @brief Registers signals
-                        *
-                        * @param s signal enumerator
-                        * @param func function invoked when the signal will be emitted
+                        * @brief Signal emitted when list has been reordered.
                         */
-                       void RegisterSignalHandler(Signals s, std::function<void(void)>func);
+                       utils::Signal<void(void)> OnListReordered;
 
                        /**
+                        * @brief Signal emitted when back button has been clicked.
+                        */
+                       utils::Signal<void(void)> OnBackButtonClicked;
+                       /**
                         * @brief Appends items(Locations) from given list to delete View genlist
                         *
                         * @details The list is identical with user_locations_ list
@@ -118,12 +111,6 @@ namespace view {
                        Ecore_Timer *timer_;
 
                        /**
-                        * @brief list of signals
-                        */
-                       std::vector<std::function<void(void)>> signals_
-                                       = std::vector<std::function<void(void)>>((int)Signals::MAX, nullptr);
-
-                       /**
                         * @brief Gets content for genlist item part
                         *
                         * @param data user data
@@ -181,27 +168,18 @@ namespace view {
                        static Evas_Object *CreatePaddingObject(Evas_Object *parent, int width);
 
                        /**
-                        * @brief emits signal
-                        *
-                        * @details it cause invocation of registered function
-                        *
-                        * @param s signal enumerator
-                        */
-                       void EmitSignal(Signals s);
-
-                       /**
                         * @brief Emits LIST_REORDERED signal
                         *
                         * @remarks Invoked everytime list is reordered
                         */
-                       static void OnListReordered(void *data, Evas_Object *obj, void *event_info);
+                       static void ListReordered(void *data, Evas_Object *obj, void *event_info);
 
                        /**
                         * @brief Emits BUTTON_BACK_CLICKED signal
                         *
                         * @remarks Invoked by clicking BACK naviframe button or back hardware key
                         */
-                       static void OnBackButtonClicked(void *data, Evas_Object *obj, void *event_info);
+                       static void BackButtonClicked(void *data, Evas_Object *obj, void *event_info);
 
                        /**
                         * @brief Timer callback for time updates.
@@ -212,7 +190,7 @@ namespace view {
                         */
                        static Eina_Bool TimeUpdateCb(void *data);
 
-                       utils::Listener time_format_change_listener_;
+                       utils::Connection time_format_change_listener_;
 
                        /**
                         * @brief Invoke when platform time format changes.
index 1cb1efd..ca6c51d 100644 (file)
 #include "View/PageView.h"
 #include "View/View.h"
 #include "View/WorldClockMap.h"
-#include "Utils/EventBus.h"
+#include "Utils/Signal.h"
 
 namespace view {
 
        /**
-        * @brief Enumeration for callbacks signals
-        */
-       enum class WorldClockSignals {
-               BUTTON_LEFT_ARROW_CLICKED,
-               BUTTON_RIGHT_ARROW_CLICKED,
-               BUTTON_MORE_CLICKED,
-               BUTTON_MORE_DELETE_CLICKED,
-               BUTTON_MORE_REORDER_CLICKED,
-
-               CUSTOM_LIST_ITEM_CLICKED,
-               CUSTOM_LIST_ITEM_ADD,
-               CUSTOM_LIST_UPDATE_REQUEST,
-
-               MAX
-       };
-
-       /**
         * @brief Class representing World Clock view and is responsible for UI layer of the view.
         *
         * @details It communicates with external classes by sending signals and do
@@ -78,12 +61,44 @@ namespace view {
                        Evas_Object *GetEvasObject(){return world_clock_main_;};
 
                        /**
-                        * @brief Registers signals
-                        *
-                        * @param[in] func function invoked when the signal will be emitted
-                        * @param[in] signal signal enumerator
+                        * @brief Signal emitted when left arrow has been clicked.
+                        */
+                       utils::Signal<void(void)> OnLeftArrowClicked;
+
+                       /**
+                        * @brief Signal emitted when right arrow has been clicked.
+                        */
+                       utils::Signal<void(void)> OnRightArrowClicked;
+
+                       /**
+                        * @brief Signal emitted when menu button has been clicked.
+                        */
+                       utils::Signal<void(void)> OnMenuButtonClicked;
+
+                       /**
+                        * @brief Signal emitted when delete item has been clicked.
                         */
-                       void RegisterSignal(std::function<void(void)>func, view::WorldClockSignals signal);
+                       utils::Signal<void(void)> OnMoreDeleteButtonClicked;
+
+                       /**
+                        * @brief Signal emitted when reorder item has been clicked.
+                        */
+                       utils::Signal<void(void)> OnMoreReorderButtonClicked;
+
+                       /**
+                        * @brief Signal emitted when custom list item has been clicked.
+                        */
+                       utils::Signal<void(void)> OnCustomListItemClicked;
+
+                       /**
+                        * @brief Signal emitted when custom list item has been added.
+                        */
+                       utils::Signal<void(void)> OnCustomListItemAdded;
+
+                       /**
+                        * @brief Signal emitted when custom list item has been updated.
+                        */
+                       utils::Signal<void(void)> OnCustomListUpdateRequested;
 
                        /**
                         * @brief Updates map area and timezone details
@@ -204,7 +219,6 @@ namespace view {
 
                        void SetItemLastClicked(const model::Location *location);
                        void SetItemToAdd(model::Location *l);
-                       void EmitSignal(view::WorldClockSignals signal);
 
                        const char *OffsetToString(int offset);
 
@@ -226,10 +240,7 @@ namespace view {
                        Ecore_Timer *timer_;
                        WorldClockMap *map_;
 
-                       std::vector<std::function<void(void)>> signals
-                                               = std::vector<std::function<void(void)>>((int)WorldClockSignals::MAX, nullptr);
-
-                       utils::Listener time_format_change_listener_;
+                       utils::Connection time_format_change_listener_;
                        void TimeFormatChanged();
 
                        model::Timezone current_timezone_; /* Currently displayed timezone */
index 7aad286..d3d6f0c 100644 (file)
@@ -71,25 +71,13 @@ void CounterAnimator::Remove()
        ecore_animator_del(animator_);
 }
 
-void CounterAnimator::RegisterSignal(std::function<void(void)>func)
-{
-       signals_.push_back(func);
-}
-
-
 Eina_Bool CounterAnimator::Task(void *data)
 {
        CounterAnimator *object = (CounterAnimator *)data;
 
-       object->EmitSignal();
+       object->OnTick();
 
        return ECORE_CALLBACK_RENEW;
 }
 
-void CounterAnimator::EmitSignal()
-{
-       for (auto func: signals_)
-               func();
-}
-
 } //namespace common
index 075fe92..d5852ab 100644 (file)
@@ -81,17 +81,17 @@ int MainController::Init()
        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_);
 
-       listeners_.push_back(utils::EventBus::AddListener<AlarmCreateRequestEvent>(
+       connections_.push_back(utils::EventBus::AddListener<AlarmCreateRequestEvent>(
                        std::bind(&MainController::CreateNewAlarmPage, this, _1)));
-       listeners_.push_back(utils::EventBus::AddListener<AlarmDeleteRequestEvent>(
+       connections_.push_back(utils::EventBus::AddListener<AlarmDeleteRequestEvent>(
                        std::bind(&MainController::CreateNewDeleteAlarmsPage, this, _1)));
-       listeners_.push_back(utils::EventBus::AddListener<AlarmEditRequestEvent>(
+       connections_.push_back(utils::EventBus::AddListener<AlarmEditRequestEvent>(
                        std::bind(&MainController::CreateEditAlarmPage, this, _1)));
 
-       listeners_.push_back(utils::EventBus::AddListener<WorldClockDeleteRequestEvent>(
+       connections_.push_back(utils::EventBus::AddListener<WorldClockDeleteRequestEvent>(
                        std::bind(&MainController::CreateNewWorldClockDeletePage, this, _1)));
 
-       listeners_.push_back(utils::EventBus::AddListener<WorldClockReorderRequestEvent>(
+       connections_.push_back(utils::EventBus::AddListener<WorldClockReorderRequestEvent>(
                        std::bind(&MainController::CreateNewWorldClockReorderPage, this, _1)));
 
        initialized_ = true;
@@ -114,7 +114,7 @@ void MainController::Deinit()
        delete timer_presenter_;
        delete timer_model_;
 
-       listeners_.clear();
+       connections_.clear();
        initialized_ = false;
 }
 
index 1f71a00..7dce580 100644 (file)
@@ -153,8 +153,6 @@ WorldClock::WorldClock()
        char *tz;
        int current_tz = 11; //GMT+0
 
-       parameter_signals_.resize((int)ParameterSignalType::MAX);
-       signals_.resize((int)SignalType::MAX);
        LoadItemsList();
 
        int ret = preference_get_int("WORLD_CLOCK_MAP_CURRENT_TIMEZONE", &current_tz);
@@ -267,7 +265,7 @@ void WorldClock::SetUserLocations(std::vector<const model::Location *> locations
        DBG();
        user_locations_ = locations;
 
-       EmitSignal(SignalType::CUSTOM_LIST_CHANGED);
+       OnCustomListChanged();
 }
 
 bool WorldClock::AddUserLocation(const model::Location *l)
@@ -292,7 +290,7 @@ void WorldClock::RemoveUserLocations(const std::vector<const model::Location *>
                for (auto it = user_locations_.begin(); it != user_locations_.end(); ++it) {
 
                        if (!((*it)->name.compare(d_it->name)) && !((*it)->country.compare(d_it->country))) {
-                               EmitSignal(ParameterSignalType::USER_LOCATION_REMOVED, **it);
+                               OnUserLocationRemoved(**it);
                                user_locations_.erase(it);
                                break;
                        }
@@ -453,27 +451,3 @@ const model::Location *WorldClock::LoadItem(int i)
 
        return location;
 }
-
-void WorldClock::RegisterSignalHandler(ParameterSignalType signal, std::function<void(const model::Location &)> func)
-{
-       parameter_signals_.at((int)signal) = func;
-}
-
-void WorldClock::EmitSignal(ParameterSignalType signal, const model::Location &location)
-{
-       if (parameter_signals_.at((int)signal) != nullptr) {
-               parameter_signals_.at((int)signal)(location);
-       }
-}
-
-void WorldClock::RegisterSignalHandler(SignalType signal, std::function<void(void)> func)
-{
-       signals_.at((int)signal) = func;
-}
-
-void WorldClock::EmitSignal(SignalType signal)
-{
-       if (signals_.at((int)signal) != nullptr) {
-               signals_.at((int)signal)();
-       }
-}
index a9462a8..c935e81 100644 (file)
@@ -30,17 +30,22 @@ using std::placeholders::_1;
 
 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));
-
-       listeners_.push_back(EventBus::AddListener<AlarmAddedEvent>(
+       connections_.push_back(
+                       view_->OnAddButtonClicked.Connect(std::bind(&AlarmPresenter::OnAddButtonClicked, this)));
+       connections_.push_back(
+                       view_->OnDeleteItemClicked.Connect(std::bind(&AlarmPresenter::OnDeleteItemClicked, this)));
+       connections_.push_back(
+                       view_->OnItemToggled.Connect(std::bind(&AlarmPresenter::OnItemActiveStatusChanged, this, _1)));
+       connections_.push_back(
+                       view_->OnItemSelected.Connect(std::bind(&AlarmPresenter::OnItemSelected, this, _1)));
+       connections_.push_back(
+                       view_->OnMenuButtonClicked.Connect(std::bind(&AlarmPresenter::OnMenuButtonClicked, this)));
+
+       connections_.push_back(EventBus::AddListener<AlarmAddedEvent>(
                        std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1)));
-       listeners_.push_back(EventBus::AddListener<AlarmRemovedEvent>(
+       connections_.push_back(EventBus::AddListener<AlarmRemovedEvent>(
                        std::bind(&AlarmPresenter::OnAlarmRemovedEvent, this, _1)));
-       listeners_.push_back(EventBus::AddListener<AlarmEditedEvent>(
+       connections_.push_back(EventBus::AddListener<AlarmEditedEvent>(
                        std::bind(&AlarmPresenter::OnAlarmEditedEvent, this, _1)));
 
        ShowAll();
index dcd7a38..09ad56a 100644 (file)
@@ -23,12 +23,14 @@ namespace presenter {
 DeleteAlarmPresenter::DeleteAlarmPresenter(DeleteAlarmView *view, AlarmProvider *model)
        : view_(view), model_(model)
 {
-       view->RegisterCancelButtonClickedCallback(
+       connections_.push_back(
+                       view->OnCancelButtonClicked.Connect(
                        std::bind(&DeleteAlarmPresenter::OnCancelButtonClicked, this)
-                       );
-       view->RegisterDeleteButtonClickedCallback(
+                       ));
+       connections_.push_back(
+                       view->OnDeleteButtonClicked.Connect(
                        std::bind(&DeleteAlarmPresenter::OnDeleteButtonClicked, this)
-                       );
+                       ));
 
        std::vector<std::reference_wrapper<Alarm>> alarms = model_->GetAlarms();
 
index 6aec549..d0f33e1 100644 (file)
@@ -34,9 +34,15 @@ const double time_truncate_factor = 60 * 1000; // 60 seconds
 EditAlarmPresenter::EditAlarmPresenter(model::AlarmProvider *provider, model::Alarm *alarm, view::EditAlarmView& view) :
        provider_(provider), alarm_(alarm), view_(view)
 {
-       view_.RegisterEditDoneCallback(std::bind(&EditAlarmPresenter::OnEditDone, this));
-       view_.RegisterEditCancelCallback(std::bind(&EditAlarmPresenter::OnEditCancel, this));
-       view_.RegisterBackButtonCallback(std::bind(&EditAlarmPresenter::OnBackButton, this));
+       connections_.push_back(
+               view_.OnEditDone.Connect(std::bind(&EditAlarmPresenter::OnEditDone, this)));
+       connections_.push_back(
+                       view_.OnEditCancel.Connect(std::bind(&EditAlarmPresenter::OnEditCancel, this)));
+       connections_.push_back(
+                       view_.OnBackButtonClicked.Connect(std::bind(&EditAlarmPresenter::OnBackButton, this)));
+       connections_.push_back(
+               view_.OnDiscardPopupOptionSelected.Connect(std::bind(&EditAlarmPresenter::OnDiscardPopupOptionClicked, this, _1)))
+               ;
        info_ = GetInfoForAlarm(alarm);
        view_.SetData(info_);
        view_.SetMode(alarm == nullptr ? EditAlarmView::Mode::Create : EditAlarmView::Mode::Edit);
@@ -188,8 +194,6 @@ void EditAlarmPresenter::OnEditCancel()
 
 void EditAlarmPresenter::OnDiscardPopupOptionClicked(EditAlarmView::DiscardPopupOption option)
 {
-       view_.RegisterDiscardPopupCallback(nullptr);
-
        switch (option)
        {
                case EditAlarmView::DiscardPopupOption::CANCEL:
@@ -220,7 +224,6 @@ void EditAlarmPresenter::OnBackButton()
 
        if (!CompareAlarmInfoStructures(info_, view_.GetData()))
        {
-               view_.RegisterDiscardPopupCallback(std::bind(&EditAlarmPresenter::OnDiscardPopupOptionClicked, this, _1));
                view_.ShowDiscardPopup();
        } else {
                view_.PopPage();
index 235aea0..159dbc3 100644 (file)
@@ -27,17 +27,17 @@ namespace presenter {
 RingPresenter::RingPresenter(view::RingView *view, model::Ring *model)
        : view_(view), model_(model)
 {
-       animator_.RegisterSignal(std::bind(&RingPresenter::TimeUpdateRequest, this));
-
-       view_->RegisterSignal(std::bind(&RingPresenter::DismissButtonClicked, this),
-                       view::RingSignal::BUTTON_DISMISS_CLICKED);
-       view_->RegisterSignal(std::bind(&RingPresenter::SnoozeButtonClicked, this),
-                       view::RingSignal::BUTTON_SNOOZE_CLICKED);
-
-       listeners_.push_back(utils::EventBus::AddListener<model::RingNewAlarmEvent>(
+       connections_.push_back(animator_.OnTick.Connect(
+                               std::bind(&RingPresenter::TimeUpdateRequest, this)));
+       connections_.push_back(view_->OnDismissButtonClicked.Connect(
+                               std::bind(&RingPresenter::DismissButtonClicked, this)));
+       connections_.push_back(view->OnSnoozeButtonClicked.Connect(
+                               std::bind(&RingPresenter::SnoozeButtonClicked, this)));
+
+       connections_.push_back(utils::EventBus::AddListener<model::RingNewAlarmEvent>(
                                std::bind(&RingPresenter::AlarmHandle,
                                this, std::placeholders::_1)));
-       listeners_.push_back(utils::EventBus::AddListener<model::RingTimeoutEvent>(
+       connections_.push_back(utils::EventBus::AddListener<model::RingTimeoutEvent>(
                                std::bind(&RingPresenter::TimeoutHandle,
                                this, std::placeholders::_1)));
 }
index a0062a4..7ab6680 100644 (file)
@@ -27,18 +27,18 @@ using namespace std::chrono;
 StopWatchPresenter::StopWatchPresenter(view::StopWatchView *ui, model::StopWatch *model)
        : ui_(ui), model_(model)
 {
-       ui_->RegisterSignal(std::bind(&StopWatchPresenter::StartButtonClicked, this),
-                       view::Signal::BUTTON_START_CLICKED);
-       ui_->RegisterSignal(std::bind(&StopWatchPresenter::StopButtonClicked, this),
-                       view::Signal::BUTTON_STOP_CLICKED);
-       ui_->RegisterSignal(std::bind(&StopWatchPresenter::ResumeButtonClicked, this),
-                       view::Signal::BUTTON_RESUME_CLICKED);
-       ui_->RegisterSignal(std::bind(&StopWatchPresenter::ResetButtonClicked, this),
-                       view::Signal::BUTTON_RESET_CLICKED);
-       ui_->RegisterSignal(std::bind(&StopWatchPresenter::LapButtonClicked, this),
-                       view::Signal::BUTTON_LAP_CLICKED);
-
-       animator_.RegisterSignal(std::bind(&StopWatchPresenter::TimeUpdateRequest, this));
+       connections_.push_back(ui_->OnStartButtonClicked.Connect(
+                       std::bind(&StopWatchPresenter::StartButtonClicked, this)));
+       connections_.push_back(ui_->OnStopButtonClicked.Connect(
+                               std::bind(&StopWatchPresenter::StopButtonClicked, this)));
+       connections_.push_back(ui_->OnResumeButtonClicked.Connect(
+                               std::bind(&StopWatchPresenter::ResumeButtonClicked, this)));
+       connections_.push_back(ui_->OnResetButtonClicked.Connect(
+                               std::bind(&StopWatchPresenter::ResetButtonClicked, this)));
+       connections_.push_back(ui_->OnLapButtonClicked.Connect(
+                               std::bind(&StopWatchPresenter::LapButtonClicked, this)));
+       connections_.push_back(animator_.OnTick.Connect(
+                               std::bind(&StopWatchPresenter::TimeUpdateRequest, this)));
 }
 
 StopWatchPresenter::~StopWatchPresenter()
index f5dd309..7239113 100644 (file)
@@ -24,19 +24,18 @@ using namespace std::chrono;
 TimerPresenter::TimerPresenter(view::TimerView *view, model::Timer *model)
        : view_(view), model_(model)
 {
-
-       view_->RegisterSignal(std::bind(&TimerPresenter::StartButtonClicked, this),
-                       view::TimerSignal::BUTTON_START_CLICKED);
-       view_->RegisterSignal(std::bind(&TimerPresenter::PauseButtonClicked, this),
-                       view::TimerSignal::BUTTON_PAUSE_CLICKED);
-       view_->RegisterSignal(std::bind(&TimerPresenter::ResumeButtonClicked, this),
-                       view::TimerSignal::BUTTON_RESUME_CLICKED);
-       view_->RegisterSignal(std::bind(&TimerPresenter::CancelButtonClicked, this),
-                       view::TimerSignal::BUTTON_CANCEL_CLICKED);
-       view_->RegisterSignal(std::bind(&TimerPresenter::ResetButtonClicked, this),
-                       view::TimerSignal::BUTTON_RESET_CLICKED);
-
-       animator_.RegisterSignal(std::bind(&TimerPresenter::TimeUpdateRequest, this));
+       connections_.push_back(view_->OnStartButtonClicked.Connect(
+                               std::bind(&TimerPresenter::StartButtonClicked, this)));
+       connections_.push_back(view_->OnPauseButtonClicked.Connect(
+                               std::bind(&TimerPresenter::PauseButtonClicked, this)));
+       connections_.push_back(view_->OnResumeButtonClicked.Connect(
+                               std::bind(&TimerPresenter::ResumeButtonClicked, this)));
+       connections_.push_back(view_->OnCancelButtonClicked.Connect(
+                               std::bind(&TimerPresenter::CancelButtonClicked, this)));
+       connections_.push_back(view_->OnResetButtonClicked.Connect(
+                               std::bind(&TimerPresenter::ResetButtonClicked, this)));
+       connections_.push_back(animator_.OnTick.Connect(
+                               std::bind(&TimerPresenter::TimeUpdateRequest, this)));
 }
 
 TimerPresenter::~TimerPresenter()
index 98cf99d..32acb78 100644 (file)
@@ -28,14 +28,14 @@ WorldClockDeletePresenter::WorldClockDeletePresenter(
                 model_(model), delete_view_(view)
 {
        DBG("");
-       delete_view_->RegisterSignal(view::WorldClockDeleteItemsView::SignalType::BUTTON_CANCEL_CLICKED,
-                       std::bind(&WorldClockDeletePresenter::OnCancelClicked, this));
-       delete_view_->RegisterSignal(view::WorldClockDeleteItemsView::SignalType::BUTTON_DELETE_CLICKED,
-                       std::bind(&WorldClockDeletePresenter::OnDeleteClicked, this));
-       delete_view_->RegisterSignal(view::WorldClockDeleteItemsView::SignalType::CHECKBOX_SELECT_ALL_CLICKED,
-                       std::bind(&WorldClockDeletePresenter::OnSelectAllClicked, this));
-       delete_view_->RegisterSignal(view::WorldClockDeleteItemsView::SignalType::LIST_ITEM_CLICKED,
-                       std::bind(&WorldClockDeletePresenter::OnListItemClicked, this));
+       connections_.push_back(delete_view_->OnCancelButtonClicked.Connect(
+                               std::bind(&WorldClockDeletePresenter::OnCancelClicked, this)));
+       connections_.push_back(delete_view_->OnDeleteButtonClicked.Connect(
+                               std::bind(&WorldClockDeletePresenter::OnDeleteClicked, this)));
+       connections_.push_back(delete_view_->OnSelectAllCheckboxClicked.Connect(
+                               std::bind(&WorldClockDeletePresenter::OnSelectAllClicked, this)));
+       connections_.push_back(delete_view_->OnListItemClicked.Connect(
+                               std::bind(&WorldClockDeletePresenter::OnListItemClicked, this)));
 
        delete_view_->PushPage();
        delete_view_->AppendItems(model_->user_locations_);
index bdcb7e5..b5706ea 100644 (file)
@@ -33,28 +33,27 @@ namespace presenter {
 WorldClockPresenter::WorldClockPresenter(WorldClockView *view, WorldClock *model)
                        : view_(view), model_(model)
 {
-       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnLeftArrowButtonClicked, this),
-                       WorldClockSignals::BUTTON_LEFT_ARROW_CLICKED);
-       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnRightArrowButtonClicked, this),
-                       WorldClockSignals::BUTTON_RIGHT_ARROW_CLICKED);
-       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnCustomListItemClicked, this),
-                       WorldClockSignals::CUSTOM_LIST_ITEM_CLICKED);
-       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnItemAdded, this),
-                       WorldClockSignals::CUSTOM_LIST_ITEM_ADD);
-       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnMapViewUpdateRequest, this),
-                       WorldClockSignals::CUSTOM_LIST_UPDATE_REQUEST);
-       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnMoreButtonClicked, this),
-                       WorldClockSignals::BUTTON_MORE_CLICKED);
-       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnMoreDeleteButtonClicked, this),
-                       WorldClockSignals::BUTTON_MORE_DELETE_CLICKED);
-       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnMoreReorderButtonClicked, this),
-                       WorldClockSignals::BUTTON_MORE_REORDER_CLICKED);
-
-       model_->RegisterSignalHandler(WorldClock::ParameterSignalType::USER_LOCATION_REMOVED,
-                       std::bind(&WorldClockPresenter::OnItemDeleted, this, _1));
-
-       model_->RegisterSignalHandler(WorldClock::SignalType::CUSTOM_LIST_CHANGED,
-                       std::bind(&WorldClockPresenter::OnCustomListChanged, this));
+       connections_.push_back(view_->OnLeftArrowClicked.Connect(
+                               std::bind(&WorldClockPresenter::OnLeftArrowButtonClicked, this)));
+       connections_.push_back(view_->OnRightArrowClicked.Connect(
+                               std::bind(&WorldClockPresenter::OnRightArrowButtonClicked, this)));
+       connections_.push_back(view_->OnCustomListItemClicked.Connect(
+                               std::bind(&WorldClockPresenter::OnCustomListItemClicked, this)));
+       connections_.push_back(view_->OnCustomListItemAdded.Connect(
+                               std::bind(&WorldClockPresenter::OnItemAdded, this)));
+       connections_.push_back(view_->OnCustomListUpdateRequested.Connect(
+                               std::bind(&WorldClockPresenter::OnMapViewUpdateRequest, this)));
+       connections_.push_back(view_->OnMenuButtonClicked.Connect(
+                               std::bind(&WorldClockPresenter::OnMoreButtonClicked, this)));
+       connections_.push_back(view_->OnMoreDeleteButtonClicked.Connect(
+                               std::bind(&WorldClockPresenter::OnMoreDeleteButtonClicked, this)));
+       connections_.push_back(view->OnMoreReorderButtonClicked.Connect(
+                               std::bind(&WorldClockPresenter::OnMoreReorderButtonClicked, this)));
+
+       connections_.push_back(model_->OnUserLocationRemoved.Connect(
+                               std::bind(&WorldClockPresenter::OnItemDeleted, this, _1)));
+       connections_.push_back(model_->OnCustomListChanged.Connect(
+                               std::bind(&WorldClockPresenter::OnCustomListChanged, this)));
 
        OnMapViewUpdateRequest();
 
index c37b548..9716ec1 100644 (file)
@@ -25,11 +25,11 @@ WorldClockReorderPresenter::WorldClockReorderPresenter(
         WorldClockReorderView *view, model::WorldClock *model) :
                model_(model), reorder_view_(view)
 {
-       reorder_view_->RegisterSignalHandler(WorldClockReorderView::Signals::LIST_REORDERED,
-                       std::bind(&WorldClockReorderPresenter::OnListReordered, this));
+       connections_.push_back(reorder_view_->OnListReordered.Connect(
+                               std::bind(&WorldClockReorderPresenter::OnListReordered, this)));
 
-       reorder_view_->RegisterSignalHandler(WorldClockReorderView::Signals::BUTTON_BACK_CLICKED,
-                       std::bind(&WorldClockReorderPresenter::OnBackClicked, this));
+       connections_.push_back(reorder_view_->OnBackButtonClicked.Connect(
+                               std::bind(&WorldClockReorderPresenter::OnBackClicked, this)));
 
        reorder_view_->PushPage();
        reorder_view_->AppendItems(model_->user_locations_);
index 6390aee..5b74121 100644 (file)
@@ -30,67 +30,11 @@ EventBus& EventBus::GetInstance()
 void EventBus::FireEvent(Event& event)
 {
        EventBus &bus = GetInstance();
-
-       auto it = bus.callbacks_[typeid(event)].begin();
-       auto end = bus.callbacks_[typeid(event)].end();
-
-       for (; it != end; ++it) {
-               (*it)(event);
-       }
+       bus.callbacks_[typeid(event)](event);
 }
 
-Listener EventBus::AddListenerInternal(const std::type_index type, std::function<void(Event&)> cb)
+utils::Connection EventBus::AddListenerInternal(const std::type_index type, std::function<void(Event&)> cb)
 {
        EventBus &bus = GetInstance();
-       bus.callbacks_[type].push_back(cb);
-       return Listener(bus.callbacks_[type], --bus.callbacks_[type].end());
-}
-
-Listener::Listener(std::list<std::function<void(Event&)>> &owner,
-       std::list<std::function<void(Event&)>>::iterator it)
-{
-       owner_ = std::addressof(owner);
-       it_ = it;
-}
-
-Listener::~Listener()
-{
-       Unregister();
-}
-
-void Listener::Unregister()
-{
-       if (owner_) {
-               owner_->erase(it_);
-               owner_ = nullptr;
-       }
-}
-
-Listener::Listener(Listener&& ref)
-{
-       owner_ = ref.owner_;
-       it_ = std::move(ref.it_);
-       ref.owner_ = nullptr;
-}
-
-Listener::Listener(const Listener& ln)
-{
-       owner_ = ln.owner_;
-       if (owner_) {
-               owner_->push_back(*ln.it_);
-               it_ = --owner_->end();
-       }
-}
-
-Listener& Listener::operator=(const Listener& ln)
-{
-       // unregister first, as subscription may be set.
-       Unregister();
-
-       owner_ = ln.owner_;
-       if (owner_) {
-               owner_->push_back(*ln.it_);
-               it_ = --owner_->end();
-       }
-       return *this;
+       return bus.callbacks_[type].Connect(cb);
 }
index 96484d7..04e2401 100644 (file)
@@ -57,8 +57,7 @@ void RingtonePicker::AppControlCb(app_control_h request, app_control_h reply,
        DBG("Recieved ringthone path: %s", ringtone_path[0]);
        instance->ringtone_ = ringtone_path[0];
        free(ringtone_path);
-       if (instance->update_cb_)
-               instance->update_cb_();
+       instance->OnPathUpdated();
 }
 
 bool RingtonePicker::ShowDialog()
@@ -130,9 +129,4 @@ bool RingtonePicker::ShowDialog()
        return true;
 }
 
-void RingtonePicker::RegisterPathUpdateSignalHandler(std::function<void(void)> cb)
-{
-       update_cb_ = cb;
-}
-
 };
index 013560d..bfb5f72 100644 (file)
@@ -64,7 +64,7 @@ void AlarmView::ItemClicked(void *data, Evas_Object *obj, void *info)
        else
                elm_object_item_signal_emit(id->it, "alarm,state,disabled", "clock");
 
-       if (id->instance->onToggled_) id->instance->onToggled_((uintptr_t)id->it);
+       id->instance->OnItemToggled((uintptr_t)id->it);
 }
 
 void AlarmView::ItemRealized(void *data, Evas_Object *obj, void *info)
@@ -82,7 +82,7 @@ void AlarmView::ItemRealized(void *data, Evas_Object *obj, void *info)
 void AlarmView::ItemSelected(void *data, Evas_Object *obj, void *info)
 {
        ItemData *id = static_cast<ItemData*>(data);
-       if (id->instance->onSelected_) id->instance->onSelected_((uintptr_t)id->it);
+       id->instance->OnItemSelected((uintptr_t)id->it);
 
        elm_genlist_item_selected_set(id->it, EINA_FALSE);
 }
@@ -204,7 +204,7 @@ void AlarmView::TimeFormatChanged()
 void AlarmView::MoreButtonClicked(void *data, Evas_Object *obj, void *info)
 {
        AlarmView *view = static_cast<AlarmView*>(data);
-       if (view->onMenuClicked_) view->onMenuClicked_();
+       view->OnMenuButtonClicked();
 }
 
 void AlarmView::Clear()
@@ -263,7 +263,7 @@ Evas_Object *AlarmView::GetEvasObject()
 void AlarmView::ButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        AlarmView *view = static_cast<AlarmView*>(data);
-       if (view->onClicked_) view->onClicked_();
+       view->OnAddButtonClicked();
 }
 
 void AlarmView::DismissPopupCallback(void *data, Evas_Object *obj, void *event_info)
@@ -276,7 +276,7 @@ void AlarmView::DismissPopupCallback(void *data, Evas_Object *obj, void *event_i
 void AlarmView::PopupDeleteItemCallback(void *data, Evas_Object *obj, void *event_info)
 {
        AlarmView *view = static_cast<AlarmView*>(data);
-       if (view->onDeleteClicked_) view->onDeleteClicked_();
+       view->OnDeleteItemClicked();
        evas_object_del(view->popup_);
        view->popup_ = nullptr;
 }
index 8ef3192..1ba05d8 100644 (file)
@@ -229,13 +229,13 @@ void DeleteAlarmView::DestroyContent()
 void DeleteAlarmView::OnCancelButtonClickedCb(void *data, Evas_Object *obj, void *event)
 {
        DeleteAlarmView *view = static_cast<DeleteAlarmView*>(data);
-       if (view->onCancelButtonClicked_) view->onCancelButtonClicked_();
+       view->OnCancelButtonClicked();
 }
 
 void DeleteAlarmView::OnDeleteButtonClickedCb(void *data, Evas_Object *obj, void *event)
 {
        DeleteAlarmView *view = static_cast<DeleteAlarmView*>(data);
-       if (view->onDeleteButtonClicked_) view->onDeleteButtonClicked_();
+       view->OnDeleteButtonClicked();
 }
 
 int DeleteAlarmView::ItemAppend(utils::Time time, const char *name,
index ba3ccfa..83abfc5 100644 (file)
@@ -36,11 +36,11 @@ using namespace model;
 #define SOUND_ICON_PATH "images/00_volume_icon.png"
 
 EditAlarmView::EditAlarmView(view::MainView &main)
-       : PageView(main), week_flags_view_(main, data_.flags), is_muted_(false), main_(main)
+       : PageView(main), discard_popup_(nullptr), week_flags_view_(main, data_.flags), is_muted_(false), main_(main)
 {
-       week_flags_view_.RegisterPoppedCallback(
+       week_flags_popped_conn_ = week_flags_view_.OnPagePopped.Connect(
                        std::bind(&EditAlarmView::OnWeekFlagsPagePopped, this));
-       picker_.RegisterPathUpdateSignalHandler(
+       picker_conn_ = picker_.OnPathUpdated.Connect(
                        std::bind(&EditAlarmView::RingtonePathUpdateCallback, this));
        time_format_change_listener_ = EventBus::AddListener<Time::PreferedTimeFormatChanged>(
                        std::bind(&EditAlarmView::TimeFormatChanged, this));
@@ -167,13 +167,13 @@ static std::string GetLabelForAlarmType(Alarm::Type type)
 void EditAlarmView::OnCancelButtonClickedCb(void *data, Evas_Object *obj, void *event_info)
 {
        EditAlarmView *view = static_cast<EditAlarmView*>(data);
-       if (view->onEditCancel_) view->onEditCancel_();
+       view->OnEditCancel();
 }
 
 void EditAlarmView::OnConfirmButtonClickedCb(void *data, Evas_Object *obj, void *event_info)
 {
        EditAlarmView *view = static_cast<EditAlarmView*>(data);
-       if (view->onEditDone_) view->onEditDone_();
+       view->OnEditDone();
 }
 
 const char *EditAlarmView::GetTitle()
@@ -190,7 +190,7 @@ const char *EditAlarmView::GetTitle()
 void EditAlarmView::BackButtonOnMainClicked(void *data, Evas_Object *obj, void *event)
 {
        EditAlarmView *view = static_cast<EditAlarmView*>(data);
-       if (view->onBackButton) view->onBackButton();
+       view->OnBackButtonClicked();
 }
 
 void EditAlarmView::CreateContent(Evas_Object *parent)
@@ -601,13 +601,13 @@ void EditAlarmView::ShowPopup(const std::string &text)
 void EditAlarmView::PopupDiscardButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        EditAlarmView *view = static_cast<EditAlarmView*>(data);
-       if (view->onDiscardPopupCallback) view->onDiscardPopupCallback(DiscardPopupOption::CONFIRM);
+       view->OnDiscardPopupOptionSelected(DiscardPopupOption::CONFIRM);
 }
 
 void EditAlarmView::PopupCancelButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        EditAlarmView *view = static_cast<EditAlarmView*>(data);
-       if (view->onDiscardPopupCallback) view->onDiscardPopupCallback(DiscardPopupOption::CANCEL);
+       view->OnDiscardPopupOptionSelected(DiscardPopupOption::CANCEL);
 }
 
 void EditAlarmView::ShowDiscardPopup()
index c24bd58..4cde7f3 100644 (file)
@@ -42,7 +42,7 @@ void PageView::ItemDeletedCallback(void *data, Evas_Object *o, void *event)
 {
        Elm_Object_Item *it = static_cast<Elm_Object_Item*>(event);
        PageView *view = static_cast<PageView*>(elm_object_item_data_get(it));
-       view->EmitPoppedEvent();
+       view->OnPagePopped();
        view->navi_item_ = NULL;
        view->DestroyContent();
 }
@@ -69,22 +69,10 @@ void PageView::PopPage()
        elm_object_item_del_cb_set(navi_item_, nullptr);
        elm_object_item_del(navi_item_);
        navi_item_ = NULL;
-       EmitPoppedEvent();
+       OnPagePopped();
 }
 
 Evas_Object *PageView::GetNaviframe()
 {
        return naviframe_;
 }
-
-void PageView::RegisterPoppedCallback(std::function<void(void)> f)
-{
-       onPopped_.push_back(f);
-}
-
-void PageView::EmitPoppedEvent()
-{
-       for (auto func: onPopped_) {
-               func();
-       }
-}
index ac6491a..2446749 100644 (file)
@@ -223,7 +223,7 @@ void RingView::DismissCb(void *data, Evas_Object *obj, const char *emission, con
 {
        RingView *object = static_cast<RingView *>(data);
 
-       object->EmitSignal(view::RingSignal::BUTTON_DISMISS_CLICKED);
+       object->OnDismissButtonClicked();
        evas_object_del(object->win_);
 }
 
@@ -231,19 +231,8 @@ void RingView::SnoozeCb(void *data, Evas_Object *obj, const char *emission, cons
 {
        RingView *object = static_cast<RingView *>(data);
 
-       object->EmitSignal(view::RingSignal::BUTTON_SNOOZE_CLICKED);
+       object->OnSnoozeButtonClicked();
        evas_object_del(object->win_);
 }
 
-void RingView::RegisterSignal(std::function<void(void)>func, RingSignal type)
-{
-       signals_.at((int)type) = func;
-}
-
-void RingView::EmitSignal(RingSignal type)
-{
-       if (signals_.at((int)type) != nullptr)
-               signals_.at((int)type)();
-}
-
 } //namespace view
index 47a0efc..0906662 100644 (file)
@@ -137,32 +137,32 @@ void StopWatchView::CreateButton(Evas_Object *parent, const char *name,
 void StopWatchView::StartButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        StopWatchView *object = static_cast<StopWatchView *>(data);
-       object->EmitSignal(Signal::BUTTON_START_CLICKED);
+       object->OnStartButtonClicked();
 }
 
 void StopWatchView::StopButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        StopWatchView *object = static_cast<StopWatchView *>(data);
-       object->EmitSignal(Signal::BUTTON_STOP_CLICKED);
+       object->OnStopButtonClicked();
 }
 
 void StopWatchView::LapButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        StopWatchView *object = static_cast<StopWatchView *>(data);
-       object->EmitSignal(Signal::BUTTON_LAP_CLICKED);
+       object->OnLapButtonClicked();
 }
 
 void StopWatchView::ResumeButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
 
        StopWatchView *object = static_cast<StopWatchView *>(data);
-       object->EmitSignal(Signal::BUTTON_RESUME_CLICKED);
+       object->OnResumeButtonClicked();
 }
 
 void StopWatchView::ResetButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        StopWatchView *object = static_cast<StopWatchView *>(data);
-       object->EmitSignal(Signal::BUTTON_RESET_CLICKED);
+       object->OnResetButtonClicked();
 }
 
 Evas_Object *StopWatchView::CreateList()
@@ -246,17 +246,6 @@ char *StopWatchView::GetListText(void *data, Evas_Object *obj, const char *part)
        return NULL;
 }
 
-void StopWatchView::RegisterSignal(std::function<void(void)>func, Signal type)
-{
-       signals.at((int)type) = func;
-}
-
-void StopWatchView::EmitSignal(Signal type)
-{
-       if (signals.at((int)type) != nullptr)
-               signals.at((int)type)();
-}
-
 void StopWatchView::DisplayTime(unsigned hour, unsigned minute, unsigned second, unsigned millisecond)
 {
        main_counter_->DisplayTime(hour, minute, second, millisecond);
index 93a73ac..0249a99 100644 (file)
@@ -108,7 +108,7 @@ void TimerView::AlarmDismiss(void *data, Evas_Object *obj, const char *emission,
 {
        TimerView *object = static_cast<TimerView *>(data);
 
-       object->EmitSignal(TimerSignal::BUTTON_CANCEL_CLICKED);
+       object->OnCancelButtonClicked();
 
        elm_object_signal_emit(object->layout_, "menu.startup.show", "timer");
 }
@@ -516,36 +516,32 @@ void TimerView::CreateButton(Evas_Object *parent, const char *name,
 void TimerView::StartButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        TimerView *object = static_cast<TimerView *>(data);
-
-       object->EmitSignal(TimerSignal::BUTTON_START_CLICKED);
+       object->OnStartButtonClicked();
 }
 
 void TimerView::PauseButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        TimerView *object = static_cast<TimerView *>(data);
-
-       object->EmitSignal(TimerSignal::BUTTON_PAUSE_CLICKED);
+       object->OnPauseButtonClicked();
 }
 
 void TimerView::CancelButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        TimerView *object = static_cast<TimerView *>(data);
-
-       object->EmitSignal(TimerSignal::BUTTON_CANCEL_CLICKED);
+       object->OnCancelButtonClicked();
 }
 
 void TimerView::ResumeButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        TimerView *object = static_cast<TimerView *>(data);
-
-       object->EmitSignal(TimerSignal::BUTTON_RESUME_CLICKED);
+       object->OnResumeButtonClicked();
 }
 
 void TimerView::ResetButtonClicked(void *data, Evas_Object *obj, void *event_info)
 {
        TimerView *object = static_cast<TimerView *>(data);
 
-       object->EmitSignal(TimerSignal::BUTTON_RESET_CLICKED);
+       object->OnResetButtonClicked();
 
        object->set_time_.Hour = 0;
        object->set_time_.Min = 0;
@@ -555,15 +551,4 @@ void TimerView::ResetButtonClicked(void *data, Evas_Object *obj, void *event_inf
        object->UnfocusEntries();
 }
 
-void TimerView::RegisterSignal(std::function<void(void)>func, TimerSignal type)
-{
-       signals.at((int)type) = func;
-}
-
-void TimerView::EmitSignal(TimerSignal type)
-{
-       if (signals.at((int)type) != nullptr)
-               signals.at((int)type)();
-}
-
 } //namespace view
index 5b4d361..c8da4ea 100644 (file)
@@ -110,7 +110,7 @@ void WorldClockDeleteItemsView::ItemClicked(void *data, Evas_Object *obj, void *
        }
        ldid->view->UpdateTitle();
 
-       ldid->view->EmitSignal(SignalType::LIST_ITEM_CLICKED);
+       ldid->view->OnListItemClicked();
 
        elm_genlist_item_selected_set(ldid->it, EINA_FALSE);
        elm_check_state_set(ldid->checkbox, ldid->selected);
@@ -271,14 +271,14 @@ void WorldClockDeleteItemsView::CreateContent(Evas_Object *parent)
        elm_object_text_set(left_button_, "CANCEL");
        elm_object_style_set(left_button_, "naviframe/title_left");
        evas_object_smart_callback_add(left_button_, "clicked",
-                       WorldClockDeleteItemsView::OnCancelButtonClicked, this);
+                       WorldClockDeleteItemsView::CancelButtonClicked, this);
        evas_object_show(left_button_);
 
        right_button_ = elm_button_add(parent);
        elm_object_text_set(right_button_, "DELETE");
        elm_object_style_set(right_button_, "naviframe/title_left");
        evas_object_smart_callback_add(right_button_, "clicked",
-                       WorldClockDeleteItemsView::OnDeleteButtonClicked, this);
+                       WorldClockDeleteItemsView::DeleteButtonClicked, this);
        evas_object_show(right_button_);
 
        content_ = elm_genlist_add(parent);
@@ -323,14 +323,14 @@ void WorldClockDeleteItemsView::CreateSelectAll()
                        elm_check_state_set(view->select_all_checkbox_, view->all_selected_);
                        evas_object_propagate_events_set(view->select_all_checkbox_, EINA_FALSE);
                        evas_object_smart_callback_add(view->select_all_checkbox_, "changed",
-                                       WorldClockDeleteItemsView::OnSelectAllClicked, view);
+                                       WorldClockDeleteItemsView::SelectAllClicked, view);
                        evas_object_show(view->select_all_checkbox_);
                        return view->select_all_checkbox_;
                }
                return nullptr;
        };
        item = elm_genlist_item_append(content_, itc, this, NULL, ELM_GENLIST_ITEM_NONE,
-                       WorldClockDeleteItemsView::OnSelectAllClicked, this);
+                       WorldClockDeleteItemsView::SelectAllClicked, this);
        elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_ALWAYS);
 
        elm_genlist_item_class_unref(itc);
@@ -344,31 +344,19 @@ void WorldClockDeleteItemsView::DestroyContent()
        evas_object_del(right_button_);
 }
 
-void WorldClockDeleteItemsView::RegisterSignal(SignalType s, std::function<void(void)>func)
-{
-       signals_.at((int)s) = func;
-}
-
-
-void WorldClockDeleteItemsView::EmitSignal(SignalType s)
-{
-       if (signals_.at((int)s) != nullptr)
-               signals_.at((int)s)();
-}
-
-void WorldClockDeleteItemsView::OnCancelButtonClicked(void *data, Evas_Object *obj, void *event_data)
+void WorldClockDeleteItemsView::CancelButtonClicked(void *data, Evas_Object *obj, void *event_data)
 {
        WorldClockDeleteItemsView * view = static_cast<WorldClockDeleteItemsView *>(data);
-       view->EmitSignal(SignalType::BUTTON_CANCEL_CLICKED);
+       view->OnCancelButtonClicked();
 }
 
-void WorldClockDeleteItemsView::OnDeleteButtonClicked(void *data, Evas_Object *obj, void *event_data)
+void WorldClockDeleteItemsView::DeleteButtonClicked(void *data, Evas_Object *obj, void *event_data)
 {
        WorldClockDeleteItemsView * view = static_cast<WorldClockDeleteItemsView *>(data);
-       view->EmitSignal(SignalType::BUTTON_DELETE_CLICKED);
+       view->OnDeleteButtonClicked();
 }
 
-void WorldClockDeleteItemsView::OnSelectAllClicked(void *data, Evas_Object *obj, void *event_info)
+void WorldClockDeleteItemsView::SelectAllClicked(void *data, Evas_Object *obj, void *event_info)
 {
        Elm_Object_Item *it = static_cast<Elm_Object_Item*>(event_info);
        WorldClockDeleteItemsView *view = static_cast<WorldClockDeleteItemsView *>(data);
@@ -376,7 +364,7 @@ void WorldClockDeleteItemsView::OnSelectAllClicked(void *data, Evas_Object *obj,
        view->all_selected_ = !view->all_selected_;
        elm_check_state_set(view->select_all_checkbox_, view->all_selected_);
 
-       view->EmitSignal(SignalType::CHECKBOX_SELECT_ALL_CLICKED);
+       view->OnSelectAllCheckboxClicked();
 }
 
 void WorldClockDeleteItemsView::ItemSelectToggle(void *data, Evas_Object *obj, void *event_info)
@@ -387,7 +375,7 @@ void WorldClockDeleteItemsView::ItemSelectToggle(void *data, Evas_Object *obj, v
        if (!ldid->selected)
                ldid->view->SetSelectAllCheckbox(false);
 
-       ldid->view->EmitSignal(SignalType::LIST_ITEM_CLICKED);
+       ldid->view->OnListItemClicked();
 }
 
 std::vector<const model::Location *> WorldClockDeleteItemsView::GetSelectedItems()
index 05a21e9..e4e0651 100644 (file)
@@ -139,7 +139,7 @@ void WorldClockReorderView::CreateContent(Evas_Object *parent)
        left_button_ = elm_button_add(parent);
        elm_object_text_set(left_button_, "BACK");
        elm_object_style_set(left_button_, "naviframe/title_left");
-       evas_object_smart_callback_add(left_button_, "clicked", OnBackButtonClicked, this);
+       evas_object_smart_callback_add(left_button_, "clicked", BackButtonClicked, this);
        evas_object_show(left_button_);
 
        content_ = elm_genlist_add(parent);
@@ -154,7 +154,7 @@ void WorldClockReorderView::CreateContent(Evas_Object *parent)
        elm_object_item_part_content_set(navi_item_, "title_left_btn", left_button_);
        elm_object_item_content_set(navi_item_, content_);
 
-       evas_object_smart_callback_add(content_, "moved" , OnListReordered, this);
+       evas_object_smart_callback_add(content_, "moved" , ListReordered, this);
 
        time_delta = utils::GetSecondsToNextExactMinute();
 
@@ -295,29 +295,18 @@ Evas_Object *WorldClockReorderView::CreatePaddingObject(Evas_Object *parent, int
        return padding;
 }
 
-void WorldClockReorderView::RegisterSignalHandler(WorldClockReorderView::Signals s, std::function<void(void)> func)
-{
-       signals_.at((int)s) = func;
-}
-
-void WorldClockReorderView::EmitSignal(Signals s)
-{
-       if (signals_.at((int)s) != nullptr)
-               signals_.at((int)s)();
-}
-
-void WorldClockReorderView::OnListReordered(void *data,
+void WorldClockReorderView::ListReordered(void *data,
         Evas_Object *obj, void *event_info)
 {
        WorldClockReorderView *view = static_cast<WorldClockReorderView *>(data);
-       view->EmitSignal(Signals::LIST_REORDERED);
+       view->OnListReordered();
 }
 
-void WorldClockReorderView::OnBackButtonClicked(void *data,
+void WorldClockReorderView::BackButtonClicked(void *data,
         Evas_Object *obj, void *event_info)
 {
        WorldClockReorderView *view = static_cast<WorldClockReorderView *>(data);
-       view->EmitSignal(Signals::BUTTON_BACK_CLICKED);
+       view->OnBackButtonClicked();
 }
 
 std::vector<const model::Location *> WorldClockReorderView::GetReorderedLocations()
index 8b9b601..786e71e 100644 (file)
@@ -134,7 +134,7 @@ void WorldClockView::ItemClicked(void *data, Evas_Object *obj, void *event_info)
        LocationItemData *lid = static_cast<LocationItemData *>(data);
 
        lid->wc_view->SetItemLastClicked(lid->location);
-       lid->wc_view->EmitSignal(view::WorldClockSignals::CUSTOM_LIST_ITEM_CLICKED);
+       lid->wc_view->OnCustomListItemClicked();
 
        elm_genlist_item_selected_set(lid->it, EINA_FALSE);
 }
@@ -220,10 +220,10 @@ void WorldClockView::ChangeTimezoneCb(void *data, Evas_Object *obj, const char *
 
 
        if (!strcmp(source, "main.world.map:arrow.left")) {
-               world_clock_view->EmitSignal(view::WorldClockSignals::BUTTON_LEFT_ARROW_CLICKED);
+               world_clock_view->OnLeftArrowClicked();
 
        } else if (!strcmp(source, "main.world.map:arrow.right")) {
-               world_clock_view->EmitSignal(view::WorldClockSignals::BUTTON_RIGHT_ARROW_CLICKED);
+               world_clock_view->OnRightArrowClicked();
        }
 }
 
@@ -246,7 +246,7 @@ Eina_Bool WorldClockView::TimeUpdateCb(void *data)
 {
        WorldClockView *view = static_cast<WorldClockView *>(data);
        elm_genlist_realized_items_update(view->custom_locations_list_);
-       view->EmitSignal(view::WorldClockSignals::CUSTOM_LIST_UPDATE_REQUEST);
+       view->OnCustomListUpdateRequested();
 
        ecore_timer_interval_set(view->timer_, utils::GetSecondsToNextExactMinute());
 
@@ -324,7 +324,7 @@ WorldClockView::~WorldClockView()
 void WorldClockView::MoreButtonClicked(void *data, Evas_Object *obj, void *info)
 {
        WorldClockView *view = static_cast<WorldClockView *>(data);
-       view->EmitSignal(view::WorldClockSignals::BUTTON_MORE_CLICKED);
+       view->OnMenuButtonClicked();
 }
 
 void WorldClockView::ShowMorePopup(MoreMenuOptions options)
@@ -358,7 +358,7 @@ void WorldClockView::MorePopupDeleteItemCallback(void *data, Evas_Object *obj, v
 {
        WorldClockView *view = static_cast<WorldClockView *>(data);
 
-       view->EmitSignal(view::WorldClockSignals::BUTTON_MORE_DELETE_CLICKED);
+       view->OnMoreDeleteButtonClicked();
        evas_object_del(view->more_popup_);
        view->more_popup_ = nullptr;
 }
@@ -367,7 +367,7 @@ void WorldClockView::MorePopupReorderItemCallback(void *data, Evas_Object *obj,
 {
        WorldClockView *view = static_cast<WorldClockView *>(data);
 
-       view->EmitSignal(view::WorldClockSignals::BUTTON_MORE_REORDER_CLICKED);
+       view->OnMoreReorderButtonClicked();
        evas_object_del(view->more_popup_);
        view->more_popup_ = nullptr;
 }
@@ -446,7 +446,7 @@ void WorldClockView::AddLocationReplayCb(app_control_h request, app_control_h re
 
        WorldClockView *view = static_cast<WorldClockView *>(user_data);
        view->SetItemToAdd(l);
-       view->EmitSignal(view::WorldClockSignals::CUSTOM_LIST_ITEM_ADD);
+       view->OnCustomListItemAdded();
 
        free(city_name);
        free(country_name);
@@ -722,17 +722,6 @@ void WorldClockView::SetItemLastClicked(const model::Location *location)
        item_last_clicked_ = location;
 }
 
-void WorldClockView::RegisterSignal(std::function<void(void)>func, view::WorldClockSignals signal)
-{
-       signals.at((int)signal) = func;
-}
-
-void WorldClockView::EmitSignal(view::WorldClockSignals signal)
-{
-       if (signals.at((int)signal) != nullptr)
-               signals.at((int)signal)();
-}
-
 const char *WorldClockView::OffsetToString(int offset)
 {
        int remainder;