summaryrefslogtreecommitdiff
path: root/src/events.hpp
blob: 03d0c5068d17756b1be1021f68368943915051be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once

#include "interfaces/mount_point_state_machine.hpp"

#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>

struct BasicEvent
{
    BasicEvent(const char* eventName) : eventName(eventName)
    {
    }

    const char* eventName;
};

struct RegisterDbusEvent : public BasicEvent
{
    RegisterDbusEvent(
        std::shared_ptr<sdbusplus::asio::connection> bus,
        std::shared_ptr<sdbusplus::asio::object_server> objServer) :
        BasicEvent(__FUNCTION__),
        bus(std::move(bus)), objServer(std::move(objServer))
    {
    }

    std::shared_ptr<sdbusplus::asio::connection> bus;
    std::shared_ptr<sdbusplus::asio::object_server> objServer;
};

struct MountEvent : public BasicEvent
{
    explicit MountEvent(
        std::optional<interfaces::MountPointStateMachine::Target> target) :
        BasicEvent(__FUNCTION__),
        target(std::move(target))
    {
    }

    MountEvent(const MountEvent&) = delete;

    MountEvent(MountEvent&& other) noexcept :
        BasicEvent(__FUNCTION__), target(std::move(other.target))
    {
        other.target = std::nullopt;
    }

    MountEvent& operator=(const MountEvent&) = delete;

    MountEvent& operator=(MountEvent&& other) noexcept
    {
        target = std::nullopt;
        std::swap(target, other.target);
        return *this;
    }

    std::optional<interfaces::MountPointStateMachine::Target> target;
};

struct UnmountEvent : public BasicEvent
{
    UnmountEvent() : BasicEvent(__FUNCTION__)
    {
    }
};

struct SubprocessStoppedEvent : public BasicEvent
{
    SubprocessStoppedEvent() : BasicEvent(__FUNCTION__)
    {
    }
};

struct UdevStateChangeEvent : public BasicEvent
{
    explicit UdevStateChangeEvent(const StateChange& devState) :
        BasicEvent(__FUNCTION__), devState{devState}
    {
    }

    StateChange devState;
};

using Event = std::variant<RegisterDbusEvent, MountEvent, UnmountEvent,
                           SubprocessStoppedEvent, UdevStateChangeEvent>;