28#include <unordered_map>
37#include "observable.h"
43 const std::function<
void(
ObservedEvt)>& on_message) {
44 ol.
Init(msg, on_message);
48 : m_sink_func(sink_func) {
51 new_msg_lstnr.
Init(NavMsgBus::GetInstance().new_msg_event,
55void DataMonitorSrc::OnNewMessage() {
57 for (
const auto& msg : messages) {
58 auto found = m_listeners.find(msg);
59 if (found == m_listeners.end()) {
61 std::string type(msg);
63 NavAddr::Bus bus = NavAddr::Bus::Undef;
64 if ((pos = type.find(
"::")) != std::string::npos) {
65 auto bus_str = type.substr(0, pos);
66 bus = NavAddr::StringToBus(bus_str);
67 type = type.substr(pos + 2);
68 if ((pos = type.find(
'-')) != std::string::npos)
69 type = type.substr(pos + 1);
70 m_listeners[msg] = std::move(listener);
75 case NavAddr::Bus::N0183: {
77 InitListener(m_listeners[msg], type_msg, listen_action);
79 case NavAddr::Bus::N2000: {
82 InitListener(m_listeners[msg], type_msg, listen_action);
84 wxLogMessage(
"Bad Nmea2000 type: %s", type.c_str());
87 case NavAddr::Bus::Plugin: {
89 InitListener(m_listeners[msg], type_msg, listen_action);
91 case NavAddr::Bus::Signalk: {
93 InitListener(m_listeners[msg], type_msg, listen_action);
104 auto ptr = UnpackEvtPointer<NavMsg>(ev);
105 if (ptr && ptr->to_string() != m_last_payload) {
106 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.