ソースを参照

QtMobility is no longer a required dependency for PluginFramework.

A new plugin, org.commontk.qtmobility.service now handles all
QtMobility ServiceFramework related tasks. The PluginFramework does
not depend on any external library anymore (except for Qt itself).
The new plugin listens to plugin events, reads a XML file from active
plugins and registers a "proxy service" on behalf of the original
plugin which represents the QtMobility service.
Sascha Zelzer 14 年 前
コミット
4eee5155e5
共有28 個のファイルを変更した793 個の追加404 個の削除を含む
  1. 80 64
      CMakeExternals/QtMobility.cmake
  2. 2 1
      CMakeLists.txt
  3. 0 33
      Libs/PluginFramework/CMakeLists.txt
  4. 0 13
      Libs/PluginFramework/ctkPlugin.cpp
  5. 0 25
      Libs/PluginFramework/ctkPluginDatabase.cpp
  6. 0 56
      Libs/PluginFramework/ctkQtServiceRegistrationPrivate.cpp
  7. 0 51
      Libs/PluginFramework/ctkQtServiceRegistrationPrivate.h
  8. 0 6
      Libs/PluginFramework/ctkServiceRegistration.cpp
  9. 0 2
      Libs/PluginFramework/ctkServiceRegistration.h
  10. 0 110
      Libs/PluginFramework/ctkServices.cpp
  11. 0 7
      Libs/PluginFramework/ctkServices_p.h
  12. 0 1
      Libs/PluginFramework/target_libraries.cmake
  13. 4 0
      Plugins/org.commontk.eventbus/manifest_headers.cmake
  14. 29 0
      Plugins/org.commontk.qtmobility.service/CMakeLists.txt
  15. 89 0
      Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceActivator.cpp
  16. 39 0
      Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceActivator_p.h
  17. 2 21
      Libs/PluginFramework/ctkQtServiceRegistration_p.h
  18. 18 10
      Libs/PluginFramework/ctkQtServiceRegistration.cpp
  19. 81 0
      Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceFactory.cpp
  20. 54 0
      Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceFactory_p.h
  21. 234 0
      Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceRuntime.cpp
  22. 82 0
      Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceRuntime_p.h
  23. 2 0
      Plugins/org.commontk.qtmobility.service/manifest_headers.cmake
  24. 10 0
      Plugins/org.commontk.qtmobility.service/target_libraries.cmake
  25. 1 0
      SuperBuild.cmake
  26. 35 0
      Utilities/CMake/FindQtMobility.cmake
  27. 7 4
      Utilities/QtMobility/QtMobility-1.0.0-install-win32.cmake.in
  28. 24 0
      Utilities/QtMobility/QtMobilityConfig.cmake.in

+ 80 - 64
CMakeExternals/QtMobility.cmake

@@ -2,84 +2,100 @@
 # QtMobility
 #
 SET(QtMobility_DEPENDS)
-ctkMacroShouldAddExternalProject(QTMOBILITY_QTSERVICEFW_LIBRARIES add_project)
+ctkMacroShouldAddExternalProject(QtMobility_LIBRARIES add_project)
 IF(${add_project})
-  SET(QtMobility_enabling_variable QTMOBILITY_QTSERVICEFW_LIBRARIES)
+  SET(QtMobility_enabling_variable QtMobility_LIBRARIES)
   SET(proj QtMobility)
 #   MESSAGE(STATUS "Adding project:${proj}")
   SET(QtMobility_DEPENDS ${proj})
 
-  # Patch program
-  FIND_PROGRAM(CTK_PATCH_EXECUTABLE patch
-    "C:/Program Files/GnuWin32/bin"
-    "C:/Program Files (x86)/GnuWin32/bin")
-  MARK_AS_ADVANCED(CTK_PATCH_EXECUTABLE)
-  IF(NOT CTK_PATCH_EXECUTABLE)
-    MESSAGE(FATAL_ERROR "error: Patch is required to build ${proj}. Set CTK_PATCH_EXECUTABLE. If running Windows, you can download it here: http://gnuwin32.sourceforge.net/packages/patch.htm")
-  ENDIF()
-  
-  # Configure patch script
-  SET(qtmobility_src_dir ${ep_source_dir}/${proj})
-  SET(qtmobility_patch_dir ${CTK_SOURCE_DIR}/Utilities/QtMobility/)
-  SET(qtmobility_configured_patch_dir ${CTK_BINARY_DIR}/Utilities/QtMobility/)
-  SET(qtmobility_patchscript
-    ${qtmobility_configured_patch_dir}/QtMobility-1.0.0-patch.cmake)
-  CONFIGURE_FILE(
-    ${qtmobility_patch_dir}/QtMobility-1.0.0-patch.cmake.in
-    ${qtmobility_patchscript} @ONLY)
+  IF(NOT DEFINED QtMobility_DIR)
+    # Patch program
+    FIND_PROGRAM(CTK_PATCH_EXECUTABLE patch
+      "C:/Program Files/GnuWin32/bin"
+      "C:/Program Files (x86)/GnuWin32/bin")
+    MARK_AS_ADVANCED(CTK_PATCH_EXECUTABLE)
+    IF(NOT CTK_PATCH_EXECUTABLE)
+      MESSAGE(FATAL_ERROR "error: Patch is required to build ${proj}. Set CTK_PATCH_EXECUTABLE. If running Windows, you can download it here: http://gnuwin32.sourceforge.net/packages/patch.htm")
+    ENDIF()
+    
+    # Configure patch script
+    SET(qtmobility_src_dir ${ep_source_dir}/${proj})
+    SET(qtmobility_patch_dir ${CTK_SOURCE_DIR}/Utilities/QtMobility/)
+    SET(qtmobility_configured_patch_dir ${CTK_BINARY_DIR}/Utilities/QtMobility/)
+    SET(qtmobility_patchscript
+      ${qtmobility_configured_patch_dir}/QtMobility-1.0.0-patch.cmake)
+    CONFIGURE_FILE(
+      ${qtmobility_patch_dir}/QtMobility-1.0.0-patch.cmake.in
+      ${qtmobility_patchscript} @ONLY)
 
-  # Define configure options
-  SET(qtmobility_modules "serviceframework")
-  SET(qtmobility_build_type "release")
-  IF(UNIX OR MINGW)
-    IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
+    # Define configure options
+    SET(qtmobility_modules "serviceframework")
+    SET(qtmobility_build_type "release")
+    IF(UNIX OR MINGW)
+      IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
+        SET(qtmobility_build_type "debug")
+      ENDIF()
+    ELSEIF(NOT ${CMAKE_CFG_INTDIR} STREQUAL "Release")
       SET(qtmobility_build_type "debug")
-    ENDIF()
-  ELSEIF(NOT ${CMAKE_CFG_INTDIR} STREQUAL "Release")
-    SET(qtmobility_build_type "debug")
-  ENDIf()
-  
-  SET(qtmobility_make_cmd)
-  SET(qtmobility_install_cmd)
-  IF(UNIX)
-    SET(qtmobility_make_cmd make)
-    SET(qtmobility_config_args -${qtmobility_build_type} -libdir ${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY} -no-docs -modules ${qtmobility_modules})
-    SET(qtmobility_install_cmd ${qtmobility_make_cmd} install)
-  ELSEIF(WIN32)
-    SET(qtmobility_make_cmd nmake)
-    IF(MINGW AND NOT MSYS)
-      SET(qtmobility_make_cmd mingw32-make)
-    ENDIF()
+    ENDIf()
+    
+    SET(qtmobility_make_cmd)
+    SET(qtmobility_install_cmd)
+    SET(qtmobility_config_in "${qtmobility_patch_dir}/QtMobilityConfig.cmake.in")
+    SET(qtmobility_config_out "${qtmobility_configured_patch_dir}/QtMobilityConfig.cmake")
+    
+    IF(UNIX)
+      SET(qtmobility_make_cmd make)
+      SET(qtmobility_config_args -${qtmobility_build_type} -libdir ${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY} -no-docs -modules ${qtmobility_modules})
+      SET(qtmobility_install_cmd ${qtmobility_make_cmd} install)
+      
+      SET(QTMOBILITY_QTSERVICEFW_INCLUDE_DIR 
+          "${CTK_BINARY_DIR}/CMakeExternals/Source/QtMobility/install/include")
+      SET(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG
+          "${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libQtServiceFrameworkd.so")
+      SET(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE
+          "${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libQtServiceFramework.so")
+          
+      CONFIGURE_FILE("${qtmobility_config_in}" "${qtmobility_config_out}" @ONLY)
+    ELSEIF(WIN32)
+      SET(qtmobility_make_cmd nmake)
+      IF(MINGW AND NOT MSYS)
+        SET(qtmobility_make_cmd mingw32-make)
+      ENDIF()
 
-    SET(qtmobility_win32_install_prefix "${ep_source_dir}/${proj}/install/")
-    STRING(REPLACE "/" "\\" qtmobility_win32_native_install_prefix ${qtmobility_win32_install_prefix})
+      SET(qtmobility_win32_install_prefix "${ep_source_dir}/${proj}/install/")
+      STRING(REPLACE "/" "\\" qtmobility_win32_native_install_prefix ${qtmobility_win32_install_prefix})
 
-    SET(qtmobility_config_args -${qtmobility_build_type} -qt ${QT_BINARY_DIR} -prefix ${qtmobility_win32_native_install_prefix} -no-docs -modules ${qtmobility_modules})
+      SET(qtmobility_config_args -${qtmobility_build_type} -qt ${QT_BINARY_DIR} -prefix ${qtmobility_win32_native_install_prefix} -no-docs -modules ${qtmobility_modules})
 
-    CONFIGURE_FILE(${qtmobility_patch_dir}/QtMobility-1.0.0-install-win32.cmake.in
-                   ${qtmobility_configured_patch_dir}/QtMobility-1.0.0-install-win32.cmake @ONLY)
-				   
-    SET(qtmobility_install_cmd ${CMAKE_COMMAND} -D INTERMEDIATE_DIRECTORY:STRING=$(IntDir) -P ${qtmobility_configured_patch_dir}/QtMobility-1.0.0-install-win32.cmake)
+      CONFIGURE_FILE(${qtmobility_patch_dir}/QtMobility-1.0.0-install-win32.cmake.in
+                     ${qtmobility_configured_patch_dir}/QtMobility-1.0.0-install-win32.cmake @ONLY)
+				     
+      SET(qtmobility_install_cmd ${CMAKE_COMMAND} -D INTERMEDIATE_DIRECTORY:STRING=$(IntDir) -P ${qtmobility_configured_patch_dir}/QtMobility-1.0.0-install-win32.cmake)
+      
+      # On Windows, the QtMobilityConfig.cmake file is written in the install script above
+    ENDIF()
+    
+    ExternalProject_Add(${proj}
+      URL ${CTK_SOURCE_DIR}/Utilities/QtMobility/qt-mobility-servicefw-opensource-src-1.0.0.tar.gz
+      PATCH_COMMAND ${CMAKE_COMMAND} -P ${qtmobility_patchscript}
+      CONFIGURE_COMMAND <SOURCE_DIR>/configure ${qtmobility_config_args}
+      BUILD_COMMAND ${qtmobility_make_cmd}
+      INSTALL_COMMAND ${qtmobility_install_cmd}
+      BUILD_IN_SOURCE 1
+      )
+      
+    SET(QtMobility_DIR ${qtmobility_configured_patch_dir})
+      
+  ELSE()
+    ctkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}")
   ENDIF()
-  
-  ExternalProject_Add(${proj}
-    URL ${CTK_SOURCE_DIR}/Utilities/QtMobility/qt-mobility-servicefw-opensource-src-1.0.0.tar.gz
-    PATCH_COMMAND ${CMAKE_COMMAND} -P ${qtmobility_patchscript}
-    CONFIGURE_COMMAND <SOURCE_DIR>/configure ${qtmobility_config_args}
-    BUILD_COMMAND ${qtmobility_make_cmd}
-    INSTALL_COMMAND ${qtmobility_install_cmd}
-    BUILD_IN_SOURCE 1
-    )
     
   # Since the full path of QtMobility library is used, there is not need to add 
   # its corresponding library output directory to CTK_EXTERNAL_LIBRARY_DIRS
 
-  IF(UNIX)
-    SET(${QtMobility_enabling_variable}_INCLUDE_DIRS 
-        "${CTK_BINARY_DIR}/CMakeExternals/Source/QtMobility/install/include")
-  ELSE()
-    SET(${QtMobility_enabling_variable}_INCLUDE_DIRS
-        "${qtmobility_win32_install_prefix}/include")
-  ENDIF()
+  SET(${QtMobility_enabling_variable}_INCLUDE_DIRS QtMobility_INCLUDE_DIRS)
+  SET(${QtMobility_enabling_variable}_FIND_PACKAGE_CMD QtMobility)
 	
 ENDIF()

+ 2 - 1
CMakeLists.txt

@@ -288,7 +288,7 @@ SET(CTK_LIBS
 # CTK Plugins - Use ON or OFF to indicate if the plugin should be built by default
 #
 SET(CTK_PLUGINS
-  org.commontk.eventbus:ON
+  org.commontk.eventbus:OFF
   org.commontk.cli:OFF
   org.commontk.dah.app:OFF
   org.commontk.dah.core:OFF
@@ -299,6 +299,7 @@ SET(CTK_PLUGINS
   org.commontk.log4qt:OFF
   org.commontk.plugingenerator.core:OFF
   org.commontk.plugingenerator.ui:OFF
+  org.commontk.qtmobility.service:OFF
   )
 
 #-----------------------------------------------------------------------------

+ 0 - 33
Libs/PluginFramework/CMakeLists.txt

@@ -1,37 +1,6 @@
 PROJECT(CTKPluginFramework)
 
 #
-# 3rd party dependencies
-#
-
-SET(_qtmob_config "${CTK_BINARY_DIR}/../Utilities/QtMobility/QtMobilityConfig.cmake")
-IF(EXISTS ${_qtmob_config})
-  INCLUDE(${_qtmob_config})
-ELSE()
-  SET(QTMOBILITY_LIBRARY_DIR "${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
-  SET(QTMOBILITY_INCLUDE_DIRS 
-  "${CTK_BINARY_DIR}/../CMakeExternals/Source/QtMobility/install/include"
-  )
-ENDIF()
-
-FIND_LIBRARY(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG QtServiceFrameworkd
-             PATHS ${QTMOBILITY_LIBRARY_DIR}
-             )
-             
-FIND_LIBRARY(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE QtServiceFramework
-             PATHS ${QTMOBILITY_LIBRARY_DIR}
-             )
-             
-SET(QTMOBILITY_QTSERVICEFW_LIBRARIES )
-IF(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE AND QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG)
-  SET(QTMOBILITY_QTSERVICEFW_LIBRARIES optimized ${QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE} debug ${QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG})
-ELSEIF(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG)
-  SET(QTMOBILITY_QTSERVICEFW_LIBRARIES ${QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG})
-ELSEIF(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE)
-  SET(QTMOBILITY_QTSERVICEFW_LIBRARIES ${QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE})
-ENDIF()
-
-#
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
 
@@ -61,8 +30,6 @@ SET(KIT_SRCS
   ctkPluginTracker.cpp
   ctkPluginTrackerPrivate.cpp
   ctkPlugins.cpp
-  ctkQtServiceRegistration.cpp
-  ctkQtServiceRegistrationPrivate.cpp
   ctkRequirePlugin.cpp
   ctkServiceEvent.cpp
   ctkServiceException.cpp

+ 0 - 13
Libs/PluginFramework/ctkPlugin.cpp

@@ -104,19 +104,6 @@ void ctkPlugin::start(const StartOptions& options)
   {
     d->finalizeActivation();
   }
-
-  //6: Register Qt Mobility service xml files
-  //only register if we are not already in the STARTING
-  //or ACTIVE state
-  if (d->state & STARTING || d->state & ACTIVE)
-  {
-    QByteArray serviceDescriptor = getResource("servicedescriptor.xml");
-    if (!serviceDescriptor.isEmpty())
-    {
-      d->fwCtx->services->registerService(d, serviceDescriptor);
-    }
-  }
-
 }
 
 void ctkPlugin::stop(const StopOptions& options)

+ 0 - 25
Libs/PluginFramework/ctkPluginDatabase.cpp

@@ -32,7 +32,6 @@
 #include <QApplication>
 #include <QFileInfo>
 #include <QUrl>
-#include <QServiceManager>
 
 #include <QDebug>
 
@@ -193,7 +192,6 @@ void ctkPluginDatabase::updateDB()
       {
         outdatedIds.append(query.value(EBindIndex).toLongLong());
         outdatedPlugins.append(qMakePair(query.value(EBindIndex1).toString(), query.value(EBindIndex2).toString()));
-        outdatedServiceNames.append(query.value(EBindIndex4).toString() + "_" + query.value(EBindIndex5).toString());
       }
     }
   }
@@ -223,29 +221,6 @@ void ctkPluginDatabase::updateDB()
     throw;
   }
 
-  try
-  {
-    QtMobility::QServiceManager serviceManager;
-    QStringListIterator serviceNameIter(outdatedServiceNames);
-    while (serviceNameIter.hasNext())
-    {
-      QString serviceName = serviceNameIter.next();
-      serviceManager.removeService(serviceName);
-      QtMobility::QServiceManager::Error error = serviceManager.error();
-      if (!(error == QtMobility::QServiceManager::NoError ||
-            error == QtMobility::QServiceManager::ComponentNotFound))
-      {
-        throw ctkServiceException(QString("Removing service named ") + serviceName +
-                               " failed: " + QString::number(static_cast<unsigned int>(error)));
-      }
-    }
-  }
-  catch (...)
-  {
-    rollbackTransaction(&query);
-    throw;
-  }
-
   commitTransaction(&query);
 
   QListIterator<QPair<QString,QString> > locationIter(outdatedPlugins);

+ 0 - 56
Libs/PluginFramework/ctkQtServiceRegistrationPrivate.cpp

@@ -1,56 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) 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 "ctkQtServiceRegistrationPrivate.h"
-
-#include "ctkPluginPrivate_p.h"
-#include "ctkPluginFrameworkContext_p.h"
-
-#include "ctkServices_p.h"
-#include "ctkQtServiceRegistration_p.h"
-
-
-ctkQtServiceRegistrationPrivate::ctkQtServiceRegistrationPrivate(ctkQtServiceRegistration* sr,
-                             ctkPluginPrivate* plugin,
-                             QtMobility::QServiceInterfaceDescriptor serviceDescriptor,
-                             const ServiceProperties& props)
-  : ctkServiceRegistrationPrivate(sr, plugin, 0, props),
-    serviceDescriptor(serviceDescriptor)
-{
-
-}
-
-QObject* ctkQtServiceRegistrationPrivate::getService()
-{
-  if (this->plugin->state != ctkPlugin::ACTIVE)
-  {
-    try
-    {
-      this->plugin->q_func().data()->start(0);
-    }
-    catch (const ctkPluginException& e)
-    {
-      qDebug() << e;
-      throw;
-    }
-  }
-  return this->plugin->fwCtx->services->qServiceManager.loadInterface(serviceDescriptor);
-}

+ 0 - 51
Libs/PluginFramework/ctkQtServiceRegistrationPrivate.h

@@ -1,51 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) 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.
-
-=============================================================================*/
-
-
-#ifndef CTKQTSERVICEREGISTRATIONPRIVATE_H
-#define CTKQTSERVICEREGISTRATIONPRIVATE_H
-
-#include "ctkServiceRegistrationPrivate.h"
-
-#include "QServiceInterfaceDescriptor"
-
-
-  class ctkQtServiceRegistration;
-
-  class ctkQtServiceRegistrationPrivate : public ctkServiceRegistrationPrivate
-  {
-  public:
-
-    ctkQtServiceRegistrationPrivate(ctkQtServiceRegistration* sr,
-                                 ctkPluginPrivate* plugin,
-                                 QtMobility::QServiceInterfaceDescriptor serviceDescriptor,
-                                 const ServiceProperties& props);
-
-    QObject* getService();
-
-  protected:
-
-    QtMobility::QServiceInterfaceDescriptor serviceDescriptor;
-
-  };
-
-
-#endif // CTKQTSERVICEREGISTRATIONPRIVATE_H

+ 0 - 6
Libs/PluginFramework/ctkServiceRegistration.cpp

@@ -41,12 +41,6 @@ ctkServiceRegistration::ctkServiceRegistration(ctkPluginPrivate* plugin, QObject
 
 }
 
-ctkServiceRegistration::ctkServiceRegistration(ctkServiceRegistrationPrivate& dd)
-  : d_ptr(&dd)
-{
-
-}
-
 ctkServiceRegistration::~ctkServiceRegistration()
 {
 

+ 0 - 2
Libs/PluginFramework/ctkServiceRegistration.h

@@ -137,8 +137,6 @@ protected:
   ctkServiceRegistration(ctkPluginPrivate* plugin, QObject* service,
                          const ServiceProperties& props);
 
-  ctkServiceRegistration(ctkServiceRegistrationPrivate& dd);
-
   const QScopedPointer<ctkServiceRegistrationPrivate> d_ptr;
 
 private:

+ 0 - 110
Libs/PluginFramework/ctkServices.cpp

@@ -32,13 +32,9 @@
 #include "ctkPluginFrameworkContext_p.h"
 #include "ctkServiceException.h"
 #include "ctkServiceRegistrationPrivate.h"
-#include "ctkQtServiceRegistration_p.h"
 #include "ctkLDAPExpr_p.h"
 
 
-using namespace QtMobility;
-
-
 struct ServiceRegistrationComparator
 {
   bool operator()(const ctkServiceRegistration* a, const ctkServiceRegistration* b) const
@@ -153,112 +149,6 @@ ctkServiceRegistration* ctkServices::registerService(ctkPluginPrivate* plugin,
   return res;
 }
 
-void ctkServices::registerService(ctkPluginPrivate* plugin, QByteArray serviceDescription)
-{
-  QMutexLocker lock(&mutex);
-
-  QBuffer serviceBuffer(&serviceDescription);
-  qServiceManager.addService(&serviceBuffer);
-  QServiceManager::Error error = qServiceManager.error();
-  if (!(error == QServiceManager::NoError || error == QServiceManager::ServiceAlreadyExists))
-  {
-    throw std::invalid_argument(std::string("Registering the service descriptor for plugin ")
-                                + plugin->symbolicName.toStdString() + " failed: " +
-                                getQServiceManagerErrorString(error).toStdString());
-  }
-
-  QString serviceName = plugin->symbolicName + "_" + plugin->version.toString();
-  QList<QServiceInterfaceDescriptor> descriptors = qServiceManager.findInterfaces(serviceName);
-
-  if (descriptors.isEmpty())
-  {
-    qDebug().nospace() << "Warning: No interfaces found for service name " << serviceName
-        << " in plugin " << plugin->symbolicName << " (ctkVersion " << plugin->version.toString() << ")";
-  }
-
-  QListIterator<QServiceInterfaceDescriptor> it(descriptors);
-  while (it.hasNext())
-  {
-    QServiceInterfaceDescriptor descr = it.next();
-    qDebug() << "Registering:" << descr.interfaceName();
-    QStringList classes;
-    ServiceProperties 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)
-    {
-      throw std::invalid_argument(std::string("The custom attribute \"") +
-                                  ctkPluginConstants::OBJECTCLASS.toStdString() +
-                                  "\" is missing in the interface description of \"" +
-                                  descr.interfaceName().toStdString());
-    }
-
-    ctkServiceRegistration* res = new ctkQtServiceRegistration(plugin,
-                                                         descr,
-                                                         createServiceProperties(props, classes));
-    services.insert(res, classes);
-    for (QStringListIterator i(classes); i.hasNext(); )
-    {
-      QString currClass = i.next();
-      QList<ctkServiceRegistration*>& s = classServices[currClass];
-      QList<ctkServiceRegistration*>::iterator ip =
-          std::lower_bound(s.begin(), s.end(), res, ServiceRegistrationComparator());
-      s.insert(ip, res);
-    }
-
-    ctkServiceReference r = res->getReference();
-    plugin->fwCtx->listeners.serviceChanged(
-        plugin->fwCtx->listeners.getMatchingServiceSlots(r),
-        ctkServiceEvent(ctkServiceEvent::REGISTERED, r));
-  }
-}
-
-QString ctkServices::getQServiceManagerErrorString(QServiceManager::Error error)
-{
-  switch (error)
-  {
-  case QServiceManager::NoError:
-    return QString("No error occurred.");
-  case QServiceManager::StorageAccessError:
-    return QString("The service data storage is not accessible. This could be because the caller does not have the required permissions.");
-  case QServiceManager::InvalidServiceLocation:
-    return QString("The service was not found at its specified location.");
-  case QServiceManager::InvalidServiceXml:
-    return QString("The XML defining the service metadata is invalid.");
-  case QServiceManager::InvalidServiceInterfaceDescriptor:
-    return QString("The service interface descriptor is invalid, or refers to an interface implementation that cannot be accessed in the current scope.");
-  case QServiceManager::ServiceAlreadyExists:
-    return QString("Another service has previously been registered with the same location.");
-  case QServiceManager::ImplementationAlreadyExists:
-    return QString("Another service that implements the same interface version has previously been registered.");
-  case QServiceManager::PluginLoadingFailed:
-    return QString("The service plugin cannot be loaded.");
-  case QServiceManager::ComponentNotFound:
-    return QString("The service or interface implementation has not been registered.");
-  case QServiceManager::ServiceCapabilityDenied:
-    return QString("The security session does not allow the service based on its capabilities.");
-  case QServiceManager::UnknownError:
-    return QString("An unknown error occurred.");
-  default:
-    return QString("Unknown error enum.");
-  }
-}
 
 void ctkServices::updateServiceRegistrationOrder(ctkServiceRegistration* sr,
                                               const QStringList& classes)

+ 0 - 7
Libs/PluginFramework/ctkServices_p.h

@@ -27,7 +27,6 @@
 #include <QObject>
 #include <QMutex>
 #include <QStringList>
-#include <QServiceManager>
 
 #include "ctkServiceRegistration.h"
 #include "ctkPluginPrivate_p.h"
@@ -43,8 +42,6 @@ public:
 
   mutable QMutex mutex;
 
-  QtMobility::QServiceManager qServiceManager;
-
   /**
    * Creates a new ServiceProperties object containing <code>in</code>
    * with the keys converted to lower case.
@@ -101,8 +98,6 @@ public:
                                QObject* service,
                                const ServiceProperties& properties);
 
-  void registerService(ctkPluginPrivate* plugin, QByteArray serviceDescription);
-
 
   /**
    * Service ranking changed, reorder registered services
@@ -184,8 +179,6 @@ public:
    */
   QList<ctkServiceRegistration*> getUsedByPlugin(QSharedPointer<ctkPlugin> p) const;
 
-  QString getQServiceManagerErrorString(QtMobility::QServiceManager::Error error);
-
 };
 
 

+ 0 - 1
Libs/PluginFramework/target_libraries.cmake

@@ -6,5 +6,4 @@
 
 SET(target_libraries
   QT_LIBRARIES
-  QTMOBILITY_QTSERVICEFW_LIBRARIES
   )

+ 4 - 0
Plugins/org.commontk.eventbus/manifest_headers.cmake

@@ -0,0 +1,4 @@
+SET(Require-Plugin org.commontk.qtmobility.service)
+SET(QtMobility-ServiceDescriptor servicedescriptor.xml)
+
+SET(Custom-Headers QtMobility-ServiceDescriptor)

+ 29 - 0
Plugins/org.commontk.qtmobility.service/CMakeLists.txt

@@ -0,0 +1,29 @@
+PROJECT(org_commontk_qtmobility_service)
+
+SET(PLUGIN_export_directive "org_commontk_qtmobsfw_EXPORT")
+
+SET(PLUGIN_SRCS
+  ctkQtMobilityServiceActivator.cpp
+  ctkQtMobilityServiceConstants.cpp
+  ctkQtMobilityServiceFactory.cpp
+  ctkQtMobilityServiceRuntime.cpp
+)
+
+SET(PLUGIN_MOC_SRCS
+  ctkQtMobilityServiceActivator_p.h
+  ctkQtMobilityServiceRuntime_p.h
+)
+
+SET(PLUGIN_resources
+
+)
+
+ctkMacroGetTargetLibraries(PLUGIN_target_libraries)
+
+ctkMacroBuildPlugin(
+  EXPORT_DIRECTIVE ${PLUGIN_export_directive}
+  SRCS ${PLUGIN_SRCS}
+  MOC_SRCS ${PLUGIN_MOC_SRCS}
+  RESOURCES ${PLUGIN_resources}
+  TARGET_LIBRARIES ${PLUGIN_target_libraries}
+)

+ 89 - 0
Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceActivator.cpp

@@ -0,0 +1,89 @@
+/*
+ * ctkQtMobilityServiceActivator.cxx
+ *
+ *  Created on: Mar 29, 2010
+ *      Author: zelzer
+ */
+
+
+#include "ctkQtMobilityServiceActivator_p.h"
+#include "ctkQtMobilityServiceRuntime_p.h"
+
+#include <ctkServiceTracker.h>
+#include <ctkServiceException.h>
+#include <ctkLogService.h>
+
+#include <QtPlugin>
+
+ctkServiceTracker* ctkQtMobilityServiceActivator::logTracker = 0;
+
+void ctkQtMobilityServiceActivator::start(ctkPluginContext* context)
+{
+  logTracker = new ctkServiceTracker(context, "ctkLogService");
+  logTracker->open();
+  mobsr = new ctkQtMobilityServiceRuntime(context);
+  mobsr->start();
+}
+
+void ctkQtMobilityServiceActivator::stop(ctkPluginContext* context)
+{
+  Q_UNUSED(context)
+
+  if (mobsr)
+  {
+    mobsr->stop();
+    delete mobsr;
+    mobsr = 0;
+  }
+
+  if (logTracker)
+  {
+    logTracker->close();
+    delete logTracker;
+    logTracker = 0;
+  }
+}
+
+ctkLogService* ctkQtMobilityServiceActivator::getLogService()
+{
+  if (logTracker == 0)
+  {
+    return 0;
+  }
+
+  return qobject_cast<ctkLogService*>(logTracker->getService());
+}
+
+void ctkQtMobilityServiceActivator::logError(ctkPluginContext* pc, const QString& msg, std::exception* e)
+{
+  logPluginContext(pc, ctkLogService::LOG_ERROR, msg, e);
+}
+
+void ctkQtMobilityServiceActivator::logWarning(ctkPluginContext* pc, const QString& msg, std::exception* e)
+{
+  logPluginContext(pc, ctkLogService::LOG_WARNING, msg, e);
+}
+
+void ctkQtMobilityServiceActivator::logInfo(ctkPluginContext* pc, const QString& msg, std::exception* e)
+{
+  logPluginContext(pc, ctkLogService::LOG_INFO, msg, e);
+}
+
+void ctkQtMobilityServiceActivator::logPluginContext(ctkPluginContext* pc, int level, const QString& msg, const std::exception* e)
+{
+  try
+  {
+    ctkServiceReference sr = pc->getServiceReference("ctkLogService");
+    ctkLogService* log = qobject_cast<ctkLogService*>(pc->getService(sr));
+    if (log)
+    {
+      log->log(level, msg, e);
+      pc->ungetService(sr);
+    }
+  }
+  catch (const ctkServiceException&)
+  { }
+}
+
+
+Q_EXPORT_PLUGIN2(org_commontk_qtmobility_service, ctkQtMobilityServiceActivator)

+ 39 - 0
Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceActivator_p.h

@@ -0,0 +1,39 @@
+#ifndef CTKEVENTBUSPLUGIN_H
+#define CTKEVENTBUSPLUGIN_H
+
+#include <ctkPluginActivator.h>
+
+class ctkLogService;
+class ctkServiceTracker;
+class ctkQtMobilityServiceRuntime;
+
+class ctkQtMobilityServiceActivator : public QObject,
+                                      public ctkPluginActivator
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkPluginActivator)
+
+public:
+
+  void start(ctkPluginContext* context);
+  void stop(ctkPluginContext* context);
+
+  static ctkLogService* getLogService();
+
+  static void logError(ctkPluginContext* pc, const QString& msg, std::exception* e = 0);
+  static void logWarning(ctkPluginContext* pc, const QString& msg, std::exception* e = 0);
+  static void logInfo(ctkPluginContext* pc, const QString& msg, std::exception* e = 0);
+
+
+private:
+
+  static void logPluginContext(ctkPluginContext* pc, int level, const QString& msg, const std::exception* e);
+
+  ctkQtMobilityServiceRuntime* mobsr;
+
+  static ctkServiceTracker* logTracker;
+
+};
+
+
+#endif // CTKEVENTBUSPLUGIN_H

+ 2 - 21
Libs/PluginFramework/ctkQtServiceRegistration_p.h

@@ -20,25 +20,6 @@
 =============================================================================*/
 
 
-#ifndef CTKQTSERVICEREGISTRATION_P_H
-#define CTKQTSERVICEREGISTRATION_P_H
+#include "ctkQtMobilityServiceConstants_p.h"
 
-#include "ctkServiceRegistration.h"
-
-#include <QServiceInterfaceDescriptor>
-
-
-  class ctkPluginPrivate;
-
-  class ctkQtServiceRegistration : public ctkServiceRegistration
-  {
-
-  public:
-
-    ctkQtServiceRegistration(ctkPluginPrivate* plugin,
-                          QtMobility::QServiceInterfaceDescriptor serviceDescriptor,
-                          const ServiceProperties& props);
-  };
-
-
-#endif // CTKQTSERVICEREGISTRATION_P_H
+const QString ctkQtMobilityServiceConstants::SERVICE_DESCRIPTOR = "QtMobility-ServiceDescriptor";

+ 18 - 10
Libs/PluginFramework/ctkQtServiceRegistration.cpp

@@ -19,18 +19,26 @@
 
 =============================================================================*/
 
-#include "ctkQtServiceRegistration_p.h"
-#include "ctkQtServiceRegistrationPrivate.h"
 
-#include <QServiceInterfaceDescriptor>
+#ifndef CTKQTMOBILITYSERVICECONSTANTS_P_H
+#define CTKQTMOBILITYSERVICECONSTANTS_P_H
 
+#include <QString>
 
-  ctkQtServiceRegistration::ctkQtServiceRegistration(ctkPluginPrivate* plugin,
-                                               QtMobility::QServiceInterfaceDescriptor serviceDescriptor,
-                                               const ServiceProperties& props)
-    : ctkServiceRegistration(*new ctkQtServiceRegistrationPrivate(this, plugin, serviceDescriptor, props))
-  {
-
-  }
+/**
+ * Defines standard names for QtMobility Service constants.
+ */
+struct ctkQtMobilityServiceConstants
+{
 
+  /**
+     * Manifest header specifying the XML document within a plugin that contains
+     * the plugin's QtMobility service descriptor.
+     * <p>
+     * The attribute value may be retrieved from the <code>ctkDictionary</code>
+     * object returned by the <code>ctkPlugin::getHeaders</code> method.
+     */
+  static const QString SERVICE_DESCRIPTOR; // = "Service-Descriptor";
+};
 
+#endif // CTKQTMOBILITYSERVICECONSTANTS_P_H

+ 81 - 0
Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceFactory.cpp

@@ -0,0 +1,81 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 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 "ctkQtMobilityServiceFactory_p.h"
+
+#include "ctkQtMobilityServiceRuntime_p.h"
+#include "ctkQtMobilityServiceActivator_p.h"
+
+#include <ctkLogService.h>
+#include <ctkPluginException.h>
+#include <ctkPluginConstants.h>
+
+#include <QBuffer>
+
+ctkQtMobilityServiceFactory::ctkQtMobilityServiceFactory(
+  const QServiceInterfaceDescriptor& descr,
+  ctkQtMobilityServiceRuntime* sr, QSharedPointer<ctkPlugin> p)
+  : activeCount(0), serviceDescriptor(descr), sr(sr), servicePlugin(p)
+{
+}
+
+QObject* ctkQtMobilityServiceFactory::getService(
+  QSharedPointer<ctkPlugin> usingPlugin, ctkServiceRegistration* registration)
+{
+  Q_UNUSED(usingPlugin)
+  Q_UNUSED(registration)
+
+  CTK_DEBUG(ctkQtMobilityServiceActivator::getLogService())
+      << "QtMobSF::getService(), " << serviceDescriptor.serviceName() << " "
+      << serviceDescriptor.interfaceName() << serviceDescriptor.majorVersion()
+      << "." << serviceDescriptor.minorVersion() << ", active = " << activeCount;
+
+  if (servicePlugin->getState() != ctkPlugin::ACTIVE)
+  {
+    try
+    {
+      servicePlugin->start(0);
+    }
+    catch (const ctkPluginException* e)
+    {
+      CTK_ERROR_EXC(ctkQtMobilityServiceActivator::getLogService(), e)
+          << "Delayed plugin activation failed.";
+      return 0;
+    }
+  }
+  ++activeCount;
+  return sr->getQServiceManager().loadInterface(serviceDescriptor);
+}
+
+void ctkQtMobilityServiceFactory::ungetService(
+  QSharedPointer<ctkPlugin> usingPlugin, ctkServiceRegistration* registration, QObject* service)
+{
+  Q_UNUSED(usingPlugin)
+  Q_UNUSED(registration)
+  Q_UNUSED(service)
+
+  CTK_DEBUG(ctkQtMobilityServiceActivator::getLogService())
+      << "QtMobSF::ungetService(), " << serviceDescriptor.serviceName() << " "
+      << serviceDescriptor.interfaceName() << serviceDescriptor.majorVersion()
+      << "." << serviceDescriptor.minorVersion() << ", active = " << activeCount;
+  --activeCount;
+}

+ 54 - 0
Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceFactory_p.h

@@ -0,0 +1,54 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 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.
+
+=============================================================================*/
+
+
+#ifndef CTKQTMOBILITYSERVICEFACTORY_P_H
+#define CTKQTMOBILITYSERVICEFACTORY_P_H
+
+#include <ctkServiceFactory.h>
+
+#include <QServiceInterfaceDescriptor>
+
+class ctkQtMobilityServiceRuntime;
+
+using namespace QtMobility;
+
+class ctkQtMobilityServiceFactory : public ctkServiceFactory
+{
+
+public:
+
+  ctkQtMobilityServiceFactory(const QServiceInterfaceDescriptor& descr,
+                              ctkQtMobilityServiceRuntime* sr, QSharedPointer<ctkPlugin> plugin);
+
+  QObject* getService(QSharedPointer<ctkPlugin> usingPlugin, ctkServiceRegistration* registration);
+  void ungetService(QSharedPointer<ctkPlugin> usingPlugin, ctkServiceRegistration* registration, QObject* service);
+
+private:
+
+  int activeCount;
+
+  QServiceInterfaceDescriptor serviceDescriptor;
+  ctkQtMobilityServiceRuntime* sr;
+  QSharedPointer<ctkPlugin> servicePlugin;
+};
+
+#endif // CTKQTMOBILITYSERVICEFACTORY_P_H

+ 234 - 0
Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceRuntime.cpp

@@ -0,0 +1,234 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 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 "ctkQtMobilityServiceRuntime_p.h"
+
+#include "ctkQtMobilityServiceConstants_p.h"
+#include "ctkQtMobilityServiceActivator_p.h"
+#include "ctkQtMobilityServiceFactory_p.h"
+
+#include <ctkPluginContext.h>
+#include <ctkPlugin.h>
+#include <ctkLogService.h>
+#include <ctkPluginConstants.h>
+#include <ctkServiceRegistration.h>
+
+#include <QBuffer>
+
+ctkQtMobilityServiceRuntime::ctkQtMobilityServiceRuntime(ctkPluginContext* pc)
+  : pc(pc)
+{
+}
+
+void ctkQtMobilityServiceRuntime::start()
+{
+  pc->connectPluginListener(this, SLOT(pluginChanged(ctkPluginEvent)), Qt::DirectConnection);
+  QList<QSharedPointer<ctkPlugin> > plugins = pc->getPlugins();
+  foreach(QSharedPointer<ctkPlugin> plugin, plugins)
+  {
+    if ((plugin->getState() & (ctkPlugin::ACTIVE | ctkPlugin::STARTING)) != 0)
+    {
+      processPlugin(plugin);
+    }
+  }
+}
+
+void ctkQtMobilityServiceRuntime::stop()
+{
+  this->disconnect(this, SLOT(pluginChanged(ctkPluginEvent)));
+//  Bundle [] b = (Bundle [])bundleComponents.keySet().toArray(new Bundle[bundleComponents.size()]);
+//      for (int i = 0; i < b.length; i++) {
+//        removeBundle(b[i], ComponentConstants.DEACTIVATION_REASON_DISABLED);
+//      }
+}
+
+QServiceManager& ctkQtMobilityServiceRuntime::getQServiceManager()
+{
+  return qServiceManager;
+}
+
+void ctkQtMobilityServiceRuntime::pluginChanged(const ctkPluginEvent& pe)
+{
+  QSharedPointer<ctkPlugin> plugin = pe.getPlugin();
+
+  ctkPluginEvent::Type eventType = pe.getType();
+  if (eventType == ctkPluginEvent::LAZY_ACTIVATION)
+  {
+    lazy.insert(plugin);
+    processPlugin(plugin);
+  }
+  else if (eventType == ctkPluginEvent::STARTED)
+  {
+    if (!lazy.remove(plugin))
+    {
+      processPlugin(plugin);
+    }
+  }
+  else if (eventType == ctkPluginEvent::STOPPING)
+  {
+    lazy.remove(plugin);
+    removePlugin(plugin);
+  }
+}
+
+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;
+      ServiceProperties 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;
+      }
+    }
+  }
+}
+
+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(serviceRegs);
+  qDeleteAll(serviceFactories);
+}
+
+QString ctkQtMobilityServiceRuntime::getQServiceManagerErrorString(QServiceManager::Error error)
+{
+  switch (error)
+  {
+  case QServiceManager::NoError:
+    return QString("No error occurred.");
+  case QServiceManager::StorageAccessError:
+    return QString("The service data storage is not accessible. This could be because the caller does not have the required permissions.");
+  case QServiceManager::InvalidServiceLocation:
+    return QString("The service was not found at its specified location.");
+  case QServiceManager::InvalidServiceXml:
+    return QString("The XML defining the service metadata is invalid.");
+  case QServiceManager::InvalidServiceInterfaceDescriptor:
+    return QString("The service interface descriptor is invalid, or refers to an interface implementation that cannot be accessed in the current scope.");
+  case QServiceManager::ServiceAlreadyExists:
+    return QString("Another service has previously been registered with the same location.");
+  case QServiceManager::ImplementationAlreadyExists:
+    return QString("Another service that implements the same interface version has previously been registered.");
+  case QServiceManager::PluginLoadingFailed:
+    return QString("The service plugin cannot be loaded.");
+  case QServiceManager::ComponentNotFound:
+    return QString("The service or interface implementation has not been registered.");
+  case QServiceManager::ServiceCapabilityDenied:
+    return QString("The security session does not allow the service based on its capabilities.");
+  case QServiceManager::UnknownError:
+    return QString("An unknown error occurred.");
+  default:
+    return QString("Unknown error enum.");
+  }
+}

+ 82 - 0
Plugins/org.commontk.qtmobility.service/ctkQtMobilityServiceRuntime_p.h

@@ -0,0 +1,82 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 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.
+
+=============================================================================*/
+
+
+#ifndef CTKQTMOBILITYSERVICERUNTIME_P_H
+#define CTKQTMOBILITYSERVICERUNTIME_P_H
+
+#include <QObject>
+#include <QServiceManager>
+
+#include <ctkPluginEvent.h>
+#include <ctkPlugin.h>
+
+class ctkPluginContext;
+class ctkServiceRegistration;
+class ctkQtMobilityServiceFactory;
+
+using namespace QtMobility;
+
+class ctkQtMobilityServiceRuntime : public QObject
+{
+  Q_OBJECT
+
+public:
+
+  ctkQtMobilityServiceRuntime(ctkPluginContext* pc);
+
+  void start();
+  void stop();
+
+  QServiceManager& getQServiceManager();
+
+protected slots:
+
+  void pluginChanged(const ctkPluginEvent& pe);
+
+private:
+
+  QtMobility::QServiceManager qServiceManager;
+
+  QMultiHash<QSharedPointer<ctkPlugin>, ctkQtMobilityServiceFactory*> mapPluginToServiceFactory;
+  QMultiHash<QSharedPointer<ctkPlugin>, ctkServiceRegistration*> mapPluginToServiceRegistration;
+  QSet<QSharedPointer<ctkPlugin> > lazy;
+
+  ctkPluginContext* pc;
+
+  /**
+   * Check if the plugin has a service descriptor and register it.
+   *
+   * @param plugin Plugin to check
+   */
+  void processPlugin(QSharedPointer<ctkPlugin> plugin);
+
+  /**
+   * Remove service resources for plugin
+   *
+   * @param p Plugin to check
+   */
+  void removePlugin(QSharedPointer<ctkPlugin> plugin);
+
+  static QString getQServiceManagerErrorString(QServiceManager::Error error);
+};
+
+#endif // CTKQTMOBILITYSERVICERUNTIME_P_H

+ 2 - 0
Plugins/org.commontk.qtmobility.service/manifest_headers.cmake

@@ -0,0 +1,2 @@
+SET(Plugin-ActivationPolicy "eager")
+SET(Require-Plugin org.commontk.log)

+ 10 - 0
Plugins/org.commontk.qtmobility.service/target_libraries.cmake

@@ -0,0 +1,10 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK plugin.
+# 
+
+SET(target_libraries
+  CTKPluginFramework
+  QtMobility_LIBRARIES
+  )

+ 1 - 0
SuperBuild.cmake

@@ -255,6 +255,7 @@ ExternalProject_Add(${proj}
     -DPYTHONQTGENERATOR_EXECUTABLE:FILEPATH=${PYTHONQTGENERATOR_EXECUTABLE} #FindPythonQtGenerator expects PYTHONQTGENERATOR_EXECUTABLE to be defined
     -DLog4Qt_DIR:PATH=${Log4Qt_DIR} # FindLog4Qt expects Log4Qt_DIR variable to be defined
     -DQtSOAP_DIR:PATH=${QtSOAP_DIR} # FindQtSOAP expects QtSOAP_DIR variable to be defined
+    -DQtMobility_DIR:PATH=${QtMobility_DIR}
     ${dependency_args}
   SOURCE_DIR ${CTK_SOURCE_DIR}
   BINARY_DIR ${CTK_BINARY_DIR}/CTK-build

+ 35 - 0
Utilities/CMake/FindQtMobility.cmake

@@ -0,0 +1,35 @@
+IF(NOT QtMobility_FOUND)
+  FIND_PACKAGE(QtMobility QUIET NO_MODULE)
+ENDIF()
+
+IF(NOT QtMobility_FOUND)
+  SET(QtMobility_DIR "/usr/include/qtmobility/" CACHE PATH "Root of QtMobility source tree")
+  MARK_AS_ADVANCED(QtMobility_DIR)
+
+  FIND_PATH(QTMOBILITY_QTSERVICEFW_INCLUDE_DIR QServiceManager
+            PATHS ${QtMobility_DIR}/include NO_DEFAULT_PATH)
+
+  FIND_LIBRARY(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG QtServiceFrameworkd
+               PATHS ${QtMobility_DIR} NO_DEFAULT_PATH)
+
+  FIND_LIBRARY(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE QtServiceFramework
+               PATHS ${QTMOBILITY_LIBRARY_DIR} NO_DEFAULT_PATH)
+
+  SET(QTMOBILITY_QTSERVICEFW_LIBRARIES )
+  IF(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE AND QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG)
+    SET(QTMOBILITY_QTSERVICEFW_LIBRARIES 
+        optimized ${QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE} 
+        debug     ${QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG})
+  ELSEIF(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG)
+    SET(QTMOBILITY_QTSERVICEFW_LIBRARIES ${QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG})
+  ELSEIF(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE)
+    SET(QTMOBILITY_QTSERVICEFW_LIBRARIES ${QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE})
+  ENDIF()
+
+  SET(QtMobility_LIBRARIES ${QTMOBILITY_QTSERVICEFW_LIBRARIES})
+  SET(QtMobility_INCLUDE_DIRS ${QTMOBILITY_QTSERVICEFW_INCLUDE_DIR})
+
+  IF(QtMobility_INCLUDE_DIRS AND QtMobility_LIBRARIES)
+    SET(QtMobility_FOUND 1)
+  ENDIF()
+ENDIF()

+ 7 - 4
Utilities/QtMobility/QtMobility-1.0.0-install-win32.cmake.in

@@ -26,7 +26,10 @@ FOREACH(_file ${_files})
   MESSAGE("Copying ${_file} to @qtmobility_win32_install_prefix@/include/")
 ENDFOREACH()
 
-SET(_qtmob_config "SET(QTMOBILITY_LIBRARY_DIR \"@CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY@/${_int_dir}/\")
-SET(QTMOBILITY_INCLUDE_DIRS \"@qtmobility_win32_install_prefix@/include/\")")
-
-FILE(WRITE "@qtmobility_configured_patch_dir@/QtMobilityConfig.cmake" ${_qtmob_config})
+SET(QTMOBILITY_QTSERVICEFW_INCLUDE_DIR "@qtmobility_win32_install_prefix@/include")
+SET(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG
+    "@CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY@/${_int_dir}/QtServiceFrameworkd.lib")
+SET(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE
+    "@CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY@/${_int_dir}/QtServiceFramework.lib")
+    
+CONFIGURE_FILE("@qtmobility_config_in@" "@qtmobility_config_out@" @ONLY)

+ 24 - 0
Utilities/QtMobility/QtMobilityConfig.cmake.in

@@ -0,0 +1,24 @@
+SET(QTMOBILITY_QTSERVICEFW_INCLUDE_DIR "@QTMOBILITY_QTSERVICEFW_INCLUDE_DIR@")
+
+SET(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG "@QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG@")
+IF(NOT EXISTS ${QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG})
+  SET(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG )
+ENDIF()
+
+SET(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE "@QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE@")
+IF(NOT EXISTS ${QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE})
+  SET(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE )
+ENDIF()
+
+SET(QTMOBILITY_QTSERVICEFW_LIBRARIES )
+IF(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE AND QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG)
+  SET(QTMOBILITY_QTSERVICEFW_LIBRARIES optimized ${QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE} debug ${QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG})
+ELSEIF(QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG)
+  SET(QTMOBILITY_QTSERVICEFW_LIBRARIES ${QTMOBILITY_QTSERVICEFW_LIBRARY_DEBUG})
+ELSEIF(QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE)
+  SET(QTMOBILITY_QTSERVICEFW_LIBRARIES ${QTMOBILITY_QTSERVICEFW_LIBRARY_RELEASE})
+ENDIF()
+
+SET(QtMobility_LIBRARIES ${QTMOBILITY_QTSERVICEFW_LIBRARIES})
+SET(QtMobility_INCLUDE_DIRS ${QTMOBILITY_QTSERVICEFW_INCLUDE_DIR})
+