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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
26#ifndef MULTIPLEXER_H_
27#define MULTIPLEXER_H_
28
29#include <functional>
30
31#include <wx/wxprec.h>
32
33#ifndef WX_PRECOMP
34#include <wx/wx.h>
35#endif
36
37#include "model/comm_navmsg.h"
38#include "model/nmea_log.h"
39
40class Multiplexer; // forward
41
42extern Multiplexer* g_pMUX;
43
45 std::function<bool()> log_is_active;
46 std::function<void(const Logline&)> log_message;
48 : log_is_active([]() { return false; }),
49 log_message([](const Logline&) {}) {}
50};
51
58class Multiplexer : public wxEvtHandler {
59public:
60 Multiplexer(const MuxLogCallbacks& log_callbacks,
61 bool& legacy_input_filter_behaviour);
62
63 ~Multiplexer() override;
64
65 void LogOutputMessage(const std::shared_ptr<const NavMsg>& msg,
66 NavmsgStatus status) const;
67
76 void LogInputMessage(const std::shared_ptr<const NavMsg>& msg,
77 bool is_filtered, bool is_error,
78 const wxString& error_msg = "") const;
79
80 [[nodiscard]] bool IsLogActive() const {
81 return m_log_callbacks.log_is_active();
82 }
83
84private:
85 MuxLogCallbacks m_log_callbacks;
86 bool& m_legacy_input_filter_behaviour;
87 std::unordered_map<std::string, ObsListener> m_listeners;
88 ObsListener m_new_msgtype_lstnr;
89 int m_n2k_repeat_count;
90 unsigned int m_last_pgn_logged;
91
92 void OnNewMessageType();
93
94 void HandleN0183(const std::shared_ptr<const Nmea0183Msg>& n0183_msg) const;
95
96 bool HandleN2kLog(const std::shared_ptr<const Nmea2000Msg>& n2k_msg);
97};
98#endif // MULTIPLEXER_H_
Handle logging and forwarding of incoming n0183/n2k messages.
Definition multiplexer.h:58
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:34