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::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);
  }
}
::boost::shared_ptr<Bundle> BundleDescriptorReader::createBundle(const ::boost::filesystem::path& location) throw(RuntimeException)
{
    ::boost::shared_ptr<Bundle> bundle;
    // Get the descriptor location.
    ::boost::filesystem::path completeLocation = location;
    if(!completeLocation.is_complete())
    {
        completeLocation = ::boost::filesystem::current_path() / location;
    }

    ::boost::filesystem::path descriptorLocation(location / "plugin.xml");
    if(::boost::filesystem::exists(descriptorLocation) == false)
    {
        throw RuntimeException("'plugin.xml': file not found.");
    }

    // Validation
    std::ostringstream fileLocation;
    fileLocation << "share/fwRuntime_" <<  FWRUNTIME_VER << "/plugin.xsd";
    const ::boost::filesystem::path pluginXSDLocation( ::boost::filesystem::current_path() / fileLocation.str() );

    Validator   validator(pluginXSDLocation);
    if( validator.validate(descriptorLocation) == false )
    {
        throw RuntimeException("Invalid bundle descriptor file. " + validator.getErrorLog());
    }

    // Get the document.
#if BOOST_FILESYSTEM_VERSION > 2
    xmlDocPtr document = xmlParseFile(  descriptorLocation.string().c_str() );
#else
    xmlDocPtr document = xmlParseFile(  descriptorLocation.native_file_string().c_str() );
#endif
    if(document == 0)
    {
        throw RuntimeException("Unable to read the bundle descriptor file.");
    }


    try
    {
        // Get the root node.
        xmlNodePtr rootNode = xmlDocGetRootElement(document);

        if (xmlXIncludeProcessTreeFlags (rootNode, XML_PARSE_NOBASEFIX) == -1)
        {
            throw RuntimeException("Unable to manage xinclude !");
        }

        if(xmlStrcmp(rootNode->name, (const xmlChar*) PLUGIN.c_str()) != 0)
        {
            throw RuntimeException("Unexpected XML element");
        }

        // Creates and process the plugin element.
        bundle = processPlugin(rootNode, completeLocation);

        // Job's done!
        xmlFreeDoc(document);

    }
    catch(std::exception& exception)
    {
        xmlFreeDoc(document);
        throw ;
    }
    return bundle;
}