Debian Codegraph @

src/Network/Swift/dbusserver.h

raw symbols SCIP
1 /*
2 * SPDX-FileCopyrightText: (C) 2019-2022 swift Project Community / Contributors (https://swift-project.org/)
3 * SPDX-FileCopyrightText: (C) 2019-2022 Lars Toenning <[email protected]>
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #pragma once
8
9 #include "dbuscallbacks.h"
10 #include "dbusdispatcher.h"
11 #include "dbuserror.h"
12 #include "dbusmessage.h"
13
14 #include <dbus/dbus.h>
15 #include <event2/event.h>
16 #include <functional>
17 #include <memory>
18 #include <string>
19 #include <unordered_map>
20 #include <vector>
21
22 namespace flightgear::swift {
23
24 class CDBusObject;
25
26 //! DBus connection
27 class CDBusServer : public IDispatchable
28 {
29 public:
30 //! New connection handler function
31 using NewConnectionFunc = std::function<void(std::shared_ptr<CDBusConnection>)>;
32
33 //! Constructor
34 CDBusServer();
35
36 //! Destructor
37 ~CDBusServer() override;
38
39 //! Set the dispatcher
40 void setDispatcher(CDBusDispatcher* dispatcher);
41
42 //! Connect to bus
43 bool listen(const std::string& address);
44
45 //! Is connected?
46 bool isConnected() const;
47
48 void dispatch() override {}
49
50 //! Close connection
51 void close();
52
53 //! Get the last error
54 CDBusError lastError() const { return m_lastError; }
55
56 //! Set the function to be used for handling new connections.
57 void setNewConnectionFunc(const NewConnectionFunc& func)
58 {
59 m_newConnectionFunc = func;
60 }
61
62 private:
63 void onNewConnection(DBusServer* server, DBusConnection* conn);
64 static void onNewConnection(DBusServer* server, DBusConnection* conn, void* data);
65
66 struct DBusServerDeleter {
67 void operator()(DBusServer* obj) const { dbus_server_unref(obj); }
68 };
69
70 CDBusDispatcher* m_dispatcher = nullptr;
71 std::unique_ptr<DBusServer, DBusServerDeleter> m_server;
72 CDBusError m_lastError;
73 NewConnectionFunc m_newConnectionFunc;
74 };
75
76 } // namespace flightgear::swift