cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsPluginMgr.h
1//
2// Copyright 2015 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7// This file is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20#pragma once
21
22#include "cc_tools_qt/ToolsApi.h"
23#include "cc_tools_qt/ToolsPlugin.h"
24#include "cc_tools_qt/version.h"
25
26#include <QtCore/QString>
27#include <QtCore/QVariantMap>
28#include <QtCore/QPluginLoader>
29
30#include <memory>
31#include <list>
32#include <array>
33
34namespace cc_tools_qt
35{
36
37class ToolsPluginMgrImpl;
38class CC_TOOLS_API ToolsPluginMgr
39{
40public:
41
42 using PluginLoaderPtr = std::shared_ptr<QPluginLoader>;
43
44 class CC_TOOLS_API PluginInfo
45 {
46 friend class ToolsPluginMgr;
47 friend class ToolsPluginMgrImpl;
48
49 public:
50 enum class Type
51 {
52 Invalid,
53 Socket,
54 Filter,
55 Protocol,
56 NumOfValues
57 };
58
59 const QString& getIid() const
60 {
61 return m_iid;
62 }
63
64 const QString& getName() const
65 {
66 return m_name;
67 }
68
69 const QString& getDescription() const
70 {
71 return m_desc;
72 }
73
74 Type getType() const
75 {
76 return m_type;
77 }
78
79 const QString& getVersion() const
80 {
81 return m_version;
82 }
83
84 QString getNameWithVersion() const;
85
86 private:
87 PluginInfo() = default;
88
89 PluginLoaderPtr m_loader;
90 QString m_iid;
91 QString m_name;
92 QString m_desc;
93 QString m_version;
94 Type m_type = Type::Invalid;
95 bool m_applied = false;
96 };
97
98 using PluginInfoPtr = std::shared_ptr<PluginInfo>;
99 using ListOfPluginInfos = std::list<PluginInfoPtr>;
100
101 ToolsPluginMgr();
102 ~ToolsPluginMgr() noexcept;
103
104 void setPluginsDir(const QString& pluginDir);
105 const ListOfPluginInfos& getAvailablePlugins();
106 const ListOfPluginInfos& getAppliedPlugins() const;
107 void setAppliedPlugins(const ListOfPluginInfos& plugins);
108 ListOfPluginInfos loadPluginsFromConfig(const QVariantMap& config);
109 ListOfPluginInfos loadPluginsFromConfigFile(const QString& filename);
110 bool savePluginsToConfigFile(const ListOfPluginInfos& infos, const QString& filename);
111 ToolsPlugin* loadPlugin(const PluginInfo& info);
112 bool hasAppliedPlugins() const;
113 bool needsReload(const ListOfPluginInfos& infos) const;
114 bool isProtocolChanging(const ListOfPluginInfos& infos) const;
115 void unloadApplied();
116 bool unloadAppliedPlugin(const PluginInfo& info);
117 static QVariantMap getConfigForPlugins(const ListOfPluginInfos& infos);
118 const QString& getLastFile() const;
119 static const QString& getFilesFilter();
120
121private:
122 std::unique_ptr<ToolsPluginMgrImpl> m_impl;
123};
124
125} // namespace cc_tools_qt
126
127Q_DECLARE_METATYPE(cc_tools_qt::ToolsPluginMgr::PluginInfoPtr);
128
Main namespace for all classes / functions of the shared library.