-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtcpinterface.cpp
More file actions
41 lines (38 loc) · 1.08 KB
/
Copy pathtcpinterface.cpp
File metadata and controls
41 lines (38 loc) · 1.08 KB
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
#include "tcpinterface.h"
#include <QDebug>
RemoteControlSocket::RemoteControlSocket(uint16_t port) : server() {
server.listen(QHostAddress::Any, port);
connect(&server, &QTcpServer::newConnection, this, &RemoteControlSocket::addClient);
}
void RemoteControlSocket::addClient() {
auto *client = server.nextPendingConnection();
clients.push_back(client);
connect(client, &QTcpSocket::readyRead, this, [this, client]() {
while(client->canReadLine())
this->handleLine(client->readLine().trimmed(), client);
});
}
void RemoteControlSocket::handleLine(QString s, QTcpSocket *sock) {
qInfo() << s;
if (s == "start")
emit start();
else if (s == "stop")
emit stop();
else if (s == "update")
emit refresh_streams();
else if (s.contains("filename")) {
emit filename(s);
} else if (s.contains("select")) {
if (s.contains("all")) {
emit select_all();
} else if (s.contains("none")) {
emit select_none();
}
}
sock->write("OK");
// TODO: select /deselect streams
// TODO: send acknowledgement
// TODO: get current state
//
// else this->sender()->sender("Whoops");
}