From 316b499b5014d4061a85f099e232c17f6fe2eec5 Mon Sep 17 00:00:00 2001 From: lijincheng Date: Sun, 12 Nov 2023 11:44:32 +0800 Subject: [PATCH] Sasdk rectification 1. Move the event_reactor.h from base/src to base/include 2. Change all methods to private and add friend class Issue:https://gitee.com/openharmony/commonlibrary_c_utils/issues/I8FRNJ Signed-off-by: lijincheng --- base/{src => include}/event_reactor.h | 9 +++++++-- base/include/timer.h | 4 ++-- bundle.json | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-) rename base/{src => include}/event_reactor.h (94%) diff --git a/base/src/event_reactor.h b/base/include/event_reactor.h similarity index 94% rename from base/src/event_reactor.h rename to base/include/event_reactor.h index 83139bd..3b4cf57 100644 --- a/base/src/event_reactor.h +++ b/base/include/event_reactor.h @@ -31,6 +31,9 @@ class TimerEventHandler; class EventReactor { public: + virtual ~EventReactor(); + +private: using TimerCallback = std::function; static const uint32_t NONE_EVENT = 0x0000; static const uint32_t READ_EVENT = 0x0001; @@ -43,7 +46,6 @@ public: EventReactor& operator=(const EventReactor&) = delete; EventReactor(const EventReactor&&) = delete; EventReactor& operator=(const EventReactor&&) = delete; - virtual ~EventReactor(); uint32_t SetUp(); void CleanUp(); @@ -67,12 +69,15 @@ public: uint32_t ScheduleTimer(const TimerCallback& cb, uint32_t interval /* ms */, int& timerFd, bool once); void CancelTimer(int timerFd); -private: mutable volatile bool loopReady_; // refers to whether reactor is ready to call RunLoop(). volatile bool switch_; // a switch to enable while-loop in RunLoop(). true: start, false: stop. std::unique_ptr demultiplexer_; std::recursive_mutex mutex_; std::list> timerEventHandlers_; + friend class Timer; + friend class EventDemultiplexer; + friend class EventHandler; + friend class TimerEventHandler; }; } // namespace Utils diff --git a/base/include/timer.h b/base/include/timer.h index acc760b..12a6f5c 100644 --- a/base/include/timer.h +++ b/base/include/timer.h @@ -16,6 +16,8 @@ #ifndef UTILS_TIMER_H #define UTILS_TIMER_H +#include "event_reactor.h" + #include #include #include @@ -25,8 +27,6 @@ #include #include -#include "../src/event_reactor.h" - namespace OHOS { namespace Utils { /** diff --git a/bundle.json b/bundle.json index 4366b17..4bdf345 100644 --- a/bundle.json +++ b/bundle.json @@ -63,7 +63,8 @@ "thread_ex.h", "thread_pool.h", "timer.h", - "unique_fd.h" + "unique_fd.h", + "event_reactor.h" ], "header_base": "//commonlibrary/c_utils/base/include" } @@ -96,7 +97,8 @@ "thread_ex.h", "thread_pool.h", "timer.h", - "unique_fd.h" + "unique_fd.h", + "event_reactor.h" ], "header_base": "//commonlibrary/c_utils/base/include" } -- Gitee