Showing the changes to interface/src/scripting/OSCScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -185,7 +185,7 @@ OSCScriptingInterface::OSCScriptingInterface(QObject* parent) : · 184 unmodified lines | |||
| 185 | 185 | ||
| 186 | connect(_socket.get(), &QUdpSocket::readyRead, this, &OSCScriptingInterface::readPacket); | 186 | connect(_socket.get(), &QUdpSocket::readyRead, this, &OSCScriptingInterface::readPacket); |
| 187 | 187 | ||
| 188 | qCInfo(osc_cat) << "Listening on" << _socket->localAddress(); | 188 | qCInfo(osc_cat) << "Listening on" << _socket->localAddress() << ":" << _socket->localPort(); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | OSCScriptingInterface::~OSCScriptingInterface() { | 191 | OSCScriptingInterface::~OSCScriptingInterface() { |
| @@ -193,6 +193,11 @@ OSCScriptingInterface::~OSCScriptingInterface() { · 1 unmodified line | |||
| 193 | qCInfo(osc_cat) << "Closed listen socket"; | 193 | qCInfo(osc_cat) << "Closed listen socket"; |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | void OSCScriptingInterface::rebindSocket() { | ||
| 197 | _socket->bind(QHostAddress(_sendHost.get()), _sendPort.get()); | ||
| 198 | qCInfo(osc_cat) << "Listening on" << _socket->localAddress() << ":" << _socket->localPort(); | ||
| 199 | } | ||
| 200 | |||
| 196 | void OSCScriptingInterface::readPacket() { | 201 | void OSCScriptingInterface::readPacket() { |
| 197 | auto datagram = _socket->receiveDatagram(); | 202 | auto datagram = _socket->receiveDatagram(); |
| 198 | 203 | ||
| @@ -472,3 +477,41 @@ ScriptValue OSCScriptingInterface::sendPacket(ScriptContext* context, ScriptEngi · 273 unmodified lines | |||
| 472 | 477 | ||
| 473 | return engine->undefinedValue(); | 478 | return engine->undefinedValue(); |
| 474 | } | 479 | } |
| 480 | |||
| 481 | void OSCScriptingInterface::setReceiveHost(QString host) { | ||
| 482 | QHostAddress address; | ||
| 483 | |||
| 484 | // only save if it's a valid address | ||
| 485 | if (address.setAddress(host)) { | ||
| 486 | _receiveHost.set(host); | ||
| 487 | rebindSocket(); | ||
| 488 | } | ||
| 489 | } | ||
| 490 | |||
| 491 | void OSCScriptingInterface::setSendHost(QString host) { | ||
| 492 | QHostAddress address; | ||
| 493 | |||
| 494 | // only save if it's a valid address | ||
| 495 | if (address.setAddress(host)) { | ||
| 496 | _sendHost.set(host); | ||
| 497 | } | ||
| 498 | } | ||
| 499 | |||
| 500 | void OSCScriptingInterface::setSendPort(int port) { | ||
| 501 | if (port < 1 || port > 65535) { | ||
| 502 | qCritical(osc_cat) << "setSendPort: invalid port" << port; | ||
| 503 | return; | ||
| 504 | } | ||
| 505 | |||
| 506 | _sendPort.set(port); | ||
| 507 | } | ||
| 508 | |||
| 509 | void OSCScriptingInterface::setReceivePort(int port) { | ||
| 510 | if (port < 1024 || port > 65535) { | ||
| 511 | qCritical(osc_cat) << "setReceivePort: invalid port" << port; | ||
| 512 | return; | ||
| 513 | } | ||
| 514 | |||
| 515 | _receivePort.set(port); | ||
| 516 | rebindSocket(); | ||
| 517 | } | ||