PluginCache.h
Go to the documentation of this file.
1 #pragma once
2 
4 
6 
7 #include <QDateTime>
8 #include <QPluginLoader>
9 #include <QSet>
10 
11 #include <memory>
12 #include <future>
13 #include <mutex>
14 
15 
16 class QProgressDialog;
17 
18 class ArmarXWidgetInfo;
19 using ArmarXWidgetInfoPtr = std::shared_ptr<ArmarXWidgetInfo>;
20 
22 using WidgetCreatorMap = std::map<QString, ArmarXWidgetInfoPtr >;
23 
24 namespace armarx
25 {
26 
27  struct PluginData
28  {
29  QSharedPointer<QPluginLoader> pluginLoader;
30  QString pluginPath;
31  QByteArray hash;
32  QDateTime lastModified;
34  };
35 
37  {
38  public:
40  ~PluginCache();
41  bool cachePlugin(const QString& pluginPath);
42  bool cacheWidget(QString widgetName, ArmarXWidgetInfoPtr widgetCreator);
43  ArmarXWidgetInfoPtr getWidgetCreator(const QString& widgetName);
44  QStringList getAvailableWidgetNames() const;
46  const QString settingsOrganization = "KIT";
47  const QString settingsApplicationName = "/PluginCache.conf";
48  void copyResourcesToCache();
49  static QString GetIconCachePath();
50  static QString GetIconPath(const QString& widgetName);
51  static QString GetCategoryIconPath(const QString& widgetName);
52  void preloadAsync(QStringList widgetNames, int delayMS = 1000);
53  void clearCacheFile();
54  QByteArray getHash(const QString& pluginPath);
55 
56  void removeWidgetFromCache(QString pluginPath, QString widgetName);
57  void removePluginFromCache(QString pluginPath);
58  static bool ContainsAny(const QString& str, const QStringList& items);
59  protected:
60  void updateLastModifiedTimestamp(const QString& pluginPath);
61  void writeToCache(const QString& pluginPath);
62  PluginData loadFromCache(const QString& pluginPath);
63  WidgetCreatorMap loadPlugin(QSharedPointer<QPluginLoader> loader);
64  const QString cachePath;
65  QMap<QString, PluginData> pluginData;
67  QSettings s;
68  mutable std::recursive_mutex cacheMutex;
69  std::future<void> preloadFuture;
70  bool shutdown = false;
71 
72  };
73  using PluginCachePtr = std::shared_ptr<PluginCache>;
74 
75 } // namespace armarx
76 
armarx::PluginCache::GetCategoryIconPath
static QString GetCategoryIconPath(const QString &widgetName)
Definition: PluginCache.cpp:189
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
armarx::PluginCache::GetIconPath
static QString GetIconPath(const QString &widgetName)
Definition: PluginCache.cpp:184
ArmarXWidgetInfo
The ArmarXWidgetInfo class.
Definition: ArmarXGuiInterface.h:42
armarx::PluginData
Definition: PluginCache.h:27
armarx::PluginCache::shutdown
bool shutdown
Definition: PluginCache.h:70
WidgetCreatorFunction
armarx::ArmarXWidgetControllerPtr(* WidgetCreatorFunction)()
Definition: PluginCache.h:21
armarx::PluginCache::preloadFuture
std::future< void > preloadFuture
Definition: PluginCache.h:69
ArmarXWidgetInfoPtr
std::shared_ptr< ArmarXWidgetInfo > ArmarXWidgetInfoPtr
Definition: ArmarXGuiInterface.h:32
armarx::PluginCache::clearCacheFile
void clearCacheFile()
Definition: PluginCache.cpp:252
armarx::PluginCache::preloadAsync
void preloadAsync(QStringList widgetNames, int delayMS=1000)
Definition: PluginCache.cpp:206
armarx::PluginData::lastModified
QDateTime lastModified
Definition: PluginCache.h:32
armarx::PluginCache::cacheMutex
std::recursive_mutex cacheMutex
Definition: PluginCache.h:68
armarx::PluginData::hash
QByteArray hash
Definition: PluginCache.h:31
armarx::PluginCache::copyResourcesToCache
void copyResourcesToCache()
Definition: PluginCache.cpp:160
armarx::PluginCache::cacheWidget
bool cacheWidget(QString widgetName, ArmarXWidgetInfoPtr widgetCreator)
Definition: PluginCache.cpp:101
armarx::PluginCache::getWidgetCreator
ArmarXWidgetInfoPtr getWidgetCreator(const QString &widgetName)
Definition: PluginCache.cpp:108
armarx::PluginCache::removePluginFromCache
void removePluginFromCache(QString pluginPath)
Definition: PluginCache.cpp:289
armarx::PluginCache::settingsOrganization
const QString settingsOrganization
Definition: PluginCache.h:46
armarx::PluginCache::getAvailableWidgets
WidgetCreatorMap getAvailableWidgets() const
Definition: PluginCache.cpp:149
armarx::PluginCache::updateLastModifiedTimestamp
void updateLastModifiedTimestamp(const QString &pluginPath)
Definition: PluginCache.cpp:314
armarx::PluginData::pluginLoader
QSharedPointer< QPluginLoader > pluginLoader
Definition: PluginCache.h:29
armarx::PluginCache::pluginData
QMap< QString, PluginData > pluginData
Definition: PluginCache.h:65
armarx::PluginCache::settingsApplicationName
const QString settingsApplicationName
Definition: PluginCache.h:47
armarx::PluginCache::manager
ArmarXManagerPtr manager
Definition: PluginCache.h:66
armarx::PluginData::pluginPath
QString pluginPath
Definition: PluginCache.h:30
ArmarXFwd.h
armarx::PluginCache::getHash
QByteArray getHash(const QString &pluginPath)
Definition: PluginCache.cpp:259
WidgetCreatorMap
std::map< QString, ArmarXWidgetInfoPtr > WidgetCreatorMap
Definition: ArmarXGuiInterface.h:35
ArmarXWidgetController.h
armarx::PluginCache::ContainsAny
static bool ContainsAny(const QString &str, const QStringList &items)
Definition: PluginCache.cpp:194
IceUtil::Handle< ArmarXManager >
armarx::PluginCache::GetIconCachePath
static QString GetIconCachePath()
Definition: PluginCache.cpp:179
armarx::PluginCache::loadFromCache
PluginData loadFromCache(const QString &pluginPath)
Definition: PluginCache.cpp:356
armarx::PluginCache::cachePath
const QString cachePath
Definition: PluginCache.h:64
armarx::PluginCache::s
QSettings s
Definition: PluginCache.h:67
armarx::PluginCache::writeToCache
void writeToCache(const QString &pluginPath)
Definition: PluginCache.cpp:332
armarx::PluginCache::loadPlugin
WidgetCreatorMap loadPlugin(QSharedPointer< QPluginLoader > loader)
Definition: PluginCache.cpp:404
armarx::PluginCache::removeWidgetFromCache
void removeWidgetFromCache(QString pluginPath, QString widgetName)
Definition: PluginCache.cpp:271
armarx::ArmarXWidgetControllerPtr
IceUtil::Handle< ArmarXWidgetController > ArmarXWidgetControllerPtr
Definition: ArmarXWidgetController.h:45
armarx::PluginCache::getAvailableWidgetNames
QStringList getAvailableWidgetNames() const
Definition: PluginCache.cpp:134
armarx::PluginData::widgets
WidgetCreatorMap widgets
Definition: PluginCache.h:33
armarx::PluginCache
Definition: PluginCache.h:36
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PluginCache::~PluginCache
~PluginCache()
Definition: PluginCache.cpp:48
armarx::PluginCache::PluginCache
PluginCache(ArmarXManagerPtr manager)
Definition: PluginCache.cpp:18
armarx::PluginCachePtr
std::shared_ptr< PluginCache > PluginCachePtr
Definition: PluginCache.h:73
armarx::PluginCache::cachePlugin
bool cachePlugin(const QString &pluginPath)
Definition: PluginCache.cpp:57