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
63public:
64 enum class Direction { kInput, kReceived, 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.