123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /*=============================================================================
- Library: CTK
- Copyright (c) 2010 German Cancer Research Center,
- Division of Medical and Biological Informatics
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =============================================================================*/
- #include "ctkPluginContext.h"
- #include "ctkPluginPrivate_p.h"
- #include "ctkPluginFrameworkContext_p.h"
- #include "ctkServiceRegistration.h"
- #include "ctkServiceReference.h"
- #include "ctkServiceReferencePrivate.h"
- #include <stdexcept>
- class ctkPluginContextPrivate
- {
- public:
- ctkPluginPrivate* plugin;
- ctkPluginContextPrivate(ctkPluginPrivate* plugin)
- : plugin(plugin)
- {}
- /**
- * Check that the plugin is still valid.
- */
- void isPluginContextValid() const
- {
- if (!plugin) {
- throw std::logic_error("This plugin context is no longer valid");
- }
- }
- void invalidate()
- {
- plugin = 0;
- }
- };
- ctkPluginContext::ctkPluginContext(ctkPluginPrivate* plugin)
- : d_ptr(new ctkPluginContextPrivate(plugin))
- {}
- ctkPluginContext::~ctkPluginContext()
- {
- Q_D(ctkPluginContext);
- delete d;
- }
- ctkPlugin* ctkPluginContext::getPlugin() const
- {
- Q_D(const ctkPluginContext);
- d->isPluginContextValid();
- return d->plugin->q_func();
- }
- ctkPlugin* ctkPluginContext::getPlugin(long id) const
- {
- Q_D(const ctkPluginContext);
- return d->plugin->fwCtx->plugins->getPlugin(id);
- }
- QList<ctkPlugin*> ctkPluginContext::getPlugins() const
- {
- Q_D(const ctkPluginContext);
- d->isPluginContextValid();
- return d->plugin->fwCtx->plugins->getPlugins();
- }
- ctkPlugin* ctkPluginContext::installPlugin(const QUrl& location, QIODevice* in)
- {
- Q_D(ctkPluginContext);
- d->isPluginContextValid();
- return d->plugin->fwCtx->plugins->install(location, in);
- }
- ctkServiceRegistration* ctkPluginContext::registerService(const QStringList& clazzes, QObject* service, const ServiceProperties& properties)
- {
- Q_D(ctkPluginContext);
- d->isPluginContextValid();
- return d->plugin->fwCtx->services.registerService(d->plugin, clazzes, service, properties);
- }
- QList<ctkServiceReference*> ctkPluginContext::getServiceReferences(const QString& clazz, const QString& filter)
- {
- Q_D(ctkPluginContext);
- d->isPluginContextValid();
- return d->plugin->fwCtx->services.get(clazz, filter);
- }
- ctkServiceReference* ctkPluginContext::getServiceReference(const QString& clazz)
- {
- Q_D(ctkPluginContext);
- d->isPluginContextValid();
- return d->plugin->fwCtx->services.get(d->plugin, clazz);
- }
- QObject* ctkPluginContext::getService(ctkServiceReference* reference)
- {
- if (reference == 0)
- {
- throw std::invalid_argument("Null ctkServiceReference is not valid");
- }
- Q_D(ctkPluginContext);
- d->isPluginContextValid();
- return reference->d_func()->getService(d->plugin->q_func());
- }
- bool ctkPluginContext::connectPluginListener(const QObject* receiver, const char* method,
- Qt::ConnectionType type)
- {
- Q_D(ctkPluginContext);
- // TODO check permissions for a direct connection
- return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChanged(ctkPluginEvent)), method, type);
- }
- bool ctkPluginContext::connectFrameworkListener(const QObject* receiver, const char* method, Qt::ConnectionType type)
- {
- Q_D(ctkPluginContext);
- return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(frameworkEvent(ctkPluginFrameworkEvent)), method, type);
- }
|