OpenCPN Partial API docs
Loading...
Searching...
No Matches
conn_states.h
Go to the documentation of this file.
1
2/***************************************************************************
3 * Copyright (C) 2024 Alec Leamas *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef CONN_STATES_H_
26#define CONN_STATES_H_
27
28#include <string>
29#include <unordered_map>
30#include <vector>
31
32#include "observable_evtvar.h"
35#include "model/comm_navmsg.h"
36
37enum class ConnState { Disabled, NoStats, NoData, Unavailable, Ok };
38
39const std::unordered_map<ConnState, std::string> ConnStateToString = {
40 {ConnState::Disabled, "Disabled"},
41 {ConnState::NoStats, "NoStats"},
42 {ConnState::NoData, "NoData"},
43 {ConnState::Unavailable, "Unavailable"},
44 {ConnState::Ok, "Ok"}};
45
47class ConnData {
48public:
49 ConnData() : state(ConnState::NoStats) {}
50
51 ConnState state;
52 struct DriverStats driver_stats;
53
54 [[nodiscard]] bool IsDriverStatsMatch(const DriverStats& ds) const;
55 [[nodiscard]] bool IsDriverMatch(NavAddr::Bus bus,
56 const std::string& iface) const;
57 std::string to_string();
58};
59
65public:
66 ConnStates();
67 ConnStates(const ConnStates&) = delete;
68
71
72 void HandleDriverStats(const struct DriverStats& stats);
73 ConnState GetDriverState(NavAddr::Bus bus, const std::string& iface);
74
75private:
76 ObsListener m_driverlist_lstnr;
77 ObsListener m_driverstat_lstnr;
78 std::vector<ConnData> m_states;
79
81 void OnDriverListChange(const ObservedEvt& ev);
82
83 void OnDriverStats(const ObservedEvt& ev);
84};
85
86#endif // CONN_STATES_H_
Runtime data for a driver and thus connection.
Definition conn_states.h:47
Filter reading driver driver_stats status reports from CommDriverRegistry transforming these to a str...
Definition conn_states.h:64
EventVar evt_conn_status_change
Notified with a shared_ptr<ConnData> when the state is changed.
Definition conn_states.h:70
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:257
Custom event class for OpenCPN's notification system.
Driver registration container, a singleton.
Communication statistics infrastructure.
Raw, undecoded messages definitions.
A common variable shared between producer and consumer which supports Listen() and Notify().
Driver statistics report.