swift
scalarobserver.cpp
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 
7 
9 
11 {
13  {
14  dataLink->subscribe(m_observer.data());
15  m_observer->setEventSubscription(CVariant::from(CAnyMatch()));
16  connect(dataLink->watcher(), &CDataLinkConnectionWatcher::connected, this,
17  &CGenericScalarObserver::reconstruct);
18  if (dataLink->watcher()->isConnected()) { reconstruct(); }
19  }
20 
21  void CGenericScalarObserver::reconstruct()
22  {
23  m_observer->requestAsync({}, [this](const CVariant &value) { handleEvent(value); });
24  }
25 
27  {
28  QMutexLocker lock(&m_valueMutex);
29  return m_value;
30  }
31 
32  void CGenericScalarObserver::handleEvent(const CVariant &param)
33  {
34  QMutexLocker lock(&m_valueMutex);
35  if (m_value == param) { return; }
36  m_value = param;
37  lock.unlock();
38  onGenericValueChanged(param);
39  }
40 } // namespace swift::misc::shared_state
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
static CVariant from(T &&value)
Synonym for fromValue().
Definition: variant.h:147
Dummy value class that matches any event.
void initialize(IDataLink *)
Subscribe using the given transport mechanism.
CVariant value() const
Get scalar value as variant.
Utilities for sharing state between multiple objects.
Definition: application.h:48