refactor: conform EiEventQueueBuffer to coding standards

This commit is contained in:
sithlord48 2025-06-19 19:49:20 -04:00 committed by Nick Bolton
parent e8c85611a0
commit 0691d586e7
2 changed files with 27 additions and 27 deletions

View file

@ -26,23 +26,23 @@ class EventQueueTimer
namespace deskflow { namespace deskflow {
EiEventQueueBuffer::EiEventQueueBuffer(const EiScreen *screen, ei *ei, IEventQueue *events) EiEventQueueBuffer::EiEventQueueBuffer(const EiScreen *screen, ei *ei, IEventQueue *events)
: ei_(ei_ref(ei)), : m_ei{ei_ref(ei)},
events_(events) m_events{events}
{ {
// We need a pipe to signal ourselves when addEvent() is called // We need a pipe to signal ourselves when addEvent() is called
int pipefd[2]; int pipefd[2];
int result = pipe2(pipefd, O_NONBLOCK); int result = pipe2(pipefd, O_NONBLOCK);
assert(result == 0); assert(result == 0);
pipe_r_ = pipefd[0]; m_pipeRead = pipefd[0];
pipe_w_ = pipefd[1]; m_pipeWrite = pipefd[1];
} }
EiEventQueueBuffer::~EiEventQueueBuffer() EiEventQueueBuffer::~EiEventQueueBuffer()
{ {
ei_unref(ei_); ei_unref(m_ei);
close(pipe_r_); close(m_pipeRead);
close(pipe_w_); close(m_pipeWrite);
} }
void EiEventQueueBuffer::waitForEvent(double timeout_in_ms) void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
@ -57,16 +57,16 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
}; };
struct pollfd pfds[POLLFD_COUNT]; struct pollfd pfds[POLLFD_COUNT];
pfds[EIFD].fd = ei_get_fd(ei_); pfds[EIFD].fd = ei_get_fd(m_ei);
pfds[EIFD].events = POLLIN; pfds[EIFD].events = POLLIN;
pfds[PIPEFD].fd = pipe_r_; pfds[PIPEFD].fd = m_pipeRead;
pfds[PIPEFD].events = POLLIN; pfds[PIPEFD].events = POLLIN;
int timeout = (timeout_in_ms < 0.0) ? -1 : static_cast<int>(1000.0 * timeout_in_ms); int timeout = (timeout_in_ms < 0.0) ? -1 : static_cast<int>(1000.0 * timeout_in_ms);
if (int retval = poll(pfds, POLLFD_COUNT, timeout); retval > 0) { if (int retval = poll(pfds, POLLFD_COUNT, timeout); retval > 0) {
if (pfds[EIFD].revents & POLLIN) { if (pfds[EIFD].revents & POLLIN) {
std::scoped_lock lock{mutex_}; std::scoped_lock lock{m_mutex};
// libei doesn't allow ei_event_ref() because events are // libei doesn't allow ei_event_ref() because events are
// supposed to be short-lived only. So instead, we create an nullptr-data // supposed to be short-lived only. So instead, we create an nullptr-data
@ -76,7 +76,7 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
// all actual pending ei events. In theory this means that a // all actual pending ei events. In theory this means that a
// flood of ei events could starve the events added with // flood of ei events could starve the events added with
// addEvents() but let's hope it doesn't come to that. // addEvents() but let's hope it doesn't come to that.
queue_.push({true, 0U}); m_queue.push({true, 0U});
} }
// the pipefd data doesn't matter, it only exists to wake up the thread // the pipefd data doesn't matter, it only exists to wake up the thread
// and potentially testCancel // and potentially testCancel
@ -84,7 +84,7 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
char buf[64]; char buf[64];
ssize_t total = 0; ssize_t total = 0;
ssize_t result; ssize_t result;
while ((result = read(pipe_r_, buf, sizeof(buf)) > 0)) { while ((result = read(m_pipeRead, buf, sizeof(buf)) > 0)) {
total += result; total += result;
} }
LOG_DEBUG2("event queue read result: %d (total drained: %zd)", result, total); LOG_DEBUG2("event queue read result: %d (total drained: %zd)", result, total);
@ -108,9 +108,9 @@ IEventQueueBuffer::Type EiEventQueueBuffer::getEvent(Event &event, uint32_t &dat
// we just have a "something happened" event on the ei fd and the rest is // we just have a "something happened" event on the ei fd and the rest is
// handled by the EiScreen. // handled by the EiScreen.
// //
std::scoped_lock lock{mutex_}; std::scoped_lock lock{m_mutex};
auto pair = queue_.front(); auto pair = m_queue.front();
queue_.pop(); m_queue.pop();
// if this an injected special event, just return the data and exit // if this an injected special event, just return the data and exit
if (pair.first == false) { if (pair.first == false) {
@ -118,18 +118,18 @@ IEventQueueBuffer::Type EiEventQueueBuffer::getEvent(Event &event, uint32_t &dat
return kUser; return kUser;
} }
event = Event(EventTypes::System, events_->getSystemTarget()); event = Event(EventTypes::System, m_events->getSystemTarget());
return kSystem; return kSystem;
} }
bool EiEventQueueBuffer::addEvent(uint32_t dataID) bool EiEventQueueBuffer::addEvent(uint32_t dataID)
{ {
std::scoped_lock lock{mutex_}; std::scoped_lock lock{m_mutex};
queue_.push({false, dataID}); m_queue.push({false, dataID});
// tickle the pipe so our read thread wakes up // tickle the pipe so our read thread wakes up
auto result = write(pipe_w_, "!", 1); auto result = write(m_pipeWrite, "!", 1);
LOG_DEBUG2("event queue write result: %d", result); LOG_DEBUG2("event queue write result: %d", result);
return true; return true;
@ -137,9 +137,9 @@ bool EiEventQueueBuffer::addEvent(uint32_t dataID)
bool EiEventQueueBuffer::isEmpty() const bool EiEventQueueBuffer::isEmpty() const
{ {
std::scoped_lock lock{mutex_}; std::scoped_lock lock{m_mutex};
return queue_.empty(); return m_queue.empty();
} }
EventQueueTimer *EiEventQueueBuffer::newTimer(double duration, bool oneShot) const EventQueueTimer *EiEventQueueBuffer::newTimer(double duration, bool oneShot) const

View file

@ -39,13 +39,13 @@ public:
void deleteTimer(EventQueueTimer *) const override; void deleteTimer(EventQueueTimer *) const override;
private: private:
ei *ei_; ei *m_ei;
IEventQueue *events_; IEventQueue *m_events;
std::queue<std::pair<bool, uint32_t>> queue_; std::queue<std::pair<bool, uint32_t>> m_queue;
int pipe_w_; int m_pipeWrite;
int pipe_r_; int m_pipeRead;
mutable std::mutex mutex_; mutable std::mutex m_mutex;
}; };
} // namespace deskflow } // namespace deskflow