fix(sharedstate): Pass success/failure with QFuture

This commit is contained in:
Lars Toenning
2024-03-17 13:49:28 +01:00
parent 5266cc1909
commit 596773baf2
5 changed files with 12 additions and 12 deletions

View File

@@ -45,7 +45,7 @@ namespace BlackMisc
virtual bool isConnected() const = 0; virtual bool isConnected() const = 0;
//! Get a duplex object for the calling process. //! Get a duplex object for the calling process.
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex(const CIdentifier &) = 0; virtual std::pair<QSharedPointer<IDuplex>, QFuture<bool>> getDuplex(const CIdentifier &) = 0;
public slots: public slots:
//! Create a duplex object for the identified process. //! Create a duplex object for the identified process.
@@ -56,7 +56,7 @@ namespace BlackMisc
protected: protected:
//! Create a duplex object and return status via future. //! Create a duplex object and return status via future.
virtual QFuture<void> openDuplexAsync(const CIdentifier &client) = 0; virtual QFuture<bool> openDuplexAsync(const CIdentifier &client) = 0;
//! Constructor. //! Constructor.
IHub(QObject *parent = nullptr); IHub(QObject *parent = nullptr);

View File

@@ -15,7 +15,7 @@ namespace BlackMisc::SharedState::DBus
if (server) { server->addObject(BLACKMISC_HUB_PATH, this); } if (server) { server->addObject(BLACKMISC_HUB_PATH, this); }
} }
std::pair<QSharedPointer<IDuplex>, QFuture<void>> CHub::getDuplex(const CIdentifier &identifier) std::pair<QSharedPointer<IDuplex>, QFuture<bool>> CHub::getDuplex(const CIdentifier &identifier)
{ {
auto future = openDuplexAsync(identifier); auto future = openDuplexAsync(identifier);
return std::make_pair(m_clients.value(identifier), future); return std::make_pair(m_clients.value(identifier), future);
@@ -37,12 +37,12 @@ namespace BlackMisc::SharedState::DBus
m_clients.take(client); m_clients.take(client);
} }
QFuture<void> CHub::openDuplexAsync(const CIdentifier &client) QFuture<bool> CHub::openDuplexAsync(const CIdentifier &client)
{ {
openDuplex(client); openDuplex(client);
CPromise<void> promise; CPromise<bool> promise;
promise.setResult(); promise.setResult(true);
return promise.future(); return promise.future();
} }

View File

@@ -40,7 +40,7 @@ namespace BlackMisc
//! \name Interface implementations //! \name Interface implementations
//! @{ //! @{
virtual bool isConnected() const override { return true; } virtual bool isConnected() const override { return true; }
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex(const CIdentifier &) override; virtual std::pair<QSharedPointer<IDuplex>, QFuture<bool>> getDuplex(const CIdentifier &) override;
//! @} //! @}
public slots: public slots:
@@ -57,7 +57,7 @@ namespace BlackMisc
protected: protected:
//! \name Interface implementations //! \name Interface implementations
//! @{ //! @{
virtual QFuture<void> openDuplexAsync(const CIdentifier &client) override; virtual QFuture<bool> openDuplexAsync(const CIdentifier &client) override;
//! @} //! @}
private: private:

View File

@@ -22,7 +22,7 @@ namespace BlackMisc::SharedState::DBus
return m_interface->isValid(); return m_interface->isValid();
} }
std::pair<QSharedPointer<IDuplex>, QFuture<void>> CHubProxy::getDuplex(const CIdentifier &identifier) std::pair<QSharedPointer<IDuplex>, QFuture<bool>> CHubProxy::getDuplex(const CIdentifier &identifier)
{ {
auto duplex = QSharedPointer<CDuplexProxy>::create(m_interface->connection(), m_service, this); auto duplex = QSharedPointer<CDuplexProxy>::create(m_interface->connection(), m_service, this);
connect(duplex.get(), &QObject::destroyed, this, [=] { closeDuplex(identifier); }); connect(duplex.get(), &QObject::destroyed, this, [=] { closeDuplex(identifier); });
@@ -39,7 +39,7 @@ namespace BlackMisc::SharedState::DBus
m_interface->callDBus(QLatin1String("closeDuplex"), client); m_interface->callDBus(QLatin1String("closeDuplex"), client);
} }
QFuture<void> CHubProxy::openDuplexAsync(const CIdentifier &client) QFuture<bool> CHubProxy::openDuplexAsync(const CIdentifier &client)
{ {
return m_interface->callDBusFuture<bool>(QLatin1String("openDuplex"), client); return m_interface->callDBusFuture<bool>(QLatin1String("openDuplex"), client);
} }

View File

@@ -33,7 +33,7 @@ namespace BlackMisc
//! \name Interface implementations //! \name Interface implementations
//! @{ //! @{
virtual bool isConnected() const override; virtual bool isConnected() const override;
virtual std::pair<QSharedPointer<IDuplex>, QFuture<void>> getDuplex(const CIdentifier &) override; virtual std::pair<QSharedPointer<IDuplex>, QFuture<bool>> getDuplex(const CIdentifier &) override;
//! @} //! @}
public slots: public slots:
@@ -50,7 +50,7 @@ namespace BlackMisc
protected: protected:
//! \name Interface implementations //! \name Interface implementations
//! @{ //! @{
virtual QFuture<void> openDuplexAsync(const CIdentifier &client) override; virtual QFuture<bool> openDuplexAsync(const CIdentifier &client) override;
//! @} //! @}
private: private: