Reimplemented broadcaster so it can send 503 when a connection is in

place.
Removed qcma/cmaserver class and reimplemented them in cmaclient.
Make sure that the scanned files are sorted by filename.
Implement filters so the database doesn't pick up unsupported formats.
Implement album cover display for album listing in the vita.
Fixed bug with streaming of pictures in wireless mode.
Some code refactoring.
This commit is contained in:
codestation
2013-08-19 09:46:03 -04:30
parent 0d8c0a2b24
commit d93de053e9
18 changed files with 581 additions and 269 deletions

101
cmabroadcast.cpp Normal file
View File

@@ -0,0 +1,101 @@
/*
* QCMA: Cross-platform content manager assistant for the PS Vita
*
* Copyright (C) 2013 Codestation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cmabroadcast.h"
#include <QDebug>
#include <QHostInfo>
#include <QMutexLocker>
#include <QSettings>
#include <QUuid>
#include <vitamtp.h>
const QString CmaBroadcast::broadcast_reply =
"%1\r\n"
"host-id:%2\r\n"
"host-type:%3\r\n"
"host-name:%4\r\n"
"host-mtp-protocol-version:%5\r\n"
"host-request-port:%6\r\n"
"host-wireless-protocol-version:%7\r\n";
const char *CmaBroadcast::broadcast_query = "SRCH * HTTP/1.1\r\n";
const char *CmaBroadcast::broadcast_ok = "HTTP/1.1 200 OK";
const char *CmaBroadcast::broadcast_unavailable = "HTTP/1.1 503 NG";
CmaBroadcast::CmaBroadcast(QObject *parent) :
QObject(parent)
{
QSettings settings;
// generate a GUID if doesn't exist yet in settings
uuid = settings.value("guid").toString();
if(uuid.isEmpty()) {
uuid = QUuid::createUuid().toString();
settings.setValue("guid", uuid);
}
hostname = QHostInfo::localHostName();
setAvailable();
socket = new QUdpSocket(this);
socket->bind(QHostAddress::Any, QCMA_REQUEST_PORT);
connect(socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
}
void CmaBroadcast::readPendingDatagrams()
{
if(socket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(socket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
socket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
if(datagram.contains(broadcast_query)) {
QMutexLocker locker(&mutex);
socket->writeDatagram(reply.toUtf8(), sender, senderPort);
} else {
qWarning("Unknown request: %.*s\n", datagram.length(), datagram.constData());
}
}
}
void CmaBroadcast::setAvailable()
{
QMutexLocker locker(&mutex);
reply = broadcast_reply
.arg(broadcast_ok, uuid, "win", hostname)
.arg(VITAMTP_PROTOCOL_MAX_VERSION, 8, 10, QChar('0'))
.arg(QCMA_REQUEST_PORT)
.arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0'));
}
void CmaBroadcast::setUnavailable()
{
QMutexLocker locker(&mutex);
reply = broadcast_reply
.arg(broadcast_unavailable, uuid, "win", hostname)
.arg(VITAMTP_PROTOCOL_MAX_VERSION, 8, 10, QChar('0'))
.arg(QCMA_REQUEST_PORT)
.arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0'));
}