28 auto &channel = getChannel(mutator);
29 Q_ASSERT_X(!channel.activeMutator, Q_FUNC_INFO,
"Tried to publish two active mutators on one channel");
30 channel.activeMutator = mutator->
weakRef();
35 getChannel(observer).passiveObservers.push_back(observer->
weakRef());
48 void CDataLinkLocal::dispatchEvent(
const CVariant ¶m,
const QString &channel)
50 for (
const auto &observerWeak : std::as_const(getChannel(channel).passiveObservers))
52 auto observer = observerWeak.lock();
53 if (observer && observer->eventSubscription().matches(param)) { observer->handleEvent(param); }
57 QFuture<CVariant> CDataLinkLocal::handleRequest(
const CVariant ¶m,
const QString &channel)
59 auto mutator = getChannel(channel).activeMutator.lock();
60 if (mutator) {
return mutator->handleRequest(param); }
64 CDataLinkLocal::Channel &CDataLinkLocal::getChannel(
const QString &name)
66 QMutexLocker lock(&m_channelsMutex);
67 return m_channels[name];
70 CDataLinkLocal::Channel &CDataLinkLocal::getChannel(
const QObject *
object)
A promise-based interface to QFuture, similar to std::promise for std::future.
void chainResult(QFuture< U > future)
When the given future is ready, use its result to set the result of this promise.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Extends CPassiveMutator with the ability to respond to requests.
QWeakPointer< const CActiveMutator > weakRef() const
Get a QWeakPointer pointing to this object.
Extends CPassiveObserver with the ability to send requests and receive replies.
void requestPosted(const swift::misc::CVariant ¶m, swift::misc::CPromise< swift::misc::CVariant > o_reply)
Emitted by request and requestAsync.
virtual ~CDataLinkLocal()
Destructor.
virtual void subscribe(const CPassiveObserver *observer)
Register an observer with this transport mechanism.
virtual void publish(const CPassiveMutator *mutator)
Register a mutator with this transport mechanism.
CDataLinkLocal(QObject *parent=nullptr)
Constructor.
Endpoint which can emit events to subscribers.
void eventPosted(const swift::misc::CVariant ¶m)
Emitted by postEvent.
Endpoint which can subscribe to events emitted by CPassiveMutator.
QWeakPointer< const CPassiveObserver > weakRef() const
Get a QWeakPointer pointing to this object.
static QString getChannelName(const QObject *object)
Get the channel name for child endpoints of the given object.
void setConnectionStatus(bool connected)
Set the connection status visible through the watcher.
Utilities for sharing state between multiple objects.