cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsPluginMgr.h
1//
2// Copyright 2015 - 2025 (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 <memory>
22#include <list>
23#include <array>
24
25#include <QtCore/QString>
26#include <QtCore/QVariantMap>
27#include <QtCore/QPluginLoader>
28
29#include "cc_tools_qt/ToolsApi.h"
30#include "cc_tools_qt/ToolsPlugin.h"
31
32namespace cc_tools_qt
33{
34
35class ToolsPluginMgrImpl;
36class CC_TOOLS_API ToolsPluginMgr
37{
38public:
39
40 using PluginLoaderPtr = std::shared_ptr<QPluginLoader>;
41
42 class PluginInfo
43 {
44 friend class ToolsPluginMgr;
45 friend class ToolsPluginMgrImpl;
46
47 public:
48 enum class Type
49 {
50 Invalid,
51 Socket,
52 Filter,
53 Protocol,
54 NumOfValues
55 };
56
57 const QString& getIid() const
58 {
59 return m_iid;
60 }
61
62 const QString& getName() const
63 {
64 return m_name;
65 }
66
67 const QString& getDescription() const
68 {
69 return m_desc;
70 }
71
72 Type getType() const
73 {
74 return m_type;
75 }
76
77 private:
78 PluginInfo() = default;
79
80 PluginLoaderPtr m_loader;
81 QString m_iid;
82 QString m_name;
83 QString m_desc;
84 Type m_type = Type::Invalid;
85 bool m_applied = false;
86 };
87
88 using PluginInfoPtr = std::shared_ptr<PluginInfo>;
89 using ListOfPluginInfos = std::list<PluginInfoPtr>;
90
91 ToolsPluginMgr();
92 ~ToolsPluginMgr() noexcept;
93
94 void setPluginsDir(const QString& pluginDir);
95 const ListOfPluginInfos& getAvailablePlugins();
96 const ListOfPluginInfos& getAppliedPlugins() const;
97 void setAppliedPlugins(const ListOfPluginInfos& plugins);
98 ListOfPluginInfos loadPluginsFromConfig(const QVariantMap& config);
99 ListOfPluginInfos loadPluginsFromConfigFile(const QString& filename);
100 bool savePluginsToConfigFile(const ListOfPluginInfos& infos, const QString& filename);
101 ToolsPlugin* loadPlugin(const PluginInfo& info);
102 bool hasAppliedPlugins() const;
103 bool needsReload(const ListOfPluginInfos& infos) const;
104 bool isProtocolChanging(const ListOfPluginInfos& infos) const;
105 void unloadApplied();
106 bool unloadAppliedPlugin(const PluginInfo& info);
107 static QVariantMap getConfigForPlugins(const ListOfPluginInfos& infos);
108 const QString& getLastFile() const;
109 static const QString& getFilesFilter();
110
111private:
112 std::unique_ptr<ToolsPluginMgrImpl> m_impl;
113};
114
115} // namespace cc_tools_qt
116
117Q_DECLARE_METATYPE(cc_tools_qt::ToolsPluginMgr::PluginInfoPtr);
118
Main namespace for all classes / functions of the shared library.