cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
PluginMgr.h
1//
2// Copyright 2015 - 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 <memory>
22#include <list>
23#include <array>
24
25#include <QtCore/QString>
26#include <QtCore/QVariantMap>
27#include <QtCore/QPluginLoader>
28
29#include "Api.h"
30#include "Plugin.h"
31
32namespace cc_tools_qt
33{
34
35class PluginMgrImpl;
36class CC_API PluginMgr
37{
38public:
39
40 typedef std::shared_ptr<QPluginLoader> PluginLoaderPtr;
41
42 class PluginInfo
43 {
44 friend class PluginMgr;
45 friend class PluginMgrImpl;
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 typedef std::shared_ptr<PluginInfo> PluginInfoPtr;
89 typedef std::list<PluginInfoPtr> ListOfPluginInfos;
90 typedef Plugin::WidgetPtr WidgetPtr;
91
92 PluginMgr();
93 ~PluginMgr() noexcept;
94
95 void setPluginsDir(const QString& pluginDir);
96 const ListOfPluginInfos& getAvailablePlugins();
97 const ListOfPluginInfos& getAppliedPlugins() const;
98 void setAppliedPlugins(const ListOfPluginInfos& plugins);
99 ListOfPluginInfos loadPluginsFromConfig(const QVariantMap& config);
100 ListOfPluginInfos loadPluginsFromConfigFile(const QString& filename);
101 bool savePluginsToConfigFile(const ListOfPluginInfos& infos, const QString& filename);
102 Plugin* loadPlugin(const PluginInfo& info);
103 bool hasAppliedPlugins() const;
104 bool needsReload(const ListOfPluginInfos& infos) const;
105 bool isProtocolChanging(const ListOfPluginInfos& infos) const;
106 void unloadApplied();
107 bool unloadAppliedPlugin(const PluginInfo& info);
108 static QVariantMap getConfigForPlugins(const ListOfPluginInfos& infos);
109 const QString& getLastFile() const;
110 static const QString& getFilesFilter();
111
112private:
113 std::unique_ptr<PluginMgrImpl> m_impl;
114};
115
116} // namespace cc_tools_qt
117
118Q_DECLARE_METATYPE(cc_tools_qt::PluginMgr::PluginInfoPtr);
119
Main namespace for all classes / functions of the shared library.