OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_drv_stats.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2024 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef _DRIVER_STATS_H
25#define _DRIVER_STATS_H
26
27#include <chrono>
28#include <memory>
29#include <string>
30
31#include "observable/observable.h"
32
33#include "comm_drv_registry.h"
34#include "comm_navmsg.h"
35#include "periodic_timer.h"
36
39 NavAddr::Bus driver_bus;
40 std::string driver_iface;
41 unsigned rx_count;
42 unsigned tx_count;
43 unsigned error_count;
44 bool available;
46 : driver_bus(NavAddr::Bus::Undef),
47 rx_count(0),
48 tx_count(0),
49 error_count(0),
50 available(false) {}
51};
52
59public:
63 virtual ~DriverStatsProvider() = default;
64
70 virtual DriverStats GetDriverStats() const = 0;
71};
72
74class StatsTimer : public PeriodicTimer {
75public:
76 StatsTimer(const DriverStatsProvider& src, std::chrono::milliseconds interval)
77 : PeriodicTimer(interval), m_src(src) {}
78
79protected:
80 const DriverStatsProvider& m_src;
81
82 void Notify() {
83 auto stats_ptr = std::make_shared<DriverStats>(m_src.GetDriverStats());
84 CommDriverRegistry::GetInstance().evt_driver_stats.Notify(stats_ptr, "");
85 };
86};
87
88#endif // DRIVER_STATS_H
obs::EventVar evt_driver_stats
Regularly notified by drivers with a DriverStats shared_ptr.
Driver interface providing driver statistics.
virtual ~DriverStatsProvider()=default
Destroy the Driver Stats Provider object.
virtual DriverStats GetDriverStats() const =0
Get the Driver Statistics.
Where messages are sent to or received from.
Continuously run Notify with given interval.
Continuously report driver stats to CommDrvRegistry.evt_driver_stats.
Driver registration container, a singleton.
Raw, undecoded messages definitions.
Pure C++17 periodic timer.
Driver statistics report.
unsigned tx_count
Number of bytes sent since program start.
DriverStats()
Is driver device available?
unsigned rx_count
Number of bytes received since program start.
unsigned error_count
Number of detected errors since program start.