File indexing completed on 2024-05-19 05:47:32
0001 /* 0002 * Copyright (C) 2012 Dario Freddi <drf@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Lesser General Public License as published by 0006 * the Free Software Foundation; either version 2.1 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . 0018 */ 0019 0020 #include "BackendsManager.h" 0021 0022 #include "BackendsConfig.h" 0023 0024 // Include backends directly 0025 #include "TestBackend.h" 0026 #include "backends/dbus/DBusHelperProxy.h" 0027 0028 #include <QPluginLoader> 0029 #include <QDir> 0030 #include <QDebug> 0031 #include <QThread> 0032 0033 namespace KAuth 0034 { 0035 0036 AuthBackend *BackendsManager::auth = nullptr; 0037 QHash< QThread *, HelperProxy * > proxiesForThreads = QHash< QThread *, HelperProxy * >(); 0038 0039 BackendsManager::BackendsManager() 0040 { 0041 } 0042 0043 void BackendsManager::init() 0044 { 0045 if (!auth) { 0046 // Load the test backend 0047 auth = new TestBackend; 0048 } 0049 0050 if (!proxiesForThreads.contains(QThread::currentThread())) { 0051 // Load the test helper backend 0052 proxiesForThreads.insert(QThread::currentThread(), new DBusHelperProxy(QDBusConnection::sessionBus())); 0053 } 0054 } 0055 0056 AuthBackend *BackendsManager::authBackend() 0057 { 0058 if (!auth) { 0059 init(); 0060 } 0061 0062 return auth; 0063 } 0064 0065 HelperProxy *BackendsManager::helperProxy() 0066 { 0067 if (!proxiesForThreads.contains(QThread::currentThread())) { 0068 qDebug() << "Creating new proxy for thread" << QThread::currentThread(); 0069 init(); 0070 } 0071 0072 return proxiesForThreads[QThread::currentThread()]; 0073 } 0074 0075 void BackendsManager::setProxyForThread(QThread *thread, HelperProxy *proxy) 0076 { 0077 qDebug() << "Adding proxy for thread" << thread; 0078 0079 proxiesForThreads.insert(thread, proxy); 0080 } 0081 0082 } // namespace Auth