cutelyst 3.9.1
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", QtInfoMsg)
13
14using namespace Cutelyst;
15
16namespace Cutelyst {
17
18class ASyncPrivate
19{
20public:
21 ASyncPrivate(Context *_c)
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 }
34 ~ASyncPrivate()
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
51ASync::ASync() = default;
52
63ASync::ASync(Context *c)
64 : d(std::make_shared<ASyncPrivate>(c))
65{
66}
67
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
101ASync::~ASync() = default;
102
103ASync &ASync::operator=(const ASync &copy)
104{
105 d = copy.d;
106 return *this;
107}
The Cutelyst Context.
Definition context.h:39
The Cutelyst namespace holds all public Cutelyst API.
Definition Mainpage.dox:8