OpenCPN Partial API docs
Loading...
Searching...
No Matches
navmsg_filter.h
Go to the documentation of this file.
1
2/***************************************************************************
3 * Copyright (C) 2025 Alec Leamas *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 **************************************************************************/
20
21#ifndef MONITOR_FILTER_H_
22#define MONITOR_FILTER_H_
23
49#include <cassert>
50#include <memory>
51#include <set>
52#include <string>
53#include <unordered_map>
54
55#include "model/comm_navmsg.h"
56
57#include "std_filesystem.h"
58
65public:
66 enum class Direction { kInput, kHandled, kOutput, kInternal, kNone };
67 enum class Accepted { kOk, kFilteredNoOutput, kFilteredDropped, kNone };
68 enum class State { kOk, kChecksumError, kMalformed, kTxError, kNone };
69
71 : direction(Direction::kInput),
72 status(State::kOk),
73 accepted(Accepted::kOk) {}
74
76 static std::string AcceptedToString(Accepted);
77
79 static Accepted StringToAccepted(const std::string& s);
80
81 Direction direction;
82 State status;
83 Accepted accepted;
84};
85
87public:
88 NavmsgFilter() : m_is_valid(true) {}
89
90 NavmsgFilter(bool is_valid) : m_is_valid(is_valid) {}
91
93 static std::vector<NavmsgFilter> GetSystemFilters();
94
96 static std::vector<NavmsgFilter> GetFilters(const fs::path& path);
97
99 static std::vector<NavmsgFilter> GetAllFilters();
100
102 static NavmsgFilter Parse(const std::string& s);
103
105 static NavmsgFilter Parse(const fs::path& path);
106
108 std::string to_string() const;
109
111 bool Pass(NavmsgStatus status, const std::shared_ptr<const NavMsg>& msg);
112
114 std::string GetName();
115
117 void SetName(const std::string& new_name);
118
119 bool m_is_valid;
120 std::string m_name;
121 std::string m_description;
122 std::set<NavmsgStatus::Direction> directions;
123 std::set<NavmsgStatus::State> status;
124 std::set<NavmsgStatus::Accepted> accepted;
125 std::set<NavAddr::Bus> buses; // Set of buses included
126 std::set<std::string> include_msg; // Set of message ids included
127 std::set<std::string> exclude_msg; // Set of message ids excluded
128 std::set<std::string> interfaces; // Set of included interfaces
129 std::set<N2kPGN> pgns; // Nmea200 only
130 std::set<N2kName> src_pgns; // Nmea200 only
131};
132
133#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.