File: AppStreamConcurrentPool.cpp

package info (click to toggle)
plasma-discover 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,288 kB
  • sloc: cpp: 30,576; xml: 2,710; python: 311; sh: 5; makefile: 5
file content (102 lines) | stat: -rw-r--r-- 2,997 bytes parent folder | download
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
/*
 *   SPDX-FileCopyrightText: 2024 Aleix Pol Gonzalez <aleixpol@kde.org>
 *
 *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#include "AppStreamConcurrentPool.h"

#include <QtConcurrentRun>

using namespace AppStream;

void ConcurrentPool::reset(AppStream::Pool *pool, QThreadPool *threadPool)
{
    m_pool.reset(pool);
    connect(pool, &Pool::loadFinished, this, &ConcurrentPool::loadFinished);

    m_threadPool = threadPool;
}

void ConcurrentPool::loadAsync()
{
    QMutexLocker lock(&m_mutex);
    return m_pool->loadAsync();
}

QString ConcurrentPool::lastError()
{
    QMutexLocker lock(&m_mutex);
    return m_pool->lastError();
}

QFuture<ComponentBox> ConcurrentPool::search(const QString &term)
{
    return QtConcurrent::run(m_threadPool.get(), [this, term] {
        QMutexLocker lock(&m_mutex);
        return m_pool->search(term);
    });
}

QFuture<ComponentBox> ConcurrentPool::components()
{
    return QtConcurrent::run(m_threadPool.get(), [this] {
        QMutexLocker lock(&m_mutex);
        return m_pool->components();
    });
}

QFuture<ComponentBox> ConcurrentPool::componentsById(const QString &cid)
{
    return QtConcurrent::run(m_threadPool.get(), [this, cid] {
        QMutexLocker lock(&m_mutex);
        return m_pool->componentsById(cid);
    });
}

QFuture<ComponentBox> ConcurrentPool::componentsByProvided(Provided::Kind kind, const QString &item)
{
    return QtConcurrent::run(m_threadPool.get(), [this, kind, item] {
        QMutexLocker lock(&m_mutex);
        return m_pool->componentsByProvided(kind, item);
    });
}

QFuture<ComponentBox> ConcurrentPool::componentsByKind(Component::Kind kind)
{
    return QtConcurrent::run(m_threadPool.get(), [this, kind] {
        QMutexLocker lock(&m_mutex);
        return m_pool->componentsByKind(kind);
    });
}

QFuture<ComponentBox> ConcurrentPool::componentsByCategories(const QStringList &categories)
{
    return QtConcurrent::run(m_threadPool.get(), [this, categories] {
        QMutexLocker lock(&m_mutex);
        return m_pool->componentsByCategories(categories);
    });
}

QFuture<ComponentBox> ConcurrentPool::componentsByLaunchable(Launchable::Kind kind, const QString &value)
{
    return QtConcurrent::run(m_threadPool.get(), [this, kind, value] {
        QMutexLocker lock(&m_mutex);
        return m_pool->componentsByLaunchable(kind, value);
    });
}

QFuture<ComponentBox> ConcurrentPool::componentsByExtends(const QString &extendedId)
{
    return QtConcurrent::run(m_threadPool.get(), [this, extendedId] {
        QMutexLocker lock(&m_mutex);
        return m_pool->componentsByExtends(extendedId);
    });
}
QFuture<ComponentBox> ConcurrentPool::componentsByBundleId(Bundle::Kind kind, const QString &bundleId, bool matchPrefix)
{
    return QtConcurrent::run(m_threadPool.get(), [this, kind, bundleId, matchPrefix] {
        QMutexLocker lock(&m_mutex);
        return m_pool->componentsByBundleId(kind, bundleId, matchPrefix);
    });
}