swift
Loading...
Searching...
No Matches
hubimpl.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2020 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
7
8#include "misc/dbusserver.h"
10#include "misc/variantlist.h"
11
12namespace swift::misc::shared_state::dbus
13{
14 CHub::CHub(CDBusServer *server, QObject *parent) : IHub(parent), m_server(server)
15 {
16 if (server)
17 {
18 server->addObject(SWIFT_MISC_HUB_PATH, this);
19 }
20 }
21
22 std::pair<QSharedPointer<IDuplex>, QFuture<bool>> CHub::getDuplex(const CIdentifier &identifier)
23 {
24 auto future = openDuplexAsync(identifier);
25 return std::make_pair(m_clients.value(identifier), future);
26 }
27
29 {
30 if (!m_clients.contains(client))
31 {
32 m_clients.insert(client, QSharedPointer<CDuplex>::create(this, client, m_server, this));
33 }
34 return true;
35 }
36
38 {
39 // Using take() instead of remove() because we need the
40 // destruction to happen after the removal, not before.
41 m_clients.take(client);
42 }
43
45 {
46 openDuplex(client);
47
48 CPromise<bool> promise;
49 promise.setResult(true);
50 return promise.future();
51 }
52
54 {
55 // Disconnect clients from the hub before destroying them,
56 // to avoid thrashing peer event subscription updates.
57 const auto clients = std::move(m_clients);
58 Q_UNUSED(clients)
59 }
60} // namespace swift::misc::shared_state::dbus
Custom DBusServer.
Definition dbusserver.h:34
void addObject(const QString &name, QObject *object)
Add a QObject to be exposed via DBus.
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition identifier.h:29
A promise-based interface to QFuture, similar to std::promise for std::future.
Definition promise.h:87
QFuture< T > future()
Return a future that can be used to access the result.
Definition promise.h:90
void setResult(const T &value)
Set the result value that will be made available through the future.
Definition promise.h:100
bool openDuplex(const swift::misc::CIdentifier &client)
Create a duplex object for the identified process.
Definition hubimpl.cpp:28
CHub(CDBusServer *server, QObject *parent=nullptr)
Constructor.
Definition hubimpl.cpp:14
QFuture< bool > openDuplexAsync(const CIdentifier &client)
Create a duplex object for the identified process.
Definition hubimpl.cpp:44
std::pair< QSharedPointer< IDuplex >, QFuture< bool > > getDuplex(const CIdentifier &)
Create a duplex object for the identified process.
Definition hubimpl.cpp:22
const auto & clients() const
Returns a range containing all duplex objects.
Definition hubimpl.h:39
void closeDuplex(const swift::misc::CIdentifier &client)
Destroy the duplex object for the identified process.
Definition hubimpl.cpp:37
IHub(QObject *parent=nullptr)
Constructor.
Definition hub.cpp:15
#define SWIFT_MISC_HUB_PATH
DBus object path root for sharedstate hub.
Definition hub.h:20
QObject(QObject *parent)
QObject * parent() const const
QSharedPointer< T > create(Args &&... args)