swift
datalinkdbus.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2017 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_DATALINKDBUS_H
7 #define SWIFT_MISC_SHAREDSTATE_DATALINKDBUS_H
8 
9 #include <QSharedPointer>
10 #include <QTimer>
11 
12 #include "misc/identifier.h"
14 #include "misc/swiftmiscexport.h"
15 #include "misc/variantlist.h"
16 
17 class QDBusConnection;
18 
19 namespace swift::misc
20 {
21  class CDBusServer;
22 
23  namespace shared_state
24  {
25  namespace dbus
26  {
27  class IHub;
28  class IDuplex;
29  } // namespace dbus
30 
35  class SWIFT_MISC_EXPORT CDataLinkDBus : public QObject, public IDataLink
36  {
37  Q_OBJECT
39 
40  public:
42  CDataLinkDBus(QObject *parent = nullptr);
43 
45  virtual ~CDataLinkDBus() override;
46 
48  void overrideIdentifier(const CIdentifier &);
49 
51  void initializeLocal(CDBusServer *server = nullptr);
52 
54  void initializeRemote(const QDBusConnection &connection, const QString &service);
55 
56  virtual void publish(const CPassiveMutator *mutator) override;
57  virtual void publish(const CActiveMutator *mutator) override;
58  virtual void subscribe(const CPassiveObserver *observer) override;
59  virtual void subscribe(const CActiveObserver *observer) override;
60 
61  private:
62  struct Channel
63  {
64  QWeakPointer<const CActiveMutator> activeMutator;
65  QVector<QWeakPointer<const CPassiveObserver>> passiveObservers;
66  CVariantList peerSubscriptions;
67  };
68  QStringList getChannelNames() const;
69  Channel &getChannel(const QString &name);
70  Channel &getChannel(const QObject *object);
71 
72  void checkConnection();
73  void onConnected();
74  void onDisconnected();
75 
76  void handleLocalEvent(const QString &channel, const CVariant &param);
77  void handlePeerEvent(const QString &channel, const CVariant &param);
78  void announceLocalSubscriptions();
79  void announceLocalSubscriptions(const QString &channel);
80  void setPeerSubscriptions(const QString &channel, const CVariantList &filters);
81  QFuture<CVariant> handleLocalRequest(const QString &channel, const CVariant &param);
82  void handlePeerRequest(const QString &channel, const CVariant &param, quint32 token);
83 
84  QTimer m_watchTimer;
85  dbus::IHub *m_hub = nullptr;
86  QSharedPointer<dbus::IDuplex> m_duplex;
87  CIdentifier m_identifier = CIdentifier::anonymous();
88 
89  QMap<QString, Channel> m_channels;
90  mutable QRecursiveMutex m_channelsMutex;
91  };
92  } // namespace shared_state
93 } // namespace swift::misc
94 
95 #endif // SWIFT_MISC_SHAREDSTATE_DATALINKDBUS_H
Custom DBusServer.
Definition: dbusserver.h:34
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition: identifier.h:29
static const CIdentifier & anonymous()
Returns an anonymous identifier, which is a valid identifier without name.
Definition: identifier.cpp:78
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
Extends CPassiveMutator with the ability to respond to requests.
Definition: activemutator.h:25
Extends CPassiveObserver with the ability to send requests and receive replies.
Endpoint which can emit events to subscribers.
Endpoint which can subscribe to events emitted by CPassiveMutator.
Abstract interface for the hub in a star topology.
Definition: hub.h:37
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.