ctkServiceReference.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 "ctkServiceReference.h"
00023 #include "ctkServiceReferencePrivate.h"
00024 #include "ctkServiceRegistrationPrivate.h"
00025 #include "ctkPluginPrivate_p.h"
00026 #include "ctkPluginConstants.h"
00027 
00028 #include <QStringList>
00029 #include <QMutexLocker>
00030 
00031 
00032   ctkServiceReference::ctkServiceReference(ctkServiceRegistrationPrivate* reg)
00033     : d_ptr(new ctkServiceReferencePrivate(reg))
00034   {
00035 
00036   }
00037 
00038   ctkServiceReference::~ctkServiceReference()
00039   {
00040     delete d_ptr;
00041   }
00042 
00043   QVariant ctkServiceReference::getProperty(const QString& key) const
00044   {
00045     Q_D(const ctkServiceReference);
00046 
00047     QMutexLocker lock(&d->registration->propsLock);
00048 
00049     return d->registration->properties.value(key);
00050   }
00051 
00052   QStringList ctkServiceReference::getPropertyKeys() const
00053   {
00054     Q_D(const ctkServiceReference);
00055 
00056     QMutexLocker lock(&d->registration->propsLock);
00057 
00058     return d->registration->properties.keys();
00059   }
00060 
00061   ctkPlugin* ctkServiceReference::getPlugin() const
00062   {
00063     return d_func()->registration->plugin->q_func();
00064   }
00065 
00066   QList<ctkPlugin*> ctkServiceReference::getUsingPlugins() const
00067   {
00068     Q_D(const ctkServiceReference);
00069 
00070     QMutexLocker lock(&d->registration->propsLock);
00071 
00072     if (d->registration->reference != 0)
00073     {
00074       return d->registration->dependents.keys();
00075     }
00076     else
00077     {
00078       return QList<ctkPlugin*>();
00079     }
00080   }
00081 
00082   bool ctkServiceReference::operator<(const ctkServiceReference& reference) const
00083   {
00084     bool sameFw = d_func()->registration->plugin->fwCtx == reference.d_func()->registration->plugin->fwCtx;
00085     if (!sameFw)
00086     {
00087       throw std::invalid_argument("Can not compare service references "
00088                                   "belonging to different framework "
00089                                   "instances.");
00090     }
00091 
00092     int r1 = getProperty(PluginConstants::SERVICE_RANKING).toInt();
00093     int r2 = reference.getProperty(PluginConstants::SERVICE_RANKING).toInt();
00094 
00095     if (r1 != r2)
00096     {
00097       // use ranking if ranking differs
00098       return r1 < r2 ? false : true;
00099     }
00100     else
00101     {
00102       qlonglong id1 = getProperty(PluginConstants::SERVICE_ID).toLongLong();
00103       qlonglong id2 = reference.getProperty(PluginConstants::SERVICE_ID).toLongLong();
00104 
00105       // otherwise compare using IDs,
00106       // is less than if it has a higher ID.
00107       return id2< id1;
00108     }
00109   }
00110 
00111   bool ctkServiceReference::operator==(const ctkServiceReference& reference) const
00112   {
00113     return d_func()->registration == reference.d_func()->registration;
00114 
00115 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1