DDPClientCallback.java 2.42 KB
Newer Older
1 2
package chat.rocket.android_ddp;

3
import android.support.annotation.NonNull;
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import android.support.annotation.Nullable;
import org.json.JSONObject;

public class DDPClientCallback {
  public static abstract class Base {
    public DDPClient client;

    public Base(DDPClient client) {
      this.client = client;
    }
  }

  public static abstract class BaseException extends Exception {
    public DDPClient client;

19 20
    public BaseException(Class<? extends BaseException> clazz, DDPClient client) {
      super(clazz.getName());
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
      this.client = client;
    }
  }

  public static class Connect extends Base {
    public String session;

    public Connect(DDPClient client, String session) {
      super(client);
      this.session = session;
    }

    public static class Failed extends BaseException {
      public String version;

      public Failed(DDPClient client, String version) {
37
        super(Failed.class, client);
38 39 40
        this.version = version;
      }
    }
Yusuke Iwaki's avatar
Yusuke Iwaki committed
41 42 43

    public static class Timeout extends BaseException {
      public Timeout(DDPClient client) {
44
        super(Timeout.class, client);
Yusuke Iwaki's avatar
Yusuke Iwaki committed
45 46
      }
    }
47 48 49 50 51 52 53 54 55 56
  }

  public static class Ping extends Base {
    @Nullable public String id;

    public Ping(DDPClient client, @Nullable String id) {
      super(client);
      this.id = id;
    }

57 58 59 60 61 62 63 64 65
    public static class UnMatched extends Base {
      @NonNull public String id;

      public UnMatched(DDPClient client, @NonNull String id) {
        super(client);
        this.id = id;
      }
    }

66 67
    public static class Timeout extends BaseException {
      public Timeout(DDPClient client) {
68
        super(Timeout.class, client);
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
      }
    }
  }

  public static class RPC extends Base {
    public String id;
    public String result;

    public RPC(DDPClient client, String id, String result) {
      super(client);
      this.id = id;
      this.result = result;
    }

    public static class Error extends BaseException {
      public String id;
      public JSONObject error;

      public Error(DDPClient client, String id, JSONObject error) {
88
        super(Error.class, client);
89 90 91 92 93 94 95
        this.id = id;
        this.error = error;
      }
    }

    public static class Timeout extends BaseException {
      public Timeout(DDPClient client) {
96
        super(Timeout.class, client);
97 98 99
      }
    }
  }
100 101 102 103 104 105

  public static class Closed extends BaseException {
    public Closed(DDPClient client) {
      super(Closed.class, client);
    }
  }
106
}