summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-02-04 09:49:24 (GMT)
committerRichard Maudsley <richard.maudsley@isode.com>2014-03-07 14:28:58 (GMT)
commita511087b1f57f1f6372374f41d0b4b7ebeef9930 (patch)
treea319c6c65f4c4722635f78ac564a823a370d011c /test/com/isode/stroke/pubsub/Client.java
parent535e1a979a164f807aa64bf2df2bb36e7015ff17 (diff)
downloadstroke-a511087b1f57f1f6372374f41d0b4b7ebeef9930.zip
stroke-a511087b1f57f1f6372374f41d0b4b7ebeef9930.tar.bz2
PubSub parsers and serializers, plus manager and test code.
Change-Id: Ie8ca77ba8dbcd83926d46307ad0e73d804ff7422
Diffstat (limited to 'test/com/isode/stroke/pubsub/Client.java')
-rw-r--r--test/com/isode/stroke/pubsub/Client.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/test/com/isode/stroke/pubsub/Client.java b/test/com/isode/stroke/pubsub/Client.java
new file mode 100644
index 0000000..712db00
--- /dev/null
+++ b/test/com/isode/stroke/pubsub/Client.java
@@ -0,0 +1,107 @@
+/*
+* Copyright (c) 2014, Isode Limited, London, England.
+* All rights reserved.
+*/
+/*
+* Copyright (c) 2014, Remko Tronçon.
+* All rights reserved.
+*/
+
+package com.isode.stroke.pubsub;
+import com.isode.stroke.client.ClientError;
+import com.isode.stroke.client.ClientOptions;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.network.JavaNetworkFactories;
+import com.isode.stroke.queries.IQRouter;
+import com.isode.stroke.signals.Slot;
+import com.isode.stroke.signals.Slot1;
+
+public class Client {
+
+ static boolean debugInfo = false;
+ static boolean debugInfoXml = false;
+
+ public Client(String name, JID jid, String password, JavaNetworkFactories networkFactories, final Slot connectCallback) {
+ name_ = name;
+ connecting_ = true;
+ connected_ = false;
+ disconnecting_ = false;
+
+ client_ = new com.isode.stroke.client.Client(jid, password, networkFactories);
+
+ client_.onConnected.connect(new Slot() {
+ public void call() {
+ if (debugInfo) {
+ System.out.println("[" + name_ + "] onConnected.");
+ }
+ connecting_ = false;
+ connected_ = true;
+ connectCallback.call();
+ }
+ });
+
+ client_.onDisconnected.connect(new Slot1<ClientError>() {
+ public void call(ClientError error) {
+ if (debugInfo) {
+ System.out.println("[" + name_ + "] onDisconnected.");
+ }
+ connected_ = false;
+ }
+ });
+
+ client_.onDataRead.connect(new Slot1<String>() {
+ public void call(String xml) {
+ if (!connecting_ && !disconnecting_) {
+ if (debugInfoXml) {
+ System.out.println("[" + name_ + "] Client.Read:");
+ System.out.println(xml + "\n");
+ }
+ }
+ }
+ });
+
+ client_.onDataWritten.connect(new Slot1<String>() {
+ public void call(String xml) {
+ if (!connecting_ && !disconnecting_) {
+ if (debugInfoXml) {
+ System.out.println("[" + name_ + "] Client.Write:");
+ System.out.println(xml + "\n");
+ }
+ }
+ }
+ });
+
+ client_.connect(new ClientOptions());
+ }
+
+ void disconnect() {
+ disconnecting_ = true;
+ client_.disconnect();
+ }
+
+ boolean isConnected() {
+ return connected_;
+ }
+
+ boolean isConnecting() {
+ return connecting_;
+ }
+
+ JID getJID() {
+ return client_.getJID();
+ }
+
+ IQRouter getIQRouter() {
+ return client_.getIQRouter();
+ }
+
+ PubSubManager getPubSubManager() {
+ return client_.getPubSubManager();
+ }
+
+ com.isode.stroke.client.Client client_;
+ String name_;
+ boolean connected_;
+ boolean connecting_;
+ boolean disconnecting_;
+}