Add API allowing xAPPs to send alarm messages
[ric-plt/xapp-frame-cpp.git] / src / messaging / msg_component.hpp
1 // 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
38 namespace xapp {
39
40 //  -------------- 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 */
49 typedef struct {
50         void operator()( unsigned char * p ){}
51 } 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 */
57 using Msg_component = std::unique_ptr<unsigned char, unfreeable>;
58
59
60 } // namespace
61 #endif