added: function to parse an addon descriptor from memory
authorJonathan Marshall <jmarshall@never.you.mind>
Sat, 15 Jan 2011 03:31:16 +0000 (16:31 +1300)
committertheuni <theuni-nospam-@xbmc.org>
Wed, 26 Jan 2011 08:55:26 +0000 (03:55 -0500)
xbmc/addons/AddonManager.cpp
xbmc/addons/AddonManager.h

index 5475bb8..dac9e2c 100644 (file)
@@ -704,6 +704,28 @@ bool CAddonMgr::AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons)
   return true;
 }
 
+bool CAddonMgr::LoadAddonDescriptionFromMemory(const TiXmlElement *root, AddonPtr &addon)
+{
+  // create a context for these addons
+  cp_status_t status;
+  cp_context_t *context = m_cpluff->create_context(&status);
+  if (!root || !context)
+    return false;
+
+  // dump the XML back to text
+  std::string xml;
+  xml << TiXmlDeclaration("1.0", "UTF-8", "");
+  xml << *root;
+  cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor_from_memory(context, xml.c_str(), xml.size(), &status);
+  if (info)
+  {
+    addon = GetAddonFromDescriptor(info);
+    m_cpluff->release_info(context, info);
+  }
+  m_cpluff->destroy_context(context);
+  return addon != NULL;
+}
+  
 int cp_to_clog(cp_log_severity_t lvl)
 {
   if (lvl >= CP_LOG_ERROR)
index 328a333..2c2a510 100644 (file)
@@ -138,6 +138,14 @@ namespace ADDON
      */
     bool LoadAddonDescription(const CStdString &path, AddonPtr &addon);
 
+    /*! \brief Load the addon in the given in-memory xml
+     This loads the addon using c-pluff which parses the addon descriptor file.
+     \param root Root element of an XML document.
+     \param addon [out] returned addon.
+     \return true if addon is set, false otherwise.
+     */
+    bool LoadAddonDescriptionFromMemory(const TiXmlElement *root, AddonPtr &addon);
+
     /*! \brief Parse a repository XML file for addons and load their descriptors
      A repository XML is essentially a concatenated list of addon descriptors.
      \param root Root element of an XML document.