cutelyst  4.4.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 
12 Q_LOGGING_CATEGORY(CUTELYST_ASYNC, "cutelyst.async", QtWarningMsg)
13 
14 using namespace Cutelyst;
15 
16 namespace Cutelyst {
17 
19 {
20 public:
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 
64 ASync::ASync() noexcept = default;
65 
76  : d(std::make_shared<ASyncPrivate>(c))
77 {
78 }
79 
80 ASync::ASync(Context *c, std::function<void(Context *)> cb)
81  : d(std::make_shared<ASyncPrivate>(c, cb))
82 {
83 }
84 
88 ASync::ASync(const ASync &other)
89  : d(other.d)
90 {
91 }
92 
96 ASync::ASync(ASync &&other) noexcept
97  : d(std::move(other.d))
98 {
99 }
100 
104 ASync::~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 attachAsync()
Definition: context.cpp:355
void detachAsync() noexcept
Definition: context.cpp:349
The Cutelyst namespace holds all public Cutelyst API.