From e2f6b83f0b1aad789b7f650b355908388e2b607d Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Mon, 26 Jun 2023 18:31:34 +0900 Subject: [PATCH] Refactor system classes Refactor CallbackManager, FileDescriptorMonitor, Timer Change-Id: I16ac23375bae537206c78b2fd630d79eea44de36 --- dali/internal/adaptor/android/framework-android.h | 4 +- .../adaptor/androidjni/framework-androidjni.h | 4 +- dali/internal/adaptor/common/adaptor-impl.cpp | 7 +- dali/internal/adaptor/common/adaptor-impl.h | 40 +++---- dali/internal/adaptor/common/framework.h | 4 +- dali/internal/adaptor/glib/framework-glib.h | 4 +- dali/internal/adaptor/libuv/framework-libuv.h | 4 +- dali/internal/adaptor/macos/framework-mac.h | 4 +- .../adaptor/tizen-wayland/framework-tizen.h | 4 +- dali/internal/adaptor/ubuntu/framework-ubuntu.h | 4 +- dali/internal/adaptor/windows/framework-win.h | 4 +- .../system/android/callback-manager-android.cpp | 8 +- .../system/android/callback-manager-android.h | 77 +++++++------- .../android/file-descriptor-monitor-android.cpp | 11 +- .../android/file-descriptor-monitor-android.h | 64 ++++++++++++ .../system/android/system-factory-android.cpp | 54 ++++++++++ .../system/android/system-factory-android.h | 42 ++++++++ .../internal/system/android/timer-impl-android.cpp | 57 +++++----- dali/internal/system/android/timer-impl-android.h | 116 +++++++++++++++++++++ dali/internal/system/common/callback-manager.h | 13 +-- .../system/common/file-descriptor-monitor.h | 23 ++-- dali/internal/system/common/system-factory.h | 52 +++++++++ dali/internal/system/common/timer-impl.h | 77 +++----------- dali/internal/system/common/timer-interface.h | 15 +-- dali/internal/system/common/trigger-event.cpp | 7 +- dali/internal/system/common/trigger-event.h | 11 +- dali/internal/system/file.list | 6 ++ .../internal/system/glib/callback-manager-glib.cpp | 6 -- dali/internal/system/glib/callback-manager-glib.h | 13 ++- .../system/glib/file-descriptor-monitor-glib.cpp | 13 +-- .../system/glib/file-descriptor-monitor-glib.h | 64 ++++++++++++ dali/internal/system/glib/system-factory-glib.cpp | 54 ++++++++++ dali/internal/system/glib/system-factory-glib.h | 42 ++++++++ dali/internal/system/glib/timer-impl-glib.cpp | 53 +++++----- dali/internal/system/glib/timer-impl-glib.h | 116 +++++++++++++++++++++ .../system/libuv/callback-manager-libuv.cpp | 6 -- .../internal/system/libuv/callback-manager-libuv.h | 11 +- .../system/libuv/file-descriptor-monitor-libuv.cpp | 11 +- .../system/libuv/file-descriptor-monitor-libuv.h | 64 ++++++++++++ .../internal/system/libuv/system-factory-libuv.cpp | 54 ++++++++++ dali/internal/system/libuv/system-factory-libuv.h | 42 ++++++++ dali/internal/system/libuv/timer-impl-libuv.cpp | 43 ++++---- dali/internal/system/libuv/timer-impl-libuv.h | 116 +++++++++++++++++++++ .../system/linux/callback-manager-ecore.cpp | 8 +- .../internal/system/linux/callback-manager-ecore.h | 77 +++++++------- .../system/linux/file-descriptor-monitor-ecore.cpp | 11 +- .../system/linux/file-descriptor-monitor-ecore.h | 64 ++++++++++++ .../internal/system/linux/system-factory-ecore.cpp | 54 ++++++++++ dali/internal/system/linux/system-factory-ecore.h | 42 ++++++++ dali/internal/system/linux/timer-impl-ecore.cpp | 43 ++++---- dali/internal/system/linux/timer-impl-ecore.h | 116 +++++++++++++++++++++ dali/internal/system/macos/callback-manager-mac.h | 23 +++- dali/internal/system/macos/callback-manager-mac.mm | 10 +- .../system/macos/file-descriptor-monitor-macos.cpp | 9 +- .../system/macos/file-descriptor-monitor-macos.h | 60 +++++++++++ dali/internal/system/macos/system-factory-mac.cpp | 54 ++++++++++ dali/internal/system/macos/system-factory-mac.h | 42 ++++++++ dali/internal/system/macos/timer-impl-mac.cpp | 57 +++++----- dali/internal/system/macos/timer-impl-mac.h | 116 +++++++++++++++++++++ .../system/windows/callback-manager-win.cpp | 8 +- .../internal/system/windows/callback-manager-win.h | 85 ++++++++------- .../windows/file-descriptor-monitor-windows.cpp | 9 +- .../windows/file-descriptor-monitor-windows.h | 67 ++++++++++++ .../internal/system/windows/system-factory-win.cpp | 54 ++++++++++ dali/internal/system/windows/system-factory-win.h | 42 ++++++++ dali/internal/system/windows/timer-impl-win.cpp | 41 ++++---- dali/internal/system/windows/timer-impl-win.h | 116 +++++++++++++++++++++ .../window-system/common/window-render-surface.cpp | 5 +- .../internal/window-system/x11/window-system-x.cpp | 6 +- dali/public-api/adaptor-framework/timer.cpp | 7 +- dali/public-api/adaptor-framework/timer.h | 10 +- 71 files changed, 2151 insertions(+), 509 deletions(-) create mode 100644 dali/internal/system/android/file-descriptor-monitor-android.h create mode 100644 dali/internal/system/android/system-factory-android.cpp create mode 100644 dali/internal/system/android/system-factory-android.h create mode 100644 dali/internal/system/android/timer-impl-android.h create mode 100644 dali/internal/system/common/system-factory.h create mode 100644 dali/internal/system/glib/file-descriptor-monitor-glib.h create mode 100644 dali/internal/system/glib/system-factory-glib.cpp create mode 100644 dali/internal/system/glib/system-factory-glib.h create mode 100644 dali/internal/system/glib/timer-impl-glib.h create mode 100644 dali/internal/system/libuv/file-descriptor-monitor-libuv.h create mode 100644 dali/internal/system/libuv/system-factory-libuv.cpp create mode 100644 dali/internal/system/libuv/system-factory-libuv.h create mode 100644 dali/internal/system/libuv/timer-impl-libuv.h create mode 100644 dali/internal/system/linux/file-descriptor-monitor-ecore.h create mode 100644 dali/internal/system/linux/system-factory-ecore.cpp create mode 100644 dali/internal/system/linux/system-factory-ecore.h create mode 100644 dali/internal/system/linux/timer-impl-ecore.h create mode 100644 dali/internal/system/macos/file-descriptor-monitor-macos.h create mode 100644 dali/internal/system/macos/system-factory-mac.cpp create mode 100644 dali/internal/system/macos/system-factory-mac.h create mode 100644 dali/internal/system/macos/timer-impl-mac.h create mode 100644 dali/internal/system/windows/file-descriptor-monitor-windows.h create mode 100644 dali/internal/system/windows/system-factory-win.cpp create mode 100644 dali/internal/system/windows/system-factory-win.h create mode 100644 dali/internal/system/windows/timer-impl-win.h diff --git a/dali/internal/adaptor/android/framework-android.h b/dali/internal/adaptor/android/framework-android.h index d6596fb..3290fcd 100644 --- a/dali/internal/adaptor/android/framework-android.h +++ b/dali/internal/adaptor/android/framework-android.h @@ -71,8 +71,8 @@ public: private: // Undefined - FrameworkAndroid(const FrameworkAndroid&); - FrameworkAndroid& operator=(FrameworkAndroid&); + FrameworkAndroid(const FrameworkAndroid&) = delete; + FrameworkAndroid& operator=(FrameworkAndroid&) = delete; private: bool mInitialised; diff --git a/dali/internal/adaptor/androidjni/framework-androidjni.h b/dali/internal/adaptor/androidjni/framework-androidjni.h index 461c568..7ee94dd 100644 --- a/dali/internal/adaptor/androidjni/framework-androidjni.h +++ b/dali/internal/adaptor/androidjni/framework-androidjni.h @@ -71,8 +71,8 @@ public: private: // Undefined - FrameworkAndroidJni(const FrameworkAndroidJni&); - FrameworkAndroidJni& operator=(FrameworkAndroidJni&); + FrameworkAndroidJni(const FrameworkAndroidJni&) = delete; + FrameworkAndroidJni& operator=(FrameworkAndroidJni&) = delete; private: bool mInitialised; diff --git a/dali/internal/adaptor/common/adaptor-impl.cpp b/dali/internal/adaptor/common/adaptor-impl.cpp index 8d4d271..3fc83d0 100644 --- a/dali/internal/adaptor/common/adaptor-impl.cpp +++ b/dali/internal/adaptor/common/adaptor-impl.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include #include // For Utils::MakeUnique #include @@ -162,7 +163,7 @@ void Adaptor::Initialize(GraphicsFactory& graphicsFactory) mEnvironmentOptions->CreateTraceManager(mPerformanceInterface); mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread - mCallbackManager = CallbackManager::New(); + mCallbackManager = Dali::Internal::Adaptor::GetSystemFactory()->CreateCallbackManager(); Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front(); @@ -365,7 +366,9 @@ Adaptor::~Adaptor() delete mDisplayConnection; delete mPlatformAbstraction; - delete mCallbackManager; + + mCallbackManager.reset(); + delete mPerformanceInterface; mGraphics->Destroy(); diff --git a/dali/internal/adaptor/common/adaptor-impl.h b/dali/internal/adaptor/common/adaptor-impl.h index 1f68c22..e058047 100644 --- a/dali/internal/adaptor/common/adaptor-impl.h +++ b/dali/internal/adaptor/common/adaptor-impl.h @@ -689,26 +689,26 @@ private: // Data TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction - CallbackManager* mCallbackManager; ///< Used to install callbacks - bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event - TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger - FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support - FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls. - Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support - ObserverContainer mObservers; ///< A list of adaptor observer pointers - EnvironmentOptions* mEnvironmentOptions; ///< environment options - PerformanceInterface* mPerformanceInterface; ///< Performance interface - KernelTrace mKernelTracer; ///< Kernel tracer - SystemTrace mSystemTracer; ///< System tracer - ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling - Dali::Timer mMemoryPoolTimer; ///< Logs memory pool capacity - SlotDelegate mMemoryPoolTimerSlotDelegate; - SocketFactory mSocketFactory; ///< Socket factory - Mutex mMutex; ///< Mutex - ThreadMode mThreadMode; ///< The thread mode - const bool mEnvironmentOptionsOwned : 1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it) - bool mUseRemoteSurface : 1; ///< whether the remoteSurface is used or not - Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window + std::unique_ptr mCallbackManager; ///< Used to install callbacks + bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event + TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger + FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support + FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls. + Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support + ObserverContainer mObservers; ///< A list of adaptor observer pointers + EnvironmentOptions* mEnvironmentOptions; ///< environment options + PerformanceInterface* mPerformanceInterface; ///< Performance interface + KernelTrace mKernelTracer; ///< Kernel tracer + SystemTrace mSystemTracer; ///< System tracer + ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling + Dali::Timer mMemoryPoolTimer; ///< Logs memory pool capacity + SlotDelegate mMemoryPoolTimerSlotDelegate; + SocketFactory mSocketFactory; ///< Socket factory + Mutex mMutex; ///< Mutex + ThreadMode mThreadMode; ///< The thread mode + const bool mEnvironmentOptionsOwned : 1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it) + bool mUseRemoteSurface : 1; ///< whether the remoteSurface is used or not + Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window std::unique_ptr mAddOnManager; ///< Pointer to the addon manager diff --git a/dali/internal/adaptor/common/framework.h b/dali/internal/adaptor/common/framework.h index 0a367c0..23244eb 100644 --- a/dali/internal/adaptor/common/framework.h +++ b/dali/internal/adaptor/common/framework.h @@ -332,8 +332,8 @@ private: private: // Undefined - Framework(const Framework&); - Framework& operator=(Framework&); + Framework(const Framework&) = delete; + Framework& operator=(Framework&) = delete; protected: Observer& mObserver; diff --git a/dali/internal/adaptor/glib/framework-glib.h b/dali/internal/adaptor/glib/framework-glib.h index 301d238..da44e6c 100644 --- a/dali/internal/adaptor/glib/framework-glib.h +++ b/dali/internal/adaptor/glib/framework-glib.h @@ -55,8 +55,8 @@ public: private: // Undefined - FrameworkGlib(const FrameworkGlib&); - FrameworkGlib& operator=(FrameworkGlib&); + FrameworkGlib(const FrameworkGlib&) = delete; + FrameworkGlib& operator=(FrameworkGlib&) = delete; private: // impl members struct Impl; diff --git a/dali/internal/adaptor/libuv/framework-libuv.h b/dali/internal/adaptor/libuv/framework-libuv.h index 15ce4ea..837bb10 100644 --- a/dali/internal/adaptor/libuv/framework-libuv.h +++ b/dali/internal/adaptor/libuv/framework-libuv.h @@ -55,8 +55,8 @@ public: private: // Undefined - FrameworkLibuv(const FrameworkLibuv&); - FrameworkLibuv& operator=(FrameworkLibuv&); + FrameworkLibuv(const FrameworkLibuv&) = delete; + FrameworkLibuv& operator=(FrameworkLibuv&) = delete; private: // impl members struct Impl; diff --git a/dali/internal/adaptor/macos/framework-mac.h b/dali/internal/adaptor/macos/framework-mac.h index 38770b9..5cde983 100644 --- a/dali/internal/adaptor/macos/framework-mac.h +++ b/dali/internal/adaptor/macos/framework-mac.h @@ -62,8 +62,8 @@ public: private: // Undefined - FrameworkMac(const FrameworkMac&); - FrameworkMac& operator=(FrameworkMac&); + FrameworkMac(const FrameworkMac&) = delete; + FrameworkMac& operator=(FrameworkMac&) = delete; }; } // namespace Adaptor diff --git a/dali/internal/adaptor/tizen-wayland/framework-tizen.h b/dali/internal/adaptor/tizen-wayland/framework-tizen.h index 724cfbf..c6c182a 100644 --- a/dali/internal/adaptor/tizen-wayland/framework-tizen.h +++ b/dali/internal/adaptor/tizen-wayland/framework-tizen.h @@ -85,8 +85,8 @@ public: private: // Undefined - FrameworkTizen(const FrameworkTizen&); - FrameworkTizen& operator=(FrameworkTizen&); + FrameworkTizen(const FrameworkTizen&) = delete; + FrameworkTizen& operator=(FrameworkTizen&) = delete; private: /** diff --git a/dali/internal/adaptor/ubuntu/framework-ubuntu.h b/dali/internal/adaptor/ubuntu/framework-ubuntu.h index 4da3904..cb34089 100644 --- a/dali/internal/adaptor/ubuntu/framework-ubuntu.h +++ b/dali/internal/adaptor/ubuntu/framework-ubuntu.h @@ -55,8 +55,8 @@ public: private: // Undefined - FrameworkUbuntu(const FrameworkUbuntu&); - FrameworkUbuntu& operator=(FrameworkUbuntu&); + FrameworkUbuntu(const FrameworkUbuntu&) = delete; + FrameworkUbuntu& operator=(FrameworkUbuntu&) = delete; private: /** diff --git a/dali/internal/adaptor/windows/framework-win.h b/dali/internal/adaptor/windows/framework-win.h index d155a09..5ddd6d7 100644 --- a/dali/internal/adaptor/windows/framework-win.h +++ b/dali/internal/adaptor/windows/framework-win.h @@ -55,8 +55,8 @@ public: private: // Undefined - FrameworkWin(const FrameworkWin&); - FrameworkWin& operator=(FrameworkWin&); + FrameworkWin(const FrameworkWin&) = delete; + FrameworkWin& operator=(FrameworkWin&) = delete; private: // impl members struct Impl; diff --git a/dali/internal/system/android/callback-manager-android.cpp b/dali/internal/system/android/callback-manager-android.cpp index 2d45b43..116db5e 100644 --- a/dali/internal/system/android/callback-manager-android.cpp +++ b/dali/internal/system/android/callback-manager-android.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -228,12 +228,6 @@ void AndroidCallbackManager::RemoveAllCallbacks() mCallbackContainer.clear(); } -// Creates a concrete interface for CallbackManager -CallbackManager* CallbackManager::New() -{ - return new AndroidCallbackManager; -} - } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/system/android/callback-manager-android.h b/dali/internal/system/android/callback-manager-android.h index fceaabc..310c3cc 100644 --- a/dali/internal/system/android/callback-manager-android.h +++ b/dali/internal/system/android/callback-manager-android.h @@ -1,8 +1,8 @@ -#ifndef __DALI_ANDROID_CALLBACK_MANAGER_H__ -#define __DALI_ANDROID_CALLBACK_MANAGER_H__ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_CALLBACK_MANAGER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_CALLBACK_MANAGER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -39,77 +39,82 @@ class AndroidCallbackManager : public CallbackManager { public: /** - * @brief constructor - */ + * @brief constructor + */ AndroidCallbackManager(); /** - * @brief destructor - */ + * @brief destructor + */ ~AndroidCallbackManager() = default; /** - * @copydoc CallbackManager::AddIdleCallback() - */ + * @copydoc CallbackManager::AddIdleCallback() + */ bool AddIdleCallback(CallbackBase* callback, bool hasReturnValue) override; /** - * @copydoc CallbackManager::RemoveIdleCallback() - */ + * @copydoc CallbackManager::RemoveIdleCallback() + */ void RemoveIdleCallback(CallbackBase* callback) override; /** - * @copydoc CallbackManager::ProcessIdle() - */ + * @copydoc CallbackManager::ProcessIdle() + */ bool ProcessIdle() override; /** - * @copydoc CallbackManager::ProcessIdle() - */ + * @copydoc CallbackManager::ProcessIdle() + */ void ClearIdleCallbacks() override; /** - * @copydoc CallbackManager::AddIdleEntererCallback() - */ + * @copydoc CallbackManager::AddIdleEntererCallback() + */ bool AddIdleEntererCallback(CallbackBase* callback) override; /** - * @copydoc CallbackManager::RemoveIdleEntererCallback() - */ + * @copydoc CallbackManager::RemoveIdleEntererCallback() + */ void RemoveIdleEntererCallback(CallbackBase* callback) override; /** - * @copydoc CallbackManager::Start() - */ + * @copydoc CallbackManager::Start() + */ void Start() override; /** - * @copydoc CallbackManager::Stop() - */ + * @copydoc CallbackManager::Stop() + */ void Stop() override; private: /** - * @brief Remove all idle call backs that are pending - * Called by Stop() - * Always called from the main thread - */ + * @brief Remove all idle call backs that are pending + * Called by Stop() + * Always called from the main thread + */ void RemoveAllCallbacks(); /** - * @brief Removes a single call back from the container - * Always called from main thread - * @param callbackData callback data - */ + * @brief Removes a single call back from the container + * Always called from main thread + * @param callbackData callback data + */ void RemoveCallbackFromContainer(CallbackData* callbackData); /** - * @brief Remove a standard call back from ecore - * Always called from main thread - * @param callbackData callback data - */ + * @brief Remove a standard call back from ecore + * Always called from main thread + * @param callbackData callback data + */ void RemoveStandardCallback(CallbackData* callbackData); + // Undefined + AndroidCallbackManager(const AndroidCallbackManager&) = delete; + AndroidCallbackManager& operator=(AndroidCallbackManager&) = delete; + +private: typedef std::list CallbackList; bool mRunning; ///< flag is set to true if when running @@ -122,4 +127,4 @@ private: } // namespace Dali -#endif // __DALI_ANDROID_CALLBACK_MANAGER_H__ +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_CALLBACK_MANAGER_H diff --git a/dali/internal/system/android/file-descriptor-monitor-android.cpp b/dali/internal/system/android/file-descriptor-monitor-android.cpp index 6f4c464..f857afc 100644 --- a/dali/internal/system/android/file-descriptor-monitor-android.cpp +++ b/dali/internal/system/android/file-descriptor-monitor-android.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // EXTERNAL INCLUDES #include @@ -33,7 +33,7 @@ namespace Adaptor /** * Using Impl to hide away Android specific members */ -struct FileDescriptorMonitor::Impl +struct FileDescriptorMonitorAndroid::Impl { // Construction Impl(int fileDescriptor, CallbackBase* callback, int eventBitmask) @@ -85,7 +85,8 @@ struct FileDescriptorMonitor::Impl } }; -FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +FileDescriptorMonitorAndroid::FileDescriptorMonitorAndroid(int fileDescriptor, CallbackBase* callback, int eventBitmask) +: FileDescriptorMonitor(fileDescriptor, callback, eventBitmask) { mImpl = new Impl(fileDescriptor, callback, eventBitmask); @@ -111,7 +112,7 @@ FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* c } } -FileDescriptorMonitor::~FileDescriptorMonitor() +FileDescriptorMonitorAndroid::~FileDescriptorMonitorAndroid() { if(mImpl->mFileDescriptor) { diff --git a/dali/internal/system/android/file-descriptor-monitor-android.h b/dali/internal/system/android/file-descriptor-monitor-android.h new file mode 100644 index 0000000..0e13eee --- /dev/null +++ b/dali/internal/system/android/file-descriptor-monitor-android.h @@ -0,0 +1,64 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_FILE_DESCRIPTOR_MONITOR_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_FILE_DESCRIPTOR_MONITOR_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +/** + * @brief FileDescriptorMonitorAndroid class provides an FileDescriptorMonitor Android implementation. + */ +class FileDescriptorMonitorAndroid : public FileDescriptorMonitor +{ +public: + /** + * @copydoc Dali::Internal::Adaptor::FileDescriptorMonitor() + */ + FileDescriptorMonitorAndroid(int fileDescriptor, CallbackBase* callback, int eventBitmask); + + /** + * Destructor + */ + ~FileDescriptorMonitorAndroid(); + +private: + // Undefined + FileDescriptorMonitorAndroid(const FileDescriptorMonitorAndroid& fileDescriptorMonitor) = delete; + + // Undefined + FileDescriptorMonitorAndroid& operator=(const FileDescriptorMonitorAndroid& fileDescriptorMonitor) = delete; + +private: + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_FILE_DESCRIPTOR_MONITOR_H diff --git a/dali/internal/system/android/system-factory-android.cpp b/dali/internal/system/android/system-factory-android.cpp new file mode 100644 index 0000000..a5787a6 --- /dev/null +++ b/dali/internal/system/android/system-factory-android.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +// CLASS HEADER +#include + +// INTERNAL HEADERS +#include +#include +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +std::unique_ptr SystemFactoryAndroid::CreateCallbackManager() +{ + return Utils::MakeUnique(); +} + +std::unique_ptr SystemFactoryAndroid::CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +{ + return Utils::MakeUnique(fileDescriptor, callback, eventBitmask); +} + +TimerPtr SystemFactoryAndroid::CreateTimer(uint32_t milliSec) +{ + return TimerAndroid::New(milliSec); +} + +std::unique_ptr GetSystemFactory() +{ + return Utils::MakeUnique(); +} + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali diff --git a/dali/internal/system/android/system-factory-android.h b/dali/internal/system/android/system-factory-android.h new file mode 100644 index 0000000..255b7f3 --- /dev/null +++ b/dali/internal/system/android/system-factory-android.h @@ -0,0 +1,42 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_SYSTEM_FACTORY_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_SYSTEM_FACTORY_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class SystemFactoryAndroid : public SystemFactory +{ +public: + std::unique_ptr CreateCallbackManager() override; + std::unique_ptr CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) override; + TimerPtr CreateTimer(uint32_t milliSec) override; +}; + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_SYSTEM_FACTORY_H diff --git a/dali/internal/system/android/timer-impl-android.cpp b/dali/internal/system/android/timer-impl-android.cpp index 333228d..6e9aee4 100644 --- a/dali/internal/system/android/timer-impl-android.cpp +++ b/dali/internal/system/android/timer-impl-android.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // EXTERNAL INCLUDES #include @@ -36,7 +36,7 @@ namespace Adaptor namespace { // Copied from x server -static unsigned int GetCurrentMilliSeconds() +static uint32_t GetCurrentMilliSeconds() { struct timeval tv; @@ -73,9 +73,9 @@ static unsigned int GetCurrentMilliSeconds() } // namespace -struct Timer::Impl +struct TimerAndroid::Impl { - Impl(unsigned int milliSec) + Impl(uint32_t milliSec) : mInterval(milliSec), mStartTimestamp(0), mPauseTimestamp(0), @@ -84,25 +84,25 @@ struct Timer::Impl { } - unsigned int mInterval; - unsigned int mStartTimestamp; - unsigned int mPauseTimestamp; - bool mRunning; - unsigned int mId; + uint32_t mInterval; + uint32_t mStartTimestamp; + uint32_t mPauseTimestamp; + bool mRunning; + uint32_t mId; }; -TimerPtr Timer::New(unsigned int milliSec) +TimerAndroidPtr TimerAndroid::New(uint32_t milliSec) { - TimerPtr timer(new Timer(milliSec)); + TimerAndroidPtr timer(new TimerAndroid(milliSec)); return timer; } -Timer::Timer(unsigned int milliSec) +TimerAndroid::TimerAndroid(uint32_t milliSec) : mImpl(new Impl(milliSec)) { } -Timer::~Timer() +TimerAndroid::~TimerAndroid() { Stop(); delete mImpl; @@ -110,7 +110,7 @@ Timer::~Timer() bool TimerCallback(void* data) { - Timer* timer = static_cast(data); + TimerAndroid* timer = static_cast(data); if(timer->IsRunning()) { return timer->Tick(); @@ -119,7 +119,7 @@ bool TimerCallback(void* data) return false; } -void Timer::Start() +void TimerAndroid::Start() { // Timer should be used in the event thread DALI_ASSERT_DEBUG(Adaptor::IsAvailable()); @@ -134,7 +134,7 @@ void Timer::Start() mImpl->mStartTimestamp = GetCurrentMilliSeconds(); } -void Timer::Stop() +void TimerAndroid::Stop() { // Timer should be used in the event thread DALI_ASSERT_DEBUG(Adaptor::IsAvailable()); @@ -149,7 +149,7 @@ void Timer::Stop() ResetTimerData(); } -void Timer::Pause() +void TimerAndroid::Pause() { // Timer should be used in the event thread DALI_ASSERT_DEBUG(Adaptor::IsAvailable()); @@ -162,15 +162,15 @@ void Timer::Pause() } } -void Timer::Resume() +void TimerAndroid::Resume() { // Timer should be used in the event thread DALI_ASSERT_DEBUG(Adaptor::IsAvailable()); if(mImpl->mRunning && mImpl->mId == 0) { - unsigned int newInterval = 0; - unsigned int runningTime = mImpl->mPauseTimestamp - mImpl->mStartTimestamp; + uint32_t newInterval = 0; + uint32_t runningTime = mImpl->mPauseTimestamp - mImpl->mStartTimestamp; if(mImpl->mInterval > runningTime) { newInterval = mImpl->mInterval - runningTime; @@ -182,7 +182,7 @@ void Timer::Resume() } } -void Timer::SetInterval(unsigned int interval, bool restart) +void TimerAndroid::SetInterval(uint32_t interval, bool restart) { // stop existing timer Stop(); @@ -195,12 +195,12 @@ void Timer::SetInterval(unsigned int interval, bool restart) } } -unsigned int Timer::GetInterval() const +uint32_t TimerAndroid::GetInterval() const { return mImpl->mInterval; } -bool Timer::Tick() +bool TimerAndroid::Tick() { // Guard against destruction during signal emission Dali::Timer handle(this); @@ -231,18 +231,13 @@ bool Timer::Tick() return retVal; } -Dali::Timer::TimerSignalType& Timer::TickSignal() -{ - return mTickSignal; -} - -void Timer::ResetTimerData() +void TimerAndroid::ResetTimerData() { mImpl->mRunning = false; mImpl->mId = 0; } -bool Timer::IsRunning() const +bool TimerAndroid::IsRunning() const { return mImpl->mRunning; } diff --git a/dali/internal/system/android/timer-impl-android.h b/dali/internal/system/android/timer-impl-android.h new file mode 100644 index 0000000..e72c8b6 --- /dev/null +++ b/dali/internal/system/android/timer-impl-android.h @@ -0,0 +1,116 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_TIMER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_TIMER_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class TimerAndroid; + +typedef IntrusivePtr TimerAndroidPtr; + +/** + * @brief TimerAndroid class provides an Timer Android implementation. + */ +class TimerAndroid : public Timer +{ +public: + static TimerAndroidPtr New(uint32_t milliSec); + + /** + * Constructor + * @param[in] milliSec Interval in milliseconds. + */ + TimerAndroid(uint32_t milliSec); + + /** + * Destructor. + */ + virtual ~TimerAndroid(); + +public: + /** + * @copydoc Dali::Timer::Start() + */ + void Start() override; + + /** + * @copydoc Dali::Timer::Stop() + */ + void Stop() override; + + /** + * @copydoc Dali::Timer::Pause() + */ + void Pause() override; + + /** + * @copydoc Dali::Timer::Resume() + */ + void Resume() override; + + /** + * @copydoc Dali::Timer::SetInterval() + */ + void SetInterval(uint32_t interval, bool restart) override; + + /** + * @copydoc Dali::Timer::GetInterval() + */ + uint32_t GetInterval() const override; + + /** + * @copydoc Dali::Timer::IsRunning() + */ + bool IsRunning() const override; + + /** + * Tick + */ + bool Tick(); + +private: // Implementation + // not implemented + TimerAndroid(const TimerAndroid&) = delete; + TimerAndroid& operator=(const TimerAndroid&) = delete; + + /** + * Resets any stored timer data. + */ + void ResetTimerData(); + +private: // Data + // To hide away implementation details + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_ANDROID_TIMER_H diff --git a/dali/internal/system/common/callback-manager.h b/dali/internal/system/common/callback-manager.h index 2a26eb4..4749be1 100644 --- a/dali/internal/system/common/callback-manager.h +++ b/dali/internal/system/common/callback-manager.h @@ -1,8 +1,8 @@ -#ifndef DALI_INTERNAL_CALLBACK_MANAGER_H -#define DALI_INTERNAL_CALLBACK_MANAGER_H +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_CALLBACK_MANAGER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_CALLBACK_MANAGER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -37,11 +37,6 @@ class CallbackManager { public: /** - * Create a new call back interface - */ - static CallbackManager* New(); - - /** * Virtual destructor */ virtual ~CallbackManager() @@ -152,4 +147,4 @@ private: } // namespace Dali -#endif // DALI_INTERNAL_CALLBACK_MANAGER_H +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_CALLBACK_MANAGER_H diff --git a/dali/internal/system/common/file-descriptor-monitor.h b/dali/internal/system/common/file-descriptor-monitor.h index a22f07a..6e9df8f 100644 --- a/dali/internal/system/common/file-descriptor-monitor.h +++ b/dali/internal/system/common/file-descriptor-monitor.h @@ -1,8 +1,8 @@ -#ifndef DALI_INTERNAL_FILE_DESCRIPTOR_MONITOR_H -#define DALI_INTERNAL_FILE_DESCRIPTOR_MONITOR_H +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_FILE_DESCRIPTOR_MONITOR_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_FILE_DESCRIPTOR_MONITOR_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -23,11 +23,6 @@ namespace Dali { -namespace Integration -{ -class Core; -} - namespace Internal { namespace Adaptor @@ -83,12 +78,14 @@ public: * readable or writable even when it isn’t. The developer should check for handle EAGAIN or equivalent * when reading from or write to the fd. */ - FileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask); + FileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) + { + } /** * Destructor */ - ~FileDescriptorMonitor(); + virtual ~FileDescriptorMonitor() = default; private: // Undefined @@ -96,10 +93,6 @@ private: // Undefined FileDescriptorMonitor& operator=(const FileDescriptorMonitor& fileDescriptorMonitor); - -private: - struct Impl; - Impl* mImpl; }; } // namespace Adaptor @@ -108,4 +101,4 @@ private: } // namespace Dali -#endif // DALI_INTERNAL_FILE_DESCRIPTOR_MONITOR_H +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_FILE_DESCRIPTOR_MONITOR_H diff --git a/dali/internal/system/common/system-factory.h b/dali/internal/system/common/system-factory.h new file mode 100644 index 0000000..62c4c45 --- /dev/null +++ b/dali/internal/system/common/system-factory.h @@ -0,0 +1,52 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_SYSTEM_FACTORY_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_SYSTEM_FACTORY_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class CallbackManager; +class FileDescriptorMonitor; + +class SystemFactory +{ +public: + SystemFactory() = default; + virtual ~SystemFactory() = default; + + virtual std::unique_ptr CreateCallbackManager() = 0; + virtual std::unique_ptr CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) = 0; + virtual TimerPtr CreateTimer(uint32_t milliSec) = 0; +}; + +extern std::unique_ptr GetSystemFactory(); + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_SYSTEM_FACTORY_H diff --git a/dali/internal/system/common/timer-impl.h b/dali/internal/system/common/timer-impl.h index ab86d83..395d4ff 100644 --- a/dali/internal/system/common/timer-impl.h +++ b/dali/internal/system/common/timer-impl.h @@ -1,8 +1,8 @@ -#ifndef DALI_INTERNAL_TIMER_H -#define DALI_INTERNAL_TIMER_H +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_TIMER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_TIMER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -24,7 +24,6 @@ // INTERNAL INCLUDES #include #include -#include namespace Dali { @@ -42,79 +41,29 @@ typedef IntrusivePtr TimerPtr; class Timer : public BaseObject, public TimerInterface { public: - static TimerPtr New(unsigned int milliSec); - /** * Constructor - * @param[in] milliSec Interval in milliseconds. */ - Timer(unsigned int milliSec); + Timer() = default; /** * Destructor. */ - virtual ~Timer(); - -public: - /** - * @copydoc Dali::Timer::Start() - */ - void Start() override; - - /** - * @copydoc Dali::Timer::Stop() - */ - void Stop() override; - - /** - * @copydoc Dali::Timer::Pause() - */ - void Pause() override; - - /** - * @copydoc Dali::Timer::Resume() - */ - void Resume() override; - - /** - * @copydoc Dali::Timer::SetInterval() - */ - void SetInterval(unsigned int interval, bool restart) override; - - /** - * @copydoc Dali::Timer::GetInterval() - */ - unsigned int GetInterval() const override; - - /** - * @copydoc Dali::Timer::IsRunning() - */ - bool IsRunning() const override; - - /** - * Tick - */ - bool Tick(); + virtual ~Timer() = default; public: // Signals - Dali::Timer::TimerSignalType& TickSignal(); + Dali::Timer::TimerSignalType& TickSignal() + { + return mTickSignal; + } private: // Implementation // not implemented - Timer(const Timer&); - Timer& operator=(const Timer&); + Timer(const Timer&) = delete; + Timer& operator=(const Timer&) = delete; - /** - * Resets any stored timer data. - */ - void ResetTimerData(); - -private: // Data +protected: // Data Dali::Timer::TimerSignalType mTickSignal; - - // To hide away implementation details - struct Impl; - Impl* mImpl; }; inline Timer& GetImplementation(Dali::Timer& timer) @@ -141,4 +90,4 @@ inline const Timer& GetImplementation(const Dali::Timer& timer) } // namespace Dali -#endif // DALI_INTERNAL_TIMER_H +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_TIMER_H diff --git a/dali/internal/system/common/timer-interface.h b/dali/internal/system/common/timer-interface.h index c6106cb..2a87658 100644 --- a/dali/internal/system/common/timer-interface.h +++ b/dali/internal/system/common/timer-interface.h @@ -1,8 +1,8 @@ -#ifndef DALI_INTERNAL_ADAPTOR_BASE_TIMER_INTERFACE_H -#define DALI_INTERNAL_ADAPTOR_BASE_TIMER_INTERFACE_H +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_TIMER_INTERFACE_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_TIMER_INTERFACE_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + namespace Dali { namespace Internal @@ -53,12 +56,12 @@ public: /** * @copydoc Dali::Timer::SetInterval() */ - virtual void SetInterval(unsigned int intervalInMilliseconds, bool restart) = 0; + virtual void SetInterval(uint32_t intervalInMilliseconds, bool restart) = 0; /** * @copydoc Dali::Timer::GetInterval() */ - virtual unsigned int GetInterval() const = 0; + virtual uint32_t GetInterval() const = 0; /** * @copydoc Dali::Timer::IsRunning() @@ -78,4 +81,4 @@ protected: } // namespace Internal } // namespace Dali -#endif // DALI_INTERNAL_ADAPTOR_BASE_TIMER_INTERFACE_H +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_TIMER_INTERFACE_H diff --git a/dali/internal/system/common/trigger-event.cpp b/dali/internal/system/common/trigger-event.cpp index 8f769af..2811689 100644 --- a/dali/internal/system/common/trigger-event.cpp +++ b/dali/internal/system/common/trigger-event.cpp @@ -25,8 +25,8 @@ #include // INTERNAL INCLUDES - #include +#include namespace Dali { @@ -35,7 +35,7 @@ namespace Internal namespace Adaptor { TriggerEvent::TriggerEvent(CallbackBase* callback, TriggerEventInterface::Options options) -: mFileDescriptorMonitor(NULL), +: mFileDescriptorMonitor(), mCallback(callback), mFileDescriptor(-1), mOptions(options) @@ -45,7 +45,7 @@ TriggerEvent::TriggerEvent(CallbackBase* callback, TriggerEventInterface::Option if(mFileDescriptor >= 0) { // Now Monitor the created event file descriptor - mFileDescriptorMonitor = new FileDescriptorMonitor(mFileDescriptor, MakeCallback(this, &TriggerEvent::Triggered), FileDescriptorMonitor::FD_READABLE); + mFileDescriptorMonitor = Dali::Internal::Adaptor::GetSystemFactory()->CreateFileDescriptorMonitor(mFileDescriptor, MakeCallback(this, &TriggerEvent::Triggered), FileDescriptorMonitor::FD_READABLE); } else { @@ -55,7 +55,6 @@ TriggerEvent::TriggerEvent(CallbackBase* callback, TriggerEventInterface::Option TriggerEvent::~TriggerEvent() { - delete mFileDescriptorMonitor; delete mCallback; if(mFileDescriptor >= 0) diff --git a/dali/internal/system/common/trigger-event.h b/dali/internal/system/common/trigger-event.h index 51221a5..8dd3242 100644 --- a/dali/internal/system/common/trigger-event.h +++ b/dali/internal/system/common/trigger-event.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_TRIGGER_EVENT_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -81,10 +82,10 @@ private: struct Source; private: - FileDescriptorMonitor* mFileDescriptorMonitor; - CallbackBase* mCallback; - int mFileDescriptor; - TriggerEventInterface::Options mOptions; + std::unique_ptr mFileDescriptorMonitor; + CallbackBase* mCallback; + int mFileDescriptor; + TriggerEventInterface::Options mOptions; }; } // namespace Adaptor diff --git a/dali/internal/system/file.list b/dali/internal/system/file.list index c22e0b2..a8f439a 100644 --- a/dali/internal/system/file.list +++ b/dali/internal/system/file.list @@ -35,6 +35,7 @@ SET( adaptor_system_linux_src_files ${adaptor_system_dir}/linux/file-descriptor-monitor-ecore.cpp ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp ${adaptor_system_dir}/common/time-service.cpp + ${adaptor_system_dir}/linux/system-factory-ecore.cpp ${adaptor_system_dir}/linux/timer-impl-ecore.cpp ) @@ -77,6 +78,7 @@ SET( adaptor_system_libuv_src_files ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp ${adaptor_system_dir}/libuv/callback-manager-libuv.cpp ${adaptor_system_dir}/libuv/file-descriptor-monitor-libuv.cpp + ${adaptor_system_dir}/linuv/system-factory-libuv.cpp ${adaptor_system_dir}/libuv/timer-impl-libuv.cpp ${adaptor_system_dir}/ubuntu-x11/logging-x.cpp ${adaptor_system_dir}/ubuntu-x11/system-settings-x.cpp @@ -93,6 +95,7 @@ SET( adaptor_system_glib_src_files ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp ${adaptor_system_dir}/glib/callback-manager-glib.cpp ${adaptor_system_dir}/glib/file-descriptor-monitor-glib.cpp + ${adaptor_system_dir}/glib/system-factory-glib.cpp ${adaptor_system_dir}/glib/timer-impl-glib.cpp ${adaptor_system_dir}/ubuntu-x11/logging-x.cpp ${adaptor_system_dir}/ubuntu-x11/system-settings-x.cpp @@ -109,6 +112,7 @@ SET( adaptor_system_android_src_files ${adaptor_system_dir}/android/file-descriptor-monitor-android.cpp ${adaptor_system_dir}/android/logging-android.cpp ${adaptor_system_dir}/android/shared-file-operations-android.cpp + ${adaptor_system_dir}/android/system-factory-android.cpp ${adaptor_system_dir}/android/system-settings-android.cpp ${adaptor_system_dir}/android/timer-impl-android.cpp ${adaptor_system_dir}/common/time-service.cpp @@ -119,6 +123,7 @@ SET( adaptor_system_android_src_files SET( adaptor_system_windows_src_files ${adaptor_system_dir}/windows/callback-manager-win.cpp ${adaptor_system_dir}/windows/file-descriptor-monitor-windows.cpp + ${adaptor_system_dir}/windows/system-factory-win.cpp ${adaptor_system_dir}/windows/system-settings-win.cpp ${adaptor_system_dir}/windows/timer-impl-win.cpp ${adaptor_system_dir}/windows/trigger-event.cpp @@ -133,6 +138,7 @@ SET( adaptor_system_windows_src_files SET( adaptor_system_macos_src_files ${adaptor_system_dir}/ubuntu-x11/logging-x.cpp ${adaptor_system_dir}/macos/file-descriptor-monitor-macos.cpp + ${adaptor_system_dir}/macos/system-factory-mac.cpp ${adaptor_system_dir}/macos/system-settings-mac.cpp ${adaptor_system_dir}/macos/timer-impl-mac.cpp ${adaptor_system_dir}/common/shared-file.cpp diff --git a/dali/internal/system/glib/callback-manager-glib.cpp b/dali/internal/system/glib/callback-manager-glib.cpp index 948a659..4b25bd3 100644 --- a/dali/internal/system/glib/callback-manager-glib.cpp +++ b/dali/internal/system/glib/callback-manager-glib.cpp @@ -228,12 +228,6 @@ void GlibCallbackManager::RemoveCallbackFromContainer(CallbackData* callbackData mCallbackContainer.remove(callbackData); } -// Creates a concrete interface for CallbackManager -CallbackManager* CallbackManager::New() -{ - return new GlibCallbackManager; -} - } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/system/glib/callback-manager-glib.h b/dali/internal/system/glib/callback-manager-glib.h index de2becf..fb3a2c0 100644 --- a/dali/internal/system/glib/callback-manager-glib.h +++ b/dali/internal/system/glib/callback-manager-glib.h @@ -1,8 +1,8 @@ -#ifndef DALI_ADAPTOR_GLIB_CALLBACK_MANAGER_H -#define DALI_ADAPTOR_GLIB_CALLBACK_MANAGER_H +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_CALLBACK_MANAGER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_CALLBACK_MANAGER_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -97,6 +97,11 @@ private: */ void RemoveCallbackFromContainer(CallbackData* callbackData); + // Undefined + GlibCallbackManager(const GlibCallbackManager&) = delete; + GlibCallbackManager& operator=(GlibCallbackManager&) = delete; + +private: typedef std::list CallbackList; ///< list of callbacks installed bool mRunning; ///< flag is set to true if when running @@ -109,4 +114,4 @@ private: } // namespace Dali -#endif // DALI_ADAPTOR_GLIB_CALLBACK_MANAGER_H +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_CALLBACK_MANAGER_H diff --git a/dali/internal/system/glib/file-descriptor-monitor-glib.cpp b/dali/internal/system/glib/file-descriptor-monitor-glib.cpp index c8b7589..572641f 100644 --- a/dali/internal/system/glib/file-descriptor-monitor-glib.cpp +++ b/dali/internal/system/glib/file-descriptor-monitor-glib.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // EXTERNAL INCLUDES #include @@ -34,7 +34,7 @@ extern GMainContext* GetMainLoopContext(); /** * Using Impl to hide away framework specific members */ -struct FileDescriptorMonitor::Impl +struct FileDescriptorMonitorGlib::Impl { public: // Constructor @@ -62,7 +62,7 @@ public: { if(userData) { - FileDescriptorMonitor::Impl* impl = static_cast(userData); + FileDescriptorMonitorGlib::Impl* impl = static_cast(userData); // filter the events that have occured based on what we are monitoring int eventType = FileDescriptorMonitor::FD_NO_EVENT; @@ -91,7 +91,8 @@ public: GSource* mPollSource; }; -FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +FileDescriptorMonitorGlib::FileDescriptorMonitorGlib(int fileDescriptor, CallbackBase* callback, int eventBitmask) +: FileDescriptorMonitor(fileDescriptor, callback, eventBitmask) { if(fileDescriptor < 1) { @@ -114,7 +115,7 @@ FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* c mImpl = new Impl(fileDescriptor, callback, static_cast(events)); } -FileDescriptorMonitor::~FileDescriptorMonitor() +FileDescriptorMonitorGlib::~FileDescriptorMonitorGlib() { delete mImpl; } diff --git a/dali/internal/system/glib/file-descriptor-monitor-glib.h b/dali/internal/system/glib/file-descriptor-monitor-glib.h new file mode 100644 index 0000000..c30ab83 --- /dev/null +++ b/dali/internal/system/glib/file-descriptor-monitor-glib.h @@ -0,0 +1,64 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_FILE_DESCRIPTOR_MONITOR_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_FILE_DESCRIPTOR_MONITOR_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +/** + * @brief FileDescriptorMonitorGlib class provides an FileDescriptorMonitor Glib implementation. + */ +class FileDescriptorMonitorGlib : public FileDescriptorMonitor +{ +public: + /** + * @copydoc Dali::Internal::Adaptor::FileDescriptorMonitor() + */ + FileDescriptorMonitorGlib(int fileDescriptor, CallbackBase* callback, int eventBitmask); + + /** + * Destructor + */ + ~FileDescriptorMonitorGlib(); + +private: + // Undefined + FileDescriptorMonitorGlib(const FileDescriptorMonitorGlib& fileDescriptorMonitor) = delete; + + // Undefined + FileDescriptorMonitorGlib& operator=(const FileDescriptorMonitorGlib& fileDescriptorMonitor) = delete; + +private: + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_FILE_DESCRIPTOR_MONITOR_H diff --git a/dali/internal/system/glib/system-factory-glib.cpp b/dali/internal/system/glib/system-factory-glib.cpp new file mode 100644 index 0000000..540cc6c --- /dev/null +++ b/dali/internal/system/glib/system-factory-glib.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +// CLASS HEADER +#include + +// INTERNAL HEADERS +#include +#include +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +std::unique_ptr SystemFactoryGlib::CreateCallbackManager() +{ + return Utils::MakeUnique(); +} + +std::unique_ptr SystemFactoryGlib::CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +{ + return Utils::MakeUnique(fileDescriptor, callback, eventBitmask); +} + +TimerPtr SystemFactoryGlib::CreateTimer(uint32_t milliSec) +{ + return TimerGlib::New(milliSec); +} + +std::unique_ptr GetSystemFactory() +{ + return Utils::MakeUnique(); +} + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali diff --git a/dali/internal/system/glib/system-factory-glib.h b/dali/internal/system/glib/system-factory-glib.h new file mode 100644 index 0000000..0d163e7 --- /dev/null +++ b/dali/internal/system/glib/system-factory-glib.h @@ -0,0 +1,42 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_SYSTEM_FACTORY_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_SYSTEM_FACTORY_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class SystemFactoryGlib : public SystemFactory +{ +public: + std::unique_ptr CreateCallbackManager() override; + std::unique_ptr CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) override; + TimerPtr CreateTimer(uint32_t milliSec) override; +}; + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_SYSTEM_FACTORY_H diff --git a/dali/internal/system/glib/timer-impl-glib.cpp b/dali/internal/system/glib/timer-impl-glib.cpp index 3277179..2fc64ef 100644 --- a/dali/internal/system/glib/timer-impl-glib.cpp +++ b/dali/internal/system/glib/timer-impl-glib.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // INTERNAL INCLUDES #include @@ -34,7 +34,7 @@ namespace { gboolean TimerSourceFunc(gpointer userData) { - Timer* timer = static_cast(userData); + TimerGlib* timer = static_cast(userData); bool keepRunning = timer->Tick(); return keepRunning ? G_SOURCE_CONTINUE : G_SOURCE_REMOVE; @@ -42,39 +42,39 @@ gboolean TimerSourceFunc(gpointer userData) } // unnamed namespace -struct Timer::Impl +struct TimerGlib::Impl { - Impl(unsigned int milliSec) + Impl(uint32_t milliSec) : mInterval(milliSec) { } - GSource* mTimerHandle{nullptr}; - unsigned int mInterval{0}; - uint32_t mStartTimestamp{0}; - uint32_t mPauseTimestamp{0}; - bool mRunning{false}; - bool mRestartAfterExpiry{false}; // Restart at full interval after pause/resume/expiry + GSource* mTimerHandle{nullptr}; + uint32_t mInterval{0}; + uint32_t mStartTimestamp{0}; + uint32_t mPauseTimestamp{0}; + bool mRunning{false}; + bool mRestartAfterExpiry{false}; // Restart at full interval after pause/resume/expiry }; -TimerPtr Timer::New(unsigned int milliSec) +TimerGlibPtr TimerGlib::New(uint32_t milliSec) { - TimerPtr timer(new Timer(milliSec)); + TimerGlibPtr timer(new TimerGlib(milliSec)); return timer; } -Timer::Timer(unsigned int milliSec) +TimerGlib::TimerGlib(uint32_t milliSec) : mImpl(new Impl(milliSec)) { } -Timer::~Timer() +TimerGlib::~TimerGlib() { Stop(); delete mImpl; } -void Timer::Start() +void TimerGlib::Start() { if(mImpl->mRunning && mImpl->mTimerHandle) { @@ -89,7 +89,7 @@ void Timer::Start() mImpl->mStartTimestamp = TimeService::GetMilliSeconds(); } -void Timer::Stop() +void TimerGlib::Stop() { if(mImpl->mTimerHandle != nullptr) { @@ -104,7 +104,7 @@ void Timer::Stop() ResetTimerData(); } -void Timer::Pause() +void TimerGlib::Pause() { if(mImpl->mRunning) { @@ -115,7 +115,7 @@ void Timer::Pause() } } -void Timer::Resume() +void TimerGlib::Resume() { if(mImpl->mRunning && mImpl->mTimerHandle == nullptr) { @@ -137,7 +137,7 @@ void Timer::Resume() } } -void Timer::SetInterval(unsigned int interval, bool restart) +void TimerGlib::SetInterval(uint32_t interval, bool restart) { // stop existing timer Stop(); @@ -150,12 +150,12 @@ void Timer::SetInterval(unsigned int interval, bool restart) } } -unsigned int Timer::GetInterval() const +uint32_t TimerGlib::GetInterval() const { return mImpl->mInterval; } -bool Timer::Tick() +bool TimerGlib::Tick() { // Guard against destruction during signal emission Dali::Timer handle(this); @@ -195,12 +195,7 @@ bool Timer::Tick() return retVal; } -Dali::Timer::TimerSignalType& Timer::TickSignal() -{ - return mTickSignal; -} - -void Timer::ResetTimerData() +void TimerGlib::ResetTimerData() { mImpl->mRunning = false; if(mImpl->mTimerHandle) @@ -210,7 +205,7 @@ void Timer::ResetTimerData() mImpl->mTimerHandle = nullptr; } -bool Timer::IsRunning() const +bool TimerGlib::IsRunning() const { return mImpl->mRunning; } diff --git a/dali/internal/system/glib/timer-impl-glib.h b/dali/internal/system/glib/timer-impl-glib.h new file mode 100644 index 0000000..1689d15 --- /dev/null +++ b/dali/internal/system/glib/timer-impl-glib.h @@ -0,0 +1,116 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_TIMER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_TIMER_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class TimerGlib; + +typedef IntrusivePtr TimerGlibPtr; + +/** + * @brief TimerGlib class provides an Timer Glib implementation. + */ +class TimerGlib : public Timer +{ +public: + static TimerGlibPtr New(uint32_t milliSec); + + /** + * Constructor + * @param[in] milliSec Interval in milliseconds. + */ + TimerGlib(uint32_t milliSec); + + /** + * Destructor. + */ + virtual ~TimerGlib(); + +public: + /** + * @copydoc Dali::Timer::Start() + */ + void Start() override; + + /** + * @copydoc Dali::Timer::Stop() + */ + void Stop() override; + + /** + * @copydoc Dali::Timer::Pause() + */ + void Pause() override; + + /** + * @copydoc Dali::Timer::Resume() + */ + void Resume() override; + + /** + * @copydoc Dali::Timer::SetInterval() + */ + void SetInterval(uint32_t interval, bool restart) override; + + /** + * @copydoc Dali::Timer::GetInterval() + */ + uint32_t GetInterval() const override; + + /** + * @copydoc Dali::Timer::IsRunning() + */ + bool IsRunning() const override; + + /** + * Tick + */ + bool Tick(); + +private: // Implementation + // not implemented + TimerGlib(const TimerGlib&) = delete; + TimerGlib& operator=(const TimerGlib&) = delete; + + /** + * Resets any stored timer data. + */ + void ResetTimerData(); + +private: // Data + // To hide away implementation details + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_GLIB_TIMER_H diff --git a/dali/internal/system/libuv/callback-manager-libuv.cpp b/dali/internal/system/libuv/callback-manager-libuv.cpp index 072c1aa..72326f9 100644 --- a/dali/internal/system/libuv/callback-manager-libuv.cpp +++ b/dali/internal/system/libuv/callback-manager-libuv.cpp @@ -236,12 +236,6 @@ void UvCallbackManager::RemoveCallbackFromContainer(CallbackData* callbackData) mCallbackContainer.remove(callbackData); } -// Creates a concrete interface for CallbackManager -CallbackManager* CallbackManager::New() -{ - return new UvCallbackManager; -} - } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/system/libuv/callback-manager-libuv.h b/dali/internal/system/libuv/callback-manager-libuv.h index e07c6e2..b7ff410 100644 --- a/dali/internal/system/libuv/callback-manager-libuv.h +++ b/dali/internal/system/libuv/callback-manager-libuv.h @@ -1,5 +1,5 @@ -#ifndef __DALI_UV_CALLBACK_MANAGER_H__ -#define __DALI_UV_CALLBACK_MANAGER_H__ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_CALLBACK_MANAGER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_CALLBACK_MANAGER_H /* * Copyright (c) 2016 Samsung Electronics Co., Ltd. @@ -97,6 +97,11 @@ private: */ void RemoveCallbackFromContainer(CallbackData* callbackData); + // Undefined + UvCallbackManager(const UvCallbackManager&) = delete; + UvCallbackManager& operator=(UvCallbackManager&) = delete; + +private: typedef std::list CallbackList; ///< list of callbacks installed bool mRunning; ///< flag is set to true if when running @@ -109,4 +114,4 @@ private: } // namespace Dali -#endif // __DALI_UV_CALLBACK_MANAGER_H__ +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_CALLBACK_MANAGER_H diff --git a/dali/internal/system/libuv/file-descriptor-monitor-libuv.cpp b/dali/internal/system/libuv/file-descriptor-monitor-libuv.cpp index a946dc4..54da49b 100644 --- a/dali/internal/system/libuv/file-descriptor-monitor-libuv.cpp +++ b/dali/internal/system/libuv/file-descriptor-monitor-libuv.cpp @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // EXTERNAL INCLUDES #include @@ -42,7 +42,7 @@ void FreeHandleCallback(uv_handle_t* handle) /** * Using Impl to hide away UV specific members */ -struct FileDescriptorMonitor::Impl +struct FileDescriptorMonitorLibuv::Impl { public: // Constructor @@ -79,7 +79,7 @@ public: { if(handle->data) { - FileDescriptorMonitor::Impl* impl = static_cast(handle->data); + FileDescriptorMonitorLibuv::Impl* impl = static_cast(handle->data); if(status < 0) { @@ -114,7 +114,8 @@ public: uv_poll_t* pollHandle; }; -FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +FileDescriptorMonitorLibuv::FileDescriptorMonitorLibuv(int fileDescriptor, CallbackBase* callback, int eventBitmask) +: FileDescriptorMonitor(fileDescriptor, callback, eventBitmask) { if(fileDescriptor < 1) { @@ -137,7 +138,7 @@ FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* c mImpl = new Impl(fileDescriptor, callback, static_cast(events)); } -FileDescriptorMonitor::~FileDescriptorMonitor() +FileDescriptorMonitorLibuv::~FileDescriptorMonitorLibuv() { delete mImpl; } diff --git a/dali/internal/system/libuv/file-descriptor-monitor-libuv.h b/dali/internal/system/libuv/file-descriptor-monitor-libuv.h new file mode 100644 index 0000000..1cc6750 --- /dev/null +++ b/dali/internal/system/libuv/file-descriptor-monitor-libuv.h @@ -0,0 +1,64 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_FILE_DESCRIPTOR_MONITOR_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_FILE_DESCRIPTOR_MONITOR_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +/** + * @brief FileDescriptorMonitorLibuv class provides an FileDescriptorMonitor Libuv implementation. + */ +class FileDescriptorMonitorLibuv : public FileDescriptorMonitor +{ +public: + /** + * @copydoc Dali::Internal::Adaptor::FileDescriptorMonitor() + */ + FileDescriptorMonitorLibuv(int fileDescriptor, CallbackBase* callback, int eventBitmask); + + /** + * Destructor + */ + ~FileDescriptorMonitorLibuv(); + +private: + // Undefined + FileDescriptorMonitorLibuv(const FileDescriptorMonitorLibuv& fileDescriptorMonitor) = delete; + + // Undefined + FileDescriptorMonitorLibuv& operator=(const FileDescriptorMonitorLibuv& fileDescriptorMonitor) = delete; + +private: + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_FILE_DESCRIPTOR_MONITOR_H diff --git a/dali/internal/system/libuv/system-factory-libuv.cpp b/dali/internal/system/libuv/system-factory-libuv.cpp new file mode 100644 index 0000000..6aa6d9d --- /dev/null +++ b/dali/internal/system/libuv/system-factory-libuv.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +// CLASS HEADER +#include + +// INTERNAL HEADERS +#include +#include +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +std::unique_ptr SystemFactoryLibuv::CreateCallbackManager() +{ + return Utils::MakeUnique(); +} + +std::unique_ptr SystemFactoryLibuv::CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +{ + return Utils::MakeUnique(fileDescriptor, callback, eventBitmask); +} + +TimerPtr SystemFactoryLibuv::CreateTimer(uint32_t milliSec) +{ + return TimerLibuv::New(milliSec); +} + +std::unique_ptr GetSystemFactory() +{ + return Utils::MakeUnique(); +} + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali diff --git a/dali/internal/system/libuv/system-factory-libuv.h b/dali/internal/system/libuv/system-factory-libuv.h new file mode 100644 index 0000000..e93ce2f --- /dev/null +++ b/dali/internal/system/libuv/system-factory-libuv.h @@ -0,0 +1,42 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_SYSTEM_FACTORY_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_SYSTEM_FACTORY_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class SystemFactoryLibuv : public SystemFactory +{ +public: + std::unique_ptr CreateCallbackManager() override; + std::unique_ptr CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) override; + TimerPtr CreateTimer(uint32_t milliSec) override; +}; + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_SYSTEM_FACTORY_H diff --git a/dali/internal/system/libuv/timer-impl-libuv.cpp b/dali/internal/system/libuv/timer-impl-libuv.cpp index 7a47119..00b3a62 100644 --- a/dali/internal/system/libuv/timer-impl-libuv.cpp +++ b/dali/internal/system/libuv/timer-impl-libuv.cpp @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // INTERNAL INCLUDES #include @@ -36,7 +36,7 @@ namespace { void TimerSourceFunc(uv_timer_t* handle) { - Timer* timer = static_cast(handle->data); + TimerLibuv* timer = static_cast(handle->data); bool keepRunning = timer->Tick(); if(!keepRunning) @@ -54,9 +54,9 @@ void FreeHandleCallback(uv_handle_t* handle) /** * Struct to hide away libuv implementation details */ -struct Timer::Impl +struct TimerLibuv::Impl { - Impl(unsigned int milliSec) + Impl(uint32_t milliSec) : mTimerHandle(NULL), mInterval(milliSec), mRunning(false) @@ -117,24 +117,24 @@ struct Timer::Impl uv_timer_start(mTimerHandle, TimerSourceFunc, mInterval, mInterval); } - uv_timer_t* mTimerHandle; - unsigned int mInterval; - bool mRunning; + uv_timer_t* mTimerHandle; + uint32_t mInterval; + bool mRunning; }; -TimerPtr Timer::New(unsigned int milliSec) +TimerLibuvPtr TimerLibuv::New(uint32_t milliSec) { DALI_LOG_ERROR(" new timer\n"); - TimerPtr timer(new Timer(milliSec)); + TimerLibuvPtr timer(new TimerLibuv(milliSec)); return timer; } -Timer::Timer(unsigned int milliSec) +TimerLibuv::TimerLibuv(uint32_t milliSec) : mImpl(new Impl(milliSec)) { } -Timer::~Timer() +TimerLibuv::~TimerLibuv() { // stop timers Stop(); @@ -142,27 +142,27 @@ Timer::~Timer() delete mImpl; } -void Timer::Start() +void TimerLibuv::Start() { mImpl->Start(this); } -void Timer::Stop() +void TimerLibuv::Stop() { mImpl->Stop(); } -void Timer::Pause() +void TimerLibuv::Pause() { mImpl->Pause(); } -void Timer::Resume() +void TimerLibuv::Resume() { mImpl->Resume(); } -void Timer::SetInterval(unsigned int interval, bool restart) +void TimerLibuv::SetInterval(uint32_t interval, bool restart) { // stop existing timer Stop(); @@ -176,12 +176,12 @@ void Timer::SetInterval(unsigned int interval, bool restart) } } -unsigned int Timer::GetInterval() const +uint32_t TimerLibuv::GetInterval() const { return mImpl->mInterval; } -bool Timer::Tick() +bool TimerLibuv::Tick() { // Guard against destruction during signal emission Dali::Timer handle(this); @@ -212,12 +212,7 @@ bool Timer::Tick() return retVal; } -Dali::Timer::TimerSignalType& Timer::TickSignal() -{ - return mTickSignal; -} - -bool Timer::IsRunning() const +bool TimerLibuv::IsRunning() const { return mImpl->mRunning; } diff --git a/dali/internal/system/libuv/timer-impl-libuv.h b/dali/internal/system/libuv/timer-impl-libuv.h new file mode 100644 index 0000000..8fbb316 --- /dev/null +++ b/dali/internal/system/libuv/timer-impl-libuv.h @@ -0,0 +1,116 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_TIMER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_TIMER_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class TimerLibuv; + +typedef IntrusivePtr TimerLibuvPtr; + +/** + * @brief TimerLibuv class provides an Timer Libuv implementation. + */ +class TimerLibuv : public Timer +{ +public: + static TimerLibuvPtr New(uint32_t milliSec); + + /** + * Constructor + * @param[in] milliSec Interval in milliseconds. + */ + TimerLibuv(uint32_t milliSec); + + /** + * Destructor. + */ + virtual ~TimerLibuv(); + +public: + /** + * @copydoc Dali::Timer::Start() + */ + void Start() override; + + /** + * @copydoc Dali::Timer::Stop() + */ + void Stop() override; + + /** + * @copydoc Dali::Timer::Pause() + */ + void Pause() override; + + /** + * @copydoc Dali::Timer::Resume() + */ + void Resume() override; + + /** + * @copydoc Dali::Timer::SetInterval() + */ + void SetInterval(uint32_t interval, bool restart) override; + + /** + * @copydoc Dali::Timer::GetInterval() + */ + uint32_t GetInterval() const override; + + /** + * @copydoc Dali::Timer::IsRunning() + */ + bool IsRunning() const override; + + /** + * Tick + */ + bool Tick(); + +private: // Implementation + // not implemented + TimerLibuv(const TimerLibuv&) = delete; + TimerLibuv& operator=(const TimerLibuv&) = delete; + + /** + * Resets any stored timer data. + */ + void ResetTimerData(); + +private: // Data + // To hide away implementation details + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_LIBUV_TIMER_H diff --git a/dali/internal/system/linux/callback-manager-ecore.cpp b/dali/internal/system/linux/callback-manager-ecore.cpp index 3c2e478..e7ea2d5 100644 --- a/dali/internal/system/linux/callback-manager-ecore.cpp +++ b/dali/internal/system/linux/callback-manager-ecore.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -259,12 +259,6 @@ void EcoreCallbackManager::RemoveAllCallbacks() mCallbackContainer.clear(); } -// Creates a concrete interface for CallbackManager -CallbackManager* CallbackManager::New() -{ - return new EcoreCallbackManager; -} - } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/system/linux/callback-manager-ecore.h b/dali/internal/system/linux/callback-manager-ecore.h index a76d5ce..214e153 100644 --- a/dali/internal/system/linux/callback-manager-ecore.h +++ b/dali/internal/system/linux/callback-manager-ecore.h @@ -1,8 +1,8 @@ -#ifndef DALI_ECORE_CALLBACK_MANAGER_H -#define DALI_ECORE_CALLBACK_MANAGER_H +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_CALLBACK_MANAGER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_CALLBACK_MANAGER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -39,79 +39,84 @@ class EcoreCallbackManager : public CallbackManager { public: /** - * @brief constructor - */ + * @brief constructor + */ EcoreCallbackManager(); /** - * @brief destructor - */ + * @brief destructor + */ ~EcoreCallbackManager() { } /** - * @copydoc CallbackManager::AddIdleCallback() - */ + * @copydoc CallbackManager::AddIdleCallback() + */ bool AddIdleCallback(CallbackBase* callback, bool hasReturnValue) override; /** - * @copydoc CallbackManager::RemoveIdleCallback() - */ + * @copydoc CallbackManager::RemoveIdleCallback() + */ void RemoveIdleCallback(CallbackBase* callback) override; /** - * @copydoc CallbackManager::ProcessIdle() - */ + * @copydoc CallbackManager::ProcessIdle() + */ bool ProcessIdle() override; /** - * @copydoc CallbackManager::ProcessIdle() - */ + * @copydoc CallbackManager::ProcessIdle() + */ void ClearIdleCallbacks() override; /** - * @copydoc CallbackManager::AddIdleEntererCallback() - */ + * @copydoc CallbackManager::AddIdleEntererCallback() + */ bool AddIdleEntererCallback(CallbackBase* callback) override; /** - * @copydoc CallbackManager::RemoveIdleEntererCallback() - */ + * @copydoc CallbackManager::RemoveIdleEntererCallback() + */ void RemoveIdleEntererCallback(CallbackBase* callback) override; /** - * @copydoc CallbackManager::Start() - */ + * @copydoc CallbackManager::Start() + */ void Start() override; /** - * @copydoc CallbackManager::Stop() - */ + * @copydoc CallbackManager::Stop() + */ void Stop() override; private: /** - * @brief Remove all idle call backs that are pending - * Called by Stop() - * Always called from the main thread - */ + * @brief Remove all idle call backs that are pending + * Called by Stop() + * Always called from the main thread + */ void RemoveAllCallbacks(); /** - * @brief Removes a single call back from the container - * Always called from main thread - * @param callbackData callback data - */ + * @brief Removes a single call back from the container + * Always called from main thread + * @param callbackData callback data + */ void RemoveCallbackFromContainer(CallbackData* callbackData); /** - * @brief Remove a standard call back from ecore - * Always called from main thread - * @param callbackData callback data - */ + * @brief Remove a standard call back from ecore + * Always called from main thread + * @param callbackData callback data + */ void RemoveStandardCallback(CallbackData* callbackData); + // Undefined + EcoreCallbackManager(const EcoreCallbackManager&) = delete; + EcoreCallbackManager& operator=(EcoreCallbackManager&) = delete; + +private: typedef std::list CallbackList; bool mRunning; ///< flag is set to true if when running @@ -124,4 +129,4 @@ private: } // namespace Dali -#endif // DALI_ECORE_CALLBACK_MANAGER_H +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_CALLBACK_MANAGER_H diff --git a/dali/internal/system/linux/file-descriptor-monitor-ecore.cpp b/dali/internal/system/linux/file-descriptor-monitor-ecore.cpp index f121abe..5d47dd8 100644 --- a/dali/internal/system/linux/file-descriptor-monitor-ecore.cpp +++ b/dali/internal/system/linux/file-descriptor-monitor-ecore.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // EXTERNAL INCLUDES #include @@ -33,7 +33,7 @@ namespace Adaptor /** * Using Impl to hide away EFL specific members */ -struct FileDescriptorMonitor::Impl +struct FileDescriptorMonitorEcore::Impl { // Construction Impl(int fileDescriptor, CallbackBase* callback, int eventsToMonitor) @@ -101,7 +101,8 @@ struct FileDescriptorMonitor::Impl } }; -FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +FileDescriptorMonitorEcore::FileDescriptorMonitorEcore(int fileDescriptor, CallbackBase* callback, int eventBitmask) +: FileDescriptorMonitor(fileDescriptor, callback, eventBitmask) { mImpl = new Impl(fileDescriptor, callback, eventBitmask); @@ -124,7 +125,7 @@ FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* c mImpl->mHandler = ecore_main_fd_handler_add(fileDescriptor, static_cast(events), &Impl::EventDispatch, mImpl, NULL, NULL); } -FileDescriptorMonitor::~FileDescriptorMonitor() +FileDescriptorMonitorEcore::~FileDescriptorMonitorEcore() { if(mImpl->mHandler) { diff --git a/dali/internal/system/linux/file-descriptor-monitor-ecore.h b/dali/internal/system/linux/file-descriptor-monitor-ecore.h new file mode 100644 index 0000000..88f6eb1 --- /dev/null +++ b/dali/internal/system/linux/file-descriptor-monitor-ecore.h @@ -0,0 +1,64 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_FILE_DESCRIPTOR_MONITOR_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_FILE_DESCRIPTOR_MONITOR_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +/** + * @brief FileDescriptorMonitorEcore class provides an FileDescriptorMonitor Ecore implementation. + */ +class FileDescriptorMonitorEcore : public FileDescriptorMonitor +{ +public: + /** + * @copydoc Dali::Internal::Adaptor::FileDescriptorMonitor() + */ + FileDescriptorMonitorEcore(int fileDescriptor, CallbackBase* callback, int eventBitmask); + + /** + * Destructor + */ + ~FileDescriptorMonitorEcore(); + +private: + // Undefined + FileDescriptorMonitorEcore(const FileDescriptorMonitorEcore& fileDescriptorMonitor) = delete; + + // Undefined + FileDescriptorMonitorEcore& operator=(const FileDescriptorMonitorEcore& fileDescriptorMonitor) = delete; + +private: + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_FILE_DESCRIPTOR_MONITOR_H diff --git a/dali/internal/system/linux/system-factory-ecore.cpp b/dali/internal/system/linux/system-factory-ecore.cpp new file mode 100644 index 0000000..9308f64 --- /dev/null +++ b/dali/internal/system/linux/system-factory-ecore.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +// CLASS HEADER +#include + +// INTERNAL HEADERS +#include +#include +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +std::unique_ptr SystemFactoryEcore::CreateCallbackManager() +{ + return Utils::MakeUnique(); +} + +std::unique_ptr SystemFactoryEcore::CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +{ + return Utils::MakeUnique(fileDescriptor, callback, eventBitmask); +} + +TimerPtr SystemFactoryEcore::CreateTimer(uint32_t milliSec) +{ + return TimerEcore::New(milliSec); +} + +std::unique_ptr GetSystemFactory() +{ + return Utils::MakeUnique(); +} + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali diff --git a/dali/internal/system/linux/system-factory-ecore.h b/dali/internal/system/linux/system-factory-ecore.h new file mode 100644 index 0000000..e4a108d --- /dev/null +++ b/dali/internal/system/linux/system-factory-ecore.h @@ -0,0 +1,42 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_SYSTEM_FACTORY_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_SYSTEM_FACTORY_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class SystemFactoryEcore : public SystemFactory +{ +public: + std::unique_ptr CreateCallbackManager() override; + std::unique_ptr CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) override; + TimerPtr CreateTimer(uint32_t milliSec) override; +}; + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_SYSTEM_FACTORY_H diff --git a/dali/internal/system/linux/timer-impl-ecore.cpp b/dali/internal/system/linux/timer-impl-ecore.cpp index b06945a..2878778 100644 --- a/dali/internal/system/linux/timer-impl-ecore.cpp +++ b/dali/internal/system/linux/timer-impl-ecore.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // INTERNAL INCLUDES #include @@ -35,7 +35,7 @@ namespace { Eina_Bool TimerSourceFunc(void* data) { - Timer* timer = static_cast(data); + TimerEcore* timer = static_cast(data); bool keepRunning = timer->Tick(); @@ -46,36 +46,36 @@ Eina_Bool TimerSourceFunc(void* data) /** * Struct to hide away Ecore implementation details */ -struct Timer::Impl +struct TimerEcore::Impl { - Impl(unsigned int milliSec) + Impl(uint32_t milliSec) : mId(NULL), mInterval(milliSec) { } Ecore_Timer* mId; - unsigned int mInterval; + uint32_t mInterval; }; -TimerPtr Timer::New(unsigned int milliSec) +TimerEcorePtr TimerEcore::New(uint32_t milliSec) { - TimerPtr timer(new Timer(milliSec)); + TimerEcorePtr timer(new TimerEcore(milliSec)); return timer; } -Timer::Timer(unsigned int milliSec) +TimerEcore::TimerEcore(uint32_t milliSec) : mImpl(new Impl(milliSec)) { } -Timer::~Timer() +TimerEcore::~TimerEcore() { ResetTimerData(); delete mImpl; } -void Timer::Start() +void TimerEcore::Start() { // Timer should be used in the event thread DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); @@ -88,7 +88,7 @@ void Timer::Start() mImpl->mId = ecore_timer_add(interval, reinterpret_cast(TimerSourceFunc), this); } -void Timer::Stop() +void TimerEcore::Stop() { // Timer should be used in the event thread DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); @@ -96,7 +96,7 @@ void Timer::Stop() ResetTimerData(); } -void Timer::Pause() +void TimerEcore::Pause() { // Timer should be used in the event thread DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); @@ -107,7 +107,7 @@ void Timer::Pause() } } -void Timer::Resume() +void TimerEcore::Resume() { // Timer should be used in the event thread DALI_ASSERT_ALWAYS(Adaptor::IsAvailable()); @@ -118,7 +118,7 @@ void Timer::Resume() } } -void Timer::SetInterval(unsigned int interval, bool restart) +void TimerEcore::SetInterval(uint32_t interval, bool restart) { // stop existing timer Stop(); @@ -131,12 +131,12 @@ void Timer::SetInterval(unsigned int interval, bool restart) } } -unsigned int Timer::GetInterval() const +uint32_t TimerEcore::GetInterval() const { return mImpl->mInterval; } -bool Timer::Tick() +bool TimerEcore::Tick() { // Guard against destruction during signal emission Dali::Timer handle(this); @@ -167,12 +167,7 @@ bool Timer::Tick() return retVal; } -Dali::Timer::TimerSignalType& Timer::TickSignal() -{ - return mTickSignal; -} - -void Timer::ResetTimerData() +void TimerEcore::ResetTimerData() { if(mImpl->mId != NULL) { @@ -181,7 +176,7 @@ void Timer::ResetTimerData() } } -bool Timer::IsRunning() const +bool TimerEcore::IsRunning() const { return mImpl->mId != NULL; } diff --git a/dali/internal/system/linux/timer-impl-ecore.h b/dali/internal/system/linux/timer-impl-ecore.h new file mode 100644 index 0000000..1da916c --- /dev/null +++ b/dali/internal/system/linux/timer-impl-ecore.h @@ -0,0 +1,116 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_TIMER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_TIMER_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class TimerEcore; + +typedef IntrusivePtr TimerEcorePtr; + +/** + * @brief TimerEcore class provides an Timer Ecore implementation. + */ +class TimerEcore : public Timer +{ +public: + static TimerEcorePtr New(uint32_t milliSec); + + /** + * Constructor + * @param[in] milliSec Interval in milliseconds. + */ + TimerEcore(uint32_t milliSec); + + /** + * Destructor. + */ + virtual ~TimerEcore(); + +public: + /** + * @copydoc Dali::Timer::Start() + */ + void Start() override; + + /** + * @copydoc Dali::Timer::Stop() + */ + void Stop() override; + + /** + * @copydoc Dali::Timer::Pause() + */ + void Pause() override; + + /** + * @copydoc Dali::Timer::Resume() + */ + void Resume() override; + + /** + * @copydoc Dali::Timer::SetInterval() + */ + void SetInterval(uint32_t interval, bool restart) override; + + /** + * @copydoc Dali::Timer::GetInterval() + */ + uint32_t GetInterval() const override; + + /** + * @copydoc Dali::Timer::IsRunning() + */ + bool IsRunning() const override; + + /** + * Tick + */ + bool Tick(); + +private: // Implementation + // not implemented + TimerEcore(const TimerEcore&) = delete; + TimerEcore& operator=(const TimerEcore&) = delete; + + /** + * Resets any stored timer data. + */ + void ResetTimerData(); + +private: // Data + // To hide away implementation details + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_LINUX_TIMER_H diff --git a/dali/internal/system/macos/callback-manager-mac.h b/dali/internal/system/macos/callback-manager-mac.h index b454af6..4b14b20 100644 --- a/dali/internal/system/macos/callback-manager-mac.h +++ b/dali/internal/system/macos/callback-manager-mac.h @@ -1,7 +1,7 @@ #pragma once /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -17,9 +17,12 @@ * */ -#include +// EXTERNAL INCLUDES #include +// INTERNAL INCLUDES +#include + namespace Dali::Internal::Adaptor { /** @@ -28,10 +31,18 @@ namespace Dali::Internal::Adaptor class CocoaCallbackManager : public CallbackManager { public: + /** + * @brief constructor + */ CocoaCallbackManager(); /** - * @copydoc CallbackManager::AddIdleCallback() + * @brief destructor + */ + ~CocoaCallbackManager(); + + /** + * @copydoc CallbackManager::AddIdleCallback() */ bool AddIdleCallback(CallbackBase* callback, bool hasReturnValue) override; @@ -70,9 +81,15 @@ public: */ void Stop() override; + /// Implementation structure struct Impl; private: + // Undefined + CocoaCallbackManager(const CocoaCallbackManager&) = delete; + CocoaCallbackManager& operator=(CocoaCallbackManager&) = delete; + +private: std::unique_ptr mImpl; bool mRunning; }; diff --git a/dali/internal/system/macos/callback-manager-mac.mm b/dali/internal/system/macos/callback-manager-mac.mm index 7e892c4..99a4c11 100644 --- a/dali/internal/system/macos/callback-manager-mac.mm +++ b/dali/internal/system/macos/callback-manager-mac.mm @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -234,18 +234,14 @@ bool CocoaCallbackManager::Impl::AddIdleCallback( return false; } -// Creates a concrete interface for CallbackManager -CallbackManager* CallbackManager::New() -{ - return new CocoaCallbackManager; -} - CocoaCallbackManager::CocoaCallbackManager() : mImpl(std::make_unique()) , mRunning(false) { } +CocoaCallbackManager::~CocoaCallbackManager() = default; + bool CocoaCallbackManager::AddIdleCallback(CallbackBase *callback, bool hasReturnValue) { return mRunning && mImpl->AddIdleCallback(callback, hasReturnValue); diff --git a/dali/internal/system/macos/file-descriptor-monitor-macos.cpp b/dali/internal/system/macos/file-descriptor-monitor-macos.cpp index 983a39f..acd90da 100644 --- a/dali/internal/system/macos/file-descriptor-monitor-macos.cpp +++ b/dali/internal/system/macos/file-descriptor-monitor-macos.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,19 +16,20 @@ */ // CLASS HEADER -#include +#include // EXTERNAL INCLUDES #include namespace Dali::Internal::Adaptor { -FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +FileDescriptorMonitorMac::FileDescriptorMonitorMac(int fileDescriptor, CallbackBase* callback, int eventBitmask) +: FileDescriptorMonitor(fileDescriptor, callback, eventBitmask) { DALI_LOG_WARNING("Implementation missing for macOS"); } -FileDescriptorMonitor::~FileDescriptorMonitor() +FileDescriptorMonitorMac::~FileDescriptorMonitorMac() { } diff --git a/dali/internal/system/macos/file-descriptor-monitor-macos.h b/dali/internal/system/macos/file-descriptor-monitor-macos.h new file mode 100644 index 0000000..bf98191 --- /dev/null +++ b/dali/internal/system/macos/file-descriptor-monitor-macos.h @@ -0,0 +1,60 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_FILE_DESCRIPTOR_MONITOR_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_FILE_DESCRIPTOR_MONITOR_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +/** + * @brief FileDescriptorMonitorMac class provides an FileDescriptorMonitor Mac implementation. + */ +class FileDescriptorMonitorMac : public FileDescriptorMonitor +{ +public: + /** + * @copydoc Dali::Internal::Adaptor::FileDescriptorMonitor() + */ + FileDescriptorMonitorMac(int fileDescriptor, CallbackBase* callback, int eventBitmask); + + /** + * Destructor + */ + ~FileDescriptorMonitorMac(); + +private: + // Undefined + FileDescriptorMonitorMac(const FileDescriptorMonitorMac& fileDescriptorMonitor) = delete; + + // Undefined + FileDescriptorMonitorMac& operator=(const FileDescriptorMonitorMac& fileDescriptorMonitor) = delete; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_FILE_DESCRIPTOR_MONITOR_H diff --git a/dali/internal/system/macos/system-factory-mac.cpp b/dali/internal/system/macos/system-factory-mac.cpp new file mode 100644 index 0000000..294c29f --- /dev/null +++ b/dali/internal/system/macos/system-factory-mac.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +// CLASS HEADER +#include + +// INTERNAL HEADERS +#include +#include +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +std::unique_ptr SystemFactoryMac::CreateCallbackManager() +{ + return Utils::MakeUnique(); +} + +std::unique_ptr SystemFactoryMac::CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +{ + return Utils::MakeUnique(fileDescriptor, callback, eventBitmask); +} + +TimerPtr SystemFactoryMac::CreateTimer(uint32_t milliSec) +{ + return TimerMac::New(milliSec); +} + +std::unique_ptr GetSystemFactory() +{ + return Utils::MakeUnique(); +} + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali diff --git a/dali/internal/system/macos/system-factory-mac.h b/dali/internal/system/macos/system-factory-mac.h new file mode 100644 index 0000000..665bfc8 --- /dev/null +++ b/dali/internal/system/macos/system-factory-mac.h @@ -0,0 +1,42 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_SYSTEM_FACTORY_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_SYSTEM_FACTORY_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class SystemFactoryMac : public SystemFactory +{ +public: + std::unique_ptr CreateCallbackManager() override; + std::unique_ptr CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) override; + TimerPtr CreateTimer(uint32_t milliSec) override; +}; + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_SYSTEM_FACTORY_H diff --git a/dali/internal/system/macos/timer-impl-mac.cpp b/dali/internal/system/macos/timer-impl-mac.cpp index f6544ee..b93c4ec 100644 --- a/dali/internal/system/macos/timer-impl-mac.cpp +++ b/dali/internal/system/macos/timer-impl-mac.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,9 @@ */ // CLASS HEADER -#include +#include + +// EXTERNAL INCLUDES #include "extern-definitions.h" namespace Dali::Internal::Adaptor @@ -24,9 +26,9 @@ namespace Dali::Internal::Adaptor /** * Struct to hide away macOS implementation details */ -struct Timer::Impl +struct TimerMac::Impl { - Impl(Timer* parent, unsigned int milliSec) + Impl(TimerMac* parent, uint32_t milliSec) : mTimer(CreateTimer(parent, milliSec)) { } @@ -40,9 +42,9 @@ struct Timer::Impl void Start(); void Stop(); - void Reset(Timer* parent, unsigned int milliSec); + void Reset(TimerMac* parent, uint32_t milliSec); - unsigned int GetInterval() const noexcept + uint32_t GetInterval() const noexcept { return CFRunLoopTimerGetInterval(mTimer.get()) * 1000.0; } @@ -53,18 +55,18 @@ struct Timer::Impl } private: - CFRef CreateTimer(Timer* parent, unsigned int milliSec); + CFRef CreateTimer(TimerMac* parent, uint32_t milliSec); CFRef mTimer; }; -void Timer::Impl::TimerProc(CFRunLoopTimerRef timer, void* info) +void TimerMac::Impl::TimerProc(CFRunLoopTimerRef timer, void* info) { - auto* pTimer = static_cast(info); + auto* pTimer = static_cast(info); pTimer->Tick(); } -void Timer::Impl::Start() +void TimerMac::Impl::Start() { if(!IsRunning()) { @@ -73,7 +75,7 @@ void Timer::Impl::Start() } } -void Timer::Impl::Stop() +void TimerMac::Impl::Stop() { if(IsRunning()) { @@ -96,7 +98,7 @@ void Timer::Impl::Stop() } } -void Timer::Impl::Reset(Timer* parent, unsigned int milliSec) +void TimerMac::Impl::Reset(TimerMac* parent, uint32_t milliSec) { Stop(); mTimer = CreateTimer(parent, milliSec); @@ -104,7 +106,7 @@ void Timer::Impl::Reset(Timer* parent, unsigned int milliSec) } CFRef -Timer::Impl::CreateTimer(Timer* parent, unsigned int milliSec) +TimerMac::Impl::CreateTimer(TimerMac* parent, uint32_t milliSec) { const auto interval = static_cast(milliSec) / 1000; const auto fireDate = CFAbsoluteTimeGetCurrent() + interval; @@ -126,17 +128,17 @@ Timer::Impl::CreateTimer(Timer* parent, unsigned int milliSec) &context)); } -TimerPtr Timer::New(unsigned int milliSec) +TimerMacPtr TimerMac::New(uint32_t milliSec) { - return new Timer(milliSec); + return new TimerMac(milliSec); } -Timer::Timer(unsigned int milliSec) +TimerMac::TimerMac(uint32_t milliSec) : mImpl(new Impl(this, milliSec)) { } -Timer::~Timer() +TimerMac::~TimerMac() { // stop timers Stop(); @@ -145,35 +147,35 @@ Timer::~Timer() mImpl = NULL; } -void Timer::Start() +void TimerMac::Start() { mImpl->Start(); } -void Timer::Stop() +void TimerMac::Stop() { mImpl->Stop(); } -void Timer::Pause() +void TimerMac::Pause() { } -void Timer::Resume() +void TimerMac::Resume() { } -void Timer::SetInterval(unsigned int interval, bool restart) +void TimerMac::SetInterval(uint32_t interval, bool restart) { mImpl->Reset(this, interval); } -unsigned int Timer::GetInterval() const +uint32_t TimerMac::GetInterval() const { return mImpl->GetInterval(); } -bool Timer::Tick() +bool TimerMac::Tick() { // Guard against destruction during signal emission Dali::Timer handle(this); @@ -204,12 +206,7 @@ bool Timer::Tick() return retVal; } -Dali::Timer::TimerSignalType& Timer::TickSignal() -{ - return mTickSignal; -} - -bool Timer::IsRunning() const +bool TimerMac::IsRunning() const { return mImpl->IsRunning(); } diff --git a/dali/internal/system/macos/timer-impl-mac.h b/dali/internal/system/macos/timer-impl-mac.h new file mode 100644 index 0000000..534ff26 --- /dev/null +++ b/dali/internal/system/macos/timer-impl-mac.h @@ -0,0 +1,116 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_TIMER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_TIMER_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class TimerMac; + +typedef IntrusivePtr TimerMacPtr; + +/** + * @brief TimerMac class provides an Timer Mac implementation. + */ +class TimerMac : public Timer +{ +public: + static TimerMacPtr New(uint32_t milliSec); + + /** + * Constructor + * @param[in] milliSec Interval in milliseconds. + */ + TimerMac(uint32_t milliSec); + + /** + * Destructor. + */ + virtual ~TimerMac(); + +public: + /** + * @copydoc Dali::Timer::Start() + */ + void Start() override; + + /** + * @copydoc Dali::Timer::Stop() + */ + void Stop() override; + + /** + * @copydoc Dali::Timer::Pause() + */ + void Pause() override; + + /** + * @copydoc Dali::Timer::Resume() + */ + void Resume() override; + + /** + * @copydoc Dali::Timer::SetInterval() + */ + void SetInterval(uint32_t interval, bool restart) override; + + /** + * @copydoc Dali::Timer::GetInterval() + */ + uint32_t GetInterval() const override; + + /** + * @copydoc Dali::Timer::IsRunning() + */ + bool IsRunning() const override; + + /** + * Tick + */ + bool Tick(); + +private: // Implementation + // not implemented + TimerMac(const TimerMac&) = delete; + TimerMac& operator=(const TimerMac&) = delete; + + /** + * Resets any stored timer data. + */ + void ResetTimerData(); + +private: // Data + // To hide away implementation details + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_MACOS_TIMER_H diff --git a/dali/internal/system/windows/callback-manager-win.cpp b/dali/internal/system/windows/callback-manager-win.cpp index b37e1ad..7871819 100644 --- a/dali/internal/system/windows/callback-manager-win.cpp +++ b/dali/internal/system/windows/callback-manager-win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -101,12 +101,6 @@ void WinCallbackManager::RemoveIdleEntererCallback(CallbackBase* callback) { } -// Creates a concrete interface for CallbackManager -CallbackManager* CallbackManager::New() -{ - return new WinCallbackManager; -} - } // namespace Adaptor } // namespace Internal diff --git a/dali/internal/system/windows/callback-manager-win.h b/dali/internal/system/windows/callback-manager-win.h index 3915ec4..b648425 100644 --- a/dali/internal/system/windows/callback-manager-win.h +++ b/dali/internal/system/windows/callback-manager-win.h @@ -1,8 +1,8 @@ -#ifndef DALI_WIN_CALLBACK_MANAGER_H -#define DALI_WIN_CALLBACK_MANAGER_H +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_CALLBACK_MANAGER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_CALLBACK_MANAGER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -38,74 +38,79 @@ class WinCallbackManager : public CallbackManager { public: /** - * @brief constructor - */ + * @brief constructor + */ WinCallbackManager(); /** - * @brief destructor - */ + * @brief destructor + */ ~WinCallbackManager() { } /** - * @copydoc CallbackManager::AddIdleCallback() - */ + * @copydoc CallbackManager::AddIdleCallback() + */ bool AddIdleCallback(CallbackBase* callback, bool hasReturnValue) override; /** - * @copydoc CallbackManager::RemoveIdleCallback() - */ + * @copydoc CallbackManager::RemoveIdleCallback() + */ void RemoveIdleCallback(CallbackBase* callback) override; /** - * @copydoc CallbackManager::ProcessIdle() - */ + * @copydoc CallbackManager::ProcessIdle() + */ bool ProcessIdle() override; /** - * @copydoc CallbackManager::ClearIdleCallbacks() - */ + * @copydoc CallbackManager::ClearIdleCallbacks() + */ void ClearIdleCallbacks() override; /** - * @brief Adds a @p callback to be run when entering an idle state. - * @note Must be called from the main thread only. - * - * A callback of the following type should be used: - * @code - * bool MyFunction(); - * @endcode - * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback. - * - * @param[in] callback custom callback function. - * - * @return true on success - */ + * @brief Adds a @p callback to be run when entering an idle state. + * @note Must be called from the main thread only. + * + * A callback of the following type should be used: + * @code + * bool MyFunction(); + * @endcode + * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback. + * + * @param[in] callback custom callback function. + * + * @return true on success + */ bool AddIdleEntererCallback(CallbackBase* callback) override; /** - * @brief Removes a previously added the idle enterer callback. - * @note Must be called from main thread only. - * - * Does nothing if the @p callback doesn't exist. - * - * @param[in] callback The callback to be removed. - */ + * @brief Removes a previously added the idle enterer callback. + * @note Must be called from main thread only. + * + * Does nothing if the @p callback doesn't exist. + * + * @param[in] callback The callback to be removed. + */ void RemoveIdleEntererCallback(CallbackBase* callback) override; /** - * @copydoc CallbackManager::Start() - */ + * @copydoc CallbackManager::Start() + */ void Start() override; /** - * @copydoc CallbackManager::Stop() - */ + * @copydoc CallbackManager::Stop() + */ void Stop() override; private: + // Undefined + WinCallbackManager(const WinCallbackManager&) = delete; + WinCallbackManager& operator=(WinCallbackManager&) = delete; + +private: std::set mCallbacks; bool mRunning; ///< flag is set to true if when running }; @@ -116,4 +121,4 @@ private: } // namespace Dali -#endif // DALI_WIN_CALLBACK_MANAGER_H +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_CALLBACK_MANAGER_H diff --git a/dali/internal/system/windows/file-descriptor-monitor-windows.cpp b/dali/internal/system/windows/file-descriptor-monitor-windows.cpp index d937daa..eee61f2 100644 --- a/dali/internal/system/windows/file-descriptor-monitor-windows.cpp +++ b/dali/internal/system/windows/file-descriptor-monitor-windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // EXTERNAL INCLUDES #include @@ -27,12 +27,13 @@ namespace Internal { namespace Adaptor { -FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +FileDescriptorMonitorWin::FileDescriptorMonitorWin(int fileDescriptor, CallbackBase* callback, int eventBitmask) +: FileDescriptorMonitor(fileDescriptor, callback, eventBitmask) { DALI_LOG_WARNING("Implementation missing for MS Windows"); } -FileDescriptorMonitor::~FileDescriptorMonitor() +FileDescriptorMonitorWin::~FileDescriptorMonitorWin() { } diff --git a/dali/internal/system/windows/file-descriptor-monitor-windows.h b/dali/internal/system/windows/file-descriptor-monitor-windows.h new file mode 100644 index 0000000..4867262 --- /dev/null +++ b/dali/internal/system/windows/file-descriptor-monitor-windows.h @@ -0,0 +1,67 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_FILE_DESCRIPTOR_MONITOR_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_FILE_DESCRIPTOR_MONITOR_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +/** + * @brief FileDescriptorMonitorWin class provides an FileDescriptorMonitor Windows implementation. + */ +class FileDescriptorMonitorWin : public FileDescriptorMonitor +{ +public: + /** + * @copydoc Dali::Internal::Adaptor::FileDescriptorMonitor() + */ + FileDescriptorMonitorWin(int fileDescriptor, CallbackBase* callback, int eventBitmask); + + /** + * Destructor + */ + ~FileDescriptorMonitorWin(); + +private: + // Undefined + FileDescriptorMonitorWin(const FileDescriptorMonitorWin& fileDescriptorMonitor) = delete; + + // Undefined + FileDescriptorMonitorWin& operator=(const FileDescriptorMonitorWin& fileDescriptorMonitor) = delete; + +private: + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_FILE_DESCRIPTOR_MONITOR_H diff --git a/dali/internal/system/windows/system-factory-win.cpp b/dali/internal/system/windows/system-factory-win.cpp new file mode 100644 index 0000000..244dcc4 --- /dev/null +++ b/dali/internal/system/windows/system-factory-win.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +// CLASS HEADER +#include + +// INTERNAL HEADERS +#include +#include +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +std::unique_ptr SystemFactoryWin::CreateCallbackManager() +{ + return Utils::MakeUnique(); +} + +std::unique_ptr SystemFactoryWin::CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) +{ + return Utils::MakeUnique(fileDescriptor, callback, eventBitmask); +} + +TimerPtr SystemFactoryWin::CreateTimer(uint32_t milliSec) +{ + return TimerWin::New(milliSec); +} + +std::unique_ptr GetSystemFactory() +{ + return Utils::MakeUnique(); +} + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali diff --git a/dali/internal/system/windows/system-factory-win.h b/dali/internal/system/windows/system-factory-win.h new file mode 100644 index 0000000..aa805b5 --- /dev/null +++ b/dali/internal/system/windows/system-factory-win.h @@ -0,0 +1,42 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_SYSTEM_FACTORY_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_SYSTEM_FACTORY_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class SystemFactoryWin : public SystemFactory +{ +public: + std::unique_ptr CreateCallbackManager() override; + std::unique_ptr CreateFileDescriptorMonitor(int fileDescriptor, CallbackBase* callback, int eventBitmask) override; + TimerPtr CreateTimer(uint32_t milliSec) override; +}; + +} // namespace Adaptor +} // namespace Internal +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_SYSTEM_FACTORY_H diff --git a/dali/internal/system/windows/timer-impl-win.cpp b/dali/internal/system/windows/timer-impl-win.cpp index 8462ab2..776efc5 100644 --- a/dali/internal/system/windows/timer-impl-win.cpp +++ b/dali/internal/system/windows/timer-impl-win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include +#include // INTERNAL INCLUDES #include @@ -32,7 +32,7 @@ namespace { bool TimerSourceFunc(void* data) { - Timer* timer = static_cast(data); + TimerWin* timer = static_cast(data); return timer->Tick(); } } // namespace @@ -40,9 +40,9 @@ bool TimerSourceFunc(void* data) /** * Struct to hide away Windows implementation details */ -struct Timer::Impl +struct TimerWin::Impl { - Impl(unsigned int milliSec) + Impl(uint32_t milliSec) : mId(-1), mInterval(milliSec) { @@ -50,21 +50,21 @@ struct Timer::Impl intptr_t mId; - unsigned int mInterval; + uint32_t mInterval; }; -TimerPtr Timer::New(unsigned int milliSec) +TimerWinPtr TimerWin::New(uint32_t milliSec) { - TimerPtr timer(new Timer(milliSec)); + TimerWinPtr timer(new TimerWin(milliSec)); return timer; } -Timer::Timer(unsigned int milliSec) +TimerWin::TimerWin(uint32_t milliSec) : mImpl(new Impl(milliSec)) { } -Timer::~Timer() +TimerWin::~TimerWin() { // stop timers Stop(); @@ -73,7 +73,7 @@ Timer::~Timer() mImpl = NULL; } -void Timer::Start() +void TimerWin::Start() { if(0 > mImpl->mId) { @@ -81,7 +81,7 @@ void Timer::Start() } } -void Timer::Stop() +void TimerWin::Stop() { if(0 <= mImpl->mId) { @@ -90,15 +90,15 @@ void Timer::Stop() } } -void Timer::Pause() +void TimerWin::Pause() { } -void Timer::Resume() +void TimerWin::Resume() { } -void Timer::SetInterval(unsigned int interval, bool restart) +void TimerWin::SetInterval(uint32_t interval, bool restart) { if(true == restart) { @@ -114,12 +114,12 @@ void Timer::SetInterval(unsigned int interval, bool restart) } } -unsigned int Timer::GetInterval() const +uint32_t TimerWin::GetInterval() const { return mImpl->mInterval; } -bool Timer::Tick() +bool TimerWin::Tick() { // Guard against destruction during signal emission Dali::Timer handle(this); @@ -150,12 +150,7 @@ bool Timer::Tick() return retVal; } -Dali::Timer::TimerSignalType& Timer::TickSignal() -{ - return mTickSignal; -} - -bool Timer::IsRunning() const +bool TimerWin::IsRunning() const { return 0 <= mImpl->mId; } diff --git a/dali/internal/system/windows/timer-impl-win.h b/dali/internal/system/windows/timer-impl-win.h new file mode 100644 index 0000000..56b738f --- /dev/null +++ b/dali/internal/system/windows/timer-impl-win.h @@ -0,0 +1,116 @@ +#ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_TIMER_H +#define DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_TIMER_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ +class TimerWin; + +typedef IntrusivePtr TimerWinPtr; + +/** + * @brief TimerWin class provides an Timer Windows implementation. + */ +class TimerWin : public Timer +{ +public: + static TimerWinPtr New(uint32_t milliSec); + + /** + * Constructor + * @param[in] milliSec Interval in milliseconds. + */ + TimerWin(uint32_t milliSec); + + /** + * Destructor. + */ + virtual ~TimerWin(); + +public: + /** + * @copydoc Dali::Timer::Start() + */ + void Start() override; + + /** + * @copydoc Dali::Timer::Stop() + */ + void Stop() override; + + /** + * @copydoc Dali::Timer::Pause() + */ + void Pause() override; + + /** + * @copydoc Dali::Timer::Resume() + */ + void Resume() override; + + /** + * @copydoc Dali::Timer::SetInterval() + */ + void SetInterval(uint32_t interval, bool restart) override; + + /** + * @copydoc Dali::Timer::GetInterval() + */ + uint32_t GetInterval() const override; + + /** + * @copydoc Dali::Timer::IsRunning() + */ + bool IsRunning() const override; + + /** + * Tick + */ + bool Tick(); + +private: // Implementation + // not implemented + TimerWin(const TimerWin&) = delete; + TimerWin& operator=(const TimerWin&) = delete; + + /** + * Resets any stored timer data. + */ + void ResetTimerData(); + +private: // Data + // To hide away implementation details + struct Impl; + Impl* mImpl; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_TIMER_H diff --git a/dali/internal/window-system/common/window-render-surface.cpp b/dali/internal/window-system/common/window-render-surface.cpp index 1f9dcfc..e6e4556 100644 --- a/dali/internal/window-system/common/window-render-surface.cpp +++ b/dali/internal/window-system/common/window-render-surface.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -763,9 +764,7 @@ void WindowRenderSurface::ProcessFrameCallback() { if(!iter->fileDescriptorMonitor) { - iter->fileDescriptorMonitor = std::unique_ptr(new FileDescriptorMonitor(iter->fileDescriptor, - MakeCallback(this, &WindowRenderSurface::OnFileDescriptorEventDispatched), - FileDescriptorMonitor::FD_READABLE)); + iter->fileDescriptorMonitor = Dali::Internal::Adaptor::GetSystemFactory()->CreateFileDescriptorMonitor(iter->fileDescriptor, MakeCallback(this, &WindowRenderSurface::OnFileDescriptorEventDispatched), FileDescriptorMonitor::FD_READABLE); DALI_LOG_RELEASE_INFO("WindowRenderSurface::ProcessFrameCallback: Add handler [%d]\n", iter->fileDescriptor); } diff --git a/dali/internal/window-system/x11/window-system-x.cpp b/dali/internal/window-system/x11/window-system-x.cpp index 616c6f2..406ca2b 100644 --- a/dali/internal/window-system/x11/window-system-x.cpp +++ b/dali/internal/window-system/x11/window-system-x.cpp @@ -21,6 +21,7 @@ // INTERNAL HEADERS #include #include +#include #include // EXTERNAL_HEADERS @@ -455,7 +456,7 @@ struct WindowSystemX::Impl XInitThreads(); mDisplay = XOpenDisplay(nullptr); // Note, DisplayConnection now reads this var. - mXEventMonitor = new FileDescriptorMonitor( + mXEventMonitor = Dali::Internal::Adaptor::GetSystemFactory()->CreateFileDescriptorMonitor( ConnectionNumber(mDisplay), MakeCallback(this, &WindowSystemX::Impl::XPollCallback), FileDescriptorMonitor::FD_READABLE); @@ -470,7 +471,6 @@ struct WindowSystemX::Impl { // @todo Flush events, delete fd handlers, shutdown other X subsystems XCloseDisplay(mDisplay); - delete mXEventMonitor; } ::Display* GetXDisplay() @@ -663,7 +663,7 @@ struct WindowSystemX::Impl using EventHandlerFunctionPointer = void (*)(const XEvent*); std::unordered_map mXEventHandlers; std::vector mHandlers; - FileDescriptorMonitor* mXEventMonitor; + std::unique_ptr mXEventMonitor; XIDeviceInfo* mXi2Devices{nullptr}; int mXi2NumberOfDevices{0}; int mXi2OpCode{-1}; diff --git a/dali/public-api/adaptor-framework/timer.cpp b/dali/public-api/adaptor-framework/timer.cpp index ef779f8..9a7a59c 100644 --- a/dali/public-api/adaptor-framework/timer.cpp +++ b/dali/public-api/adaptor-framework/timer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -19,6 +19,7 @@ #include // INTERNAL INCLUDES +#include #include #include @@ -28,9 +29,9 @@ Timer::Timer() { } -Timer Timer::New(unsigned int milliSec) +Timer Timer::New(uint32_t milliSec) { - Internal::Adaptor::TimerPtr internal = Internal::Adaptor::Timer::New(milliSec); + Internal::Adaptor::TimerPtr internal = Dali::Internal::Adaptor::GetSystemFactory()->CreateTimer(milliSec); return Timer(internal.Get()); } diff --git a/dali/public-api/adaptor-framework/timer.h b/dali/public-api/adaptor-framework/timer.h index 2b1df7f..3569f29 100644 --- a/dali/public-api/adaptor-framework/timer.h +++ b/dali/public-api/adaptor-framework/timer.h @@ -2,7 +2,7 @@ #define DALI_TIMER_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -75,7 +75,7 @@ public: // API * @param[in] milliSec Interval in milliseconds * @return A new timer */ - static Timer New(unsigned int milliSec); + static Timer New(uint32_t milliSec); /** * @brief Copy constructor. @@ -165,7 +165,7 @@ public: // API * @SINCE_1_0.0 * @param[in] milliSec Interval in milliseconds */ - void SetInterval(unsigned int milliSec); + void SetInterval(uint32_t milliSec); /** * @brief Sets a new interval on the timer with option to restart the timer. @@ -175,7 +175,7 @@ public: // API * @param[in] milliSec Interval in milliseconds * @param[in] restart Flag to set enabled to restart or not. */ - void SetInterval(unsigned int milliSec, bool restart); + void SetInterval(uint32_t milliSec, bool restart); /** * @brief Gets the interval of timer. @@ -183,7 +183,7 @@ public: // API * @SINCE_1_0.0 * @return Interval in milliseconds */ - unsigned int GetInterval() const; + uint32_t GetInterval() const; /** * @brief Tells whether timer is running. -- 2.7.4