mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
47 lines
1.5 KiB
C++
47 lines
1.5 KiB
C++
/* Copyright (C) 2017
|
|
* swift Project Community / Contributors
|
|
*
|
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
|
* or distributed except according to the terms contained in the LICENSE file.
|
|
*/
|
|
|
|
//! \file
|
|
|
|
#include "blackmisc/sharedstate/scalarobserver.h"
|
|
#include "blackmisc/sharedstate/datalink.h"
|
|
|
|
namespace BlackMisc
|
|
{
|
|
namespace SharedState
|
|
{
|
|
void CGenericScalarObserver::initialize(IDataLink *dataLink)
|
|
{
|
|
dataLink->subscribe(m_observer.data());
|
|
m_observer->setEventSubscription(CVariant::from(CAnyMatch()));
|
|
connect(dataLink->watcher(), &CDataLinkConnectionWatcher::connected, this, &CGenericScalarObserver::reconstruct);
|
|
if (dataLink->watcher()->isConnected()) { reconstruct(); }
|
|
}
|
|
|
|
void CGenericScalarObserver::reconstruct()
|
|
{
|
|
m_observer->requestAsync({}, [this](const CVariant &value) { handleEvent(value); });
|
|
}
|
|
|
|
CVariant CGenericScalarObserver::value() const
|
|
{
|
|
QMutexLocker lock(&m_valueMutex);
|
|
return m_value;
|
|
}
|
|
|
|
void CGenericScalarObserver::handleEvent(const CVariant ¶m)
|
|
{
|
|
QMutexLocker lock(&m_valueMutex);
|
|
if (m_value == param) { return; }
|
|
m_value = param;
|
|
lock.unlock();
|
|
onGenericValueChanged(param);
|
|
}
|
|
}
|
|
}
|