NAWA  0.8
Web Application Framework for C++
HandleRequestFunction.cpp
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2019-2021 Tobias Flaig.
8  *
9  * This file is part of nawa.
10  *
11  * nawa is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License,
13  * version 3, as published by the Free Software Foundation.
14  *
15  * nawa is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with nawa. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
25 
26 using namespace nawa;
27 using namespace std;
28 
29 struct HandleRequestFunctionWrapper::Data {
30  HandleRequestFunction handleRequestFunction;
31  void* reference = nullptr;
32  DestructionCallbackFunction destructionCallback;
33 
38  ~Data() {
39  if (destructionCallback) {
40  destructionCallback(reference);
41  }
42  }
43 
44  Data(HandleRequestFunction handleRequestFunction, void* reference, DestructionCallbackFunction destructionCallback)
45  : handleRequestFunction(move(handleRequestFunction)), reference(reference),
46  destructionCallback(move(destructionCallback)) {}
47 };
48 
50 
52  void* reference,
53  DestructionCallbackFunction destructionCallback) {
54  data = make_unique<Data>(move(handleRequestFunction), reference, move(destructionCallback));
55 }
56 
58  return data->handleRequestFunction(connection);
59 }
Function wrapper for handleRequest functions of nawa apps.
int operator()(nawa::Connection &connection) const
#define NAWA_DEFAULT_DESTRUCTOR_IMPL(Class)
Definition: macros.h:36
Definition: AppInit.h:31
std::function< void(void *)> DestructionCallbackFunction
std::function< int(nawa::Connection &)> HandleRequestFunction