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, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 **************************************************************************/
20
21#ifndef CONN_STATES_H_
22#define CONN_STATES_H_
23
24#include <string>
25#include <unordered_map>
26#include <vector>
27
28#include "observable_evtvar.h"
31#include "model/comm_navmsg.h"
32
38enum class ConnState { Disabled, NoStats, NoData, Unavailable, Ok };
39
40const std::unordered_map<ConnState, std::string> ConnStateToString = {
41 {ConnState::Disabled, "Disabled"},
42 {ConnState::NoStats, "NoStats"},
43 {ConnState::NoData, "NoData"},
44 {ConnState::Unavailable, "Unavailable"},
45 {ConnState::Ok, "Ok"}};
46
48class ConnData {
49public:
50 ConnData() : state(ConnState::NoStats) {}
51
52 ConnState state;
53 struct DriverStats driver_stats;
54
55 [[nodiscard]] bool IsDriverStatsMatch(const DriverStats& ds) const;
56 [[nodiscard]] bool IsDriverMatch(NavAddr::Bus bus,
57 const std::string& iface) const;
58 std::string to_string();
59};
60
66public:
67 ConnStates();
68 ConnStates(const ConnStates&) = delete;
69
72
73 void HandleDriverStats(const struct DriverStats& stats);
74 ConnState GetDriverState(NavAddr::Bus bus, const std::string& iface);
75
76private:
77 ObsListener m_driverlist_lstnr;
78 ObsListener m_driverstat_lstnr;
79 std::vector<ConnData> m_states;
80
82 void OnDriverListChange(const ObservedEvt& ev);
83
84 void OnDriverStats(const ObservedEvt& ev);
85};
86
87#endif // CONN_STATES_H_
Runtime data for a driver and thus connection.
Definition conn_states.h:48
Filter reading driver driver_stats status reports from CommDriverRegistry transforming these to a str...
Definition conn_states.h:65
EventVar evt_conn_status_change
Notified with a shared_ptr<ConnData> when the state is changed.
Definition conn_states.h:71
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:228
Adds a std::shared<void> element to wxCommandEvent.
Driver registration container, a singleton.
Communication statistics infrastructure.
Raw, undecoded messages definitions.
Driver statistics report.