Cutelyst  2.14.2
async.cpp
1 /*
2  * Copyright (C) 2020 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #include "async.h"
19 #include "context.h"
20 
21 #include <QPointer>
22 #include <QLoggingCategory>
23 
24 Q_LOGGING_CATEGORY(CUTELYST_ASYNC, "cutelyst.async", QtInfoMsg)
25 
26 using namespace Cutelyst;
27 
28 namespace Cutelyst {
29 
30 class ASyncPrivate {
31 public:
32  ASyncPrivate(Context *_c) : c(_c) {}
33  ASyncPrivate(Context *_c, std::function<void(Context *c)> _cb) : c(_c), cb(_cb) {}
34  ~ASyncPrivate() {
35  if (!c.isNull()) {
36  if (cb) {
37  cb(c);
38  }
39 // qDebug(CUTELYST_ASYNC, "Attaching async %s", qPrintable(c->objectName()));
40  c->attachAsync();
41  }
42  }
43 
45  std::function<void(Context *c)> cb;
46 };
47 
48 }
49 
50 ASync::ASync()
51 {
52 
53 }
54 
65 ASync::ASync(Context *c)
66 {
67 // qDebug(CUTELYST_ASYNC, "Detaching async %s", qPrintable(c->objectName()));
68  c->detachAsync();
70 }
71 
84 ASync::ASync(Context *c, std::function<void (Context *)> cb)
85 {
86  c->detachAsync();
88 }
89 
93 ASync::ASync(const ASync &other)
94 {
95  d = other.d;
96 }
97 
98 ASync::~ASync()
99 {
100 
101 }
102 
103 ASync &ASync::operator =(const ASync &copy)
104 {
105  d = copy.d;
106  return *this;
107 }
void detachAsync()
Definition: context.cpp:356
The Cutelyst Context.
Definition: context.h:51
void attachAsync()
attachAsync
Definition: context.cpp:363