cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
async.cpp
1/*
2 * SPDX-FileCopyrightText: (C) 2020-2022 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#include "async.h"
6
7#include "context.h"
8
9#include <QLoggingCategory>
10#include <QPointer>
11
12Q_LOGGING_CATEGORY(CUTELYST_ASYNC, "cutelyst.async", QtWarningMsg)
13
14using namespace Cutelyst;
15
16namespace Cutelyst {
17
19{
20public:
22 : c(_c)
23 {
24 // qDebug(CUTELYST_ASYNC, "Detaching async %s", qPrintable(c->objectName()));
25 c->detachAsync();
26 }
27 ASyncPrivate(Context *_c, std::function<void(Context *c)> _cb)
28 : c(_c)
29 , cb(_cb)
30 {
31 // qDebug(CUTELYST_ASYNC, "Detaching async %s", qPrintable(c->objectName()));
32 c->detachAsync();
33 }
35 {
36 if (!c.isNull()) {
37 if (cb) {
38 cb(c);
39 }
40 // qDebug(CUTELYST_ASYNC, "Attaching async %s", qPrintable(c->objectName()));
41 c->attachAsync();
42 }
43 }
44
46 std::function<void(Context *c)> cb;
47};
48
49} // namespace Cutelyst
50
64ASync::ASync() noexcept = default;
65
76 : d(std::make_shared<ASyncPrivate>(c))
77{
78}
79
80ASync::ASync(Context *c, std::function<void(Context *)> cb)
81 : d(std::make_shared<ASyncPrivate>(c, cb))
82{
83}
84
88ASync::ASync(const ASync &other)
89 : d(other.d)
90{
91}
92
96ASync::ASync(ASync &&other) noexcept
97 : d(std::move(other.d))
98{
99}
100
104ASync::~ASync() = default;
105
110{
111 d = copy.d;
112 return *this;
113}
Helper class for asynchronous processing.
Definition async.h:16
ASync & operator=(const ASync &copy)
Definition async.cpp:109
ASync() noexcept
The Cutelyst Context.
Definition context.h:42
void detachAsync() noexcept
Definition context.cpp:349
The Cutelyst namespace holds all public Cutelyst API.