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
68 NavmsgStatus(Direction direction_, State status_, Accepted accepted_)
69 : direction(direction_), status(status_), accepted(accepted_) {}
70
71 NavmsgStatus(Direction direction)
72 : NavmsgStatus(direction, State::kOk, Accepted::kOk) {}
73
74 NavmsgStatus(State status)
75 : NavmsgStatus(Direction::kInput, status, Accepted::kOk) {}
76
77 NavmsgStatus(Accepted accepted)
78 : NavmsgStatus(Direction::kInput, State::kOk, accepted) {}
79
80 NavmsgStatus() : NavmsgStatus(Direction::kInput, State::kOk, Accepted::kOk) {}
81
83 static std::string AcceptedToString(Accepted);
84
86 static Accepted StringToAccepted(const std::string& s);
87
88 Direction direction;
89 State status;
90 Accepted accepted;
91};
92
94public:
95 NavmsgFilter() : m_is_valid(true) {}
96
97 NavmsgFilter(bool is_valid) : m_is_valid(is_valid) {}
98
100 static std::vector<NavmsgFilter> GetSystemFilters();
101
103 static std::vector<NavmsgFilter> GetFilters(const fs::path& path);
104
106 static std::vector<NavmsgFilter> GetAllFilters();
107
109 static NavmsgFilter Parse(const std::string& s);
110
112 static NavmsgFilter Parse(const fs::path& path);
113
115 std::string to_string() const;
116
118 bool Pass(NavmsgStatus status, const std::shared_ptr<const NavMsg>& msg);
119
121 std::string GetName();
122
124 void SetName(const std::string& new_name);
125
126 bool m_is_valid;
127 std::string m_name;
128 std::string m_description;
129 std::set<NavmsgStatus::Direction> directions;
130 std::set<NavmsgStatus::State> status;
131 std::set<NavmsgStatus::Accepted> accepted;
132 std::set<NavAddr::Bus> buses; // Set of buses included
133 std::set<std::string> include_msg; // Set of message ids included
134 std::set<std::string> exclude_msg; // Set of message ids excluded
135 std::set<std::string> interfaces; // Set of included interfaces
136 std::set<N2kPGN> pgns; // Nmea200 only
137 std::set<N2kName> src_pgns; // Nmea200 only
138};
139
140#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.