aboutsummaryrefslogtreecommitdiff
path: root/examples/example_6_rpcClient
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-12-10 16:46:56 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-12-10 16:46:56 +0000
commit322725554e52c46638481c34ee6f652d173c58f4 (patch)
treeb104bdc6db1b05f2babd3c15da66951e34e065a1 /examples/example_6_rpcClient
parent0fc9ad87ac985ae40b2f205c88f901024967c3ec (diff)
downloadqxmpp-322725554e52c46638481c34ee6f652d173c58f4.tar.gz
cleanup RPC examples to use qxmpp.testX@gmail.com accounts
Diffstat (limited to 'examples/example_6_rpcClient')
-rw-r--r--examples/example_6_rpcClient/main.cpp9
-rw-r--r--examples/example_6_rpcClient/rpcClient.cpp50
-rw-r--r--examples/example_6_rpcClient/rpcClient.h10
3 files changed, 34 insertions, 35 deletions
diff --git a/examples/example_6_rpcClient/main.cpp b/examples/example_6_rpcClient/main.cpp
index c892dd5b..44ee7d96 100644
--- a/examples/example_6_rpcClient/main.cpp
+++ b/examples/example_6_rpcClient/main.cpp
@@ -32,14 +32,7 @@ int main(int argc, char *argv[])
QXmppLogger::getLogger()->setLoggingType(QXmppLogger::StdoutLogging);
- QXmppConfiguration config;
- config.setUser("client");
- config.setDomain("geiseri.com");
- config.setPassword("Passw0rd");
- config.setHost("jabber.geiseri.com");
- config.setUseSASLAuthentication(false);
-
rpcClient client;
- client.connectToServer(config);
+ client.connectToServer("qxmpp.test2@gmail.com", "qxmpp123");
return a.exec();
}
diff --git a/examples/example_6_rpcClient/rpcClient.cpp b/examples/example_6_rpcClient/rpcClient.cpp
index 3f63d062..9e244393 100644
--- a/examples/example_6_rpcClient/rpcClient.cpp
+++ b/examples/example_6_rpcClient/rpcClient.cpp
@@ -21,46 +21,52 @@
*
*/
+#include <QDebug>
+#include <QTimer>
-#include "rpcClient.h"
#include "QXmppRemoteMethod.h"
-#include <qdebug.h>
-#include <QTimer>
+#include "QXmppUtils.h"
+
+#include "rpcClient.h"
rpcClient::rpcClient(QObject *parent)
: QXmppClient(parent)
{
- connect( this, SIGNAL(connected()), this, SLOT(isConnected()));
+ bool check = connect(this, SIGNAL(presenceReceived(QXmppPresence)),
+ this, SLOT(slotPresenceReceived(QXmppPresence)));
+ Q_ASSERT(check);
+ Q_UNUSED(check);
}
rpcClient::~rpcClient()
{
-
-}
-
-void rpcClient::isConnected()
-{
- //We need to wait until we have sent the presense stuff, or for some
- //reason the server ignores us...
- QTimer::singleShot(5000, this, SLOT(invokeRemoteMethod()));
}
-void rpcClient::invokeRemoteMethod()
+void rpcClient::slotInvokeRemoteMethod()
{
QXmppRemoteMethodResult methodResult = callRemoteMethod(
- "server@geiseri.com/QXmpp", "RemoteInterface.echoString", "This is a test" );
+ m_remoteJid, "RemoteInterface.echoString", "This is a test" );
if( methodResult.hasError )
- error( methodResult.code, methodResult.errorMessage );
+ qDebug() << "Error:" << methodResult.code << methodResult.errorMessage;
else
- result( methodResult.result );
+ qDebug() << "Result:" << methodResult.result;
}
-void rpcClient::result(const QVariant &value )
-{
- qDebug() << "Result:" << value;
-}
+/// A presence was received.
-void rpcClient::error( int code, const QString &message )
+void rpcClient::slotPresenceReceived(const QXmppPresence &presence)
{
- qDebug() << "Error:" << code << message;
+ const QLatin1String recipient("qxmpp.test1@gmail.com");
+
+ // if we are the recipient, or if the presence is not from the recipient,
+ // do nothing
+ if (jidToBareJid(configuration().jid()) == recipient ||
+ jidToBareJid(presence.from()) != recipient ||
+ presence.type() != QXmppPresence::Available)
+ return;
+
+ // invoke the remote method in 1 second
+ m_remoteJid = presence.from();
+ QTimer::singleShot(1000, this, SLOT(slotInvokeRemoteMethod()));
}
+
diff --git a/examples/example_6_rpcClient/rpcClient.h b/examples/example_6_rpcClient/rpcClient.h
index aeb7d605..49ab8b7b 100644
--- a/examples/example_6_rpcClient/rpcClient.h
+++ b/examples/example_6_rpcClient/rpcClient.h
@@ -35,12 +35,12 @@ public:
rpcClient(QObject *parent = 0);
~rpcClient();
-public slots:
- void isConnected();
- void invokeRemoteMethod();
- void result(const QVariant &value );
- void error( int code, const QString &message );
+private slots:
+ void slotInvokeRemoteMethod();
+ void slotPresenceReceived(const QXmppPresence &presence);
+private:
+ QString m_remoteJid;
};
#endif // RPCCLIENT_H