swift
activeobserver.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_ACTIVEOBSERVER_H
7 #define SWIFT_MISC_SHAREDSTATE_ACTIVEOBSERVER_H
8 
9 #include <QObject>
10 #include <QSharedPointer>
11 
12 #include "misc/promise.h"
14 #include "misc/swiftmiscexport.h"
15 #include "misc/variant.h"
16 
18 {
24  {
25  Q_OBJECT
26  friend QSharedPointer<CActiveObserver>;
27 
28  template <typename T, typename F>
29  CActiveObserver(T *parent, F eventHandler) : CPassiveObserver(parent, eventHandler)
30  {}
31 
32  public:
34  template <typename T, typename F>
35  static auto create(T *parent, F eventHandler)
36  {
37  return QSharedPointer<CActiveObserver>::create(parent, eventHandler);
38  }
39 
41  CVariant request(const CVariant &param);
42 
45  void requestAsync(const CVariant &param, std::function<void(const CVariant &)> callback);
46 
48  QWeakPointer<const CActiveObserver> weakRef() const
49  {
50  return qSharedPointerCast<const CActiveObserver>(CPassiveObserver::weakRef());
51  }
52 
53  signals:
56  };
57 } // namespace swift::misc::shared_state
58 
59 #endif // SWIFT_MISC_SHAREDSTATE_ACTIVEOBSERVER_H
A promise-based interface to QFuture, similar to std::promise for std::future.
Definition: promise.h:78
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
Extends CPassiveObserver with the ability to send requests and receive replies.
QWeakPointer< const CActiveObserver > weakRef() const
Get a QWeakPointer pointing to this object.
static auto create(T *parent, F eventHandler)
Factory method.
void requestPosted(const swift::misc::CVariant &param, swift::misc::CPromise< swift::misc::CVariant > o_reply)
Emitted by request and requestAsync.
Endpoint which can subscribe to events emitted by CPassiveMutator.
QWeakPointer< const CPassiveObserver > weakRef() const
Get a QWeakPointer pointing to this object.
Utilities for sharing state between multiple objects.
Definition: application.h:48
#define SWIFT_MISC_EXPORT
Export a class or function from the library.