cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
Filter.h
1//
2// Copyright 2014 - 2024 (C). Alex Robenko. All rights reserved.
3//
4
5// This file 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 3 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, see <http://www.gnu.org/licenses/>.
17
18
19#pragma once
20
21#include <cstdint>
22#include <cstddef>
23#include <vector>
24#include <functional>
25
26#include <QtCore/QString>
27#include <QtCore/QList>
28
29#include "DataInfo.h"
30#include "Api.h"
31
32namespace cc_tools_qt
33{
34
39class CC_API Filter
40{
41public:
44
46 virtual ~Filter() noexcept;
47
54 bool start();
55
60 void stop();
61
69 QList<DataInfoPtr> recvData(DataInfoPtr dataPtr);
70
78 QList<DataInfoPtr> sendData(DataInfoPtr dataPtr);
79
82 void socketConnectionReport(bool connected);
83
89 void applyInterPluginConfig(const QVariantMap& props);
90
92 using DataToSendCallback = std::function<void (DataInfoPtr)>;
93
98 template <typename TFunc>
99 void setDataToSendCallback(TFunc&& func)
100 {
101 m_dataToSendCallback = std::forward<TFunc>(func);
102 }
103
105 using ErrorReportCallback = std::function<void (const QString& msg)>;
106
109 template <typename TFunc>
110 void setErrorReportCallback(TFunc&& func)
111 {
112 m_errorReportCallback = std::forward<TFunc>(func);
113 }
114
116 using InterPluginConfigReportCallback = std::function <void (const QVariantMap&)>;
117
120 template <typename TFunc>
122 {
123 m_interPluginConfigReportCallback = std::forward<TFunc>(func);
124 }
125
128 void setDebugOutputLevel(unsigned level = 0U);
129
130protected:
135 virtual bool startImpl();
136
140 virtual void stopImpl();
141
145 virtual QList<DataInfoPtr> recvDataImpl(DataInfoPtr dataPtr);
146
150 virtual QList<DataInfoPtr> sendDataImpl(DataInfoPtr dataPtr);
151
154 virtual void socketConnectionReportImpl(bool connected);
155
159 virtual void applyInterPluginConfigImpl(const QVariantMap& props);
160
162 virtual const char* debugNameImpl() const;
163
170
176 void reportError(const QString& msg);
177
184 void reportInterPluginConfig(const QVariantMap& props);
185
187 static unsigned long long currTimestamp();
188
190 unsigned getDebugOutputLevel() const;
191
192private:
193 DataToSendCallback m_dataToSendCallback;
194 ErrorReportCallback m_errorReportCallback;
195 InterPluginConfigReportCallback m_interPluginConfigReportCallback;
196 unsigned m_debugLevel = 0U;
197};
198
200using FilterPtr = std::shared_ptr<Filter>;
201
202} // namespace cc_tools_qt
203
Main polymorphic interface class for filters.
Definition Filter.h:40
void reportDataToSend(DataInfoPtr dataPtr)
Report new data to send generated by the filter itself.
virtual const char * debugNameImpl() const
Get plugin name for the debug output.
void reportInterPluginConfig(const QVariantMap &props)
Report inter-plugin configuration.
void setDebugOutputLevel(unsigned level=0U)
Set debug output level.
unsigned getDebugOutputLevel() const
Get current debug output level.
virtual QList< DataInfoPtr > recvDataImpl(DataInfoPtr dataPtr)
Polymorphic processing of incoming data.
std::function< void(DataInfoPtr)> DataToSendCallback
Type of callback to report outgoing data.
Definition Filter.h:92
void setInterPluginConfigReportCallback(TFunc &&func)
Set callback to report inter-plugin configuration.
Definition Filter.h:121
virtual void stopImpl()
Polymorphic stop functionality implementation.
Filter()
Constructor.
static unsigned long long currTimestamp()
Get current timestamp.
virtual QList< DataInfoPtr > sendDataImpl(DataInfoPtr dataPtr)
Polymorphic processing of outgoing data.
virtual bool startImpl()
Polymorphic start functionality implementation.
virtual void applyInterPluginConfigImpl(const QVariantMap &props)
Polymorphic inter-plugin configuration application.
void reportError(const QString &msg)
Report operation error.
void setErrorReportCallback(TFunc &&func)
Set callback to report errors.
Definition Filter.h:110
virtual void socketConnectionReportImpl(bool connected)
Polymorphic processing of the socket connection report.
std::function< void(const QVariantMap &)> InterPluginConfigReportCallback
Callback to report inter-plugin configuration updates.
Definition Filter.h:116
virtual ~Filter() noexcept
Destructor.
std::function< void(const QString &msg)> ErrorReportCallback
Type of callback to report errors.
Definition Filter.h:105
Main namespace for all classes / functions of the shared library.
std::shared_ptr< DataInfo > DataInfoPtr
Pointer to DataInfo.
Definition DataInfo.h:57
std::shared_ptr< Filter > FilterPtr
Pointer to Filter object.
Definition Filter.h:200