Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxPluginFramework.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXPLUGINFRAMEWORK_H_
34 #define CXPLUGINFRAMEWORK_H_
35 
36 #include "cxLogicManagerExport.h"
37 
38 #include <QString>
39 #include <QObject>
40 #include <boost/shared_ptr.hpp>
41 
42 #include "ctkPlugin.h"
43 #include "ctkPluginFramework_global.h"
44 
45 typedef QSharedPointer<ctkPlugin> ctkPluginPtr;
46 typedef std::pair<QString,ctkPluginPtr> PluginData;
47 
48 class ctkPluginFramework;
49 class ctkPluginFrameworkFactory;
50 
51 namespace cx
52 {
53 typedef boost::shared_ptr<class PluginFrameworkManager> PluginFrameworkManagerPtr;
54 
60 class cxLogicManager_EXPORT PluginFrameworkManager : public QObject
61 {
62  Q_OBJECT
63 
64  struct PluginLoadInfo
65  {
66  QString symbolicName;
67  QString storedState;
68  ctkPlugin::State targetState;
69  bool isNew;
70  };
71 
72 public:
74 
77 
78  void install(const QString& symbolicName);
79  void uninstall(const QString& symbolicName);
80  bool start(const QString& symbolicName, ctkPlugin::StartOptions options = ctkPlugin::START_ACTIVATION_POLICY);
81  bool stop(const QString& symbolicName, ctkPlugin::StopOptions options = 0);
82  bool start();
83  bool stop();
84 
85  ctkPluginContext* getPluginContext();
86  QSharedPointer<ctkPluginFramework> getPluginFramework();
87 
88 // void addSearchPath(const QString& searchPath);
89  void setSearchPaths(const QStringList& searchPath);
90  QStringList getSearchPaths() const;
91  QStringList getPluginSymbolicNames();
92  QSharedPointer<ctkPlugin> getInstalledPluginFromSymbolicName(QString symbolicName);
93  ctkPlugin::State getStateFromSymbolicName(QString name);
94  void loadState();
95 
96 signals:
97  void pluginPoolChanged();
98  void aboutToStop();
99 
100 private:
101  QString getPluginPath(const QString& symbolicName);
102  QStringList getPluginSymbolicNames(const QString& searchPath);
103  bool nameIsProbablyPlugin(QString name) const;
104  std::vector<PluginFrameworkManager::PluginLoadInfo> getPluginLoadInfo(QStringList symbolicNames);
105 
106  QScopedPointer<ctkPluginFrameworkFactory> mFrameworkFactory;
107  QSharedPointer<ctkPluginFramework> mFramework;
108 
109  void initializeFramework();
110  void startFramework();
111 
112  bool frameworkInitialized() const;
113  bool frameworkStarted() const;
114 
115  void saveState();
116  void loadPluginFromStoredState(QString symbolicName, QString storedState);
117 
118  QString convertToRelativePath(QString path) const;
119  QString convertToAbsolutePath(QString path) const;
120 
121  QStringList mPluginSearchPaths;
122  QStringList mPluginLibFilter;
123 
124  QString mSettingsSearchPaths;
125  QString mSettingsBase;
126 
127 };
128 
129 } /* namespace cx */
130 #endif /* CXPLUGINFRAMEWORK_H_ */
QSharedPointer< ctkPlugin > ctkPluginPtr
std::pair< QString, ctkPluginPtr > PluginData
boost::shared_ptr< class PluginFrameworkManager > PluginFrameworkManagerPtr
static PluginFrameworkManagerPtr create()