| 1 |
/* |
| 2 |
* Copyright (C) 2010-2021 Team Kodi (https://kodi.tv) |
| 3 |
* Copyright (C) 2010 Alwin Esch (Team Kodi) |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSE.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "Addon.h" |
| 10 |
|
| 11 |
#include "ClientInstance.h" |
| 12 |
#include "Settings.h" |
| 13 |
|
| 14 |
ADDON_STATUS CPVRAddon::Create() |
| 15 |
{ |
| 16 |
if (!CVNSISettings::Get().Load()) |
| 17 |
{ |
| 18 |
kodi::Log(ADDON_LOG_ERROR, "%s: Failed to load addon settings", __func__); |
| 19 |
return ADDON_STATUS_UNKNOWN; |
| 20 |
} |
| 21 |
|
| 22 |
return ADDON_STATUS_OK; |
| 23 |
} |
| 24 |
|
| 25 |
ADDON_STATUS CPVRAddon::SetSetting(const std::string& settingName, |
| 26 |
const kodi::addon::CSettingValue& settingValue) |
| 27 |
{ |
| 28 |
return CVNSISettings::Get().SetSetting(settingName, settingValue); |
| 29 |
} |
| 30 |
|
| 31 |
ADDON_STATUS CPVRAddon::CreateInstance(const kodi::addon::IInstanceInfo& instance, |
| 32 |
KODI_ADDON_INSTANCE_HDL& hdl) |
| 33 |
{ |
| 34 |
kodi::Log(ADDON_LOG_DEBUG, "%s: Creating VDR VNSI PVR-Client", __func__); |
| 35 |
|
| 36 |
if (instance.GetID().empty()) |
| 37 |
{ |
| 38 |
kodi::Log(ADDON_LOG_ERROR, "%s: Instance creation called without id", __func__); |
| 39 |
return ADDON_STATUS_UNKNOWN; |
| 40 |
} |
| 41 |
|
| 42 |
if (instance.IsType(ADDON_INSTANCE_PVR)) |
| 43 |
{ |
| 44 |
CVNSIClientInstance* client = nullptr; |
| 45 |
try |
| 46 |
{ |
| 47 |
client = new CVNSIClientInstance(*this, instance); |
| 48 |
if (client->Start(CVNSISettings::Get().GetHostname(), CVNSISettings::Get().GetPort(), nullptr, |
| 49 |
CVNSISettings::Get().GetWolMac())) |
| 50 |
{ |
| 51 |
hdl = client; |
| 52 |
m_usedInstances.emplace(instance.GetID(), client); |
| 53 |
return ADDON_STATUS_OK; |
| 54 |
} |
| 55 |
} |
| 56 |
catch (std::exception e) |
| 57 |
{ |
| 58 |
kodi::Log(ADDON_LOG_ERROR, "%s - %s", __func__, e.what()); |
| 59 |
delete client; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
return ADDON_STATUS_UNKNOWN; |
| 64 |
} |
| 65 |
|
| 66 |
void CPVRAddon::DestroyInstance(const kodi::addon::IInstanceInfo& instance, |
| 67 |
const KODI_ADDON_INSTANCE_HDL hdl) |
| 68 |
{ |
| 69 |
if (instance.IsType(ADDON_INSTANCE_PVR)) |
| 70 |
{ |
| 71 |
const auto& it = m_usedInstances.find(instance.GetID()); |
| 72 |
if (it != m_usedInstances.end()) |
| 73 |
{ |
| 74 |
m_usedInstances.erase(it); |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
kodi::Log(ADDON_LOG_ERROR, "%s: DestroyInstance call with not known instance", __func__); |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
ADDONCREATOR(CPVRAddon) |