From b256886a5cb9f2ae3ebda70a2045b19ed9f4233e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 3 Dec 2017 22:23:08 +0100 Subject: api: add status check for modules --- proto-udp/ftnoir_ftncontrols.ui | 399 ++++++++++++++----------------- proto-udp/ftnoir_protocol_ftn.cpp | 28 ++- proto-udp/ftnoir_protocol_ftn.h | 13 +- proto-udp/ftnoir_protocol_ftn_dialog.cpp | 4 +- 4 files changed, 215 insertions(+), 229 deletions(-) (limited to 'proto-udp') diff --git a/proto-udp/ftnoir_ftncontrols.ui b/proto-udp/ftnoir_ftncontrols.ui index 28f8ccdf..d6a4dfce 100644 --- a/proto-udp/ftnoir_ftncontrols.ui +++ b/proto-udp/ftnoir_ftncontrols.ui @@ -9,15 +9,15 @@ 0 0 - 411 - 169 + 372 + 106 UDP protocol settings - + :/images/facetracknoir.png:/images/facetracknoir.png @@ -26,222 +26,176 @@ false - - - - - - - - 60 - 16777215 - - - - 255 - - - 1 - - - - - - - - 60 - 16777215 - - - - 255 - - - 1 - - - - - - - - 60 - 16777215 - - - - 255 - - - 1 - - - - - - - - 60 - 16777215 - - - - 255 - - - 1 - - - - - - - IP-address remote PC - - - - - - - Port-number - - - - - - - 1000 - - - 10000 - - - - - - - - - Qt::Vertical + + + + + + 0 + 0 + - - - 20 - 40 - + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - Enter IP-address and port-number for the remote PC. - - - true - - - - - - - Remember: you may have to change firewall-settings too! - - - - + - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QLayout::SetDefaultConstraint - - - - - - 0 - 0 - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - OK - - - - - - - - 0 - 0 - + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 22 + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + + 12 - - - 100 - 0 - + + 0 - - - 100 - 16777215 - + + 0 - - Cancel + + 0 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - + + + + + 60 + 16777215 + + + + 255 + + + 1 + + + + + + + + 60 + 16777215 + + + + 255 + + + 1 + + + + + + + + 60 + 16777215 + + + + 255 + + + 1 + + + + + + + + 60 + 16777215 + + + + 255 + + + 1 + + + + + + + + + + + 0 + 0 + + + + 1024 + + + 65535 + + + + + + + + 0 + 0 + + + + Remote IP address + + + + + + + + 0 + 0 + + + + Port + + + + + @@ -251,13 +205,28 @@ spinIPThirdNibble spinIPFourthNibble spinPortNumber - btnOK - btnCancel - + + + + 5 + + + 5 + + + true + + + true + + + false + + startEngineClicked() stopEngineClicked() diff --git a/proto-udp/ftnoir_protocol_ftn.cpp b/proto-udp/ftnoir_protocol_ftn.cpp index b659e3b5..a1f445f0 100644 --- a/proto-udp/ftnoir_protocol_ftn.cpp +++ b/proto-udp/ftnoir_protocol_ftn.cpp @@ -14,21 +14,29 @@ udp::udp() { + set_dest_address(); + QObject::connect(s.b.get(), &bundle_::changed, this, &udp::set_dest_address); } void udp::pose(const double *headpose) { - int destPort = s.port; - QHostAddress destIP(QString("%1.%2.%3.%4").arg( - QString::number(static_cast(s.ip1)), - QString::number(static_cast(s.ip2)), - QString::number(static_cast(s.ip3)), - QString::number(static_cast(s.ip4)))); - outSocket.writeDatagram((const char *) headpose, sizeof( double[6] ), destIP, destPort); + outSocket.writeDatagram((const char *) headpose, sizeof(double[6]), dest_ip, dest_port); } -bool udp::correct() -{ - return outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); +void udp::set_dest_address() +{ + dest_port = s.port; + dest_ip = QHostAddress((s.ip1.to() & 0xff) << 24 | + (s.ip2.to() & 0xff) << 16 | + (s.ip3.to() & 0xff) << 8 | + (s.ip4.to() & 0xff) << 0 ); +} + +module_status udp::check_status() +{ + if (outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) + return status_ok(); + else + return error(tr("Can't bind socket: %1").arg(outSocket.errorString())); } OPENTRACK_DECLARE_PROTOCOL(udp, FTNControls, udpDll) diff --git a/proto-udp/ftnoir_protocol_ftn.h b/proto-udp/ftnoir_protocol_ftn.h index b234cd89..7838f01a 100644 --- a/proto-udp/ftnoir_protocol_ftn.h +++ b/proto-udp/ftnoir_protocol_ftn.h @@ -31,11 +31,13 @@ struct settings : opts { {} }; -class udp : public IProtocol +class udp : public QObject, public IProtocol { + Q_OBJECT + public: udp(); - bool correct(); + module_status check_status() override; void pose(const double *headpose); QString game_name() { return QCoreApplication::translate("udp_proto", "UDP over network"); @@ -43,12 +45,19 @@ public: private: QUdpSocket outSocket; settings s; + + QHostAddress dest_ip { 127u << 24 | 1u }; + unsigned short dest_port = 65535; + +private slots: + void set_dest_address(); }; // Widget that has controls for FTNoIR protocol client-settings. class FTNControls: public IProtocolDialog { Q_OBJECT + public: FTNControls(); void register_protocol(IProtocol *) {} diff --git a/proto-udp/ftnoir_protocol_ftn_dialog.cpp b/proto-udp/ftnoir_protocol_ftn_dialog.cpp index 70416a69..51ce483c 100644 --- a/proto-udp/ftnoir_protocol_ftn_dialog.cpp +++ b/proto-udp/ftnoir_protocol_ftn_dialog.cpp @@ -21,8 +21,8 @@ FTNControls::FTNControls() tie_setting(s.ip4, ui.spinIPFourthNibble); tie_setting(s.port, ui.spinPortNumber); - connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); - connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); + connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &FTNControls::doOK); + connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &FTNControls::doCancel); } // -- cgit v1.2.3