File indexing completed on 2024-05-19 05:31:37

0001 /*
0002     SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "session.h"
0008 #include "session_consolekit.h"
0009 #include "session_logind.h"
0010 #include "session_noop.h"
0011 
0012 namespace KWin
0013 {
0014 
0015 static const struct
0016 {
0017     Session::Type type;
0018     std::function<std::unique_ptr<Session>()> createFunc;
0019 } s_availableSessions[] = {
0020     {Session::Type::Logind, &LogindSession::create},
0021     {Session::Type::ConsoleKit, &ConsoleKitSession::create},
0022     {Session::Type::Noop, &NoopSession::create},
0023 };
0024 
0025 std::unique_ptr<Session> Session::create()
0026 {
0027     for (const auto &sessionInfo : s_availableSessions) {
0028         std::unique_ptr<Session> session = sessionInfo.createFunc();
0029         if (session) {
0030             return session;
0031         }
0032     }
0033     return nullptr;
0034 }
0035 
0036 std::unique_ptr<Session> Session::create(Type type)
0037 {
0038     for (const auto &sessionInfo : s_availableSessions) {
0039         if (sessionInfo.type == type) {
0040             return sessionInfo.createFunc();
0041         }
0042     }
0043     return nullptr;
0044 }
0045 
0046 } // namespace KWin
0047 
0048 #include "moc_session.cpp"