blob: 95e445c62e7875dcc0cb5fb9e7498a7f4fe9fbfb [file] [log] [blame]
E. Scott Daniels8cb3c6f2020-03-19 11:36:37 -04001// vi: ts=4 sw=4 noet:
2/*
3==================================================================================
4 Copyright (c) 2020 Nokia
5 Copyright (c) 2020 AT&T Intellectual Property.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18==================================================================================
19*/
20
21/*
22 Mnemonic: msg_component.hpp
23 Abstract: Defines a message component type which is needed in order
24 to use smart pointers (unique) to point at bytes in the
25 RMR message (which are not directly allocated and cannot
26 be freed/deleted outside of RMR (require a special destruction
27 call in the smart pointer).
28
29 Date: 17 March 2020
30 Author: E. Scott Daniels
31*/
32
33#ifndef _MSG_COMPONENT_HPP
34#define _MSG_COMPONENT_HPP
35
36#include <memory>
37
E. Scott Daniels6ef23e12020-07-15 08:03:22 -040038namespace xapp {
39
E. Scott Daniels8cb3c6f2020-03-19 11:36:37 -040040// -------------- smart pointer support --------------------------------
41/*
42 Pointers to a lot of things in the RMR message aren't directly
43 allocated and thus cannot be directly freed. To return a smart
44 pointer to these we have to ensure that no attempt to free/delete
45 the reference is made. This struct defines a type with a function
46 pointer (operator) that is 'registered' as the delete function for
47 such a smart pointer, and does _nothing_ when called.
48*/
49typedef struct {
E. Scott Danielsc85ac8b2020-08-19 09:51:33 -040050 void operator()( unsigned char * p ) const { /* empty to prevent free */ }
E. Scott Daniels8cb3c6f2020-03-19 11:36:37 -040051} unfreeable;
52
53/*
54 A 'generic' smart pointer to a component in the message which cannot
55 be directly freed (e.g. the payload, meid, etc).
56*/
57using Msg_component = std::unique_ptr<unsigned char, unfreeable>;
58
E. Scott Daniels6ef23e12020-07-15 08:03:22 -040059
60} // namespace
E. Scott Daniels8cb3c6f2020-03-19 11:36:37 -040061#endif