void ctkMetaTypeActivator::start(ctkPluginContext* context) { delete metaTypeProviderTracker; delete metaTypeService; delete logTracker; ctkMTLogTracker* lsTracker = 0; logFileFallback.open(stdout, QIODevice::WriteOnly); ctkLDAPSearchFilter filter(FILTER()); ctkServiceTracker<>* mtpTracker = 0; { QMutexLocker l(&mutex); lsTracker = logTracker = new ctkMTLogTracker(context, &logFileFallback); mtpTracker = metaTypeProviderTracker = new ctkServiceTracker<>(context, filter); } // Do this first to make logging available as early as possible. lsTracker->open(); CTK_DEBUG(lsTracker) << "====== Meta Type Service starting ! ====="; // Do this next to make ctkMetaTypeProviders available as early as possible. mtpTracker->open(); // Register the Meta Type service ctkDictionary properties; properties.insert(ctkPluginConstants::SERVICE_VENDOR, "CommonTK"); properties.insert(ctkPluginConstants::SERVICE_DESCRIPTION, ctkMTMsg::SERVICE_DESCRIPTION); properties.insert(ctkPluginConstants::SERVICE_PID, SERVICE_PID); metaTypeService = new ctkMetaTypeServiceImpl(lsTracker, mtpTracker); context->connectPluginListener(metaTypeService, SLOT(pluginChanged(ctkPluginEvent)), Qt::DirectConnection); metaTypeServiceRegistration = context->registerService<ctkMetaTypeService>(metaTypeService, properties); }
void ctkMetaTypeActivator::stop(ctkPluginContext* context) { Q_UNUSED(context) CTK_DEBUG(logTracker) << "====== Meta Type Service stopping ! ====="; metaTypeService->disconnect(); metaTypeProviderTracker->close(); metaTypeServiceRegistration.unregister(); metaTypeServiceRegistration = 0; // Do this last to leave logging available as long as possible. logTracker->close(); }
void ctkQtMobilityServiceRuntime::removePlugin(QSharedPointer<ctkPlugin> plugin) { CTK_DEBUG(ctkQtMobilityServiceActivator::getLogService()) << "Remove " << plugin->getSymbolicName() << " from QtMobSR"; QList<ctkQtMobilityServiceFactory*> serviceFactories = mapPluginToServiceFactory.values(plugin); QList<ctkServiceRegistration> serviceRegs = mapPluginToServiceRegistration.values(plugin); foreach(ctkServiceRegistration serviceReg, serviceRegs) { serviceReg.unregister(); } mapPluginToServiceRegistration.remove(plugin); mapPluginToServiceFactory.remove(plugin); qDeleteAll(serviceFactories); }
void ctkQtMobilityServiceRuntime::processPlugin(QSharedPointer<ctkPlugin> plugin) { QHash<QString, QString> headers = plugin->getHeaders(); QHash<QString, QString>::const_iterator it = headers.find(ctkQtMobilityServiceConstants::SERVICE_DESCRIPTOR); ctkLogService* log = ctkQtMobilityServiceActivator::getLogService(); CTK_DEBUG(log) << "Process header " << ctkQtMobilityServiceConstants::SERVICE_DESCRIPTOR << " for plugin #" << plugin->getPluginId() << ": " << (it != headers.end() ? it.value() : "[missing]"); if (it != headers.end()) { QString sd = it.value(); if (sd.isEmpty()) { QString msg = QString("Header ") + ctkQtMobilityServiceConstants::SERVICE_DESCRIPTOR + " empty."; ctkQtMobilityServiceActivator::logError(plugin->getPluginContext(), msg); return; } QByteArray serviceDescription = plugin->getResource(sd); QBuffer serviceBuffer(&serviceDescription); qServiceManager.addService(&serviceBuffer); QServiceManager::Error error = qServiceManager.error(); if (!(error == QServiceManager::NoError || error == QServiceManager::ServiceAlreadyExists)) { QString msg = QString("Registering the QtMobility service descriptor failed: ") + getQServiceManagerErrorString(error); ctkQtMobilityServiceActivator::logError(plugin->getPluginContext(), msg); return; } QString serviceName = plugin->getSymbolicName() + "_" + plugin->getVersion().toString(); QList<QServiceInterfaceDescriptor> descriptors = qServiceManager.findInterfaces(serviceName); if (descriptors.isEmpty()) { QString msg = QString("No interfaces found for service name ") + serviceName; ctkQtMobilityServiceActivator::logWarning(plugin->getPluginContext(), msg); return; } QListIterator<QServiceInterfaceDescriptor> it(descriptors); while (it.hasNext()) { QServiceInterfaceDescriptor descr = it.next(); CTK_DEBUG(ctkQtMobilityServiceActivator::getLogService()) << "Registering:" << descr.interfaceName(); QStringList classes; ctkDictionary props; QStringList customKeys = descr.customAttributes(); QStringListIterator keyIt(customKeys); bool classAttrFound = false; while (keyIt.hasNext()) { QString key = keyIt.next(); if (key == ctkPluginConstants::OBJECTCLASS) { classAttrFound = true; classes << descr.customAttribute(key); } else { props.insert(key, descr.customAttribute(key)); } } if (!classAttrFound) { QString msg = QString("The custom attribute \"") + ctkPluginConstants::OBJECTCLASS + "\" is missing in the interface description of \"" + descr.interfaceName(); ctkQtMobilityServiceActivator::logError(plugin->getPluginContext(), msg); continue; } ctkQtMobilityServiceFactory* serviceObject = new ctkQtMobilityServiceFactory(descr, this, plugin); ctkServiceRegistration serviceReg = plugin->getPluginContext()->registerService(classes, serviceObject, props); if (serviceReg) { mapPluginToServiceFactory.insert(plugin, serviceObject); mapPluginToServiceRegistration.insert(plugin, serviceReg); } else { QString msg = QString("Could not register QtMobility service ") + descr.serviceName() + " " + descr.interfaceName(); ctkQtMobilityServiceActivator::logError(plugin->getPluginContext(), msg); continue; } } } }