swift
Loading...
Searching...
No Matches
dbusdispatcher.h
1// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#ifndef SWIFT_SIM_XSWIFTBUS_DBUSDISPATCHER_H
5#define SWIFT_SIM_XSWIFTBUS_DBUSDISPATCHER_H
6
7#include <dbus/dbus.h>
8#include <event2/event.h>
9
10#include <memory>
11#include <unordered_map>
12#include <vector>
13
14#include "dbuscallbacks.h"
15
16namespace XSwiftBus
17{
18
19 class WatchHandler;
20 class TimeoutHandler;
21 class CDBusConnection;
22 class CDBusDispatcher;
23
26 {
27 public:
29 IDispatchable() = default;
30
32 virtual ~IDispatchable() = default;
33
35 virtual void dispatch() = 0;
36
37 private:
38 friend CDBusDispatcher;
39 };
40
43 {
44 public:
47
49 virtual ~CDBusDispatcher();
50
52 void add(IDispatchable *dispatchable);
53
55 void remove(IDispatchable *dispatchable);
56
58 void waitAndRun();
59
61 void runOnce();
62
63 private:
64 friend class WatchHandler;
65 friend class TimeoutHandler;
66 friend class Timer;
67 friend class CDBusConnection;
68 friend class CDBusServer;
69
70 struct EventBaseDeleter
71 {
72 void operator()(event_base *obj) const { event_base_free(obj); }
73 };
74
75 using WatchCallbacks = DBusAsyncCallbacks<DBusWatch>;
76 using TimeoutCallbacks = DBusAsyncCallbacks<DBusTimeout>;
77
78 void dispatch();
79
80 dbus_bool_t dbusAddWatch(DBusWatch *watch);
81 void dbusRemoveWatch(const DBusWatch *watch);
82 void dbusWatchToggled(DBusWatch *watch);
83
84 dbus_bool_t dbusAddTimeout(DBusTimeout *timeout);
85 void dbusRemoveTimeout(DBusTimeout *timeout);
86 void dbusTimeoutToggled(DBusTimeout *timeout);
87
88 WatchCallbacks m_watchCallbacks;
89 TimeoutCallbacks m_timeoutCallbacks;
90 std::unordered_multimap<evutil_socket_t, std::unique_ptr<WatchHandler>> m_watchers;
91 std::vector<std::unique_ptr<TimeoutHandler>> m_timeouts;
92 std::unique_ptr<event_base, EventBaseDeleter> m_eventBase;
93
94 std::vector<IDispatchable *> m_dispatchList;
95 };
96} // namespace XSwiftBus
97
98#endif // SWIFT_SIM_XSWIFTBUS_DBUSDISPATCHER_H
void add(IDispatchable *dispatchable)
Add dispatchable object.
virtual ~CDBusDispatcher()
Destructor.
void remove(IDispatchable *dispatchable)
Remove dispatchable object.
void runOnce()
Dispatches ready handlers and returns without waiting.
void waitAndRun()
Waits for events to be dispatched and handles them.
Dispatchable Interface.
virtual ~IDispatchable()=default
Default destructor.
virtual void dispatch()=0
Dispatch execution method.
IDispatchable()=default
Default constructor.
DBus timeout handler.
DBus watch handler.
Plugin loaded by X-Plane which publishes a DBus service.
Definition command.h:14