Wallet: Cache connection status query

This commit is contained in:
Jaquee 2016-11-26 16:31:27 +01:00
parent 36a6b89b54
commit 3f8e05d7a4
No known key found for this signature in database
GPG key ID: 384E52B09F45DC39
2 changed files with 20 additions and 5 deletions

View file

@ -15,6 +15,7 @@
namespace {
static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 10;
static const int DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS = 60;
static const int WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS = 5;
}
class WalletListenerImpl : public Bitmonero::WalletListener
@ -90,12 +91,19 @@ Wallet::Status Wallet::status() const
Wallet::ConnectionStatus Wallet::connected()
{
qDebug("Checking wallet connection status");
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
if(newStatus != m_connectionStatus) {
m_connectionStatus = newStatus;
emit connectionStatusChanged();
// cache connection status
if(m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl){
qDebug("connectionStatus query");
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
if(newStatus != m_connectionStatus) {
m_connectionStatus = newStatus;
emit connectionStatusChanged();
}
m_connectionStatusTime.restart();
}
return newStatus;
return m_connectionStatus;
}
bool Wallet::synchronized() const
@ -425,10 +433,15 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent)
, m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS)
, m_daemonBlockChainTargetHeight(0)
, m_daemonBlockChainTargetHeightTtl(DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS)
, m_connectionStatusTtl(WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS)
{
m_history = new TransactionHistory(m_walletImpl->history(), this);
m_walletImpl->setListener(new WalletListenerImpl(this));
m_connectionStatus = Wallet::ConnectionStatus_Disconnected;
// start cache timers
m_connectionStatusTime.restart();
m_daemonBlockChainHeightTime.restart();
m_daemonBlockChainTargetHeightTime.restart();
}
Wallet::~Wallet()

View file

@ -220,6 +220,8 @@ private:
mutable quint64 m_daemonBlockChainTargetHeight;
int m_daemonBlockChainTargetHeightTtl;
ConnectionStatus m_connectionStatus;
int m_connectionStatusTtl;
mutable QTime m_connectionStatusTime;
};