2 ==================================================================================
4 Copyright (c) 2019-2020 AT&T Intellectual Property.
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
22 * Created on: Apr, 2020
23 * Author: Shraboni Jana
25 /* Classes to handle E2 service model based on e2sm-HelloWorld-v001.asn */
26 #include "e2sm_indication.hpp"
29 e2sm_indication::e2sm_indication(void){
31 memset(&head_fmt1, 0, sizeof(E2SM_HelloWorld_IndicationHeader_Format1_t));
33 memset(&msg_fmt1, 0, sizeof(E2SM_HelloWorld_IndicationMessage_Format1_t));
38 indication_head = ( E2SM_HelloWorld_IndicationHeader_t *)calloc(1, sizeof( E2SM_HelloWorld_IndicationHeader_t));
39 assert(indication_head != 0);
42 indication_msg = (E2SM_HelloWorld_IndicationMessage_t*)calloc(1, sizeof(E2SM_HelloWorld_IndicationMessage_t));
43 assert(indication_msg !=0);
48 e2sm_indication::~e2sm_indication(void){
50 mdclog_write(MDCLOG_DEBUG, "Freeing event trigger object memory");
52 indication_head->choice.indicationHeader_Format1 = 0;
54 indication_msg->choice.indicationMessage_Format1 = 0;
56 ASN_STRUCT_FREE(asn_DEF_E2SM_HelloWorld_IndicationHeader, indication_head);
57 ASN_STRUCT_FREE(asn_DEF_E2SM_HelloWorld_IndicationMessage, indication_msg);
62 bool e2sm_indication::encode_indication_header(unsigned char *buf, size_t *size, e2sm_indication_helper &helper){
64 ASN_STRUCT_RESET(asn_DEF_E2SM_HelloWorld_IndicationHeader, indication_head);
67 res = set_fields(indication_head, helper);
73 int ret_constr = asn_check_constraints(&asn_DEF_E2SM_HelloWorld_IndicationHeader, indication_head, errbuf, &errbuf_len);
75 error_string.assign(&errbuf[0], errbuf_len);
79 xer_fprint(stdout, &asn_DEF_E2SM_HelloWorld_IndicationHeader, indication_head);
81 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationHeader, indication_head, buf, *size);
83 if(retval.encoded == -1){
84 error_string.assign(strerror(errno));
87 else if (retval.encoded > *size){
89 ss <<"Error encoding event trigger definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
90 error_string = ss.str();
94 *size = retval.encoded;
100 bool e2sm_indication::encode_indication_message(unsigned char *buf, size_t *size, e2sm_indication_helper &helper){
103 res = set_fields(indication_msg, helper);
109 int ret_constr = asn_check_constraints(&asn_DEF_E2SM_HelloWorld_IndicationMessage, indication_msg, errbuf, &errbuf_len);
111 error_string.assign(&errbuf[0], errbuf_len);
115 xer_fprint(stdout, &asn_DEF_E2SM_HelloWorld_IndicationMessage, indication_msg);
117 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationMessage, indication_msg, buf, *size);
119 if(retval.encoded == -1){
120 error_string.assign(strerror(errno));
123 else if (retval.encoded > *size){
124 std::stringstream ss;
125 ss <<"Error encoding action definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
126 error_string = ss.str();
130 *size = retval.encoded;
136 bool e2sm_indication::set_fields(E2SM_HelloWorld_IndicationHeader_t * ref_indication_head, e2sm_indication_helper & helper){
138 if(ref_indication_head == 0){
139 error_string = "Invalid reference for Event Trigger Definition set fields";
143 ref_indication_head->present = E2SM_HelloWorld_IndicationHeader_PR_indicationHeader_Format1;
145 head_fmt1.indicationHeaderParam = helper.header;
147 ref_indication_head->choice.indicationHeader_Format1 = &head_fmt1;
152 bool e2sm_indication::set_fields(E2SM_HelloWorld_IndicationMessage_t * ref_indication_msg, e2sm_indication_helper & helper){
154 if(ref_indication_msg == 0){
155 error_string = "Invalid reference for Event Action Definition set fields";
158 ref_indication_msg->present = E2SM_HelloWorld_IndicationMessage_PR_indicationMessage_Format1;
160 msg_fmt1.indicationMsgParam.buf = helper.message;
161 msg_fmt1.indicationMsgParam.size = helper.message_len;
164 ref_indication_msg->choice.indicationMessage_Format1 = &msg_fmt1;
170 bool e2sm_indication::get_fields(E2SM_HelloWorld_IndicationHeader_t * ref_indictaion_header, e2sm_indication_helper & helper){
172 if (ref_indictaion_header == 0){
173 error_string = "Invalid reference for Indication Header get fields";
177 helper.header = ref_indictaion_header->choice.indicationHeader_Format1->indicationHeaderParam;
181 bool e2sm_indication::get_fields(E2SM_HelloWorld_IndicationMessage_t * ref_indication_message, e2sm_indication_helper & helper){
183 if (ref_indication_message == 0){
184 error_string = "Invalid reference for Indication Message get fields";
187 helper.message = ref_indication_message->choice.indicationMessage_Format1->indicationMsgParam.buf;
188 helper.message_len = ref_indication_message->choice.indicationMessage_Format1->indicationMsgParam.size;