diff options
author | 2022-06-16 00:28:36 -0400 | |
---|---|---|
committer | 2022-06-17 21:48:19 +0000 | |
commit | 471656151c2b35b0f2f96983c09ffb51aec310eb (patch) | |
tree | 4460e774afcfa16c62a0cfbb4839d625bbf37ca8 /src/vis-session.hpp | |
parent | b071b982c1ec3a53035a25389740f42275272957 (diff) |
Repurpose into VIS clientmarlin
Repurpose repository for a spiritual successor of the previous
binding. The replacement is a daemon that demonstrates servicing
HVAC actuators from the VSS schema via VIS signals from KUKSA.val.
Currently the connection to KUKSA.val is websocket based using the
boost::asio framework, but the plan is to migrate to grpc as that
becomes more robust in KUKSA.val.
Notable changes:
- New code is completely C++, partly to leverage using Boost, but
also to futureproof future work with grpc.
- Switch from CMake to meson for ease of development and some
degree of futureproofing.
- Use with systemd is assumed; behavior follows the systemd
daemon guidelines barring the use of journald logging prefixes,
which may be addressed with future work. A systemd unit is
also installed as part of the build.
- SPDX license headers using SPDX "short identifiers" are used in
source files rather than the full copyright headers used in the
previous codebase. This follows the direction that projects such
as the Linux kernel are going in.
- The JSON configuration file for the LED control files for the
demo platform has been migrated to a INI format configuration
file matching what has been done for the VIS client configuration
in other recent work.
Bug-AGL: SPEC-4409
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: Ic2061bca9670b1e461d6f1e6591471e257fff5b9
Diffstat (limited to 'src/vis-session.hpp')
-rw-r--r-- | src/vis-session.hpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/vis-session.hpp b/src/vis-session.hpp new file mode 100644 index 0000000..8c7b0d9 --- /dev/null +++ b/src/vis-session.hpp @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: Apache-2.0 + +#ifndef _VIS_SESSION_HPP +#define _VIS_SESSION_HPP + +#include "vis-config.hpp" +#include <atomic> +#include <string> +#include <boost/beast/core.hpp> +#include <boost/beast/ssl.hpp> +#include <boost/beast/websocket.hpp> +#include <boost/beast/websocket/ssl.hpp> +#include <boost/asio/strand.hpp> +#include <nlohmann/json.hpp> + +namespace beast = boost::beast; +namespace websocket = beast::websocket; +namespace net = boost::asio; +namespace ssl = boost::asio::ssl; +using tcp = boost::asio::ip::tcp; +using json = nlohmann::json; + + +class VisSession : public std::enable_shared_from_this<VisSession> +{ + //net::io_context m_ioc; + tcp::resolver m_resolver; + tcp::resolver::results_type m_results; + std::string m_hostname; + websocket::stream<beast::ssl_stream<beast::tcp_stream>> m_ws; + beast::flat_buffer m_buffer; + +public: + // Resolver and socket require an io_context + explicit VisSession(const VisConfig &config, net::io_context& ioc, ssl::context& ctx); + + // Start the asynchronous operation + void run(); + +protected: + VisConfig m_config; + std::atomic_uint m_requestid; + + void on_resolve(beast::error_code error, tcp::resolver::results_type results); + + void connect(); + + void on_connect(beast::error_code error, tcp::resolver::results_type::endpoint_type endpoint); + + void on_ssl_handshake(beast::error_code error); + + void on_handshake(beast::error_code error); + + void on_authorize(beast::error_code error, std::size_t bytes_transferred); + + void on_write(beast::error_code error, std::size_t bytes_transferred); + + void on_read(beast::error_code error, std::size_t bytes_transferred); + + void get(const std::string &path); + + void set(const std::string &path, const std::string &value); + + void subscribe(const std::string &path); + + void handle_message(const json &message); + + bool parseData(const json &message, std::string &path, std::string &value, std::string ×tamp); + + virtual void handle_authorized_response(void) = 0; + + virtual void handle_get_response(std::string &path, std::string &value, std::string ×tamp) = 0; + + virtual void handle_notification(std::string &path, std::string &value, std::string ×tamp) = 0; + +}; + +#endif // _VIS_SESSION_HPP |