E2AP Abstraction Changes
[ric-app/hw.git] / src / xapp-asn / e2ap / e2ap_action.hpp
1 /*
2 ==================================================================================
3
4         Copyright (c) 2019-2020 AT&T Intellectual Property.
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 /*
20  * action_e2ap.hpp
21  *
22  *  Created on: Jun 30, 2020
23  *      Author: sjana
24  */
25
26 #ifndef XAPP_ASN_REFACTOR_E2AP_ACTION_HPP_
27 #define XAPP_ASN_REFACTOR_E2AP_ACTION_HPP_
28 #define E2SM_SIZE ((int)128)
29
30 #include <mdclog/mdclog.h>
31
32 #include <string>
33 #include <memory>
34 #include <sstream>
35 #include <vector>
36 /*
37  RICaction-ToBeSetup-Item ::= SEQUENCE {
38         ricActionID                                     RICactionID,
39         ricActionType                           RICactionType,
40         ricActionDefinition                     RICactionDefinition     OPTIONAL,
41         ricSubsequentAction                     RICsubsequentAction     OPTIONAL,
42         ...
43 }
44 RICsubsequentAction ::=SEQUENCE{
45         ricSubsequentActionType         RICsubsequentActionType,
46         ricTimeToWait                           RICtimeToWait,
47         ...
48 }
49
50 */
51
52
53 template<typename E2SMActionDefinition>
54 class E2APAction{
55
56 public:
57         class ActionIEs{
58         private:
59                          bool is_ricSubsequentAction;
60                          unsigned int ricActionType, ricActionID,ricSubsequentActionType,ricTimeToWait;
61                          unsigned char ricActionDefinition[E2SM_SIZE];
62                          size_t ricActionDefinition_size = E2SM_SIZE;
63         public:
64                          ActionIEs():ricActionType(0),ricActionID(0),ricSubsequentActionType(0),ricTimeToWait(0),is_ricSubsequentAction(false){ };
65                          ActionIEs& set_ricSubsequentAction(int subsequentActionType, int timeToWait){
66                                  is_ricSubsequentAction = true;
67                                  ricSubsequentActionType = subsequentActionType;
68                                  ricTimeToWait = timeToWait;
69                                  return *this;
70                          };
71
72                          ActionIEs& set_ricActionDefinition(E2SMActionDefinition &e2smObj){
73                                  bool res = e2smObj.encode(&(this->ricActionDefinition)[0],&this->ricActionDefinition_size);
74                                  if(!res){
75                                          mdclog_write(MDCLOG_ERR, "Failed to encode: %s","RIC Action Definition");
76                                          mdclog_write(MDCLOG_ERR, "Error during encode: %s",e2smObj.get_error());
77
78                                  } else {
79                                          mdclog_write(MDCLOG_INFO, "Successfully encoded: %s","RIC Action Definition");
80                                  }
81                                  return *this;
82                          };
83                          ActionIEs& set_ricActionID(int actionID){ricActionID = actionID; return *this;};
84                          ActionIEs& set_ricActionType(int actionType) {ricActionType = actionType; return *this;};
85
86                          int    get_ricActionID(){return this->ricActionID;};
87                          int    get_ricActionType() {return this->ricActionType;};
88                          bool   get_is_ricSubsequentAction() { return this->is_ricSubsequentAction; };
89                          int    get_ricSubsequentActionType(){return this->ricSubsequentActionType; }
90                          int    get_ricTimeToWait(){ return this->ricTimeToWait; }
91                          void*  get_ricActionDefinition(){ return this->ricActionDefinition; };
92                          size_t get_ricActionDefinition_size(){return this->ricActionDefinition_size; };
93
94         };
95         E2APAction(){ _ref_list = std::make_unique<std::vector<ActionIEs>>(); _count_list = 0;};
96
97         std::vector<E2APAction<E2SMActionDefinition>::ActionIEs> * get_list() const {return _ref_list.get();};
98         int get_list_count() {return _count_list;};
99
100         void add(E2APAction<E2SMActionDefinition>::ActionIEs &actionObj) { _ref_list.get()->push_back(actionObj); _count_list++;};
101 private:
102
103         std::unique_ptr<std::vector<ActionIEs>> _ref_list;
104         int _count_list;
105 };
106
107
108 #endif /* XAPP_ASN_REFACTOR_E2AP_ACTION_HPP_ */