From 8700539107adfe8f5e17b578d1b479762c33c597 Mon Sep 17 00:00:00 2001 From: Seoyeon Kim Date: Mon, 9 Jul 2018 11:03:35 +0900 Subject: [PATCH] [Tizen] Add SetInterval, Pause, and Resume APIs in Timer - Added enabled to restart the timer to SetInterval - Added to pause and resume the timer Change-Id: Ie9334dc9f03fd8b660138c1bc4297e6cd87d06ea Signed-off-by: Seoyeon Kim --- .../src/dali-adaptor/utc-Dali-Timer.cpp | 40 +++++++++++++++++++++- dali/internal/system/common/timer-impl-ecore.cpp | 32 +++++++++++++++-- dali/internal/system/common/timer-impl.h | 12 ++++++- dali/internal/system/common/timer-interface.h | 14 ++++++-- dali/public-api/adaptor-framework/timer.cpp | 17 ++++++++- dali/public-api/adaptor-framework/timer.h | 22 ++++++++++++ 6 files changed, 129 insertions(+), 8 deletions(-) diff --git a/automated-tests/src/dali-adaptor/utc-Dali-Timer.cpp b/automated-tests/src/dali-adaptor/utc-Dali-Timer.cpp index bbd8555..6b2b283 100644 --- a/automated-tests/src/dali-adaptor/utc-Dali-Timer.cpp +++ b/automated-tests/src/dali-adaptor/utc-Dali-Timer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -268,6 +268,44 @@ int UtcDaliTimerSetInterval(void) END_TEST; } +int UtcDaliTimerSetInterval02(void) +{ + AdaptorTestApplication application; + + tet_printf("timer set interval 02 \n"); + Timer timer = Timer::New(10); + timer.SetInterval(20); + + DALI_TEST_CHECK( timer.GetInterval() == 20 ); + DALI_TEST_CHECK( timer.IsRunning() == true ); + + timer.SetInterval(5000, false); + + DALI_TEST_CHECK( timer.GetInterval() == 5000 ); + DALI_TEST_CHECK( timer.IsRunning() == false ); + + END_TEST; +} + +int UtcDaliTimerSetInterval03(void) +{ + AdaptorTestApplication application; + + tet_printf("UtcDaliTimerSetInterval03 SetInterval and ensure timer restarts \n"); + Timer timer = Timer::New(10); + timer.SetInterval(20); + + DALI_TEST_CHECK( timer.GetInterval() == 20 ); + DALI_TEST_CHECK( timer.IsRunning() == true ); + + timer.SetInterval(5000, true); + + DALI_TEST_CHECK( timer.GetInterval() == 5000 ); + DALI_TEST_CHECK( timer.IsRunning() == true ); + + END_TEST; +} + int UtcDaliTimerCopyConstructor(void) { AdaptorTestApplication application; diff --git a/dali/internal/system/common/timer-impl-ecore.cpp b/dali/internal/system/common/timer-impl-ecore.cpp index 1c3e541..46ef603 100644 --- a/dali/internal/system/common/timer-impl-ecore.cpp +++ b/dali/internal/system/common/timer-impl-ecore.cpp @@ -101,13 +101,39 @@ void Timer::Stop() ResetTimerData(); } -void Timer::SetInterval( unsigned int interval ) +void Timer::Pause() +{ + // Timer should be used in the event thread + DALI_ASSERT_DEBUG( Adaptor::IsAvailable() ); + + if( mImpl->mId != NULL ) + { + ecore_timer_freeze( mImpl->mId ); + } +} + +void Timer::Resume() +{ + // Timer should be used in the event thread + DALI_ASSERT_DEBUG( Adaptor::IsAvailable() ); + + if( mImpl->mId != NULL ) + { + ecore_timer_thaw( mImpl->mId ); + } +} + +void Timer::SetInterval( unsigned int interval, bool restart ) { // stop existing timer Stop(); mImpl->mInterval = interval; - // start new tick - Start(); + + if( restart ) + { + // start new tick + Start(); + } } unsigned int Timer::GetInterval() const diff --git a/dali/internal/system/common/timer-impl.h b/dali/internal/system/common/timer-impl.h index a382d8f..17d8ca4 100644 --- a/dali/internal/system/common/timer-impl.h +++ b/dali/internal/system/common/timer-impl.h @@ -70,9 +70,19 @@ public: virtual void Stop(); /** + * @copydoc Dali::Timer::Pause() + */ + virtual void Pause(); + + /** + * @copydoc Dali::Timer::Resume() + */ + virtual void Resume(); + + /** * @copydoc Dali::Timer::SetInterval() */ - virtual void SetInterval( unsigned int interval ); + virtual void SetInterval( unsigned int interval, bool restart ); /** * @copydoc Dali::Timer::GetInterval() diff --git a/dali/internal/system/common/timer-interface.h b/dali/internal/system/common/timer-interface.h index f2b1462..a648b5a 100644 --- a/dali/internal/system/common/timer-interface.h +++ b/dali/internal/system/common/timer-interface.h @@ -2,7 +2,7 @@ #define __DALI_INTERNAL_ADAPTOR_BASE_TIMER_INTERFACE_H__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,9 +42,19 @@ public: virtual void Stop() = 0; /** + * @copydoc Dali::Timer::Pause() + */ + virtual void Pause() = 0; + + /** + * @copydoc Dali::Timer::Resume() + */ + virtual void Resume() = 0; + + /** * @copydoc Dali::Timer::SetInterval() */ - virtual void SetInterval( unsigned int intervalInMilliseconds ) = 0; + virtual void SetInterval( unsigned int intervalInMilliseconds, bool restart ) = 0; /** * @copydoc Dali::Timer::GetInterval() diff --git a/dali/public-api/adaptor-framework/timer.cpp b/dali/public-api/adaptor-framework/timer.cpp index 244aa26..ba98792 100644 --- a/dali/public-api/adaptor-framework/timer.cpp +++ b/dali/public-api/adaptor-framework/timer.cpp @@ -69,9 +69,24 @@ void Timer::Stop() Internal::Adaptor::GetImplementation(*this).Stop(); } +void Timer::Pause() +{ + Internal::Adaptor::GetImplementation(*this).Pause(); +} + +void Timer::Resume() +{ + Internal::Adaptor::GetImplementation(*this).Resume(); +} + void Timer::SetInterval( unsigned int interval ) { - Internal::Adaptor::GetImplementation(*this).SetInterval( interval ); + Internal::Adaptor::GetImplementation(*this).SetInterval( interval, true ); +} + +void Timer::SetInterval( unsigned int interval, bool restart ) +{ + Internal::Adaptor::GetImplementation(*this).SetInterval( interval, restart ); } unsigned int Timer::GetInterval() const diff --git a/dali/public-api/adaptor-framework/timer.h b/dali/public-api/adaptor-framework/timer.h index 9e9beac..28481ba 100755 --- a/dali/public-api/adaptor-framework/timer.h +++ b/dali/public-api/adaptor-framework/timer.h @@ -132,6 +132,18 @@ public: // API void Stop(); /** + * @brief Pauses timer. + * @SINCE_1_3.41 + */ + void Pause(); + + /** + * @brief Resumes timer. + * @SINCE_1_3.41 + */ + void Resume(); + + /** * @brief Sets a new interval on the timer and starts the timer. * * Cancels the previous timer. @@ -141,6 +153,16 @@ public: // API void SetInterval( unsigned int milliSec ); /** + * @brief Sets a new interval on the timer with option to restart the timer. + * + * Cancels the previous timer. + * @SINCE_1_3.41 + * @param[in] milliSec Interval in milliseconds + * @param[in] restart Flag to set enabled to restart or not. + */ + void SetInterval( unsigned int milliSec, bool restart ); + + /** * @brief Gets the interval of timer. * * @SINCE_1_0.0 -- 2.7.4