From 2746a19c1d68447d4328349587c0b5f16b750afe Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Fri, 14 Jan 2022 10:55:03 +0800 Subject: [PATCH] modify single instance template Signed-off-by: chenqinxin Change-Id: I1c66e5b878854e7a872af4b5ecebac08d91f086b --- dm/src/display_manager.cpp | 1 + dm/src/display_manager_adapter.cpp | 1 + dm/src/screen_manager.cpp | 1 + dmserver/src/abstract_display_controller.cpp | 1 + dmserver/src/display_manager_service.cpp | 2 +- .../src/display_manager_service_inner.cpp | 1 + dmserver/src/rs_adapter.cpp | 2 +- utils/include/wm_single_instance.h | 21 +++++++++++-------- utils/src/singleton_container.cpp | 1 + wm/src/input_transfer_station.cpp | 2 ++ wm/src/static_call.cpp | 2 ++ wm/src/vsync_station.cpp | 1 + wm/src/window_adapter.cpp | 1 + wm/src/window_manager.cpp | 1 + wmserver/src/window_manager_service.cpp | 1 + wmserver/src/window_manager_service_inner.cpp | 1 + 16 files changed, 29 insertions(+), 11 deletions(-) diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index c4137ff161..de010b2816 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -27,6 +27,7 @@ namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManager"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManager) DisplayManager::DisplayManager() { diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 1bac96aa7d..d5f8919284 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -25,6 +25,7 @@ namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerAdapter"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter) DisplayId DisplayManagerAdapter::GetDefaultDisplayId() { diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index 9278df3f0b..746646b904 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -27,6 +27,7 @@ private: std::map> monitorMap_; }; +WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManager) ScreenManager::ScreenManager() { diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index 40f24ba2a1..0faac6890d 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -24,6 +24,7 @@ namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractDisplayController"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(AbstractDisplayController) AbstractDisplayController::AbstractDisplayController() : rsInterface_(&(RSInterfaces::GetInstance())) { diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 74d85f85a4..3def77c0bb 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -28,7 +28,7 @@ namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; } - +WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService) const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true) diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp index b1ad4d34bf..c43552543e 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -30,6 +30,7 @@ namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerServiceInner"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner) DisplayId DisplayManagerServiceInner::GetDefaultDisplayId() { diff --git a/dmserver/src/rs_adapter.cpp b/dmserver/src/rs_adapter.cpp index 3b5e59a25e..cf56bcb414 100644 --- a/dmserver/src/rs_adapter.cpp +++ b/dmserver/src/rs_adapter.cpp @@ -25,7 +25,7 @@ namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"}; } - +WM_IMPLEMENT_SINGLE_INSTANCE(RsAdapter) bool RsAdapter::InitRSProxyLocked() { WLOGFI("InitRProxy"); diff --git a/utils/include/wm_single_instance.h b/utils/include/wm_single_instance.h index d5f0e3abdc..07433080be 100644 --- a/utils/include/wm_single_instance.h +++ b/utils/include/wm_single_instance.h @@ -19,11 +19,7 @@ namespace OHOS { namespace Rosen { #define WM_DECLARE_SINGLE_INSTANCE_BASE(className) \ public: \ - static className& GetInstance() \ - { \ - static className instance; \ - return instance; \ - } \ + static className& GetInstance(); \ className(const className&) = delete; \ className& operator= (const className&) = delete; \ className(className&&) = delete; \ @@ -31,10 +27,17 @@ public: \ #define WM_DECLARE_SINGLE_INSTANCE(className) \ WM_DECLARE_SINGLE_INSTANCE_BASE(className) \ -protected: \ - className() = default; \ - virtual ~className() = default; \ - +protected: \ + className() = default; \ + virtual ~className() = default; \ + +#define WM_IMPLEMENT_SINGLE_INSTANCE(className) \ +className& className::GetInstance() \ +{ \ + static className instance; \ + return instance; \ +} \ + } // namespace OHOS } #endif // OHOS_SINGLE_INSTANCE_H diff --git a/utils/src/singleton_container.cpp b/utils/src/singleton_container.cpp index 09eeb22a2e..c0194be5a8 100644 --- a/utils/src/singleton_container.cpp +++ b/utils/src/singleton_container.cpp @@ -22,6 +22,7 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager_SingletonContainer"}; } // namespace +WM_IMPLEMENT_SINGLE_INSTANCE(SingletonContainer) SingletonContainer::~SingletonContainer() { diff --git a/wm/src/input_transfer_station.cpp b/wm/src/input_transfer_station.cpp index 8c5e4521a8..44465b20a5 100644 --- a/wm/src/input_transfer_station.cpp +++ b/wm/src/input_transfer_station.cpp @@ -21,6 +21,8 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputTransferStation"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(InputTransferStation) + void InputEventListener::OnInputEvent(std::shared_ptr keyEvent) const { WLOGFI("OnInputEvent: receive keyEvent"); diff --git a/wm/src/static_call.cpp b/wm/src/static_call.cpp index 1e8153217c..102612b895 100644 --- a/wm/src/static_call.cpp +++ b/wm/src/static_call.cpp @@ -17,6 +17,8 @@ namespace OHOS { namespace Rosen { +WM_IMPLEMENT_SINGLE_INSTANCE(StaticCall) + sptr StaticCall::CreateWindow(const std::string& windowName, sptr& option, std::shared_ptr abilityContext) { diff --git a/wm/src/vsync_station.cpp b/wm/src/vsync_station.cpp index 39a5117f7f..20b2bfb56f 100644 --- a/wm/src/vsync_station.cpp +++ b/wm/src/vsync_station.cpp @@ -22,6 +22,7 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "VsyncStation"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(VsyncStation) void VsyncStation::RequestVsync(CallbackType type, std::shared_ptr vsyncCallback) { diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 7e68e1ced2..cd7a826840 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -24,6 +24,7 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAdapter"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(WindowAdapter) WMError WindowAdapter::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) { diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index 6753df7a1d..9221ce70b3 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -25,6 +25,7 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(WindowManager) class WindowManager::Impl { public: diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 7b8478581a..d95239f8aa 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -30,6 +30,7 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerService"}; } +WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerService) const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); diff --git a/wmserver/src/window_manager_service_inner.cpp b/wmserver/src/window_manager_service_inner.cpp index 3a933d9946..01701d4742 100644 --- a/wmserver/src/window_manager_service_inner.cpp +++ b/wmserver/src/window_manager_service_inner.cpp @@ -18,6 +18,7 @@ namespace OHOS { namespace Rosen { +WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerServiceInner) bool WindowManagerServiceInner::NotifyDisplaySuspend() { -- Gitee