MCPcopy Create free account
hub / github.com/Kistler-Group/sdbus-cpp / callMethodAsync

Method callMethodAsync

src/Connection.cpp:690–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

688}
689
690Slot Connection::callMethodAsync(sd_bus_message* sdbusMsg, sd_bus_message_handler_t callback, void* userData, uint64_t timeout, return_slot_t)
691{
692 sd_bus_slot *slot{};
693
694 // TODO: Think of ways of optimizing these three locking/unlocking of sdbus mutex (merge into one call?)
695 auto timeoutBefore = getEventLoopPollData().timeout;
696 auto r = sdbus_->sd_bus_call_async(nullptr, &slot, sdbusMsg, callback, userData, timeout);
697 SDBUS_THROW_ERROR_IF(r < 0, "Failed to call method asynchronously", -r);
698 auto timeoutAfter = getEventLoopPollData().timeout;
699
700 // An event loop may wait in poll with timeout `t1', while in another thread an async call is made with
701 // timeout `t2'. If `t2' < `t1', then we have to wake up the event loop thread to update its poll timeout.
702 // We also have to wake up the event loop to process the messages that may be in the read/write queues.
703 if (timeoutAfter < timeoutBefore || arePendingMessagesInQueues())
704 notifyEventLoopToWakeUpFromPoll();
705
706 return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref(static_cast<sd_bus_slot*>(slot)); }};
707}
708
709void Connection::sendMessage(sd_bus_message* sdbusMsg)
710{

Callers

nothing calls this directly

Calls 2

sd_bus_call_asyncMethod · 0.80
sd_bus_slot_unrefMethod · 0.80

Tested by

no test coverage detected