Provide better names to event loop-related IConnection methods

This commit is contained in:
sangelovic
2020-02-02 22:22:26 +01:00
parent dee6adce02
commit 3a4f343fb9
13 changed files with 128 additions and 66 deletions
+13 -13
View File
@@ -61,7 +61,7 @@ Connection::Connection(std::unique_ptr<ISdBus>&& interface, remote_system_bus_t,
Connection::~Connection()
{
leaveProcessingLoop();
Connection::leaveEventLoop();
}
void Connection::requestName(const std::string& name)
@@ -84,7 +84,7 @@ std::string Connection::getUniqueName() const
return unique;
}
void Connection::enterProcessingLoop()
void Connection::enterEventLoop()
{
loopThreadId_ = std::this_thread::get_id();
@@ -98,25 +98,25 @@ void Connection::enterProcessingLoop()
auto success = waitForNextRequest();
if (!success)
break; // Exit processing loop
break; // Exit I/O event loop
}
loopThreadId_ = std::thread::id{};
}
void Connection::enterProcessingLoopAsync()
void Connection::enterEventLoopAsync()
{
if (!asyncLoopThread_.joinable())
asyncLoopThread_ = std::thread([this](){ enterProcessingLoop(); });
asyncLoopThread_ = std::thread([this](){ enterEventLoop(); });
}
void Connection::leaveProcessingLoop()
void Connection::leaveEventLoop()
{
notifyProcessingLoopToExit();
joinWithProcessingLoop();
notifyEventLoopToExit();
joinWithEventLoop();
}
sdbus::IConnection::PollData Connection::getProcessLoopPollData() const
Connection::PollData Connection::getEventLoopPollData() const
{
ISdBus::PollData pollData;
auto r = iface_->sd_bus_get_poll_data(bus_.get(), &pollData);
@@ -358,13 +358,13 @@ void Connection::finishHandshake(sd_bus* bus)
SDBUS_THROW_ERROR_IF(r < 0, "Failed to flush bus on opening", -r);
}
void Connection::notifyProcessingLoopToExit()
void Connection::notifyEventLoopToExit()
{
assert(loopExitFd_.fd >= 0);
uint64_t value = 1;
auto r = write(loopExitFd_.fd, &value, sizeof(value));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to notify processing loop", -errno);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to notify event loop", -errno);
}
void Connection::clearExitNotification()
@@ -374,7 +374,7 @@ void Connection::clearExitNotification()
SDBUS_THROW_ERROR_IF(r < 0, "Failed to read from the event descriptor", -errno);
}
void Connection::joinWithProcessingLoop()
void Connection::joinWithEventLoop()
{
if (asyncLoopThread_.joinable())
asyncLoopThread_.join();
@@ -398,7 +398,7 @@ bool Connection::waitForNextRequest()
assert(bus != nullptr);
assert(loopExitFd_.fd != 0);
auto sdbusPollData = getProcessLoopPollData();
auto sdbusPollData = getEventLoopPollData();
struct pollfd fds[] = {{sdbusPollData.fd, sdbusPollData.events, 0}, {loopExitFd_.fd, POLLIN, 0}};
auto fdsCount = sizeof(fds)/sizeof(fds[0]);
+7 -7
View File
@@ -42,7 +42,7 @@
namespace sdbus::internal {
class Connection
class Connection final
: public sdbus::IConnection // External, public interface
, public sdbus::internal::IConnection // Internal, private interface
{
@@ -60,10 +60,10 @@ namespace sdbus::internal {
void requestName(const std::string& name) override;
void releaseName(const std::string& name) override;
std::string getUniqueName() const override;
void enterProcessingLoop() override;
void enterProcessingLoopAsync() override;
void leaveProcessingLoop() override;
sdbus::IConnection::PollData getProcessLoopPollData() const override;
void enterEventLoop() override;
void enterEventLoopAsync() override;
void leaveEventLoop() override;
PollData getEventLoopPollData() const override;
bool processPendingRequest() override;
void addObjectManager(const std::string& objectPath) override;
@@ -118,9 +118,9 @@ namespace sdbus::internal {
static std::string composeSignalMatchFilter( const std::string& objectPath
, const std::string& interfaceName
, const std::string& signalName );
void notifyProcessingLoopToExit();
void notifyEventLoopToExit();
void clearExitNotification();
void joinWithProcessingLoop();
void joinWithEventLoop();
static std::vector</*const */char*> to_strv(const std::vector<std::string>& strings);
struct LoopExitEventFd
+2 -2
View File
@@ -88,8 +88,8 @@ namespace sdbus::internal {
, sd_bus_message_handler_t callback
, void* userData ) = 0;
virtual void enterProcessingLoopAsync() = 0;
virtual void leaveProcessingLoop() = 0;
virtual void enterEventLoopAsync() = 0;
virtual void leaveEventLoop() = 0;
virtual MethodReply tryCallMethodSynchronously(const MethodCall& message, uint64_t timeout) = 0;
};
+1 -1
View File
@@ -56,7 +56,7 @@ Proxy::Proxy( std::unique_ptr<sdbus::internal::IConnection>&& connection
{
// The connection is ours only, i.e. it's us who has to manage the event loop upon this connection,
// in order that we get and process signals, async call replies, and other messages from D-Bus.
connection_->enterProcessingLoopAsync();
connection_->enterEventLoopAsync();
}
MethodCall Proxy::createMethodCall(const std::string& interfaceName, const std::string& methodName)