-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathtcpinterface.cpp
More file actions
51 lines (48 loc) · 1.44 KB
/
tcpinterface.cpp
File metadata and controls
51 lines (48 loc) · 1.44 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
42
43
44
45
46
47
48
49
50
51
#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 all"))
emit select_all();
else if (s.contains("select none"))
emit select_none();
else if (s.contains("select")) {
QString search_str = s.mid(7).trimmed(); // Assuming "select" is 7 characters long
if (!search_str.isEmpty()) {
emit select_stream(search_str);
}
}
else if (s.contains("regexselect")) {
QString regexPattern = s.mid(12).trimmed(); // Assuming "regexselect" is 12 characters long
if (!regexPattern.isEmpty()) {
emit select_stream_regex(regexPattern);
}
}
sock->write("OK");
// TODO: select /deselect streams
// TODO: send acknowledgement
// TODO: get current state
//
// else this->sender()->sender("Whoops");
}