summaryrefslogtreecommitdiff
path: root/src/state_machine.hpp
diff options
context:
space:
mode:
authorPrzemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>2022-03-15 00:20:54 +0300
committerGitHub <noreply@github.com>2022-03-15 00:20:54 +0300
commited2aceab6ee059a40d939ea21364bc18ec80d94b (patch)
tree654bbae1b29b9dcdc6e4ed0036dc5d70ad0544a5 /src/state_machine.hpp
parent1fb7beae5e97aadf8471ae7b6e07f5c2e5f33c78 (diff)
downloadvirtual-media-ed2aceab6ee059a40d939ea21364bc18ec80d94b.tar.xz
Make mount/unmount dbus calls asynchronous
Change the default behavior of mount/umount dbus calls from blocking to unblocking ones. Once mount/unmount is triggered, appropriate action is running in the background moving handling of operation result to async event. At the end of processing dbus completion signal is sent to client with uint value of operation status (identical with errno code). Tested: Manual scheduling of mount and unmount operations with monitoring dbus communication of virtual-media service - matching api calls with completion signal. Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
Diffstat (limited to 'src/state_machine.hpp')
-rw-r--r--src/state_machine.hpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/state_machine.hpp b/src/state_machine.hpp
index 259802c..d5f3265 100644
--- a/src/state_machine.hpp
+++ b/src/state_machine.hpp
@@ -1,10 +1,13 @@
#pragma once
-
#include "interfaces/mount_point_state_machine.hpp"
#include "state/initial_state.hpp"
+#include "utils.hpp"
+#include <boost/asio/steady_timer.hpp>
+#include <functional>
#include <memory>
#include <sdbusplus/asio/object_server.hpp>
+#include <system_error>
struct MountPointStateMachine : public interfaces::MountPointStateMachine
{
@@ -106,9 +109,52 @@ struct MountPointStateMachine : public interfaces::MountPointStateMachine
}
}
+ virtual void
+ notificationInitialize(std::shared_ptr<sdbusplus::asio::connection> con,
+ const std::string& svc, const std::string& iface,
+ const std::string& name) override
+ {
+ auto signal = std::make_unique<utils::SignalSender>(std::move(con), svc,
+ iface, name);
+
+ auto timer = std::make_unique<boost::asio::steady_timer>(ioc);
+
+ completionNotification = std::make_unique<utils::NotificationWrapper>(
+ std::move(signal), std::move(timer));
+ }
+ void notificationStart()
+ {
+ auto notificationHandler = [this](const boost::system::error_code& ec) {
+ if (ec == boost::system::errc::operation_canceled)
+ {
+ return;
+ }
+
+ LogMsg(Logger::Error,
+ "[App] timedout when waiting for target state");
+
+ completionNotification->notify(
+ std::make_error_code(std::errc::device_or_resource_busy));
+ };
+
+ LogMsg(Logger::Debug, "Started notification");
+ completionNotification->start(
+ std::move(notificationHandler),
+ std::chrono::seconds(
+ config.timeout.value_or(
+ Configuration::MountPoint::defaultTimeout) +
+ 5));
+ }
+
+ virtual void notify(const std::error_code& ec = {}) override
+ {
+ completionNotification->notify(ec);
+ }
+
boost::asio::io_context& ioc;
std::string name;
Configuration::MountPoint config;
+ std::unique_ptr<utils::NotificationWrapper> completionNotification;
std::optional<Target> target;
std::unique_ptr<BasicState> state = std::make_unique<InitialState>(*this);