From 9d11b08ad61b1f0d6d7023ce403285d8662efaed Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 4 Mar 2015 00:23:39 +0100 Subject: sync with upstream --- xbmc/addons/Service.cpp | 158 ------------------------------------------------ 1 file changed, 158 deletions(-) delete mode 100644 xbmc/addons/Service.cpp (limited to 'xbmc/addons/Service.cpp') diff --git a/xbmc/addons/Service.cpp b/xbmc/addons/Service.cpp deleted file mode 100644 index 2fc7670..0000000 --- a/xbmc/addons/Service.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://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, see - * . - * - */ -#include "Service.h" -#include "AddonManager.h" -#include "interfaces/generic/ScriptInvocationManager.h" -#include "utils/log.h" -#include "system.h" - -using namespace std; - -namespace ADDON -{ - -CService::CService(const cp_extension_t *ext) - : CAddon(ext), m_type(UNKNOWN), m_startOption(LOGIN) -{ - BuildServiceType(); - - std::string start = CAddonMgr::Get().GetExtValue(ext->configuration, "@start"); - if (start == "startup") - m_startOption = STARTUP; -} - - -CService::CService(const AddonProps &props) - : CAddon(props), m_type(UNKNOWN), m_startOption(LOGIN) -{ - BuildServiceType(); -} - -AddonPtr CService::Clone() const -{ - return AddonPtr(new CService(*this)); -} - -bool CService::Start() -{ - bool ret = true; - switch (m_type) - { -#ifdef HAS_PYTHON - case PYTHON: - ret = (CScriptInvocationManager::Get().ExecuteAsync(LibPath(), this->shared_from_this()) != -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 = CScriptInvocationManager::Get().Stop(LibPath()); - break; -#endif - - case UNKNOWN: - default: - ret = false; - break; - } - - return ret; -} - -void CService::BuildServiceType() -{ - std::string str = LibPath(); - std::string ext; - - size_t p = str.find_last_of('.'); - if (p != string::npos) - ext = str.substr(p + 1); - -#ifdef HAS_PYTHON - std::string pythonExt = ADDON_PYTHON_EXT; - pythonExt.erase(0, 2); - if ( ext == 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()); - } -} - -void CService::OnDisabled() -{ - Stop(); -} - -void CService::OnEnabled() -{ - Start(); -} - -bool CService::OnPreInstall() -{ - // make sure the addon is stopped - AddonPtr localAddon; // need to grab the local addon so we have the correct library path to stop - if (CAddonMgr::Get().GetAddon(ID(), localAddon, ADDON_SERVICE, false)) - { - std::shared_ptr service = std::dynamic_pointer_cast(localAddon); - if (service) - service->Stop(); - } - return !CAddonMgr::Get().IsAddonDisabled(ID()); -} - -void CService::OnPostInstall(bool restart, bool update, bool modal) -{ - if (restart) // reload/start it if it was running - { - AddonPtr localAddon; // need to grab the local addon so we have the correct library path to stop - if (CAddonMgr::Get().GetAddon(ID(), localAddon, ADDON_SERVICE, false)) - { - std::shared_ptr service = std::dynamic_pointer_cast(localAddon); - if (service) - service->Start(); - } - } -} - -void CService::OnPreUnInstall() -{ - Stop(); -} - -} -- cgit v1.2.3