Skip to content

Commit

Permalink
clean up disconnection notifications, fix a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
sandsmark committed Apr 29, 2012
1 parent c008e8f commit 9434553
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
37 changes: 14 additions & 23 deletions src/com/iskrembilen/quasseldroid/io/CoreConnection.java
Expand Up @@ -96,8 +96,6 @@ public final class CoreConnection {
private Timer heartbeatTimer;
private ReadThread readThread;

private boolean connected;
private boolean connecting;
private boolean initComplete;
private int initBacklogBuffers;

Expand All @@ -111,8 +109,6 @@ public CoreConnection(String address, int port, String username,
this.ssl = ssl;
this.service = parent;

this.connected = false;

readThread = new ReadThread();
readThread.start();
}
Expand Down Expand Up @@ -140,7 +136,8 @@ public void requestMarkBufferAsRead(int buffer) {
sendQVariantList(retFunc);
} catch (IOException e) {
e.printStackTrace();
connected = false;
service.getHandler().obtainMessage(R.id.LOST_CONNECTION, "Lost connection").sendToTarget();
disconnect();
}
}

Expand All @@ -157,7 +154,8 @@ public void requestSetLastMsgRead(int buffer, int msgid) {
sendQVariantList(retFunc);
} catch (IOException e) {
e.printStackTrace();
connected = false;
service.getHandler().obtainMessage(R.id.LOST_CONNECTION, "Lost connection").sendToTarget();
disconnect();
}
}

Expand All @@ -174,7 +172,8 @@ public void requestSetMarkerLine(int buffer, int msgid) {
sendQVariantList(retFunc);
} catch (IOException e) {
e.printStackTrace();
connected = false;
service.getHandler().obtainMessage(R.id.LOST_CONNECTION, "Lost connection").sendToTarget();
disconnect();
}
}

Expand All @@ -195,7 +194,8 @@ public void requestUnhideTempHiddenBuffer(int bufferId) {
sendQVariantList(retFunc);
} catch (IOException e) {
e.printStackTrace();
connected = false;
service.getHandler().obtainMessage(R.id.LOST_CONNECTION, "Lost connection").sendToTarget();
disconnect();
}
}

Expand Down Expand Up @@ -249,7 +249,8 @@ private void requestBacklog(int buffer, int firstMsgId, int lastMsgId, int maxAm
sendQVariantList(retFunc);
} catch (IOException e) {
e.printStackTrace();
connected = false;
service.getHandler().obtainMessage(R.id.LOST_CONNECTION, "Lost connection").sendToTarget();
disconnect();
}
}

Expand Down Expand Up @@ -283,8 +284,9 @@ public void sendMessage(int buffer, String message) {
try {
sendQVariantList(retFunc);
} catch (IOException e) {
service.getHandler().obtainMessage(R.id.LOST_CONNECTION, "Lost connection").sendToTarget();
e.printStackTrace();
connected = false;
disconnect();
}
}

Expand All @@ -302,9 +304,6 @@ public void connect() throws UnknownHostException, IOException, GeneralSecurityE
outStream = new QDataOutputStream(socket.getOutputStream());
// END CREATE SOCKETS


connecting = true;

// Notify the UI we have an open socket
Message msg = service.getHandler().obtainMessage(R.id.CONNECTING);
msg.sendToTarget();
Expand Down Expand Up @@ -466,6 +465,7 @@ public void run() {
try {
sendQVariantList(packedFunc);
} catch (IOException e) {
service.getHandler().obtainMessage(R.id.LOST_CONNECTION, "Lost connection").sendToTarget();
e.printStackTrace();
disconnect();
}
Expand All @@ -478,8 +478,6 @@ public void run() {
Log.i(TAG, "Connected!");

initComplete = false;
connected = true;
connecting = false;
}

/**
Expand All @@ -503,14 +501,7 @@ public void disconnect() {
} catch (IOException e) {
e.printStackTrace();
}

connected = false;
}
/****************************
* Private internal communication stuff.
* Please don't look below this line.
* @author sandsmark
*/

/**
* Type of a given request (should be pretty self-explanatory).
Expand Down Expand Up @@ -707,7 +698,7 @@ public String doRun() throws EmptyQVariantException {
System.err.println("IO error!");
e.printStackTrace();
this.running = false;
CoreConnection.this.connected = false;
CoreConnection.this.disconnect();
return null;
}
//We received a package, aka we are not disconnected, restart timer
Expand Down
Expand Up @@ -778,7 +778,7 @@ public void handleMessage(Message msg) {
}
bundle = (Bundle) msg.obj;
user = networks.getNetworkById(msg.arg1).getUserByNick(bundle.getString("nick"));
String modes = (String)bundle.get("mode");
String modes = (String)bundle.get("mode");
networks.getNetworkById(msg.arg1).getBuffers().getBuffer(msg.arg2).getUsers().addUser(user, modes);
break;
case R.id.USER_CHANGEDNICK:
Expand All @@ -788,6 +788,10 @@ public void handleMessage(Message msg) {
}
bundle = (Bundle) msg.obj;
user = networks.getNetworkById(msg.arg1).getUserByNick(bundle.getString("oldNick"));
if (user == null) {
System.err.println("Unable to find user " + bundle.getString("oldNick"));
return;
}
user.changeNick(bundle.getString("newNick"));
break;
case R.id.USER_ADD_MODE:
Expand Down

0 comments on commit 9434553

Please sign in to comment.