28#include <unordered_map>
42 const std::function<
void(
ObservedEvt)>& on_message) {
43 ol.
Init(msg, on_message);
47 : m_sink_func(sink_func) {
48 new_msg_lstnr.Init(NavMsgBus::GetInstance().new_msg_event,
50 undelivered_msg_lstnr.Init(CommDriverRegistry::GetInstance().evt_dropped_msg,
54void DataMonitorSrc::OnNewMessage() {
55 auto messages = NavMsgBus::GetInstance().GetActiveMessages();
56 for (
const auto& msg : messages) {
57 auto found = m_listeners.find(msg);
58 if (found == m_listeners.end()) {
60 std::string type(msg);
62 NavAddr::Bus bus = NavAddr::Bus::Undef;
63 if ((pos = type.find(
"::")) != std::string::npos) {
64 auto bus_str = type.substr(0, pos);
65 bus = NavAddr::StringToBus(bus_str);
66 type = type.substr(pos + 2);
67 if ((pos = type.find(
'-')) != std::string::npos)
68 type = type.substr(pos + 1);
69 m_listeners[msg] = std::move(listener);
74 case NavAddr::Bus::N0183: {
75 auto type_msg = Nmea0183Msg(type);
76 InitListener(m_listeners[msg], type_msg, listen_action);
78 case NavAddr::Bus::N2000: {
80 auto type_msg = Nmea2000Msg(std::stoi(type));
81 InitListener(m_listeners[msg], type_msg, listen_action);
83 wxLogMessage(
"Bad Nmea2000 type: %s", type.c_str());
86 case NavAddr::Bus::Plugin: {
87 auto type_msg = PluginMsg(type,
"");
88 InitListener(m_listeners[msg], type_msg, listen_action);
90 case NavAddr::Bus::Signalk: {
91 auto type_msg = SignalkMsg();
92 InitListener(m_listeners[msg], type_msg, listen_action);
103 auto ptr = obs::UnpackEvtPointer<NavMsg>(ev);
DataMonitorSrc(const SinkFunc &sink_func)
Create instance which listens and forwards messages using the sink_func callback function.
Actual data sent between application and transport layer.
Custom event class for OpenCPN's notification system.
Define an action to be performed when a KeyProvider is notified.
void Init(const KeyProvider &kp, const std::function< void(ObservedEvt &ev)> &action)
Initiate an object yet not listening so it invokes action when the kp key is notified.
Driver registration container, a singleton.
Raw, undecoded messages definitions.
Raw messages layer, supports sending and recieving navmsg messages.
Provide a data stream of input messages for the Data Monitor.
General observable pattern implementation built on top of wxWidgets event handling.
Miscellaneous utilities, many of which string related.