7 #ifndef ZPP_INCLUDE_ZPP_POLL_EVENT_SET_HPP
8 #define ZPP_INCLUDE_ZPP_POLL_EVENT_SET_HPP
12 #include <zephyr/kernel.h>
13 #include <zephyr/sys/__assert.h>
40 auto begin() noexcept {
return m_events.begin(); }
41 auto end() noexcept {
return m_events.end(); }
55 template <
class... T_Args>
58 assign(0, std::forward<T_Args>(t)...);
70 __ASSERT_NO_MSG(idx < T_Size);
81 return poll(K_FOREVER);
91 return poll(K_NO_WAIT);
101 template<
class T_Rep,
class T_Period>
105 using namespace std::chrono;
117 void assign(
int index) noexcept
119 __ASSERT_NO_MSG(index == T_Size);
129 template<
class T_FirstArg,
class... T_Args>
130 void assign(
int index, T_FirstArg&& f, T_Args&&... t) noexcept
132 poll_event(&m_events[index]).assign(std::forward<T_FirstArg>(f));
133 assign(index+1, std::forward<T_Args>(t)...);
143 auto poll(k_timeout_t timeout) noexcept
145 for (
auto& e: m_events) {
146 e.state = K_POLL_STATE_NOT_READY;
148 __ASSERT_NO_MSG(e.signal !=
nullptr);
149 e.signal->signaled = 0;
153 auto rc = k_poll(m_events.data(), m_events.size(), timeout);
162 std::array<struct k_poll_event, T_Size> m_events;
172 template <
class... T_Args>
poll_event_set() noexcept
default constructor
poll_event_set(T_Args &&... t) noexcept
constructor that takes arguments for initialization
auto poll() noexcept
poll events waiting for ever
auto try_poll() noexcept
try poll events without waiting
auto try_poll_for(const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
try poll events waiting for e certain time
auto operator[](size_t idx) noexcept
access an element of the set
wrapper class around a k_poll_event
constexpr k_timeout_t to_timeout(const std::chrono::duration< T_Rep, T_Period > &d) noexcept
convert a duration to tick