diff options
| author | manuel <manuel@mausz.at> | 2015-03-04 00:23:39 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2015-03-04 00:23:39 +0100 |
| commit | 9d11b08ad61b1f0d6d7023ce403285d8662efaed (patch) | |
| tree | 5bc0c947d9e10d3e8c9dc1e6b26f3d6599f0cea1 /xbmc/addons/Service.cpp | |
| parent | c159d9f91f1573901868100a9464527a5a71575b (diff) | |
| download | kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.tar.gz kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.tar.bz2 kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.zip | |
sync with upstream
Diffstat (limited to 'xbmc/addons/Service.cpp')
| -rw-r--r-- | xbmc/addons/Service.cpp | 158 |
1 files changed, 0 insertions, 158 deletions
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2013 Team XBMC | ||
| 3 | * http://xbmc.org | ||
| 4 | * | ||
| 5 | * This Program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 8 | * any later version. | ||
| 9 | * | ||
| 10 | * This Program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with XBMC; see the file COPYING. If not, see | ||
| 17 | * <http://www.gnu.org/licenses/>. | ||
| 18 | * | ||
| 19 | */ | ||
| 20 | #include "Service.h" | ||
| 21 | #include "AddonManager.h" | ||
| 22 | #include "interfaces/generic/ScriptInvocationManager.h" | ||
| 23 | #include "utils/log.h" | ||
| 24 | #include "system.h" | ||
| 25 | |||
| 26 | using namespace std; | ||
| 27 | |||
| 28 | namespace ADDON | ||
| 29 | { | ||
| 30 | |||
| 31 | CService::CService(const cp_extension_t *ext) | ||
| 32 | : CAddon(ext), m_type(UNKNOWN), m_startOption(LOGIN) | ||
| 33 | { | ||
| 34 | BuildServiceType(); | ||
| 35 | |||
| 36 | std::string start = CAddonMgr::Get().GetExtValue(ext->configuration, "@start"); | ||
| 37 | if (start == "startup") | ||
| 38 | m_startOption = STARTUP; | ||
| 39 | } | ||
| 40 | |||
| 41 | |||
| 42 | CService::CService(const AddonProps &props) | ||
| 43 | : CAddon(props), m_type(UNKNOWN), m_startOption(LOGIN) | ||
| 44 | { | ||
| 45 | BuildServiceType(); | ||
| 46 | } | ||
| 47 | |||
| 48 | AddonPtr CService::Clone() const | ||
| 49 | { | ||
| 50 | return AddonPtr(new CService(*this)); | ||
| 51 | } | ||
| 52 | |||
| 53 | bool CService::Start() | ||
| 54 | { | ||
| 55 | bool ret = true; | ||
| 56 | switch (m_type) | ||
| 57 | { | ||
| 58 | #ifdef HAS_PYTHON | ||
| 59 | case PYTHON: | ||
| 60 | ret = (CScriptInvocationManager::Get().ExecuteAsync(LibPath(), this->shared_from_this()) != -1); | ||
| 61 | break; | ||
| 62 | #endif | ||
| 63 | |||
| 64 | case UNKNOWN: | ||
| 65 | default: | ||
| 66 | ret = false; | ||
| 67 | break; | ||
| 68 | } | ||
| 69 | |||
| 70 | return ret; | ||
| 71 | } | ||
| 72 | |||
| 73 | bool CService::Stop() | ||
| 74 | { | ||
| 75 | bool ret = true; | ||
| 76 | |||
| 77 | switch (m_type) | ||
| 78 | { | ||
| 79 | #ifdef HAS_PYTHON | ||
| 80 | case PYTHON: | ||
| 81 | ret = CScriptInvocationManager::Get().Stop(LibPath()); | ||
| 82 | break; | ||
| 83 | #endif | ||
| 84 | |||
| 85 | case UNKNOWN: | ||
| 86 | default: | ||
| 87 | ret = false; | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | |||
| 91 | return ret; | ||
| 92 | } | ||
| 93 | |||
| 94 | void CService::BuildServiceType() | ||
| 95 | { | ||
| 96 | std::string str = LibPath(); | ||
| 97 | std::string ext; | ||
| 98 | |||
| 99 | size_t p = str.find_last_of('.'); | ||
| 100 | if (p != string::npos) | ||
| 101 | ext = str.substr(p + 1); | ||
| 102 | |||
| 103 | #ifdef HAS_PYTHON | ||
| 104 | std::string pythonExt = ADDON_PYTHON_EXT; | ||
| 105 | pythonExt.erase(0, 2); | ||
| 106 | if ( ext == pythonExt ) | ||
| 107 | m_type = PYTHON; | ||
| 108 | else | ||
| 109 | #endif | ||
| 110 | { | ||
| 111 | m_type = UNKNOWN; | ||
| 112 | CLog::Log(LOGERROR, "ADDON: extension '%s' is not currently supported for service addon", ext.c_str()); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | void CService::OnDisabled() | ||
| 117 | { | ||
| 118 | Stop(); | ||
| 119 | } | ||
| 120 | |||
| 121 | void CService::OnEnabled() | ||
| 122 | { | ||
| 123 | Start(); | ||
| 124 | } | ||
| 125 | |||
| 126 | bool CService::OnPreInstall() | ||
| 127 | { | ||
| 128 | // make sure the addon is stopped | ||
| 129 | AddonPtr localAddon; // need to grab the local addon so we have the correct library path to stop | ||
| 130 | if (CAddonMgr::Get().GetAddon(ID(), localAddon, ADDON_SERVICE, false)) | ||
| 131 | { | ||
| 132 | std::shared_ptr<CService> service = std::dynamic_pointer_cast<CService>(localAddon); | ||
| 133 | if (service) | ||
| 134 | service->Stop(); | ||
| 135 | } | ||
| 136 | return !CAddonMgr::Get().IsAddonDisabled(ID()); | ||
| 137 | } | ||
| 138 | |||
| 139 | void CService::OnPostInstall(bool restart, bool update, bool modal) | ||
| 140 | { | ||
| 141 | if (restart) // reload/start it if it was running | ||
| 142 | { | ||
| 143 | AddonPtr localAddon; // need to grab the local addon so we have the correct library path to stop | ||
| 144 | if (CAddonMgr::Get().GetAddon(ID(), localAddon, ADDON_SERVICE, false)) | ||
| 145 | { | ||
| 146 | std::shared_ptr<CService> service = std::dynamic_pointer_cast<CService>(localAddon); | ||
| 147 | if (service) | ||
| 148 | service->Start(); | ||
| 149 | } | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | void CService::OnPreUnInstall() | ||
| 154 | { | ||
| 155 | Stop(); | ||
| 156 | } | ||
| 157 | |||
| 158 | } | ||
