- add new class

- change how signal subscriptions are handled in client
This commit is contained in:
Dorian Zedler 2020-07-11 11:17:20 +02:00
parent c44cd117a8
commit e853e246ab
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
6 changed files with 54 additions and 8 deletions

View file

@ -60,7 +60,10 @@ public:
*
* \brief ScStwClient
*/
explicit ScStwClient(QObject *parent = nullptr);
explicit ScStwClient(
QObject *parent = nullptr,
QList<ScStw::SignalKey> signalSubscriptions = {ScStw::ExtensionsChanged}
);
enum State {DISCONNECTED, CONNECTING, INITIALISING, CONNECTED};
Q_ENUM(State);
@ -76,6 +79,8 @@ private:
QVariantList extensions;
QList<ScStw::SignalKey> signalSubscriptions;
//---general status values---//
// some meta data of the base station
@ -200,6 +205,8 @@ public slots:
*/
void setIP(QString ipAdress);
void addSignalSubscription(ScStw::SignalKey key);
private slots:
/*!
* \brief called when timeout timer times out

View file

@ -0,0 +1,16 @@
#ifndef SCSTWQMLSETTING_H
#define SCSTWQMLSETTING_H
#include <QObject>
class ScStwQmlSetting : public QObject
{
Q_OBJECT
public:
explicit ScStwQmlSetting(QObject *parent = nullptr);
signals:
};
#endif // SCSTWQMLSETTING_H

View file

@ -20,11 +20,12 @@
ScStwClient * pGlobalScStwClient = nullptr;
ScStwClient::ScStwClient(QObject * parent) : QObject(parent)
ScStwClient::ScStwClient(QObject * parent, QList<ScStw::SignalKey> signalSubscriptions) : QObject(parent)
{
this->state = DISCONNECTED;
this->nextConnectionId = 1;
this->extensions = QVariantList({});
this->signalSubscriptions = signalSubscriptions;
this->socket = new QTcpSocket(this);
@ -72,9 +73,13 @@ bool ScStwClient::init() {
this->setState(INITIALISING);
this->timeoutTimer->stop();
QJsonArray signalSubs;
foreach (ScStw::SignalKey key, this->signalSubscriptions) {
signalSubs.append(key);
}
// init remote session
QJsonArray updateSubs = {ScStw::RaceStateChanged, ScStw::TimersChanged, ScStw::ExtensionsChanged, ScStw::NextStartActionChanged};
QJsonObject sessionParams = {{"updateSubs", updateSubs}, {"init", true}, {"usingTerminationKeys", true}};
QJsonObject sessionParams = {{"signalSubscriptions", signalSubs}, {"init", true}, {"usingTerminationKeys", true}};
QVariantMap initResponse = this->sendCommand(1, sessionParams, 3000, false);
@ -368,7 +373,7 @@ void ScStwClient::handleSignal(QVariantMap data) {
ScStw::SignalKey signalKey = ScStw::signalKeyFromInt(data["header"].toInt());
//qDebug() << "got signal: " << signalKey << " with data: " << data["data"];
qDebug() << "got signal: " << signalKey << " with data: " << data["data"];
switch (signalKey) {
case ScStw::ExtensionsChanged:
@ -452,3 +457,9 @@ void ScStwClient::setExtensions(QVariantList extensions) {
emit this->extensionsChanged();
}
}
void ScStwClient::addSignalSubscription(ScStw::SignalKey key) {
if(!this->signalSubscriptions.contains(key))
this->signalSubscriptions.append(key);
}

View file

@ -0,0 +1,6 @@
#include "../../headers/client/scstwqmlsetting.h"
ScStwQmlSetting::ScStwQmlSetting(QObject *parent) : QObject(parent)
{
}

View file

@ -22,6 +22,10 @@ ScStwRemoteMonitorRace::ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObje
{
this->scStwClient = monitorClient;
this->scStwClient->addSignalSubscription(ScStw::RaceStateChanged);
this->scStwClient->addSignalSubscription(ScStw::TimersChanged);
this->scStwClient->addSignalSubscription(ScStw::NextStartActionChanged);
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteMonitorRace::handleClientStateChanged);
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteMonitorRace::handleBaseStationSignal);
}

View file

@ -3,6 +3,7 @@
ScStwRemoteSettings::ScStwRemoteSettings(ScStwClient * scStwClient, QObject * parent) : ScStwSettings(parent)
{
this->scStwClient = scStwClient;
this->scStwClient->addSignalSubscription(ScStw::SettingChanged);
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteSettings::handleBaseStationSignal);
}
@ -25,10 +26,11 @@ bool ScStwRemoteSettings::writeSetting(QString key, QVariant value, int keyInt,
if(this->getMode() == LOCAL || keyLevel > 0)
return ScStwSettings::writeSetting(key, value, keyInt, keyLevel);
this->scStwClient->writeRemoteSetting(ScStwSettings::BaseStationSetting(keyInt), value);
emit this->settingChanged(keyInt, keyLevel);
qDebug() << "changing setting";
ScStw::StatusCode res = this->scStwClient->writeRemoteSetting(ScStwSettings::BaseStationSetting(keyInt), value);
qDebug() << "changed setting " << res;
return true;
return res == ScStw::Success;
}
void ScStwRemoteSettings::setDefaultSetting(QString key, QVariant defaultVariant, int keyInt, int keyLevel) {