From ceafe544919a35f674684c2e71593b9fb35747a5 Mon Sep 17 00:00:00 2001 From: Javier Date: Sat, 26 Dec 2015 20:02:47 +0100 Subject: prepare new agent for music controller --- libwatchfish | 2 +- main.cc | 2 ++ musicagent.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ musicagent.h | 26 ++++++++++++++++++++++++++ musicconn.cc | 30 ++++++++++++++++++++++++++++++ musicconn.h | 26 ++++++++++++++++++++++++++ sapd.pro | 8 ++++++-- webproxyagent.cc | 1 - 8 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 musicagent.cc create mode 100644 musicagent.h create mode 100644 musicconn.cc create mode 100644 musicconn.h diff --git a/libwatchfish b/libwatchfish index b91c2c3..ffeca2b 160000 --- a/libwatchfish +++ b/libwatchfish @@ -1 +1 @@ -Subproject commit b91c2c3aff5c91d6afb2b9fa2f3ceceaf0642d24 +Subproject commit ffeca2b8740fba10e916fe04e89ef2fd5c606a90 diff --git a/main.cc b/main.cc index 71d2b9f..b6538ea 100644 --- a/main.cc +++ b/main.cc @@ -9,6 +9,7 @@ #include "hostmanageragent.h" #include "webproxyagent.h" #include "notificationagent.h" +#include "musicagent.h" using std::cerr; using std::endl; @@ -47,6 +48,7 @@ int main(int argc, char *argv[]) HostManagerAgent::registerServices(manager); WebProxyAgent::registerServices(manager); NotificationAgent::registerServices(manager); + MusicAgent::registerServices(manager); QScopedPointer sap_listener(new SAPBTListener); diff --git a/musicagent.cc b/musicagent.cc new file mode 100644 index 0000000..5d7836a --- /dev/null +++ b/musicagent.cc @@ -0,0 +1,55 @@ +#include "sapsocket.h" +#include "sapconnectionrequest.h" +#include "sapserviceinfo.h" +#include "sapchannelinfo.h" +#include "musicconn.h" +#include "musicagent.h" + +static MusicAgent *agent = 0; +static const QLatin1String music_profile("/system/music"); + +MusicAgent::MusicAgent(QObject *parent) + : QObject(parent), _peer(0), _socket(0) +{ +} + +MusicAgent* MusicAgent::instance() +{ + if (!agent) { + agent = new MusicAgent; + } + return agent; +} + +void MusicAgent::peerFound(SAPPeer *peer) +{ +} + +void MusicAgent::requestConnection(SAPConnectionRequest *request) +{ + qDebug() << "MusicAgent request connection from" << request->peer()->peerName(); + SAPConnection *conn = request->connection(); + new MusicConn(conn, this); + request->accept(); +} + +void MusicAgent::registerServices(SAPManager *manager) +{ + SAPServiceInfo service; + SAPChannelInfo channel; + + service.setProfile(music_profile); + service.setFriendlyName("Media controller"); + service.setRole(SAPServiceInfo::RoleConsumer); + service.setVersion(1, 0); + service.setConnectionTimeout(0); + + channel.setChannelId(100); + channel.setPayloadType(SAPChannelInfo::PayloadJson); + channel.setQoSType(SAPChannelInfo::QoSReliabilityDisable); + channel.setQoSDataRate(SAPChannelInfo::QoSDataRateLow); + channel.setQoSPriority(SAPChannelInfo::QoSPriorityLow); + service.addChannel(channel); + + manager->registerServiceAgent(service, instance()); +} diff --git a/musicagent.h b/musicagent.h new file mode 100644 index 0000000..32121d4 --- /dev/null +++ b/musicagent.h @@ -0,0 +1,26 @@ +#ifndef MUSICAGENT_H +#define MUSICAGENT_H + +#include +#include "sappeer.h" +#include "sapmanager.h" +#include "sapagent.h" + +class MusicAgent : public QObject, public SAPAgent +{ +public: + explicit MusicAgent(QObject *parent = 0); + +public: + static MusicAgent * instance(); + static void registerServices(SAPManager *manager); + + void peerFound(SAPPeer *peer); + void requestConnection(SAPConnectionRequest *request); + +private: + SAPPeer *_peer; + SAPSocket *_socket; +}; + +#endif // MUSICAGENT_H diff --git a/musicconn.cc b/musicconn.cc new file mode 100644 index 0000000..256e6a8 --- /dev/null +++ b/musicconn.cc @@ -0,0 +1,30 @@ +#include + +#include "sappeer.h" +#include "musicconn.h" + +#if SAILFISH +#include "libwatchfish/musiccontroller.h" + +static watchfish::MusicController *controller = 0; +#endif + +MusicConn::MusicConn(SAPConnection *conn, QObject *parent) + : QObject(parent), _conn(conn), _socket(conn->getSocket(100)) +{ + connect(_conn, SIGNAL(disconnected()), SLOT(deleteLater())); + connect(_conn, SIGNAL(destroyed()), SLOT(deleteLater())); + Q_ASSERT(_socket); + connect(_socket, SIGNAL(connected()), SLOT(handleConnected())); + connect(_socket, SIGNAL(messageReceived()), SLOT(handleMessageReceived())); +} + +void MusicConn::handleConnected() +{ + +} + +void MusicConn::handleMessageReceived() +{ + +} diff --git a/musicconn.h b/musicconn.h new file mode 100644 index 0000000..a38bf94 --- /dev/null +++ b/musicconn.h @@ -0,0 +1,26 @@ +#ifndef MUSICCONN_H +#define MUSICCONN_H + +#include +#include "sapconnection.h" +#include "sapsocket.h" + +class MusicConn : public QObject +{ + Q_OBJECT + +public: + MusicConn(SAPConnection *conn, QObject *parent = 0); + +protected: + +private slots: + void handleConnected(); + void handleMessageReceived(); + +private: + SAPConnection *_conn; + SAPSocket *_socket; +}; + +#endif // MUSICCONN_H diff --git a/sapd.pro b/sapd.pro index 2ca4132..f52821a 100644 --- a/sapd.pro +++ b/sapd.pro @@ -59,7 +59,9 @@ SOURCES += main.cc \ notificationconn.cc \ webproxyagent.cc \ webproxyconn.cc \ - webproxytrans.cc + webproxytrans.cc \ + musicagent.cc \ + musicconn.cc HEADERS += \ sapbtlistener.h \ @@ -86,7 +88,9 @@ HEADERS += \ endianhelpers.h \ webproxyagent.h \ webproxyconn.h \ - webproxytrans.h + webproxytrans.h \ + musicagent.h \ + musicconn.h OTHER_FILES += \ rpm/sapd.yaml \ diff --git a/webproxyagent.cc b/webproxyagent.cc index 126cd75..0b1a753 100644 --- a/webproxyagent.cc +++ b/webproxyagent.cc @@ -23,7 +23,6 @@ WebProxyAgent* WebProxyAgent::instance() void WebProxyAgent::peerFound(SAPPeer *peer) { - qDebug() << "WebProxy peer found" << peer->peerName(); } void WebProxyAgent::requestConnection(SAPConnectionRequest *request) -- cgit v1.2.3