2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "BinaryAddonBase.h"
11 #include "addons/addoninfo/AddonInfo.h"
12 #include "addons/binary-addons/AddonDll.h"
13 #include "addons/binary-addons/AddonInstanceHandler.h"
14 #include "utils/log.h"
18 using namespace ADDON
;
20 const std::string
& CBinaryAddonBase::ID() const
22 return m_addonInfo
->ID();
25 AddonDllPtr
CBinaryAddonBase::GetAddon(IAddonInstanceHandler
* handler
)
27 if (handler
== nullptr)
29 CLog::Log(LOGERROR
, "CBinaryAddonBase::{}: for Id '{}' called with empty instance handler",
34 std::unique_lock
<CCriticalSection
> lock(m_critSection
);
36 // If no 'm_activeAddon' is defined create it new.
37 if (m_activeAddon
== nullptr)
38 m_activeAddon
= std::make_shared
<CAddonDll
>(m_addonInfo
, shared_from_this());
40 // add the instance handler to the info to know used amount on addon
41 m_activeAddonHandlers
.insert(handler
);
46 void CBinaryAddonBase::ReleaseAddon(IAddonInstanceHandler
* handler
)
48 if (handler
== nullptr)
50 CLog::Log(LOGERROR
, "CBinaryAddonBase::{}: for Id '{}' called with empty instance handler",
55 std::unique_lock
<CCriticalSection
> lock(m_critSection
);
57 auto presentHandler
= m_activeAddonHandlers
.find(handler
);
58 if (presentHandler
== m_activeAddonHandlers
.end())
61 m_activeAddonHandlers
.erase(presentHandler
);
63 // if no handler is present anymore reset and delete the add-on class on information
64 if (m_activeAddonHandlers
.empty())
66 m_activeAddon
.reset();
70 size_t CBinaryAddonBase::UsedInstanceCount() const
72 std::unique_lock
<CCriticalSection
> lock(m_critSection
);
73 return m_activeAddonHandlers
.size();
76 AddonDllPtr
CBinaryAddonBase::GetActiveAddon()
78 std::unique_lock
<CCriticalSection
> lock(m_critSection
);
82 void CBinaryAddonBase::OnPreInstall()
84 const std::unordered_set
<IAddonInstanceHandler
*> activeAddonHandlers
= m_activeAddonHandlers
;
85 for (const auto& instance
: activeAddonHandlers
)
86 instance
->OnPreInstall();
89 void CBinaryAddonBase::OnPostInstall(bool update
, bool modal
)
91 const std::unordered_set
<IAddonInstanceHandler
*> activeAddonHandlers
= m_activeAddonHandlers
;
92 for (const auto& instance
: activeAddonHandlers
)
93 instance
->OnPostInstall(update
, modal
);
96 void CBinaryAddonBase::OnPreUnInstall()
98 const std::unordered_set
<IAddonInstanceHandler
*> activeAddonHandlers
= m_activeAddonHandlers
;
99 for (const auto& instance
: activeAddonHandlers
)
100 instance
->OnPreUnInstall();
103 void CBinaryAddonBase::OnPostUnInstall()
105 const std::unordered_set
<IAddonInstanceHandler
*> activeAddonHandlers
= m_activeAddonHandlers
;
106 for (const auto& instance
: activeAddonHandlers
)
107 instance
->OnPostUnInstall();