From 21c3eb15ffd1c491911fde5bf8cca57c857b33f7 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 31 Jul 2020 12:38:05 +0900 Subject: [PATCH] DSEventLoop: add addIdleEnterer method addIdleEnterer is static method in order to use this method anywhere. Change-Id: Ic82c62caed004c813c6c68913af74f15b644de88 --- src/DSEventLoop/DSEventLoop.cpp | 13 ++++++++++++- src/DSEventLoop/DSEventLoop.h | 8 ++++++++ tests/DSEventLoop-test.cpp | 29 ++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/DSEventLoop/DSEventLoop.cpp b/src/DSEventLoop/DSEventLoop.cpp index 6cbf6aa..7977f16 100644 --- a/src/DSEventLoop/DSEventLoop.cpp +++ b/src/DSEventLoop/DSEventLoop.cpp @@ -5,6 +5,8 @@ namespace display_server { +static std::list __ecoreIdleEntererList; + DSEventLoop::DSEventLoop() : __running(false) { @@ -15,6 +17,10 @@ DSEventLoop::DSEventLoop() DSEventLoop::~DSEventLoop() { + for (auto ecoreIdleEnterer : __ecoreIdleEntererList) + ecore_idle_enterer_del(ecoreIdleEnterer); + __ecoreIdleEntererList.clear(); + ecore_shutdown(); } @@ -46,4 +52,9 @@ bool DSEventLoop::quit() return true; } -} // namespace display_server \ No newline at end of file +void DSEventLoop::addIdleEnterer(DSObject *slot, Ecore_Task_Cb func) +{ + __ecoreIdleEntererList.push_back(ecore_idle_enterer_add(func, slot)); +} + +} // namespace display_server diff --git a/src/DSEventLoop/DSEventLoop.h b/src/DSEventLoop/DSEventLoop.h index d343371..76a8c7a 100644 --- a/src/DSEventLoop/DSEventLoop.h +++ b/src/DSEventLoop/DSEventLoop.h @@ -1,6 +1,9 @@ #ifndef __DS_EVENT_LOOP_H__ #define __DS_EVENT_LOOP_H__ +#include "DSObject.h" +#include + namespace display_server { @@ -15,6 +18,11 @@ public: bool isRunning(); + // add Ecore_Idle_Enterer + // TODO: make generalization, hiding Ecore_Idle_Enterer, Ecore_Task_Cb + // TODO: need + static void addIdleEnterer(DSObject *slot, Ecore_Task_Cb func); + private: bool __running; }; diff --git a/tests/DSEventLoop-test.cpp b/tests/DSEventLoop-test.cpp index 773d890..31d11ea 100644 --- a/tests/DSEventLoop-test.cpp +++ b/tests/DSEventLoop-test.cpp @@ -38,4 +38,31 @@ TEST_F(DSEventLoopTest, RunAndQuit) if (timer != nullptr) { EXPECT_TRUE(eventLoop.run() == true); } -} \ No newline at end of file +} + +TEST_F(DSEventLoopTest, addIdleEnterer) +{ + DSEventLoop eventLoop; + + Ecore_Timer *timer = nullptr; + double delayInSecond = 1.0; + auto timerCb = [](void *data) -> Eina_Bool { + DSEventLoop *loop = (DSEventLoop *)data; + EXPECT_TRUE(loop->quit() == true); + return EINA_FALSE; + }; + + auto idleCb = [](void *data) -> Eina_Bool { + EXPECT_TRUE(true); + return EINA_TRUE; + }; + + timer = ecore_timer_loop_add(delayInSecond, timerCb, &eventLoop); + EXPECT_TRUE(timer != nullptr); + + DSEventLoop::addIdleEnterer(nullptr, idleCb); + + if (timer != nullptr) { + EXPECT_TRUE(eventLoop.run() == true); + } +} -- 2.7.4