/src/trafficserver/include/tsutil/PostScript.h
Line | Count | Source |
1 | | /** @file |
2 | | |
3 | | Generic "guard" class templates. The destructor calls a function object with arbitrary parameters. This utility is |
4 | | available in both the core and plugins. |
5 | | |
6 | | @section license License |
7 | | |
8 | | Licensed to the Apache Software Foundation (ASF) under one |
9 | | or more contributor license agreements. See the NOTICE file |
10 | | distributed with this work for additional information |
11 | | regarding copyright ownership. The ASF licenses this file |
12 | | to you under the Apache License, Version 2.0 (the |
13 | | "License"); you may not use this file except in compliance |
14 | | with the License. You may obtain a copy of the License at |
15 | | |
16 | | http://www.apache.org/licenses/LICENSE-2.0 |
17 | | |
18 | | Unless required by applicable law or agreed to in writing, software |
19 | | distributed under the License is distributed on an "AS IS" BASIS, |
20 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
21 | | See the License for the specific language governing permissions and |
22 | | limitations under the License. |
23 | | */ |
24 | | |
25 | | #pragma once |
26 | | |
27 | | namespace ts |
28 | | { |
29 | | // The destructor of this class calls the function object passed to its constructor. The function object must support a |
30 | | // function call operator with no parameters. For example: |
31 | | // |
32 | | // ts::PostScript g([=]() -> void { TSHandleMLocRelease(bufp, parent, hdr); }); |
33 | | // |
34 | | // The release() member will prevent the call to the function upon destruction. |
35 | | // |
36 | | // Helpful in avoiding errors due to exception throws or error function return points (like the one that caused Heartbleed). |
37 | | // |
38 | | template <typename Callable> class PostScript |
39 | | { |
40 | | public: |
41 | 0 | PostScript(Callable f) : _f(f) {}Unexecuted instantiation: RemapYamlConfig.cc:ts::PostScript<remap_validate_yaml_filter_args(acl_filter_rule**, YAML::Node const&, ACLBehaviorPolicy)::$_0>::PostScript(remap_validate_yaml_filter_args(acl_filter_rule**, YAML::Node const&, ACLBehaviorPolicy)::$_0) Unexecuted instantiation: Http2ConnectionState.cc:ts::PostScript<Http2ConnectionState::send_push_promise_frame(Http2Stream*, URL&, MIMEField const*)::$_0>::PostScript(Http2ConnectionState::send_push_promise_frame(Http2Stream*, URL&, MIMEField const*)::$_0) |
42 | | |
43 | | ~PostScript() |
44 | 0 | { |
45 | 0 | if (_armed) { |
46 | 0 | _f(); |
47 | 0 | } |
48 | 0 | } Unexecuted instantiation: RemapYamlConfig.cc:ts::PostScript<remap_validate_yaml_filter_args(acl_filter_rule**, YAML::Node const&, ACLBehaviorPolicy)::$_0>::~PostScript() Unexecuted instantiation: Http2ConnectionState.cc:ts::PostScript<Http2ConnectionState::send_push_promise_frame(Http2Stream*, URL&, MIMEField const*)::$_0>::~PostScript() |
49 | | |
50 | | void |
51 | | release() |
52 | 0 | { |
53 | 0 | _armed = false; |
54 | 0 | } |
55 | | |
56 | | // No copying or moving. |
57 | | PostScript(const PostScript &) = delete; |
58 | | PostScript &operator=(const PostScript &) = delete; |
59 | | |
60 | | private: |
61 | | bool _armed = true; |
62 | | Callable _f; |
63 | | }; |
64 | | |
65 | | } // end namespace ts |