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#pragma once
19
20#include "cc_tools_qt/ToolsApi.h"
21#include "cc_tools_qt/ToolsPlugin.h"
22#include "cc_tools_qt/version.h"
23
24#include <QtCore/QString>
25#include <QtCore/QVariantMap>
26#include <QtCore/QPluginLoader>
27
28#include <memory>
29#include <list>
30#include <array>
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 CC_TOOLS_API 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 const QString& getVersion() const
78 {
79 return m_version;
80 }
81
82 QString getNameWithVersion() const;
83
84 private:
85 PluginInfo() = default;
86
87 PluginLoaderPtr m_loader;
88 QString m_iid;
89 QString m_name;
90 QString m_desc;
91 QString m_version;
92 Type m_type = Type::Invalid;
93 bool m_applied = false;
94 };
95
96 using PluginInfoPtr = std::shared_ptr<PluginInfo>;
97 using ListOfPluginInfos = std::list<PluginInfoPtr>;
98
99 ToolsPluginMgr();
100 ~ToolsPluginMgr() noexcept;
101
102 void setPluginsDir(const QString& pluginDir);
103 const ListOfPluginInfos& getAvailablePlugins();
104 const ListOfPluginInfos& getAppliedPlugins() const;
105 void setAppliedPlugins(const ListOfPluginInfos& plugins);
106 ListOfPluginInfos loadPluginsFromConfig(const QVariantMap& config);
107 ListOfPluginInfos loadPluginsFromConfigFile(const QString& filename);
108 bool savePluginsToConfigFile(const ListOfPluginInfos& infos, const QString& filename);
109 ToolsPlugin* loadPlugin(const PluginInfo& info);
110 bool hasAppliedPlugins() const;
111 bool needsReload(const ListOfPluginInfos& infos) const;
112 bool isProtocolChanging(const ListOfPluginInfos& infos) const;
113 void unloadApplied();
114 bool unloadAppliedPlugin(const PluginInfo& info);
115 static QVariantMap getConfigForPlugins(const ListOfPluginInfos& infos);
116 const QString& getLastFile() const;
117 static const QString& getFilesFilter();
118
119private:
120 std::unique_ptr<ToolsPluginMgrImpl> m_impl;
121};
122
123} // namespace cc_tools_qt
124
125Q_DECLARE_METATYPE(cc_tools_qt::ToolsPluginMgr::PluginInfoPtr);
126
Main namespace for all classes / functions of the shared library.