Refactored: work with wallet api statuses to make setting and getting operations atomic along with error strings

WalletApi: added method statusWithErrorString to atomically retrieve error with error string
This commit is contained in:
naughtyfox 2018-03-21 20:34:15 +03:00
parent 8361d60aef
commit 47fdb74273
3 changed files with 175 additions and 255 deletions

File diff suppressed because it is too large Load diff

View file

@ -83,6 +83,7 @@ public:
// void setListener(Listener *) {} // void setListener(Listener *) {}
int status() const; int status() const;
std::string errorString() const; std::string errorString() const;
void statusWithErrorString(int& status, std::string& errorString) const override;
bool setPassword(const std::string &password); bool setPassword(const std::string &password);
std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const; std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const;
std::string integratedAddress(const std::string &payment_id) const; std::string integratedAddress(const std::string &payment_id) const;
@ -174,6 +175,9 @@ public:
private: private:
void clearStatus() const; void clearStatus() const;
void setStatusError(const std::string& message) const;
void setStatusCritical(const std::string& message) const;
void setStatus(int status, const std::string& message) const;
void refreshThreadFunc(); void refreshThreadFunc();
void doRefresh(); void doRefresh();
bool daemonSynced() const; bool daemonSynced() const;
@ -191,7 +195,8 @@ private:
friend class SubaddressAccountImpl; friend class SubaddressAccountImpl;
tools::wallet2 * m_wallet; tools::wallet2 * m_wallet;
mutable std::atomic<int> m_status; mutable boost::mutex m_statusMutex;
mutable int m_status;
mutable std::string m_errorString; mutable std::string m_errorString;
std::string m_password; std::string m_password;
TransactionHistoryImpl * m_history; TransactionHistoryImpl * m_history;

View file

@ -358,9 +358,11 @@ struct Wallet
virtual std::string getSeedLanguage() const = 0; virtual std::string getSeedLanguage() const = 0;
virtual void setSeedLanguage(const std::string &arg) = 0; virtual void setSeedLanguage(const std::string &arg) = 0;
//! returns wallet status (Status_Ok | Status_Error) //! returns wallet status (Status_Ok | Status_Error)
virtual int status() const = 0; virtual int status() const = 0; //deprecated: use safe alternative statusWithErrorString
//! in case error status, returns error string //! in case error status, returns error string
virtual std::string errorString() const = 0; virtual std::string errorString() const = 0; //deprecated: use safe alternative statusWithErrorString
//! returns both error and error string atomically. suggested to use in instead of status() and errorString()
virtual void statusWithErrorString(int& status, std::string& errorString) const = 0;
virtual bool setPassword(const std::string &password) = 0; virtual bool setPassword(const std::string &password) = 0;
virtual std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const = 0; virtual std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const = 0;
std::string mainAddress() const { return address(0, 0); } std::string mainAddress() const { return address(0, 0); }