| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 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 |
|
| 27 |
class CDBusServer : public IDispatchable |
| 28 |
{ |
| 29 |
public: |
| 30 |
|
| 31 |
using NewConnectionFunc = std::function<void(std::shared_ptr<CDBusConnection>)>; |
| 32 |
|
| 33 |
|
| 34 |
CDBusServer(); |
| 35 |
|
| 36 |
|
| 37 |
~CDBusServer() override; |
| 38 |
|
| 39 |
|
| 40 |
void setDispatcher(CDBusDispatcher* dispatcher); |
| 41 |
|
| 42 |
|
| 43 |
bool listen(const std::string& address); |
| 44 |
|
| 45 |
|
| 46 |
bool isConnected() const; |
| 47 |
|
| 48 |
void dispatch() override {} |
| 49 |
|
| 50 |
|
| 51 |
void close(); |
| 52 |
|
| 53 |
|
| 54 |
CDBusError lastError() const { return m_lastError; } |
| 55 |
|
| 56 |
|
| 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 |
} |