+ private void handle(int cmd, Messenger mgr)
+ {
+ // Setup communication with Main
+ if (cmd == REGISTER) {
+ Os.debug("Task: handle - register");
+ this.messenger = mgr;
+ this.command(REGISTER, this);
+ }
+
+ // Create client thread
+ if (cmd == CONNECT && this.thread == null) {
+ Os.debug("Task: handle - connect");
+ this.thread = new Thread(this);
+ this.thread.start();
+ }
+
+ // Stop client thread
+ if (cmd == DISCONNECT && this.thread != null) {
+ Os.debug("Task: handle - register");
+ try {
+ this.client.abort();
+ this.thread.join();
+ } catch (Exception e) {
+ Os.debug("Task: error stopping service", e);
+ }
+ }
+ }
+