-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathqserver.cpp
52 lines (37 loc) · 1.56 KB
/
qserver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "qserver.h"
QServer::QServer(QObject *parent) :
QTcpServer(parent) {
}
void QServer::incomingConnection(qintptr socketDescriptor) {
qDebug() << "Incoming connection... " << endl;
QServerChildThread *clientConnectionThread = new QServerChildThread(socketDescriptor, this);
QObject::connect(clientConnectionThread, SIGNAL(playSong(quint32)),
this, SLOT(playSong(quint32)));
QObject::connect(clientConnectionThread, SIGNAL(pauseSong()),
this, SLOT(pauseSong()));
QObject::connect(clientConnectionThread, SIGNAL(setVolume(int)),
this, SLOT(setVolume(int)));
QObject::connect(clientConnectionThread, SIGNAL(stopSong()),
this, SLOT(stopSong()));
QObject::connect(clientConnectionThread, SIGNAL(error(QTcpSocket::SocketError)),
this, SLOT(onClientSocketError(QTcpSocket::SocketError)));
QObject::connect(clientConnectionThread, SIGNAL(finished()),
clientConnectionThread, SLOT(deleteLater()));
clientConnectionThread->start();
}
void QServer::playSong(quint32 songId) {
emit sendCommand(Player::Play, songId);
}
void QServer::pauseSong() {
emit sendCommand(Player::Pause);
}
void QServer::stopSong() {
emit sendCommand(Player::Stop);
}
void QServer::setVolume(int volume) {
emit sendCommand(Player::SetVol, volume);
}
// Handle socket errors or just print them out for now.
void QServer::onClientSocketError(QTcpSocket::SocketError error) {
qDebug() << "Client socket error: " << error << endl;
}