OpenCPN Partial API docs
Loading...
Searching...
No Matches
navmsg_filter.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2025 Alec Leamas *
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
18#ifndef MONITOR_FILTER_H_
19#define MONITOR_FILTER_H_
20
47#include <cassert>
48#include <memory>
49#include <set>
50#include <string>
51#include <unordered_map>
52
53#include "model/comm_navmsg.h"
54
55#include "std_filesystem.h"
56
63public:
64 enum class Direction { kInput, kHandled, kOutput, kInternal, kNone };
65 enum class Accepted { kOk, kFilteredNoOutput, kFilteredDropped, kNone };
66 enum class State { kOk, kChecksumError, kMalformed, kTxError, kNone };
67
69 : direction(Direction::kInput),
70 status(State::kOk),
71 accepted(Accepted::kOk) {}
72
74 static std::string AcceptedToString(Accepted);
75
77 static Accepted StringToAccepted(const std::string& s);
78
79 Direction direction;
80 State status;
81 Accepted accepted;
82};
83
85public:
86 NavmsgFilter() : m_is_valid(true) {}
87
88 NavmsgFilter(bool is_valid) : m_is_valid(is_valid) {}
89
91 static std::vector<NavmsgFilter> GetSystemFilters();
92
94 static std::vector<NavmsgFilter> GetFilters(const fs::path& path);
95
97 static std::vector<NavmsgFilter> GetAllFilters();
98
100 static NavmsgFilter Parse(const std::string& s);
101
103 static NavmsgFilter Parse(const fs::path& path);
104
106 std::string to_string() const;
107
109 bool Pass(NavmsgStatus status, const std::shared_ptr<const NavMsg>& msg);
110
112 std::string GetName();
113
115 void SetName(const std::string& new_name);
116
117 bool m_is_valid;
118 std::string m_name;
119 std::string m_description;
120 std::set<NavmsgStatus::Direction> directions;
121 std::set<NavmsgStatus::State> status;
122 std::set<NavmsgStatus::Accepted> accepted;
123 std::set<NavAddr::Bus> buses; // Set of buses included
124 std::set<std::string> include_msg; // Set of message ids included
125 std::set<std::string> exclude_msg; // Set of message ids excluded
126 std::set<std::string> interfaces; // Set of included interfaces
127 std::set<N2kPGN> pgns; // Nmea200 only
128 std::set<N2kName> src_pgns; // Nmea200 only
129};
130
131#endif // MONITOR_FILTER
bool Pass(NavmsgStatus status, const std::shared_ptr< const NavMsg > &msg)
Return true if message is not matched by filter.
static std::vector< NavmsgFilter > GetFilters(const fs::path &path)
Return list of pre-defined filters shipped with app, test hook.
static std::vector< NavmsgFilter > GetAllFilters()
Return list of all filters, system + user defined.
std::string to_string() const
Output parsable JSON string representation.
std::string GetName()
Return human-readable name.
static NavmsgFilter Parse(const std::string &s)
Parse text as created by to_string().
void SetName(const std::string &new_name)
Set human-readable name.
static std::vector< NavmsgFilter > GetSystemFilters()
Return list of pre-defined filters shipped with application.
Representation of message status as determined by the multiplexer.
static Accepted StringToAccepted(const std::string &s)
Return Accepted value corresponding to argument s.
static std::string AcceptedToString(Accepted)
Return string representation of argument.
Raw, undecoded messages definitions.