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 83139bdc6277a4153a068696ddcba0d504cc7d26..3b4cf57f5964cae6e8382bf93e5306ff97270fb6 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 acc760b4bbbbce46b1b95d5546c75d28c9df0853..12a6f5c95dae79b3ede06697e7155ac26d98bef9 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 4366b17f3a2b7b01632d8a22924cd58e4428e730..4bdf345ed986162a4ee1c6b52e36ba3d9a05a1da 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" }