From d9745efcd24e547ba0185732bfc9b0c9f931162e Mon Sep 17 00:00:00 2001 From: Ian Geiser Date: Wed, 11 Nov 2009 11:09:28 +0000 Subject: 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. --- source/QXmppRemoteMethod.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 source/QXmppRemoteMethod.cpp (limited to 'source/QXmppRemoteMethod.cpp') 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 +#include + +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(); + } +} -- cgit v1.2.3