diff options
| author | Ian Geiser <ian.geiser@gmail.com> | 2009-11-11 11:09:28 +0000 |
|---|---|---|
| committer | Ian Geiser <ian.geiser@gmail.com> | 2009-11-11 11:09:28 +0000 |
| commit | d9745efcd24e547ba0185732bfc9b0c9f931162e (patch) | |
| tree | c66bc1c52329ea1a21771b74845009a9a0addd70 /source/QXmppRemoteMethod.cpp | |
| parent | 5b0870ddaac421af2639058648a218c7061cdd6f (diff) | |
| download | qxmpp-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.cpp | 51 |
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(); + } +} |
