mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
Issue #15 Shared state unittest
This commit is contained in:
@@ -35,6 +35,11 @@ namespace BlackMisc
|
||||
setConnectionStatus(false);
|
||||
}
|
||||
|
||||
void CDataLinkDBus::overrideIdentifier(const CIdentifier &id)
|
||||
{
|
||||
m_identifier = id;
|
||||
}
|
||||
|
||||
void CDataLinkDBus::initializeLocal(CDBusServer *server)
|
||||
{
|
||||
Q_ASSERT_X(!m_hub, Q_FUNC_INFO, "Already initialized");
|
||||
@@ -62,7 +67,7 @@ namespace BlackMisc
|
||||
if (m_duplex) { return; }
|
||||
|
||||
QFuture<void> ready;
|
||||
std::tie(m_duplex, ready) = m_hub->getDuplex();
|
||||
std::tie(m_duplex, ready) = m_hub->getDuplex(m_identifier);
|
||||
connect(m_duplex.get(), &IDuplex::eventPosted, this, &CDataLinkDBus::handlePeerEvent);
|
||||
connect(m_duplex.get(), &IDuplex::peerSubscriptionsReceived, this, &CDataLinkDBus::setPeerSubscriptions);
|
||||
connect(m_duplex.get(), &IDuplex::requestReceived, this, &CDataLinkDBus::handlePeerRequest);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "blackmisc/sharedstate/datalink.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/variantlist.h"
|
||||
#include "blackmisc/identifier.h"
|
||||
#include <QSharedPointer>
|
||||
|
||||
class QDBusConnection;
|
||||
@@ -46,6 +47,9 @@ namespace BlackMisc
|
||||
//! Destructor.
|
||||
virtual ~CDataLinkDBus() override;
|
||||
|
||||
//! Override identifier for testing purposes.
|
||||
void overrideIdentifier(const CIdentifier &);
|
||||
|
||||
//! Initialize on server side.
|
||||
void initializeLocal(CDBusServer *server = nullptr);
|
||||
|
||||
@@ -83,6 +87,8 @@ namespace BlackMisc
|
||||
QTimer m_watchTimer;
|
||||
DBus::IHub *m_hub = nullptr;
|
||||
QSharedPointer<DBus::IDuplex> m_duplex;
|
||||
CIdentifier m_identifier = CIdentifier::anonymous();
|
||||
|
||||
QMap<QString, Channel> m_channels;
|
||||
mutable QMutex m_channelsMutex { QMutex::Recursive };
|
||||
};
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace BlackMisc
|
||||
virtual bool isConnected() const = 0;
|
||||
|
||||
//! Get a duplex object for the calling process.
|
||||
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex() = 0;
|
||||
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex(const CIdentifier &) = 0;
|
||||
|
||||
public slots:
|
||||
//! Create a duplex object for the identified process.
|
||||
|
||||
@@ -24,10 +24,10 @@ namespace BlackMisc
|
||||
if (server) { server->addObject(BLACKMISC_HUB_PATH, this); }
|
||||
}
|
||||
|
||||
std::pair<QSharedPointer<IDuplex>, QFuture<void>> CHub::getDuplex()
|
||||
std::pair<QSharedPointer<IDuplex>, QFuture<void>> CHub::getDuplex(const CIdentifier &identifier)
|
||||
{
|
||||
auto future = openDuplexAsync(CIdentifier::anonymous());
|
||||
return std::make_pair(m_clients.value(CIdentifier::anonymous()), future);
|
||||
auto future = openDuplexAsync(identifier);
|
||||
return std::make_pair(m_clients.value(identifier), future);
|
||||
}
|
||||
|
||||
bool CHub::openDuplex(const BlackMisc::CIdentifier &client)
|
||||
|
||||
@@ -48,8 +48,7 @@ namespace BlackMisc
|
||||
//! \name Interface implementations
|
||||
//! @{
|
||||
virtual bool isConnected() const override { return true; }
|
||||
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex() override;
|
||||
//! @}
|
||||
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex(const CIdentifier &) override;
|
||||
|
||||
public slots:
|
||||
//! \name Interface implementations
|
||||
|
||||
@@ -31,11 +31,11 @@ namespace BlackMisc
|
||||
return m_interface->isValid();
|
||||
}
|
||||
|
||||
std::pair<QSharedPointer<IDuplex>, QFuture<void>> CHubProxy::getDuplex()
|
||||
std::pair<QSharedPointer<IDuplex>, QFuture<void>> CHubProxy::getDuplex(const CIdentifier &identifier)
|
||||
{
|
||||
auto duplex = QSharedPointer<CDuplexProxy>::create(m_interface->connection(), m_service, this);
|
||||
connect(duplex.get(), &QObject::destroyed, this, [ = ] { closeDuplex(CIdentifier::anonymous()); });
|
||||
return std::make_pair(duplex, openDuplexAsync(CIdentifier::anonymous()));
|
||||
connect(duplex.get(), &QObject::destroyed, this, [ = ] { closeDuplex(identifier); });
|
||||
return std::make_pair(duplex, openDuplexAsync(identifier));
|
||||
}
|
||||
|
||||
bool CHubProxy::openDuplex(const CIdentifier& client)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace BlackMisc
|
||||
//! \name Interface implementations
|
||||
//! @{
|
||||
virtual bool isConnected() const override;
|
||||
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex() override;
|
||||
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex(const CIdentifier &) override;
|
||||
//! @}
|
||||
|
||||
public slots:
|
||||
|
||||
Reference in New Issue
Block a user