OpenCPN Partial API docs
Loading...
Searching...
No Matches
multiplexer.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by David S. Register *
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 MULTIPLEXER_H_
25#define MULTIPLEXER_H_
26
27#include <functional>
28
29#include <wx/wxprec.h>
30
31#ifndef WX_PRECOMP
32#include <wx/wx.h>
33#endif
34
35#include "model/comm_navmsg.h"
36#include "model/nmea_log.h"
37
38class Multiplexer; // forward
39
40extern Multiplexer* g_pMUX;
41
43 std::function<bool()> log_is_active;
44 std::function<void(const Logline&)> log_message;
46 : log_is_active([]() { return false; }),
47 log_message([](const Logline&) {}) {}
48};
49
56class Multiplexer : public wxEvtHandler {
57public:
58 Multiplexer(const MuxLogCallbacks& log_callbacks,
59 bool& legacy_input_filter_behaviour);
60
61 ~Multiplexer() override;
62
63 void LogOutputMessage(const std::shared_ptr<const NavMsg>& msg,
64 NavmsgStatus status) const;
65
74 void LogInputMessage(const std::shared_ptr<const NavMsg>& msg,
75 bool is_filtered, bool is_error,
76 const wxString& error_msg = "") const;
77
78 [[nodiscard]] bool IsLogActive() const {
79 return m_log_callbacks.log_is_active();
80 }
81
82private:
83 MuxLogCallbacks m_log_callbacks;
84 bool& m_legacy_input_filter_behaviour;
85 std::unordered_map<std::string, ObsListener> m_listeners;
86 ObsListener m_new_msgtype_lstnr;
87 int m_n2k_repeat_count;
88 unsigned int m_last_pgn_logged;
89
90 void OnNewMessageType();
91
92 void HandleN0183(const std::shared_ptr<const Nmea0183Msg>& n0183_msg) const;
93
94 bool HandleN2kLog(const std::shared_ptr<const Nmea2000Msg>& n2k_msg);
95};
96#endif // MULTIPLEXER_H_
Handle logging and forwarding of incoming n0183/n2k messages.
Definition multiplexer.h:56
void LogInputMessage(const std::shared_ptr< const NavMsg > &msg, bool is_filtered, bool is_error, const wxString &error_msg="") const
Logs an input message with context information.
Representation of message status as determined by the multiplexer.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:257
Raw, undecoded messages definitions.
Basic DataMonitor logging interface: LogLine (reflects a line in the log) and NmeaLog,...
Item in the log window.
Definition nmea_log.h:32