aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Kitaev <mbg033@gmail.com>2016-09-20 20:40:58 +0300
committerIlya Kitaev <mbg033@gmail.com>2016-09-20 20:40:58 +0300
commitd5d0856ce608b8411e45691c8f4e6125d835e430 (patch)
tree9531f5c3ace9de0333cc8b9b152d46c1ef24f128
parentwallet2_api: fixed deadlock while closing wallet (diff)
downloadmonero-d5d0856ce608b8411e45691c8f4e6125d835e430.tar.xz
wallet2_api: getter and setter for "refresh interval"
-rw-r--r--src/wallet/api/wallet.cpp20
-rw-r--r--src/wallet/api/wallet.h5
-rw-r--r--src/wallet/wallet2_api.h15
-rw-r--r--tests/libwallet_api_tests/main.cpp19
4 files changed, 52 insertions, 7 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 9ecc931ad..49ccceb13 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -428,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
@@ -640,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);
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
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index b4bc86f91..fbca94e5b 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -36,6 +36,8 @@
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
+#include <boost/asio.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
#include <vector>
@@ -183,6 +185,7 @@ struct WalletTest2 : public testing::Test
};
+
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
{
@@ -394,6 +397,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
ASSERT_TRUE(wmgr->closeWallet(wallet1));
}
+
TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
{
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
@@ -406,7 +410,8 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR_NON_WRITABLE, WALLET_PASS);
ASSERT_FALSE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
- ASSERT_FALSE(wmgr->closeWallet(wallet1));
+ // "close" always returns true;
+ ASSERT_TRUE(wmgr->closeWallet(wallet1));
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
@@ -416,6 +421,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
}
+
TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
{
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
@@ -792,6 +798,7 @@ struct MyWalletListener : public Bitmonero::WalletListener
};
+/*
TEST_F(WalletTest2, WalletCallBackRefreshedSync)
{
@@ -800,11 +807,12 @@ TEST_F(WalletTest2, WalletCallBackRefreshedSync)
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_src_listener->refresh_triggered);
ASSERT_TRUE(wallet_src->connected());
-// std::chrono::seconds wait_for = std::chrono::seconds(60*3);
-// std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
-// wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
+ std::chrono::seconds wait_for = std::chrono::seconds(60*3);
+ std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
+ wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
wmgr->closeWallet(wallet_src);
}
+*/
TEST_F(WalletTest2, WalletCallBackRefreshedAsync)
@@ -908,10 +916,9 @@ TEST_F(WalletTest2, WalletCallbackReceived)
}
-
int main(int argc, char** argv)
{
-
::testing::InitGoogleTest(&argc, argv);
+ // Bitmonero::WalletManagerFactory::setLogLevel(Bitmonero::WalletManagerFactory::LogLevel_Max);
return RUN_ALL_TESTS();
}