#include "toqmanager.h" #include "obexconnection.h" #include "versionmanager.h" #include "systemmanager.h" #include "fmsmanager.h" #include "storagemanager.h" #include "musicmanager.h" #include "commmanager.h" #include "voicecallmanager.h" #include "weathermanager.h" ToqManager::ToqManager(const QBluetoothAddress &address, QObject *parent) : QObject(parent), _conn(new ToqConnection(address, this)), _obex(new ObexConnection(_conn, this)), _versionManager(new VersionManager(this)), _systemManager(new SystemManager(this)), _fmsManager(new FmsManager(_obex, this)), _storageManager(new StorageManager(_obex, this)), _musicManager(new MusicManager(this)), _commManager(new CommManager(_storageManager, this)), _voiceCallManager(new VoiceCallManager(this)), _weatherManager(new WeatherManager(_fmsManager, this)) { connect(_conn, &ToqConnection::messageReceived, this, &ToqManager::handleToqMessage); connect(_conn, &ToqConnection::connected, this, &ToqManager::connected); connect(_conn, &ToqConnection::disconnected, this, &ToqManager::disconnected); } void ToqManager::setEndpointListener(ToqConnection::Endpoint ep, EndpointHandler *handler) { Q_ASSERT(!_handlers.contains(ep)); _handlers.insert(ep, handler); } void ToqManager::sendMessage(const ToqConnection::Message &msg) { if (1) { QString json = QString::fromUtf8(msg.payload.toJson(QJsonDocument::Compact)); qDebug() << "Sending message to" << ToqConnection::nameOfEndpoint(msg.destination) << "from" << ToqConnection::nameOfEndpoint(msg.source) << "type" << msg.type << json; } _conn->sendMessage(msg); } void ToqManager::sendMessage(ToqConnection::Endpoint source, ToqConnection::Endpoint destination, quint16 transactionId, quint32 type, const QJsonObject &payload) { QJsonDocument doc(payload); ToqConnection::Message msg(source, destination, transactionId, type, doc); sendMessage(msg); } quint16 ToqManager::sendMessage(ToqConnection::Endpoint source, ToqConnection::Endpoint destination, quint32 type, const QJsonObject &payload) { QJsonDocument doc(payload); quint16 transactionId = newTransactionId(); ToqConnection::Message msg(source, destination, transactionId, type, doc); sendMessage(msg); return transactionId; } void ToqManager::sendReply(const ToqConnection::Message &msg, quint32 type, const QJsonObject &payload) { ToqConnection::Message reply(msg.destination, msg.source, msg.transactionId, type, QJsonDocument(payload)); sendMessage(reply); } void ToqManager::handleToqMessage(const ToqConnection::Message &msg) { EndpointHandler *handler = _handlers.value(msg.destination, 0); if (1) { QString json = QString::fromUtf8(msg.payload.toJson(QJsonDocument::Compact)); qDebug() << "Received message to" << ToqConnection::nameOfEndpoint(msg.destination) << "from" << ToqConnection::nameOfEndpoint(msg.destination) << "type" << msg.type << json; } if (handler) { handler->handleMessage(msg); } else { qWarning() << "No registered handler for endpoint" << ToqConnection::nameOfEndpoint(msg.destination); } }