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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
25#ifndef _DRIVER_STATS_H
26#define _DRIVER_STATS_H
27
28#include <chrono>
29#include <memory>
30#include <string>
31
32#include "observable.h"
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
55public:
56 virtual DriverStats GetDriverStats() const = 0;
57};
58
60class StatsTimer : public PeriodicTimer {
61public:
62 StatsTimer(const DriverStatsProvider& src, std::chrono::milliseconds interval)
63 : PeriodicTimer(interval), m_src(src) {}
64
65protected:
66 const DriverStatsProvider& m_src;
67
68 void Notify() {
69 auto stats_ptr = std::make_shared<DriverStats>(m_src.GetDriverStats());
70 CommDriverRegistry::GetInstance().evt_driver_stats.Notify(stats_ptr, "");
71 };
72};
73
74#endif // DRIVER_STATS_H
EventVar evt_driver_stats
Regularly notified by drivers with a DriverStats shared_ptr.
Driver interface providing driver statistics.
const void Notify()
Notify all listeners, no data supplied.
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.