swift
duplex.h
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 
6 #ifndef SWIFT_MISC_SHAREDSTATE_DBUS_DUPLEX_H
7 #define SWIFT_MISC_SHAREDSTATE_DBUS_DUPLEX_H
8 
9 #include <QFuture>
10 #include <QMap>
11 #include <QObject>
12 
14 #include "misc/promise.h"
15 #include "misc/swiftmiscexport.h"
16 #include "misc/variant.h"
17 
19 #define SWIFT_MISC_DUPLEX_INTERFACE "org.swift_project.misc.sharedstate.duplex"
20 
22 #define SWIFT_MISC_DUPLEX_PATH_ROOT "/org/swift_project/duplex"
23 
24 namespace swift::misc
25 {
26  class CVariantList;
27 
28  namespace shared_state::dbus
29  {
35  class SWIFT_MISC_EXPORT IDuplex : public QObject
36  {
37  Q_OBJECT
38  Q_CLASSINFO("D-Bus Interface", SWIFT_MISC_DUPLEX_INTERFACE)
39 
40  public:
42  QFuture<CVariant> submitRequest(const QString &channel, const swift::misc::CVariant &param);
43 
45  QFuture<CVariant> receiveRequest(const QString &channel, const swift::misc::CVariant &param);
46 
47  public slots:
49  virtual void postEvent(const QString &channel, const swift::misc::CVariant &param) = 0;
50 
52  virtual void setSubscription(const QString &channel, const swift::misc::CVariantList &filters) = 0;
53 
55  virtual void requestPeerSubscriptions() = 0;
56 
58  virtual void submitRequest(const QString &channel, const swift::misc::CVariant &param, quint32 token) = 0;
59 
61  virtual void reply(const swift::misc::CVariant &param, quint32 token);
62 
64  virtual void advertise(const QString &channel) = 0;
65 
67  virtual void withdraw(const QString &channel) = 0;
68 
69  signals:
71  void eventPosted(const QString &channel, const swift::misc::CVariant &param);
72 
74  void peerSubscriptionsReceived(const QString &channel, const swift::misc::CVariantList &filters);
75 
77  void requestReceived(const QString &channel, const swift::misc::CVariant &param, quint32 token,
78  QPrivateSignal);
79 
81  void replyReceived(const QString &channel, const swift::misc::CVariant &param, quint32 token);
82 
83  protected:
85  IDuplex(QObject *parent = nullptr);
86 
87  private:
88  quint32 getToken();
89 
90  quint32 m_token = 0;
91  QMap<quint32, CPromise<CVariant>> m_submittedRequests;
92  QMap<quint32, CPromise<CVariant>> m_receivedRequests;
93  };
94  } // namespace shared_state::dbus
95 } // namespace swift::misc
96 
97 #endif // SWIFT_MISC_SHAREDSTATE_DBUS_DUPLEX_H
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
Value object encapsulating a list of variants.
Definition: variantlist.h:29
Abstract interface for the spoke in a star topology.
Definition: duplex.h:36
virtual void advertise(const QString &channel)=0
Client advertises that it can handle requests for the given channel.
void requestReceived(const QString &channel, const swift::misc::CVariant &param, quint32 token, QPrivateSignal)
Server has submitted a request to be handled by the client.
virtual void submitRequest(const QString &channel, const swift::misc::CVariant &param, quint32 token)=0
Client submits a request to the server.
void eventPosted(const QString &channel, const swift::misc::CVariant &param)
Server has notified the client that an event has been posted.
void peerSubscriptionsReceived(const QString &channel, const swift::misc::CVariantList &filters)
Server has notified the client that other clients' event subscriptions have changed.
virtual void postEvent(const QString &channel, const swift::misc::CVariant &param)=0
Client posts an event to the server.
virtual void withdraw(const QString &channel)=0
Client advertises that it can no longer handle requests for the given channel.
virtual void requestPeerSubscriptions()=0
Client requests to be notified of all other clients' subscriptions.
virtual void setSubscription(const QString &channel, const swift::misc::CVariantList &filters)=0
Client announces its subscription to an event channel.
#define SWIFT_MISC_DUPLEX_INTERFACE
DBus interface for sharedstate hub.
Definition: duplex.h:19
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.