swift
activemutator.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_ACTIVEMUTATOR_H
7 #define SWIFT_MISC_SHAREDSTATE_ACTIVEMUTATOR_H
8 
9 #include <functional>
10 
11 #include <QFuture>
12 #include <QObject>
13 
15 #include "misc/swiftmiscexport.h"
16 #include "misc/variant.h"
17 
19 {
25  {
26  Q_OBJECT
27  friend QSharedPointer<CActiveMutator>;
28 
29  template <typename T, typename F>
30  CActiveMutator(T *parent, F requestHandler)
31  : CPassiveMutator(parent), m_requestHandler([=](const CVariant &param) {
32  return private_ns::invokeMethod(parent, requestHandler, param);
33  })
34  {}
35 
36  public:
38  template <typename T, typename F>
39  static auto create(T *parent, F requestHandler)
40  {
41  return QSharedPointer<CActiveMutator>::create(parent, requestHandler);
42  }
43 
45  QFuture<CVariant> handleRequest(const CVariant &param) const;
46 
48  QWeakPointer<const CActiveMutator> weakRef() const
49  {
50  return qSharedPointerCast<const CActiveMutator>(CPassiveMutator::weakRef());
51  }
52 
53  private:
54  const std::function<QFuture<CVariant>(const CVariant &)> m_requestHandler;
55  };
56 } // namespace swift::misc::shared_state
57 
58 #endif // SWIFT_MISC_SHAREDSTATE_ACTIVEMUTATOR_H
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
Extends CPassiveMutator with the ability to respond to requests.
Definition: activemutator.h:25
QWeakPointer< const CActiveMutator > weakRef() const
Get a QWeakPointer pointing to this object.
Definition: activemutator.h:48
static auto create(T *parent, F requestHandler)
Factory method.
Definition: activemutator.h:39
Endpoint which can emit events to subscribers.
QWeakPointer< const CPassiveMutator > 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.