Added ability to integrate with foreign event loops

This commit is contained in:
hogliux
2019-10-08 22:09:05 +02:00
committed by Stanislav Angelovič
parent e30ce194ab
commit 0440dcb15b
3 changed files with 60 additions and 6 deletions
+16 -5
View File
@@ -108,6 +108,20 @@ void Connection::leaveProcessingLoop()
joinWithProcessingLoop();
}
sdbus::IConnection::PollData Connection::getProcessLoopPollData()
{
sdbus::IConnection::PollData pollData;
ISdBus::PollData sdbusPollData;
auto r = iface_->sd_bus_get_poll_data(bus_.get(), &sdbusPollData);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus poll data", -r);
pollData.fd = sdbusPollData.fd;
pollData.events = sdbusPollData.events;
pollData.timeout_usec = sdbusPollData.timeout_usec;
return pollData;
}
const ISdBus& Connection::getSdBusInterface() const
{
return *iface_.get();
@@ -345,15 +359,12 @@ bool Connection::waitForNextRequest()
assert(bus != nullptr);
assert(loopExitFd_ != 0);
ISdBus::PollData sdbusPollData;
auto r = iface_->sd_bus_get_poll_data(bus, &sdbusPollData);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus poll data", -r);
auto sdbusPollData = getProcessLoopPollData();
struct pollfd fds[] = {{sdbusPollData.fd, sdbusPollData.events, 0}, {loopExitFd_, POLLIN, 0}};
auto fdsCount = sizeof(fds)/sizeof(fds[0]);
auto timeout = sdbusPollData.timeout_usec == (uint64_t) -1 ? (uint64_t)-1 : (sdbusPollData.timeout_usec+999)/1000;
r = poll(fds, fdsCount, timeout);
auto r = poll(fds, fdsCount, timeout);
if (r < 0 && errno == EINTR)
return true; // Try again
+2 -1
View File
@@ -57,6 +57,8 @@ namespace sdbus { namespace internal {
void enterProcessingLoop() override;
void enterProcessingLoopAsync() override;
void leaveProcessingLoop() override;
bool processPendingRequest() override;
sdbus::IConnection::PollData getProcessLoopPollData() override;
void addObjectManager(const std::string& objectPath) override;
SlotPtr addObjectManager(const std::string& objectPath, void* /*dummy*/) override;
@@ -99,7 +101,6 @@ namespace sdbus { namespace internal {
void finishHandshake(sd_bus* bus);
static int createProcessingLoopExitDescriptor();
static void closeProcessingLoopExitDescriptor(int fd);
bool processPendingRequest();
bool waitForNextRequest();
static std::string composeSignalMatchFilter( const std::string& objectPath
, const std::string& interfaceName