Sync libxrme.

This commit is contained in:
John Maguire 2011-03-01 14:34:06 +00:00
parent 7f48896aa6
commit a3b78a0043
6 changed files with 129 additions and 11 deletions

View File

@ -1,9 +1,9 @@
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../gloox/src)
set(SOURCES
common.cpp
connection.cpp
extensions.cpp
handler.cpp
mediaplayerhandler.cpp
mediaplayerinterface.cpp

View File

@ -17,6 +17,7 @@
#include "common.h"
#include "connection.h"
#include "extensions.h"
#include "mediaplayerhandler.h"
#include "remotecontrolhandler.h"
@ -47,7 +48,9 @@ struct Connection::Private : public gloox::ConnectionListener,
verbose_(false),
media_player_(NULL),
remote_control_(NULL),
spontaneous_disconnect_(true) {}
spontaneous_disconnect_(true),
media_player_extension_(new MediaPlayerExtension()),
remote_control_extension_(new RemoteControlExtension()) {}
static const char* kDefaultServer;
static const char* kDefaultJIDResource;
@ -73,6 +76,9 @@ struct Connection::Private : public gloox::ConnectionListener,
QScopedPointer<gloox::Client> client_;
QScopedPointer<QSocketNotifier> socket_notifier_;
MediaPlayerExtension* media_player_extension_;
RemoteControlExtension* remote_control_extension_;
// After discovering a peer we query it to find its capabilities. Only after
// it replies to the query do we put it in peers_ and emit PeerFound().
QList<Peer> peers_;
@ -245,6 +251,9 @@ bool Connection::Connect() {
d->client_->disco()->setVersion(d->agent_name_.toUtf8().constData(), std::string());
d->client_->disco()->addFeature(kXmlnsXrme);
d->client_->registerStanzaExtension(d->media_player_extension_);
d->client_->registerStanzaExtension(d->remote_control_extension_);
// Initialise the handlers
foreach (Handler* handler, d->handlers_) {
handler->Init(this, d->client_.data());

10
3rdparty/libxrme/extensions.cpp vendored Normal file
View File

@ -0,0 +1,10 @@
#include "extensions.h"
namespace xrme {
const char* MediaPlayerExtension::kFilterString =
"/iq/xrme[@xmlns='http://purplehatstands.com/xmlns/xrme/mediaplayer']";
const char* RemoteControlExtension::kFilterString =
"/iq/xrme[@xmlns='http://purplehatstands.com/xmlns/xrme/remotecontrol']";
}

92
3rdparty/libxrme/extensions.h vendored Normal file
View File

@ -0,0 +1,92 @@
#ifndef EXTENSIONS_H
#define EXTENSIONS_H
#include <gloox/stanzaextension.h>
#include <gloox/tag.h>
#include "common.h"
namespace xrme {
template <typename T>
class XRMEExtension : public gloox::StanzaExtension {
public:
XRMEExtension();
// gloox::StanzaExtension
const std::string& filterString() const;
StanzaExtension* newInstance(const gloox::Tag* tag) const;
gloox::Tag* tag() const;
StanzaExtension* clone() const;
int extension_type() const {
return T::kExtensionType;
}
protected:
explicit XRMEExtension(const gloox::Tag* tag);
explicit XRMEExtension(const XRMEExtension& other);
static const char* kMediaPlayerFilterString;
static const char* kRemoteControlFilterString;
const std::string filter_string_;
const gloox::Tag* tag_;
};
class RemoteControlExtension : public XRMEExtension<RemoteControlExtension> {
public:
static const int kExtensionType = gloox::ExtUser + 1;
static const char* kFilterString;
};
class MediaPlayerExtension : public XRMEExtension<MediaPlayerExtension> {
public:
static const int kExtensionType = gloox::ExtUser + 2;
static const char* kFilterString;
};
template <typename T>
XRMEExtension<T>::XRMEExtension()
: StanzaExtension(T::kExtensionType),
filter_string_(T::kFilterString),
tag_(NULL) {
}
template <typename T>
const std::string& XRMEExtension<T>::filterString() const {
return filter_string_;
}
template <typename T>
gloox::StanzaExtension* XRMEExtension<T>::newInstance(const gloox::Tag* tag) const {
return new XRMEExtension(tag);
}
template <typename T>
gloox::Tag* XRMEExtension<T>::tag() const {
return tag_ ? tag_->clone() : NULL;
}
template <typename T>
gloox::StanzaExtension* XRMEExtension<T>::clone() const {
return new XRMEExtension(*this);
}
template <typename T>
XRMEExtension<T>::XRMEExtension(const gloox::Tag* tag)
: StanzaExtension(T::kExtensionType),
filter_string_(T::kFilterString),
tag_(tag) {
}
template <typename T>
XRMEExtension<T>::XRMEExtension(const XRMEExtension& other)
: StanzaExtension(T::kExtensionType),
filter_string_(T::kFilterString),
tag_(other.tag_) {
}
} // namespace xrme
#endif // EXTENSIONS_H

View File

@ -123,7 +123,8 @@ void MediaPlayerHandler::AlbumArtChanged() {
void MediaPlayerHandler::Init(Connection* connection, gloox::Client* client) {
Handler::Init(connection, client);
client->registerIqHandler(this, XRMEExtension::kExtensionType);
client->registerIqHandler(
this, MediaPlayerExtension::kExtensionType);
client->disco()->addFeature(kXmlnsXrmeMediaPlayer);
}
@ -134,15 +135,17 @@ bool MediaPlayerHandler::handleIq(const gloox::IQ& stanza) {
return false;
}
if (stanza.tag()->hasChild("playpause")) {
gloox::Tag* xrme = stanza.tag()->findChild("xrme");
if (xrme->hasChild("playpause")) {
interface_->PlayPause();
} else if (stanza.tag()->hasChild("stop")) {
} else if (xrme->hasChild("stop")) {
interface_->Stop();
} else if (stanza.tag()->hasChild("previous")) {
} else if (xrme->hasChild("previous")) {
interface_->Previous();
} else if (stanza.tag()->hasChild("next")) {
} else if (xrme->hasChild("next")) {
interface_->Next();
} else if (stanza.tag()->hasChild("querystate")) {
} else if (xrme->hasChild("querystate")) {
StateChanged();
AlbumArtChanged();
} else {

View File

@ -36,7 +36,8 @@ RemoteControlHandler::RemoteControlHandler(RemoteControlInterface* interface)
void RemoteControlHandler::Init(Connection* connection, gloox::Client* client) {
Handler::Init(connection, client);
client->registerIqHandler(this, XRMEExtension::kExtensionType);
client->registerIqHandler(
this, RemoteControlExtension::kExtensionType);
client->disco()->addFeature(kXmlnsXrmeRemoteControl);
}
@ -92,6 +93,7 @@ QString RemoteControlHandler::ParseString(gloox::Tag* tag, const char* attribute
}
bool RemoteControlHandler::handleIq(const gloox::IQ& stanza) {
qDebug() << Q_FUNC_INFO << stanza.tag()->xml().c_str();
// Ignore stanzas from anyone else
if (stanza.from().bareJID() != client_->jid().bareJID()) {
return false;
@ -101,7 +103,9 @@ bool RemoteControlHandler::handleIq(const gloox::IQ& stanza) {
qDebug() << resource << stanza.tag()->xml().c_str();
gloox::Tag* state = stanza.tag()->findChild("state");
gloox::Tag* xrme = stanza.tag()->findChild("xrme");
gloox::Tag* state = xrme->findChild("state");
if (state) {
gloox::Tag* metadata = state->findChild("metadata");
if (metadata) {
@ -129,7 +133,7 @@ bool RemoteControlHandler::handleIq(const gloox::IQ& stanza) {
}
}
gloox::Tag* album_art = stanza.tag()->findChild("album_art");
gloox::Tag* album_art = xrme->findChild("album_art");
if (album_art) {
QByteArray data(album_art->cdata().c_str(), album_art->cdata().size());