попытки сделать crsf, не взлетела часть с пультом
This commit is contained in:
51
lib/port/unix/poller.cpp
Normal file
51
lib/port/unix/poller.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "port/poller.h"
|
||||
|
||||
#include <sys/poll.h>
|
||||
#include <algorithm>
|
||||
|
||||
bool poller::PollObject::isPollIn() const { return revents & POLLIN; }
|
||||
bool poller::PollObject::isPollOut() const { return revents & POLLOUT; }
|
||||
bool poller::PollObject::isPollHup() const { return revents & POLLHUP; }
|
||||
poller::PollObject::~PollObject() = default;
|
||||
|
||||
poller::PollWrapper::PollWrapper() = default;
|
||||
|
||||
void poller::PollWrapper::loop(int timeoutMs) {
|
||||
if (this->objects.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// проверяем, что нет объектов с fd < 0, удаляем такие объекты если они есть
|
||||
for (size_t index = 0; index < this->objects.size();) {
|
||||
if (this->objects[index]->fd < 0) {
|
||||
this->objects.erase(this->objects.begin() + static_cast<ssize_t>(index));
|
||||
} else {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
const auto qsize = this->objects.size();
|
||||
|
||||
// массив для вызова poll
|
||||
pollfd pollFds[qsize];
|
||||
|
||||
// заполняем данные для poll
|
||||
for (size_t i = 0; i < qsize; i++) {
|
||||
pollFds[i].revents = 0;
|
||||
pollFds[i].fd = this->objects[i]->fd;
|
||||
pollFds[i].events = this->objects[i]->events;
|
||||
}
|
||||
|
||||
// выполняем poll
|
||||
poll(pollFds, qsize, timeoutMs);
|
||||
|
||||
// проверяем события
|
||||
for (size_t i = 0; i < qsize; i++) {
|
||||
objects[i]->revents = pollFds[i].revents;
|
||||
// if (pollFds[i].revents != 0) {
|
||||
// objects[i]->callback();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
poller::PollWrapper::~PollWrapper() = default;
|
||||
Reference in New Issue
Block a user