Reorganize directories and switch libaries to using asn1c
[it/test.git] / simulators / e2sim / src / ASN1 / lib / asn_e2ap_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_E2AP_PDU_WRAPPER_HPP
20 #define ASN_E2AP_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
28 // #include <X2AP-Constants.hpp>
29 // #include <X2AP-Containers.hpp>
30 // #include <X2AP-IEs.hpp>
31 // #include <X2AP-PDU-Contents.hpp>
32 // #include <X2AP-PDU-Descriptions.hpp>
33
34 #include <E2AP-Constants.hpp>
35 // #include <E2AP-Containers.hpp>
36 #include <E2AP-IEs.hpp>
37 #include <E2AP-PDU-Contents.hpp>
38 #include <E2AP-PDU-Descriptions.hpp>
39
40 #define E2AP_PDU_DEFAULT_BUFFER_SIZE 4096
41
42 //Credit: copied from E2-Manager
43 struct E2APpduWrapper
44 {
45     unsigned char* m_allocation_buffer;
46     size_t m_allocation_buffer_size;
47
48     E2APpduWrapper(size_t allocation_buffer_size = E2AP_PDU_DEFAULT_BUFFER_SIZE)
49     {
50         m_allocation_buffer_size = allocation_buffer_size;
51         m_allocation_buffer = 0;
52         if (allocation_buffer_size) {
53             m_allocation_buffer =
54               new (std::nothrow) unsigned char[allocation_buffer_size];
55             m_allocator.reset(
56               m_allocation_buffer,
57               m_allocation_buffer_size); // initialized correctly on
58                                          // allocation failure.
59         }
60     }
61
62     ~E2APpduWrapper()
63     {
64         if (m_allocation_buffer)
65             delete[] m_allocation_buffer;
66     }
67
68     asn::allocator& ref_allocator() { return m_allocator; }
69
70     E2AP_PDU& ref_pdu() { return m_pdu; }
71
72     // reset pdu and allocation buffer. Allows reusing.
73     void clear()
74     {
75         m_pdu.clear();
76         m_allocator.reset(m_allocation_buffer, m_allocation_buffer_size);
77     }
78
79   private:
80     E2AP_PDU m_pdu;
81     asn::allocator m_allocator;
82 };
83
84
85 #endif