aboutsummaryrefslogtreecommitdiff
path: root/include/Hotplug.hpp
blob: 38fe25d4f8e2ba5ad9bffd32cdb2e4b21f1ea0d4 (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
#pragma once

#include <functional>

namespace gsr {
    enum class HotplugAction {
        ADD,
        REMOVE
    };

    using HotplugEventCallback = std::function<void(HotplugAction hotplug_action, const char *devname)>;

    class Hotplug {
    public:
        Hotplug() = default;
        Hotplug(const Hotplug&) = delete;
        Hotplug& operator=(const Hotplug&) = delete;
        ~Hotplug();

        bool start();
        int steal_fd();
        void process_event_data(int fd, const HotplugEventCallback &callback);
    private:
        void parse_netlink_data(const char *line, const HotplugEventCallback &callback);
    private:
        int fd = -1;
        bool started = false;
        bool event_is_add = false;
        bool event_is_remove = false;
        bool subsystem_is_input = false;
        char event_data[1024];
    };
}