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