diff options
author | 2023-08-24 15:21:40 -0400 | |
---|---|---|
committer | 2023-08-24 15:58:58 -0400 | |
commit | e6e998428529bb788e2412e84757ad9a0b71fb32 (patch) | |
tree | 732447f581be177a0b181cb1de00c481b82bbda6 /vehicle-signals/QtKuksaClient.h | |
parent | 1234b2771bc45a885df54a779dfb8a125f315f93 (diff) |
Rework vehicle signals support to use KUKSA.val databroker
Rework the VehicleSignals class and its use in the Navigation and
Hvac classes to switch from using the original KUKSA.val server
via WebSockets to the KUKSA.val databroker's gRPC "VAL" API.
Notable changes:
- The VehicleSignals API has changed a bit with respect to setting
signals, callers now need to pass the new value as the type that
matches the signal as opposed to always passing a string, and
optionally indicate if an actuator's target or value is being set.
Subscribe operations now also allow subscribing for either
actuator targets or values.
- It is possible that the values returned by get and subscribe
operations will be changed to using QVariant instead of QStrings
in a future follow up, but that has not been done in these changes.
- The connected signal from VehicleSignals still has roughly the
same meaning, but the authorize function and authorized signals
are to some degree redundant now. They have been kept for
compatibility, but may be removed in a follow up set of changes.
- The section header in the .ini files expected by the
VehicleSignalsConfig class has been changed from "vis-client" to
"kuksa-client" since the databroker is not a VIS server, and to
some degree forcing an update on the part of clients is useful
since their authorization tokens also need to change.
- The client key and certificate support has been removed from the
VehicleSignalsConfig class, as they are no longer used in either
the server or databroker as of KUKSA.val 0.4.0. A new optional
parameter, "tls-server-name", has been added to work with the new
TLS support behavior. It can be used to override the expected
host name for connecting to a non-local databroker instance.
- The Navigation constructor now takes an additional parameter to
indicate whether the instance acts as a router or a client.
The underlying need for this stems from an application acting as
a router needing to subscribe to the destination setting actuator
targets.
Bug-AGL: SPEC-4762
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I253480ae2abf068dc6e41a495454960ed5c0feaf
Diffstat (limited to 'vehicle-signals/QtKuksaClient.h')
-rw-r--r-- | vehicle-signals/QtKuksaClient.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/vehicle-signals/QtKuksaClient.h b/vehicle-signals/QtKuksaClient.h new file mode 100644 index 0000000..1f24e09 --- /dev/null +++ b/vehicle-signals/QtKuksaClient.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2023 Konsulko Group + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef QT_KUKSA_CLIENT_H +#define QT_KUKSA_CLIENT_H + +#include <QObject> +#include <QMap> +#include <QMutex> +#include <grpcpp/grpcpp.h> +#include "kuksa/val/v1/val.grpc.pb.h" + +// Just pull in the whole namespace since Datapoint contains a lot of +// definitions that may potentially be needed. +using namespace kuksa::val::v1; + +using grpc::Status; + +#include "VehicleSignalsConfig.h" + +// KUKSA.val databroker gRPC API Qt client class + +class QtKuksaClient : public QObject +{ + Q_OBJECT + +public: + explicit QtKuksaClient(const std::shared_ptr< ::grpc::ChannelInterface>& channel, + const VehicleSignalsConfig &config, + QObject * parent = Q_NULLPTR); + + Q_INVOKABLE void connect(); + + Q_INVOKABLE void get(const QString &path, const bool actuator = false); + + Q_INVOKABLE void set(const QString &path, const QString &value, const bool actuator = false); + Q_INVOKABLE void set(const QString &path, const qint32 value, const bool actuator = false); + Q_INVOKABLE void set(const QString &path, const qint64 value, const bool actuator = false); + Q_INVOKABLE void set(const QString &path, const quint32 value, const bool actuator = false); + Q_INVOKABLE void set(const QString &path, const quint64 value, const bool actuator = false); + Q_INVOKABLE void set(const QString &path, const float value, const bool actuator = false); + Q_INVOKABLE void set(const QString &path, const double value, const bool actuator = false); + + Q_INVOKABLE void subscribe(const QString &path, const bool actuator = false); + Q_INVOKABLE void subscribe(const QMap<QString, bool> &signals_); + +signals: + void connected(); + void getResponse(QString path, QString value, QString timestamp); + void setResponse(QString path, QString error); + void subscribeResponse(QString path, QString value, QString timestamp); + void subscribeDone(const QMap<QString, bool> &signals_, bool canceled); + +private: + class SubscribeReader; + + std::shared_ptr< ::grpc::ChannelInterface> m_channel; + VehicleSignalsConfig m_config; + std::shared_ptr<VAL::Stub> m_stub; + bool m_connected; + QMutex m_connected_mutex; + + void waitForConnected(); + + void set(const QString &path, const Datapoint &dp, const bool actuator); + + void handleGetResponse(const GetResponse *response); + + void handleSetResponse(const SetResponse *response); + + void handleSubscribeResponse(const SubscribeResponse *response); + + void handleSubscribeDone(const QMap<QString, bool> &signals_, const Status &status); + + void handleCriticalFailure(const QString &error); + void handleCriticalFailure(const char *error) { handleCriticalFailure(QString(error)); }; + + void resubscribe(const QMap<QString, bool> &signals_); + + bool convertDatapoint(const Datapoint &dp, QString &value, QString ×tamp); +}; + +#endif // QT_KUKSA_CLIENT_H |