Debian Codegraph @

xbmc/pvr/channels/PVRChannelGroupFromClient.cpp

raw
1 /*
2 * Copyright (C) 2012-2023 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "PVRChannelGroupFromClient.h"
10
11 #include "ServiceBroker.h"
12 #include "pvr/PVRManager.h"
13 #include "pvr/addons/PVRClient.h"
14 #include "pvr/addons/PVRClients.h"
15 #include "utils/log.h"
16
17 using namespace PVR;
18
19 CPVRChannelGroupFromClient::CPVRChannelGroupFromClient(
20 const CPVRChannelsPath& path, const std::shared_ptr<const CPVRChannelGroup>& allChannelsGroup)
21 : CPVRChannelGroup(path, allChannelsGroup)
22 {
23 }
24
25 CPVRChannelGroupFromClient::CPVRChannelGroupFromClient(
26 const PVR_CHANNEL_GROUP& group,
27 int clientID,
28 const std::shared_ptr<const CPVRChannelGroup>& allChannelsGroup)
29 : CPVRChannelGroup(CPVRChannelsPath(group.bIsRadio, group.strGroupName, clientID),
30 allChannelsGroup)
31 {
32 SetClientGroupName(group.strGroupName);
33 SetClientPosition(group.iPosition);
34 }
35
36 bool CPVRChannelGroupFromClient::UpdateFromClients(
37 const std::vector<std::shared_ptr<CPVRClient>>& clients)
38 {
39 std::shared_ptr<CPVRClient> client;
40 if (clients.empty())
41 {
42 // Requested to update groups from all clients
43 client = CServiceBroker::GetPVRManager().GetClient(GetClientID());
44 if (!client)
45 {
46 CLog::LogF(LOGERROR, "Unable to obtain client for group {}, clientid={}", GroupName(),
47 GetClientID());
48 return false;
49 }
50 }
51 else
52 {
53 const auto it =
54 std::find_if(clients.cbegin(), clients.cend(),
55 [this](const auto& client) { return client->GetID() == GetClientID(); });
56 if (it == clients.cend())
57 return true; // this group is not provided by one of the clients to get the group members for
58
59 client = *it;
60 }
61
62 // get the channel group members from the backends.
63 std::vector<std::shared_ptr<CPVRChannelGroupMember>> groupMembers;
64 CServiceBroker::GetPVRManager().Clients()->GetChannelGroupMembers({client}, this, groupMembers,
65 m_failedClients);
66 return UpdateGroupEntries(groupMembers);
67 }