Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added: service addons.

A new extension point is available for service addons: xbmc.service
A service addon starts/stops when xbmc starts/stops or when the user enables/disables the addon.

git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@35348 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
  • Loading branch information...
commit b55ac44bacbfcf0219bdd465022500b191679edd 1 parent dbf20e3
blinkseb authored
View
1  language/English/strings.xml
@@ -2202,6 +2202,7 @@
<string id="24015">Music video information</string>
<string id="24016">Album information</string>
<string id="24017">Artist information</string>
+ <string id="24018">Services</string>
<string id="24020">Configure</string>
<string id="24021">Disable</string>
View
21 xbmc/AddonDatabase.cpp
@@ -24,6 +24,7 @@
#include "utils/log.h"
#include "DateTime.h"
#include "StringUtils.h"
+#include "addons/Service.h"
using namespace ADDON;
using namespace std;
@@ -578,6 +579,16 @@ bool CAddonDatabase::DisableAddon(const CStdString &addonID, bool disable /* = t
m_pDS->close();
sql = PrepareSQL("insert into disabled(id, addonID) values(NULL, '%s')", addonID.c_str());
m_pDS->exec(sql);
+
+ AddonPtr addon;
+ // If the addon is a service, stop it
+ if (CAddonMgr::Get().GetAddon(addonID, addon, ADDON_SERVICE, false) && addon)
+ {
+ boost::shared_ptr<CService> service = boost::dynamic_pointer_cast<CService>(addon);
+ if (service)
+ service->Stop();
+ }
+
return true;
}
return false; // already disabled or failed query
@@ -586,6 +597,16 @@ bool CAddonDatabase::DisableAddon(const CStdString &addonID, bool disable /* = t
{
CStdString sql = PrepareSQL("delete from disabled where addonID='%s'", addonID.c_str());
m_pDS->exec(sql);
+
+ AddonPtr addon;
+ // If the addon is a service, start it
+ if (CAddonMgr::Get().GetAddon(addonID, addon, ADDON_SERVICE, false) && addon)
+ {
+ boost::shared_ptr<CService> service = boost::dynamic_pointer_cast<CService>(addon);
+ if (service)
+ service->Start();
+ }
+
}
return true;
}
View
5 xbmc/Application.cpp
@@ -1153,6 +1153,8 @@ bool CApplication::Initialize()
CCrystalHD::GetInstance();
#endif
+ CAddonMgr::Get().StartServices();
+
CLog::Log(LOGNOTICE, "initialize done");
m_bInitializing = false;
@@ -3313,6 +3315,9 @@ void CApplication::Stop()
g_mediaManager.Stop();
+ // Stop services before unloading Python
+ CAddonMgr::Get().StopServices();
+
/* Python resource freeing must be done after skin has been unloaded, not before
some windows still need it when deinitializing during skin unloading. */
#ifdef HAS_PYTHON
View
5 xbmc/addons/Addon.cpp
@@ -153,7 +153,8 @@ static const TypeMapping types[] =
{"xbmc.addon.video", ADDON_VIDEO, 1037, "DefaultAddonVideo.png" },
{"xbmc.addon.audio", ADDON_AUDIO, 1038, "DefaultAddonMusic.png" },
{"xbmc.addon.image", ADDON_IMAGE, 1039, "DefaultAddonPicture.png" },
- {"xbmc.addon.executable", ADDON_EXECUTABLE, 1043, "DefaultAddonProgram.png" }};
+ {"xbmc.addon.executable", ADDON_EXECUTABLE, 1043, "DefaultAddonProgram.png" },
+ {"xbmc.service", ADDON_SERVICE, 24018, "DefaultAddonService.png" }};
const CStdString TranslateType(const ADDON::TYPE &type, bool pretty/*=false*/)
{
@@ -365,6 +366,7 @@ void CAddon::BuildLibName(const cp_extension_t *extension)
case ADDON_SCRIPT_WEATHER:
case ADDON_SCRIPT_SUBTITLES:
case ADDON_PLUGIN:
+ case ADDON_SERVICE:
ext = ADDON_PYTHON_EXT;
break;
default:
@@ -394,6 +396,7 @@ void CAddon::BuildLibName(const cp_extension_t *extension)
case ADDON_SCRAPER_TVSHOWS:
case ADDON_SCRAPER_LIBRARY:
case ADDON_PLUGIN:
+ case ADDON_SERVICE:
{
CStdString temp = CAddonMgr::Get().GetExtValue(extension->configuration, "@library");
m_strLibName = temp;
View
40 xbmc/addons/AddonManager.cpp
@@ -48,6 +48,7 @@
#include "PluginSource.h"
#include "Repository.h"
#include "Skin.h"
+#include "Service.h"
using namespace std;
@@ -89,6 +90,8 @@ AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
case ADDON_SCRIPT_MODULE:
case ADDON_WEB_INTERFACE:
return AddonPtr(new CAddon(props));
+ case ADDON_SERVICE:
+ return AddonPtr(new CService(props));
case ADDON_SCRAPER_ALBUMS:
case ADDON_SCRAPER_ARTISTS:
case ADDON_SCRAPER_MOVIES:
@@ -481,6 +484,8 @@ AddonPtr CAddonMgr::AddonFromProps(AddonProps& addonProps)
case ADDON_SCRIPT_MODULE:
case ADDON_WEB_INTERFACE:
return AddonPtr(new CAddon(addonProps));
+ case ADDON_SERVICE:
+ return AddonPtr(new CService(addonProps));
case ADDON_SCRAPER_ALBUMS:
case ADDON_SCRAPER_ARTISTS:
case ADDON_SCRAPER_MOVIES:
@@ -704,6 +709,41 @@ bool CAddonMgr::AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons)
return true;
}
+bool CAddonMgr::StartServices()
+{
+ CLog::Log(LOGDEBUG, "ADDON: Starting service addons.");
+
+ VECADDONS services;
+ if (!GetAddons(ADDON_SERVICE, services))
+ return false;
+
+ bool ret = true;
+ for (IVECADDONS it = services.begin(); it != services.end(); ++it)
+ {
+ boost::shared_ptr<CService> service = boost::dynamic_pointer_cast<CService>(*it);
+ if (service)
+ ret &= service->Start();
+ }
+
+ return ret;
+}
+
+void CAddonMgr::StopServices()
+{
+ CLog::Log(LOGDEBUG, "ADDON: Stopping service addons.");
+
+ VECADDONS services;
+ if (!GetAddons(ADDON_SERVICE, services))
+ return;
+
+ for (IVECADDONS it = services.begin(); it != services.end(); ++it)
+ {
+ boost::shared_ptr<CService> service = boost::dynamic_pointer_cast<CService>(*it);
+ if (service)
+ service->Stop();
+ }
+}
+
int cp_to_clog(cp_log_severity_t lvl)
{
if (lvl >= CP_LOG_ERROR)
View
9 xbmc/addons/AddonManager.h
@@ -146,6 +146,15 @@ namespace ADDON
*/
bool AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons);
ADDONDEPS GetDeps(const CStdString& id);
+
+ /*! \brief Start all services addons.
+ \return True is all addons are started, false otherwise
+ */
+ bool StartServices();
+ /*! \brief Stop all services addons.
+ */
+ void StopServices();
+
private:
void LoadAddons(const CStdString &path,
std::map<CStdString, AddonPtr>& unresolved);
View
1  xbmc/addons/IAddon.h
@@ -47,6 +47,7 @@ namespace ADDON
ADDON_PLUGIN,
ADDON_REPOSITORY,
ADDON_WEB_INTERFACE,
+ ADDON_SERVICE,
ADDON_VIDEO, // virtual addon types
ADDON_AUDIO,
ADDON_IMAGE,
View
109 xbmc/addons/Service.cpp
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2005-2009 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+#include "Service.h"
+#include "AddonManager.h"
+#include "log.h"
+#ifdef HAS_PYTHON
+#include "lib/libPython/XBPython.h"
+#endif
+
+using namespace std;
+
+namespace ADDON
+{
+
+CService::CService(const cp_extension_t *ext)
+ : CAddon(ext), m_type(UNKNOWN)
+{
+ BuildServiceType();
+}
+
+
+CService::CService(const AddonProps &props)
+ : CAddon(props), m_type(UNKNOWN)
+{
+ BuildServiceType();
+}
+
+bool CService::Start()
+{
+ bool ret = true;
+ switch (m_type)
+ {
+#ifdef HAS_PYTHON
+ case PYTHON:
+ ret = (g_pythonParser.evalFile(LibPath()) != -1);
+ break;
+#endif
+
+ case UNKNOWN:
+ default:
+ ret = false;
+ break;
+ }
+
+ return ret;
+}
+
+bool CService::Stop()
+{
+ bool ret = true;
+
+ switch (m_type)
+ {
+#ifdef HAS_PYTHON
+ case PYTHON:
+ ret = g_pythonParser.StopScript(LibPath());
+ break;
+#endif
+
+ case UNKNOWN:
+ default:
+ ret = false;
+ break;
+ }
+
+ return ret;
+}
+
+void CService::BuildServiceType()
+{
+ CStdString str = LibPath();
+ CStdString ext;
+
+ size_t p = str.find_last_of('.');
+ if (p != string::npos)
+ ext = str.substr(p + 1);
+
+#ifdef HAS_PYTHON
+ CStdString pythonExt = ADDON_PYTHON_EXT;
+ pythonExt.erase(0, 2);
+ if ( ext.Equals(pythonExt) )
+ m_type = PYTHON;
+ else
+#endif
+ {
+ m_type = UNKNOWN;
+ CLog::Log(LOGERROR, "ADDON: extension '%s' is not currently supported for service addon", ext.c_str());
+ }
+}
+
+}
View
50 xbmc/addons/Service.h
@@ -0,0 +1,50 @@
+#pragma once
+/*
+ * Copyright (C) 2005-2009 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+#include "Addon.h"
+
+namespace ADDON
+{
+
+ class CService: public CAddon
+ {
+ public:
+
+ enum TYPE
+ {
+ UNKNOWN,
+ PYTHON
+ };
+
+ CService(const cp_extension_t *ext);
+ CService(const AddonProps &props);
+
+ bool Start();
+ bool Stop();
+ TYPE GetServiceType() { return m_type; }
+
+ protected:
+ void BuildServiceType();
+
+ private:
+ TYPE m_type;
+ };
+}
Please sign in to comment.
Something went wrong with that request. Please try again.