28#include <unordered_map>
38#include "observable.h"
41 const std::function<
void(
ObservedEvt)>& on_message) {
42 ol.
Init(msg, on_message);
46 : m_sink_func(sink_func) {
49 new_msg_lstnr.
Init(NavMsgBus::GetInstance().new_msg_event,
53void DataMonitorSrc::OnNewMessage() {
55 for (
const auto& msg : messages) {
56 auto found = m_listeners.find(msg);
57 if (found == m_listeners.end()) {
59 std::string type(msg);
61 NavAddr::Bus bus = NavAddr::Bus::Undef;
62 if ((pos = type.find(
"::")) != std::string::npos) {
63 auto bus_str = type.substr(0, pos);
64 bus = NavAddr::StringToBus(bus_str);
65 type = type.substr(pos + 2);
66 if ((pos = type.find(
'-')) != std::string::npos)
67 type = type.substr(pos + 1);
68 m_listeners[msg] = std::move(listener);
73 case NavAddr::Bus::N0183: {
75 InitListener(m_listeners[msg], type_msg, listen_action);
77 case NavAddr::Bus::N2000: {
80 InitListener(m_listeners[msg], type_msg, listen_action);
82 wxLogMessage(
"Bad Nmea2000 type: %s", type.c_str());
85 case NavAddr::Bus::Plugin: {
87 InitListener(m_listeners[msg], type_msg, listen_action);
89 case NavAddr::Bus::Signalk: {
91 InitListener(m_listeners[msg], type_msg, listen_action);
102 auto ptr = UnpackEvtPointer<NavMsg>(ev);
103 if (ptr && ptr->to_string() != m_last_payload) {
104 m_last_payload = ptr->to_string();
DataMonitorSrc(const SinkFunc &sink_func)
Create instance which listens and forwards messages using the sink_func callback function.
const std::set< std::string > & GetActiveMessages()
Return list of message types sent or received.
Actual data sent between application and transport layer.
A regular Nmea0183 message.
See: https://github.com/OpenCPN/OpenCPN/issues/2729#issuecomment-1179506343.
Define an action to be performed when a KeyProvider is notified.
void Init(const KeyProvider &kp, std::function< void(ObservedEvt &ev)> action)
Initiate an object yet not listening.
Custom event class for OpenCPN's notification system.
A plugin to plugin json message over the REST interface.
A parsed SignalK message over ipv4.
Raw, undecoded messages definitions.
Raw messages layer, supports sending and recieving navmsg messages.
Provide a data stream of input messages for the Data Monitor.
Miscellaneous utilities, many of which string related.