diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-09-26 17:34:06 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-09-26 17:34:06 +0200 |
commit | cf74a137f3528482396a9d260660c287994730f1 (patch) | |
tree | 628c17086a0d676fbfbad01dd4e8e58166218e99 /src | |
parent | Merge pull request #1113 (diff) | |
parent | libwallet_api: simple documentation on testing environment (diff) | |
download | monero-cf74a137f3528482396a9d260660c287994730f1.tar.xz |
Merge pull request #1116
2e18e10 libwallet_api: simple documentation on testing environment (Ilya Kitaev)
69c9824 libwallet_api: tests: env variables for WALLETS_ROOT_DIR and TESTNET_DAEMON_ADDRESS (Ilya Kitaev)
1f8a70c libwallet_api: tests: changed testwallets path, uncommitted all tests (Ilya Kitaev)
d5d0856 wallet2_api: getter and setter for "refresh interval" (Ilya Kitaev)
cdb6c96 wallet2_api: fixed deadlock while closing wallet (Ilya Kitaev)
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/api/wallet.cpp | 30 | ||||
-rw-r--r-- | src/wallet/api/wallet.h | 5 | ||||
-rw-r--r-- | src/wallet/wallet2_api.h | 15 |
3 files changed, 46 insertions, 4 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 74552bc03..49ccceb13 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -169,7 +169,9 @@ WalletImpl::WalletImpl(bool testnet) m_wallet->callback(m_wallet2Callback); m_refreshThreadDone = false; m_refreshEnabled = false; + m_refreshIntervalSeconds = DEFAULT_REFRESH_INTERVAL_SECONDS; + m_refreshThread = boost::thread([this] () { this->refreshThreadFunc(); }); @@ -272,14 +274,15 @@ bool WalletImpl::close() { bool result = false; + LOG_PRINT_L3("closing wallet..."); try { // do not store wallet with invalid status if (status() == Status_Ok) m_wallet->store(); - // LOG_PRINT_L0("wallet::store done"); - // LOG_PRINT_L0("Calling wallet::stop..."); + LOG_PRINT_L3("wallet::store done"); + LOG_PRINT_L3("Calling wallet::stop..."); m_wallet->stop(); - // LOG_PRINT_L0("wallet::stop done"); + LOG_PRINT_L3("wallet::stop done"); result = true; clearStatus(); } catch (const std::exception &e) { @@ -425,6 +428,16 @@ void WalletImpl::refreshAsync() m_refreshCV.notify_one(); } +void WalletImpl::setAutoRefreshInterval(int seconds) +{ + m_refreshIntervalSeconds = seconds; +} + +int WalletImpl::autoRefreshInterval() const +{ + return m_refreshIntervalSeconds; +} + // TODO: // 1 - properly handle payment id (add another menthod with explicit 'payment_id' param) // 2 - check / design how "Transaction" can be single interface @@ -637,7 +650,15 @@ void WalletImpl::refreshThreadFunc() break; } LOG_PRINT_L3(__FUNCTION__ << ": waiting for refresh..."); - m_refreshCV.wait(lock); + // if auto refresh enabled, we wait for the "m_refreshIntervalSeconds" interval. + // if not - we wait forever + if (m_refreshIntervalSeconds > 0) { + boost::posix_time::milliseconds wait_for_ms(m_refreshIntervalSeconds * 1000); + m_refreshCV.timed_wait(lock, wait_for_ms); + } else { + m_refreshCV.wait(lock); + } + LOG_PRINT_L3(__FUNCTION__ << ": refresh lock acquired..."); LOG_PRINT_L3(__FUNCTION__ << ": m_refreshEnabled: " << m_refreshEnabled); LOG_PRINT_L3(__FUNCTION__ << ": m_status: " << m_status); @@ -680,6 +701,7 @@ void WalletImpl::stopRefresh() if (!m_refreshThreadDone) { m_refreshEnabled = false; m_refreshThreadDone = true; + m_refreshCV.notify_one(); m_refreshThread.join(); } } diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 658296c30..11880d555 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -77,6 +77,11 @@ public: uint64_t unlockedBalance() const; bool refresh(); void refreshAsync(); + void setAutoRefreshInterval(int seconds); + int autoRefreshInterval() const; + + + PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id, uint64_t amount, uint32_t mixin_count, PendingTransaction::Priority priority = PendingTransaction::Priority_Low); diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index e880b1c68..2d2877856 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -223,10 +223,25 @@ struct Wallet * @return - true if refreshed successfully; */ virtual bool refresh() = 0; + /** * @brief refreshAsync - refreshes wallet asynchronously. */ virtual void refreshAsync() = 0; + + /** + * @brief setAutoRefreshInterval - setup interval for automatic refresh. + * @param seconds - interval in seconds. if zero or less than zero - automatic refresh disabled; + */ + virtual void setAutoRefreshInterval(int seconds) = 0; + + /** + * @brief autoRefreshInterval - returns automatic refresh interval in seconds + * @return + */ + virtual int autoRefreshInterval() const = 0; + + /*! * \brief createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored * \param dst_addr destination address as string |