Skip to content

Commit

Permalink
LW: handle disconnections from server
Browse files Browse the repository at this point in the history
Still need to go through and make sure we don't do stupid things if
we're disconnected, but at least now it'll try to reconnect.
  • Loading branch information
nathanielhourt committed Feb 10, 2015
1 parent a77467d commit 2667bae
Show file tree
Hide file tree
Showing 17 changed files with 2,491 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libraries/fc
Submodule fc updated from 9c5450 to b06886
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace bts { namespace light_wallet {
void connect( const string& host, const string& user = "any", const string& pass = "none", uint16_t port = 0,
const public_key_type& server_key = public_key_type() );
bool is_connected()const;
void set_disconnect_callback(std::function<void (fc::exception_ptr)> callback);
void disconnect();

void open();
Expand Down
17 changes: 14 additions & 3 deletions libraries/light_wallet/light_wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ void light_wallet::connect(const string& host, const string& user, const string&
{
try {
_rpc.connect_to( item, blockchain::public_key_type(server_key) );
set_disconnect_callback(nullptr);
if( user != "any" && pass != "none" )
_rpc.login( user, pass );
FC_ASSERT( is_connected(), "Unable to connect to server." );

fetch_welcome_package();

Expand All @@ -81,11 +83,20 @@ bool light_wallet::is_connected() const
return bool(_rpc.get_json_connection());
}

void light_wallet::set_disconnect_callback(std::function<void(fc::exception_ptr)> callback)
{
auto connection = _rpc.get_json_connection();
if( !connection ) return;
_rpc.get_json_connection()->set_close_callback([this, callback](fc::exception_ptr e) {
_rpc.reset_json_connection();
if( callback )
callback(e);
});
}

void light_wallet::disconnect()
{
// TODO: note there is no clear way of closing the json connection
auto json_con = _rpc.get_json_connection();
//if( json_con ) json_con->close();
_rpc.reset_json_connection();
}

void light_wallet::open()
Expand Down
1 change: 1 addition & 0 deletions libraries/rpc/include/bts/rpc/rpc_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace bts { namespace rpc {

bool login(const std::string& username, const std::string& password);
virtual fc::rpc::json_connection_ptr get_json_connection() const override;
void reset_json_connection();
private:
std::unique_ptr<detail::rpc_client_impl> my;
};
Expand Down
7 changes: 6 additions & 1 deletion libraries/rpc/rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ namespace bts { namespace rpc {

fc::rpc::json_connection_ptr rpc_client::get_json_connection() const
{
return my->_json_connection;
return my->_json_connection;
}

void rpc_client::reset_json_connection()
{
my->_json_connection.reset();
}

} } // bts::rpc
36 changes: 36 additions & 0 deletions programs/light_wallet/LightWallet.app/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>LightWallet</string>
<key>CFBundleGetInfoString</key>
<string>BitShares Light Wallet - version 0.9.0</string>
<key>CFBundleIconFile</key>
<string>bitshares.icns</string>
<key>CFBundleIdentifier</key>
<string>com.nathanhourt.bts.light</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>0.9.0</string>
<key>CFBundleName</key>
<string>LightWallet.app</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.9.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.9.0</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>LSRequiresCarbon</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>(C) 2014 God</string>
</dict>
</plist>
Binary file not shown.
910 changes: 910 additions & 0 deletions programs/light_wallet/LightWallet.cbp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions programs/light_wallet/LightWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ void LightWallet::connectToServer(QString host, quint16 port, QString serverKey,
else
m_wallet.connect(convert(host), convert(user), convert(password), port,
bts::blockchain::public_key_type(convert(serverKey)));
m_wallet.set_disconnect_callback([this](fc::exception_ptr) {
Q_EMIT connectedChanged(false);
});
Q_EMIT connectedChanged(isConnected());
Q_EMIT allAssetsChanged();
} catch (fc::exception e) {
Expand Down
Binary file added programs/light_wallet/LightWallet.dmg
Binary file not shown.
4 changes: 4 additions & 0 deletions programs/light_wallet/LightWallet_automoc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* This file is autogenerated, do not edit*/
#include "moc_Account.cpp"
#include "moc_LightWallet.cpp"
#include "moc_QtWrappers.cpp"
2 changes: 2 additions & 0 deletions programs/light_wallet/light_wallet_automoc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* This file is autogenerated, do not edit*/
enum some_compilers { need_more_than_nothing };
Loading

0 comments on commit 2667bae

Please sign in to comment.