swift
Loading...
Searching...
No Matches
duplex.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
8namespace swift::misc::shared_state::dbus
9{
11 {
12 connect(this, &IDuplex::replyReceived, this, [this](const QString &, const CVariant &param, quint32 token) {
13 const auto it = m_submittedRequests.find(token);
14 if (it == m_submittedRequests.end())
15 {
16 return;
17 }
18 it->setResult(param);
19 m_submittedRequests.erase(it);
20 });
21 }
22
24 {
25 const auto token = getToken();
26 auto future = m_submittedRequests.insert(token, {})->future();
27 submitRequest(channel, param, token);
28 return future;
29 }
30
32 {
33 const auto token = getToken();
34 auto future = m_receivedRequests.insert(token, {})->future();
35 emit requestReceived(channel, param, token, QPrivateSignal {});
36 return future;
37 }
38
39 void IDuplex::reply(const swift::misc::CVariant &param, quint32 token)
40 {
41 const auto it = m_receivedRequests.find(token);
42 if (it == m_receivedRequests.end())
43 {
44 return;
45 }
46 it->setResult(param);
47 m_receivedRequests.erase(it);
48 }
49
50 quint32 IDuplex::getToken() { return m_token++; }
51} // namespace swift::misc::shared_state::dbus
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition variant.h:69
IDuplex(QObject *parent=nullptr)
Constructor.
Definition duplex.cpp:10
void requestReceived(const QString &channel, const swift::misc::CVariant &param, quint32 token, QPrivateSignal)
Server has submitted a request to be handled by the client.
QFuture< CVariant > receiveRequest(const QString &channel, const swift::misc::CVariant &param)
Server submits a request to the client. Reply is returned via a future.
Definition duplex.cpp:31
virtual void reply(const swift::misc::CVariant &param, quint32 token)
Client replies to a submitted request.
Definition duplex.cpp:39
QFuture< CVariant > submitRequest(const QString &channel, const swift::misc::CVariant &param)
Client submits a request to the server. Reply is returned via a future.
Definition duplex.cpp:23
QObject(QObject *parent)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const