aboutsummaryrefslogtreecommitdiff
path: root/source/QXmppRemoteMethod.cpp
diff options
context:
space:
mode:
authorIan Geiser <ian.geiser@gmail.com>2009-11-11 11:09:28 +0000
committerIan Geiser <ian.geiser@gmail.com>2009-11-11 11:09:28 +0000
commitd9745efcd24e547ba0185732bfc9b0c9f931162e (patch)
treec66bc1c52329ea1a21771b74845009a9a0addd70 /source/QXmppRemoteMethod.cpp
parent5b0870ddaac421af2639058648a218c7061cdd6f (diff)
downloadqxmpp-d9745efcd24e547ba0185732bfc9b0c9f931162e.tar.gz
This is the rest of XEP-009. This needs some cleanup and testing still. I am not happy with the implementation, but I am happy with the interface on QXmppClient.
Diffstat (limited to 'source/QXmppRemoteMethod.cpp')
-rw-r--r--source/QXmppRemoteMethod.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/source/QXmppRemoteMethod.cpp b/source/QXmppRemoteMethod.cpp
new file mode 100644
index 00000000..835a67bf
--- /dev/null
+++ b/source/QXmppRemoteMethod.cpp
@@ -0,0 +1,51 @@
+#include "QXmppRemoteMethod.h"
+#include "QXmppClient.h"
+#include "QXmppUtils.h"
+#include "QXmppConfiguration.h"
+
+#include <QEventLoop>
+#include <QTimer>
+
+QXmppRemoteMethod::QXmppRemoteMethod(const QString &jid, const QString &method, const QVariantList &args, QXmppClient *client) :
+ QObject(client), m_client(client)
+{
+ m_payload.setId( generateStanzaHash() );
+ m_payload.setTo( jid );
+ m_payload.setFrom( client->getConfiguration().getJid() );
+ m_payload.setInterface( method.section('.', 0 ) );
+ m_payload.setMethod( method.section('.', 1) );
+ m_payload.setPayload( args );
+}
+
+QXmppRemoteMethodResult QXmppRemoteMethod::call( )
+{
+ QEventLoop loop(this);
+ connect( this, SIGNAL(callDone()), &loop, SLOT(quit()));
+ QTimer::singleShot(30000,&loop, SLOT(quit())); // Timeout incase the other end hangs...
+
+ m_client->sendPacket( m_payload );
+
+ loop.exec( QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents );
+ return m_result;
+}
+
+void QXmppRemoteMethod::gotError( const QXmppRpcErrorIq &iq )
+{
+ if ( iq.getId() == m_payload.getId() )
+ {
+ m_result.hasError = true;
+ m_result.errorMessage = iq.getError().getText();
+ m_result.code = iq.getError().getType();
+ emit callDone();
+ }
+}
+
+void QXmppRemoteMethod::gotResult( const QXmppRpcResponseIq &iq )
+{
+ if ( iq.getId() == m_payload.getId() )
+ {
+ m_result.hasError = false;
+ m_result.result = iq.getPayload();
+ emit callDone();
+ }
+}