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 {
EiEventQueueBuffer::EiEventQueueBuffer(const EiScreen *screen, ei *ei, IEventQueue *events)
: ei_(ei_ref(ei)),
events_(events)
: m_ei{ei_ref(ei)},
m_events{events}
{
// We need a pipe to signal ourselves when addEvent() is called
int pipefd[2];
int result = pipe2(pipefd, O_NONBLOCK);
assert(result == 0);
pipe_r_ = pipefd[0];
pipe_w_ = pipefd[1];
m_pipeRead = pipefd[0];
m_pipeWrite = pipefd[1];
}
EiEventQueueBuffer::~EiEventQueueBuffer()
{
ei_unref(ei_);
close(pipe_r_);
close(pipe_w_);
ei_unref(m_ei);
close(m_pipeRead);
close(m_pipeWrite);
}
void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
@ -57,16 +57,16 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
};
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[PIPEFD].fd = pipe_r_;
pfds[PIPEFD].fd = m_pipeRead;
pfds[PIPEFD].events = POLLIN;
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 (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
// 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
// flood of ei events could starve the events added with
// 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
// and potentially testCancel
@ -84,7 +84,7 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
char buf[64];
ssize_t total = 0;
ssize_t result;
while ((result = read(pipe_r_, buf, sizeof(buf)) > 0)) {
while ((result = read(m_pipeRead, buf, sizeof(buf)) > 0)) {
total += result;
}
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
// handled by the EiScreen.
//
std::scoped_lock lock{mutex_};
auto pair = queue_.front();
queue_.pop();
std::scoped_lock lock{m_mutex};
auto pair = m_queue.front();
m_queue.pop();
// if this an injected special event, just return the data and exit
if (pair.first == false) {
@ -118,18 +118,18 @@ IEventQueueBuffer::Type EiEventQueueBuffer::getEvent(Event &event, uint32_t &dat
return kUser;
}
event = Event(EventTypes::System, events_->getSystemTarget());
event = Event(EventTypes::System, m_events->getSystemTarget());
return kSystem;
}
bool EiEventQueueBuffer::addEvent(uint32_t dataID)
{
std::scoped_lock lock{mutex_};
queue_.push({false, dataID});
std::scoped_lock lock{m_mutex};
m_queue.push({false, dataID});
// 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);
return true;
@ -137,9 +137,9 @@ bool EiEventQueueBuffer::addEvent(uint32_t dataID)
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

View File

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