[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / platform / linux / powermanagement / LinuxPowerSyscall.cpp
blobf3dbcdb1060c9e7724d2d1c87318da619c743b50
1 /*
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.
7 */
9 #include "LinuxPowerSyscall.h"
10 #include "FallbackPowerSyscall.h"
11 #if defined(HAS_DBUS)
12 #include "ConsoleUPowerSyscall.h"
13 #include "LogindUPowerSyscall.h"
14 #include "UPowerSyscall.h"
15 #endif // HAS_DBUS
17 #include <functional>
18 #include <list>
19 #include <memory>
20 #include <utility>
22 IPowerSyscall* CLinuxPowerSyscall::CreateInstance()
24 #if defined(HAS_DBUS)
25 std::unique_ptr<IPowerSyscall> bestPowerManager;
26 std::unique_ptr<IPowerSyscall> currPowerManager;
27 int bestCount = -1;
28 int currCount = -1;
30 std::list< std::pair< std::function<bool()>,
31 std::function<IPowerSyscall*()> > > powerManagers =
33 std::make_pair(CConsoleUPowerSyscall::HasConsoleKitAndUPower,
34 [] { return new CConsoleUPowerSyscall(); }),
35 std::make_pair(CLogindUPowerSyscall::HasLogind,
36 [] { return new CLogindUPowerSyscall(); }),
37 std::make_pair(CUPowerSyscall::HasUPower,
38 [] { return new CUPowerSyscall(); })
40 for(const auto& powerManager : powerManagers)
42 if (powerManager.first())
44 currPowerManager.reset(powerManager.second());
45 currCount = currPowerManager->CountPowerFeatures();
46 if (currCount > bestCount)
48 bestCount = currCount;
49 bestPowerManager = std::move(currPowerManager);
51 if (bestCount == IPowerSyscall::MAX_COUNT_POWER_FEATURES)
52 break;
55 if (bestPowerManager)
56 return bestPowerManager.release();
57 else
58 #endif // HAS_DBUS
59 return new CFallbackPowerSyscall();
62 void CLinuxPowerSyscall::Register()
64 IPowerSyscall::RegisterPowerSyscall(CLinuxPowerSyscall::CreateInstance);