blob: e05a037ecea5c4bdb6db7ab3aa38857c09748491 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*
* Copyright (C) 2013-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "MultiProvider.h"
#include "utils/XBMCTinyXML.h"
#include <mutex>
CMultiProvider::CMultiProvider(const TiXmlNode *first, int parentID)
: IListProvider(parentID)
{
for (const TiXmlNode *content = first; content; content = content->NextSiblingElement("content"))
{
IListProviderPtr sub(IListProvider::CreateSingle(content, parentID));
if (sub)
m_providers.push_back(std::move(sub));
}
}
CMultiProvider::CMultiProvider(const CMultiProvider& other) : IListProvider(other.m_parentID)
{
for (const auto& provider : other.m_providers)
{
std::unique_ptr<IListProvider> newProvider = provider->Clone();
if (newProvider)
m_providers.emplace_back(std::move(newProvider));
}
}
std::unique_ptr<IListProvider> CMultiProvider::Clone()
{
return std::make_unique<CMultiProvider>(*this);
}
bool CMultiProvider::Update(bool forceRefresh)
{
bool result = false;
for (auto& provider : m_providers)
result |= provider->Update(forceRefresh);
return result;
}
void CMultiProvider::Fetch(std::vector<CGUIListItemPtr> &items)
{
std::unique_lock<CCriticalSection> lock(m_section);
std::vector<CGUIListItemPtr> subItems;
items.clear();
m_itemMap.clear();
for (auto const& provider : m_providers)
{
provider->Fetch(subItems);
for (auto& item : subItems)
{
auto key = GetItemKey(item);
m_itemMap[key] = provider.get();
items.push_back(item);
}
subItems.clear();
}
}
bool CMultiProvider::IsUpdating() const
{
bool result = false;
for (auto const& provider : m_providers)
result |= provider->IsUpdating();
return result;
}
void CMultiProvider::Reset()
{
{
std::unique_lock<CCriticalSection> lock(m_section);
m_itemMap.clear();
}
for (auto const& provider : m_providers)
provider->Reset();
}
bool CMultiProvider::OnClick(const CGUIListItemPtr &item)
{
std::unique_lock<CCriticalSection> lock(m_section);
auto key = GetItemKey(item);
auto it = m_itemMap.find(key);
if (it != m_itemMap.end())
return it->second->OnClick(item);
else
return false;
}
bool CMultiProvider::OnInfo(const CGUIListItemPtr &item)
{
std::unique_lock<CCriticalSection> lock(m_section);
auto key = GetItemKey(item);
auto it = m_itemMap.find(key);
if (it != m_itemMap.end())
return it->second->OnInfo(item);
else
return false;
}
bool CMultiProvider::OnContextMenu(const CGUIListItemPtr &item)
{
std::unique_lock<CCriticalSection> lock(m_section);
auto key = GetItemKey(item);
auto it = m_itemMap.find(key);
if (it != m_itemMap.end())
return it->second->OnContextMenu(item);
else
return false;
}
CMultiProvider::item_key_type CMultiProvider::GetItemKey(CGUIListItemPtr const &item)
{
return reinterpret_cast<item_key_type>(item.get());
}
|