CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkPluginContext.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  Library: CTK
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =============================================================================*/
21 
22 #ifndef CTKPLUGINCONTEXT_H_
23 #define CTKPLUGINCONTEXT_H_
24 
25 #include <QHash>
26 #include <QString>
27 #include <QVariant>
28 #include <QUrl>
29 #include <QSharedPointer>
30 #include <QFileInfo>
31 
33 
34 #include "ctkPluginEvent.h"
35 #include "ctkServiceException.h"
36 #include "ctkServiceReference.h"
37 #include "ctkServiceRegistration.h"
38 
39 #include "ctkPluginFrameworkExport.h"
40 
41 
42 // CTK class forward declarations
43 class ctkPlugin;
44 class ctkPluginPrivate;
45 class ctkPluginContextPrivate;
46 
98 class CTK_PLUGINFW_EXPORT ctkPluginContext
99 {
100 
101 public:
102 
104 
114  QVariant getProperty(const QString& key) const;
115 
125  QSharedPointer<ctkPlugin> getPlugin() const;
126 
134  QSharedPointer<ctkPlugin> getPlugin(long id) const;
135 
136 
149 
215  ctkServiceRegistration registerService(const QStringList& clazzes, QObject* service, const ctkDictionary& properties = ctkDictionary());
216 
238  ctkServiceRegistration registerService(const char* clazz, QObject* service, const ctkDictionary& properties = ctkDictionary());
239 
240  template<class S>
241  ctkServiceRegistration registerService(QObject* service, const ctkDictionary& properties = ctkDictionary())
242  {
243  const char* clazz = qobject_interface_iid<S*>();
244  if (clazz == 0)
245  {
246  throw ctkServiceException(QString("The interface class you are registering your service %1 against has no Q_DECLARE_INTERFACE macro")
247  .arg(service->metaObject()->className()));
248  }
249  return registerService(clazz, service, properties);
250  }
251 
297  QList<ctkServiceReference> getServiceReferences(const QString& clazz, const QString& filter = QString());
298 
319  template<class S>
320  QList<ctkServiceReference> getServiceReferences(const QString& filter = QString())
321  {
322  const char* clazz = qobject_interface_iid<S*>();
323  if (clazz == 0) throw ctkServiceException("The service interface class has no Q_DECLARE_INTERFACE macro");
324  return getServiceReferences(QString(clazz), filter);
325  }
326 
358 
374  template<class S>
376  {
377  const char* clazz = qobject_interface_iid<S*>();
378  if (clazz == 0) throw ctkServiceException("The service interface class has no Q_DECLARE_INTERFACE macro");
379  return getServiceReference(QString(clazz));
380  }
381 
440  QObject* getService(const ctkServiceReference& reference);
441 
465  template<class S>
466  S* getService(const ctkServiceReference& reference)
467  {
468  return qobject_cast<S*>(getService(reference));
469  }
470 
510  bool ungetService(const ctkServiceReference& reference);
511 
534  QFileInfo getDataFile(const QString& filename);
535 
594  QSharedPointer<ctkPlugin> installPlugin(const QUrl& location, QIODevice* input = 0);
595 
613  bool connectPluginListener(const QObject* receiver, const char* slot, Qt::ConnectionType type = Qt::QueuedConnection);
614 
628  void disconnectPluginListener(const QObject* receiver, const char* slot = 0);
629 
645  bool connectFrameworkListener(const QObject* receiver, const char* slot, Qt::ConnectionType type = Qt::QueuedConnection);
646 
660  void disconnectFrameworkListener(const QObject* receiver, const char* slot = 0);
661 
713  void connectServiceListener(QObject* receiver, const char* slot,
714  const QString& filter = QString());
715 
724  void disconnectServiceListener(QObject* receiver, const char* slot);
725 
726 protected:
727 
728  friend class ctkPluginFrameworkPrivate;
729  friend class ctkPlugin;
730  friend class ctkPluginPrivate;
731 
732  ctkPluginContext(ctkPluginPrivate* plugin);
733 
734  ctkPluginContextPrivate * const d_ptr;
735 
736 private:
737  Q_DECLARE_PRIVATE(ctkPluginContext)
738 };
739 
740 
741 #endif /* CTKPLUGINCONTEXT_H_ */
bool connectPluginListener(const QObject *receiver, const char *slot, Qt::ConnectionType type=Qt::QueuedConnection)
QSharedPointer< ctkPlugin > installPlugin(const QUrl &location, QIODevice *input=0)
void disconnectFrameworkListener(const QObject *receiver, const char *slot=0)
ctkPluginContext(ctkPluginPrivate *plugin)
QVariant getProperty(const QString &key) const
void disconnectPluginListener(const QObject *receiver, const char *slot=0)
void connectServiceListener(QObject *receiver, const char *slot, const QString &filter=QString())
QSharedPointer< ctkPlugin > getPlugin(long id) const
QObject * getService(const ctkServiceReference &reference)
bool ungetService(const ctkServiceReference &reference)
ctkServiceRegistration registerService(const QStringList &clazzes, QObject *service, const ctkDictionary &properties=ctkDictionary())
ctkPluginContextPrivate *const d_ptr
ctkServiceRegistration registerService(QObject *service, const ctkDictionary &properties=ctkDictionary())
QFileInfo getDataFile(const QString &filename)
bool connectFrameworkListener(const QObject *receiver, const char *slot, Qt::ConnectionType type=Qt::QueuedConnection)
QSharedPointer< ctkPlugin > getPlugin() const
ctkServiceReference getServiceReference()
ctkServiceReference getServiceReference(const QString &clazz)
void disconnectServiceListener(QObject *receiver, const char *slot)
QList< ctkServiceReference > getServiceReferences(const QString &clazz, const QString &filter=QString())
QList< ctkServiceReference > getServiceReferences(const QString &filter=QString())
QList< QSharedPointer< ctkPlugin > > getPlugins() const
S * getService(const ctkServiceReference &reference)
ctkServiceRegistration registerService(const char *clazz, QObject *service, const ctkDictionary &properties=ctkDictionary())
QHash< QString, QVariant > ctkDictionary
Definition: ctkDictionary.h:37