ctkPlugin.cpp

Go to the documentation of this file.
00001 /*=============================================================================
00002 
00003   Library: CTK
00004 
00005   Copyright (c) 2010 German Cancer Research Center,
00006     Division of Medical and Biological Informatics
00007 
00008   Licensed under the Apache License, Version 2.0 (the "License");
00009   you may not use this file except in compliance with the License.
00010   You may obtain a copy of the License at
00011 
00012     http://www.apache.org/licenses/LICENSE-2.0
00013 
00014   Unless required by applicable law or agreed to in writing, software
00015   distributed under the License is distributed on an "AS IS" BASIS,
00016   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017   See the License for the specific language governing permissions and
00018   limitations under the License.
00019 
00020 =============================================================================*/
00021 
00022 #include "ctkPlugin.h"
00023 
00024 #include "ctkPluginPrivate_p.h"
00025 #include "ctkPluginArchive_p.h"
00026 #include "ctkPluginFrameworkContext_p.h"
00027 
00028 #include <QStringList>
00029 
00030 
00031   ctkPlugin::ctkPlugin(ctkPluginFrameworkContext* fw,
00032                  ctkPluginArchive* pa)
00033     : d_ptr(new ctkPluginPrivate(*this, fw, pa))
00034   {
00035 
00036   }
00037 
00038   ctkPlugin::ctkPlugin(ctkPluginPrivate& dd)
00039     : d_ptr(&dd)
00040   {
00041 
00042   }
00043 
00044   ctkPlugin::~ctkPlugin()
00045   {
00046     delete d_ptr;
00047   }
00048 
00049   ctkPlugin::State ctkPlugin::getState() const
00050   {
00051     Q_D(const ctkPlugin);
00052     return d->state;
00053   }
00054 
00055   void ctkPlugin::start(const StartOptions& options)
00056   {
00057     Q_D(ctkPlugin);
00058 
00059     if (d->state == UNINSTALLED)
00060     {
00061       throw std::logic_error("ctkPlugin is uninstalled");
00062     }
00063 
00064     // Initialize the activation; checks initialization of lazy
00065     // activation.
00066 
00067     //TODO 1: If activating or deactivating, wait a litle
00068     // we don't use mutliple threads to start plugins for now
00069     //waitOnActivation(lock, "ctkPlugin::start", false);
00070 
00071     //2: start() is idempotent, i.e., nothing to do when already started
00072     if (d->state == ACTIVE)
00073     {
00074       return;
00075     }
00076 
00077     //3: Record non-transient start requests.
00078     if ((options & START_TRANSIENT) == 0)
00079     {
00080       d->setAutostartSetting(options);
00081     }
00082 
00083     //4: Resolve plugin (if needed)
00084     d->getUpdatedState();
00085 
00086     //5: Register Qt Mobility service xml files
00087     //only register if we are not already in the STARTING state
00088     if (d->state != STARTING)
00089     {
00090       QByteArray serviceDescriptor = getResource("servicedescriptor.xml");
00091       if (!serviceDescriptor.isEmpty())
00092       {
00093         d->fwCtx->services.registerService(d, serviceDescriptor);
00094       }
00095     }
00096 
00097     //6: Eager?
00098     if ((options & START_ACTIVATION_POLICY) && !d->eagerActivation )
00099     {
00100       if (STARTING == d->state) return;
00101       d->state = STARTING;
00102       d->pluginContext = new ctkPluginContext(this->d_func());
00103       ctkPluginEvent pluginEvent(ctkPluginEvent::LAZY_ACTIVATION, this);
00104       d->fwCtx->listeners.emitPluginChanged(pluginEvent);
00105     }
00106     else
00107     {
00108       d->finalizeActivation();
00109     }
00110   }
00111 
00112   void ctkPlugin::stop(const StopOptions& options)
00113   {
00114 
00115   }
00116 
00117   ctkPluginContext* ctkPlugin::getPluginContext() const
00118   {
00119     //TODO security checks
00120     Q_D(const ctkPlugin);
00121     return d->pluginContext;
00122   }
00123 
00124   long ctkPlugin::getPluginId() const
00125   {
00126     Q_D(const ctkPlugin);
00127     return d->id;
00128   }
00129 
00130   QString ctkPlugin::getLocation() const
00131   {
00132     //TODO security
00133     Q_D(const ctkPlugin);
00134     return d->location;
00135   }
00136 
00137   QHash<QString, QString> ctkPlugin::getHeaders()
00138   {
00139     //TODO security
00140     Q_D(ctkPlugin);
00141     if (d->cachedRawHeaders.empty())
00142     {
00143       d->cachedRawHeaders = d->archive->getUnlocalizedAttributes();
00144     }
00145 
00146     if (d->state == UNINSTALLED)
00147     {
00148       return d->cachedHeaders;
00149     }
00150 
00151     //TODO use the embedded .qm files to localize header values
00152     return d->cachedRawHeaders;
00153   }
00154 
00155   QString ctkPlugin::getSymbolicName() const
00156   {
00157     Q_D(const ctkPlugin);
00158     return d->symbolicName;
00159   }
00160 
00161   QStringList ctkPlugin::getResourceList(const QString& path) const
00162   {
00163     Q_D(const ctkPlugin);
00164     return d->archive->findResourcesPath(path);
00165   }
00166 
00167   QByteArray ctkPlugin::getResource(const QString& path) const
00168   {
00169     Q_D(const ctkPlugin);
00170     return d->archive->getPluginResource(path);
00171   }
00172 
00173   ctkVersion ctkPlugin::getVersion() const
00174   {
00175     Q_D(const ctkPlugin);
00176     return d->version;
00177 
00178 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines