Reorganize directories and switch libaries to using asn1c
[it/test.git] / simulators / e2sim / src / ASN1 / lib / asn_x2ap_wrapper.hpp
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 # Copyright 2019 Nokia                                                       *
5 #                                                                            *
6 # Licensed under the Apache License, Version 2.0 (the "License");            *
7 # you may not use this file except in compliance with the License.           *
8 # You may obtain a copy of the License at                                    *
9 #                                                                            *
10 #      http://www.apache.org/licenses/LICENSE-2.0                            *
11 #                                                                            *
12 # Unless required by applicable law or agreed to in writing, software        *
13 # distributed under the License is distributed on an "AS IS" BASIS,          *
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
15 # See the License for the specific language governing permissions and        *
16 # limitations under the License.                                             *
17 #                                                                            *
18 ******************************************************************************/
19 #ifndef ASN_X2AP_PDU_WRAPPER_HPP
20 #define ASN_X2AP_PDU_WRAPPER_HPP
21
22 #include <asn/per/codec.hpp>
23 #include <asn/printer.hpp>
24 #include <asn/utility.hpp>
25
26 #include <X2AP-CommonDataTypes.hpp>
27 #include <X2AP-Constants.hpp>
28 #include <X2AP-Containers.hpp>
29 #include <X2AP-IEs.hpp>
30 #include <X2AP-PDU-Contents.hpp>
31 #include <X2AP-PDU-Descriptions.hpp>
32
33 #define X2AP_PDU_DEFAULT_BUFFER_SIZE 4096
34
35 //Credit: copied from E2-Manager
36 struct X2APpduWrapper
37 {
38     unsigned char* m_allocation_buffer;
39     size_t m_allocation_buffer_size;
40
41     X2APpduWrapper(size_t allocation_buffer_size = X2AP_PDU_DEFAULT_BUFFER_SIZE)
42     {
43         m_allocation_buffer_size = allocation_buffer_size;
44         m_allocation_buffer = 0;
45         if (allocation_buffer_size) {
46             m_allocation_buffer =
47               new (std::nothrow) unsigned char[allocation_buffer_size];
48             m_allocator.reset(
49               m_allocation_buffer,
50               m_allocation_buffer_size); // initialized correctly on
51                                          // allocation failure.
52         }
53     }
54
55     ~X2APpduWrapper()
56     {
57         if (m_allocation_buffer)
58             delete[] m_allocation_buffer;
59     }
60
61     asn::allocator& ref_allocator() { return m_allocator; }
62
63     X2AP_PDU& ref_pdu() { return m_pdu; }
64
65     // reset pdu and allocation buffer. Allows reusing.
66     void clear()
67     {
68         m_pdu.clear();
69         m_allocator.reset(m_allocation_buffer, m_allocation_buffer_size);
70     }
71
72   private:
73     X2AP_PDU m_pdu;
74     asn::allocator m_allocator;
75 };
76
77
78 #endif