Fraxinus  17.12
An IGT application
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 class ctkException;
51 
52 namespace cx
53 {
54 typedef boost::shared_ptr<class PluginFrameworkManager> PluginFrameworkManagerPtr;
55 
61 class cxLogicManager_EXPORT PluginFrameworkManager : public QObject
62 {
63  Q_OBJECT
64 
65  struct PluginLoadInfo
66  {
67  QString symbolicName;
68  QString storedState;
69  ctkPlugin::State targetState;
70  bool isNew;
71  };
72 
73 public:
74  static PluginFrameworkManagerPtr create() { return PluginFrameworkManagerPtr(new PluginFrameworkManager()); }
75 
78 
79  void install(const QString& symbolicName);
80  void uninstall(const QString& symbolicName);
81  bool start(const QString& symbolicName, ctkPlugin::StartOptions options = ctkPlugin::START_ACTIVATION_POLICY);
82  bool stop(const QString& symbolicName, ctkPlugin::StopOptions options = 0);
83  bool start();
84  bool stop();
85 
86  ctkPluginContext* getPluginContext();
87  QSharedPointer<ctkPluginFramework> getPluginFramework();
88 
89 // void addSearchPath(const QString& searchPath);
90  void setSearchPaths(const QStringList& searchPath);
91  QStringList getSearchPaths() const;
92  QStringList getPluginSymbolicNames();
93  QSharedPointer<ctkPlugin> getInstalledPluginFromSymbolicName(QString symbolicName);
94  ctkPlugin::State getStateFromSymbolicName(QString name);
95  void loadState();
96 
97 signals:
98  void pluginPoolChanged();
99  void aboutToStop();
100 
101 private:
102  QString getPluginPath(const QString& symbolicName);
103  QStringList getPluginSymbolicNames(const QString& searchPath);
104  bool nameIsProbablyPlugin(QString name) const;
105  std::vector<PluginFrameworkManager::PluginLoadInfo> getPluginLoadInfo(QStringList symbolicNames);
106 
107  QScopedPointer<ctkPluginFrameworkFactory> mFrameworkFactory;
108  QSharedPointer<ctkPluginFramework> mFramework;
109 
110  void initializeFramework();
111  void startFramework();
112 
113  bool frameworkInitialized() const;
114  bool frameworkStarted() const;
115 
116  void saveState();
117  void loadPluginFromStoredState(QString symbolicName, QString storedState);
118 
119  QString convertToRelativePath(QString path) const;
120  QString convertToAbsolutePath(QString path) const;
121 
122  QStringList mPluginSearchPaths;
123  QStringList mPluginLibFilter;
124 
125  QString mSettingsSearchPaths;
126  QString mSettingsBase;
127 
128  void handlePluginException(const QString& message, const ctkException &exc);
129 };
130 
131 } /* namespace cx */
132 #endif /* CXPLUGINFRAMEWORK_H_ */
QSharedPointer< ctkPlugin > ctkPluginPtr
std::pair< QString, ctkPluginPtr > PluginData
boost::shared_ptr< class PluginFrameworkManager > PluginFrameworkManagerPtr
static PluginFrameworkManagerPtr create()
Namespace for all CustusX production code.