Initial commit of source directory
[ric-app/hw.git] / src / xapp-asn / e2ap / subscription_helper.hpp
1 /*
2 ==================================================================================
3         Copyright (c) 2018-2019 AT&T Intellectual Property.
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================================
17 */
18
19
20 #ifndef SUB_HELPER_
21 #define SUB_HELPER_
22
23 /* 
24    Simple structure to store action related information based on E2 v0.22
25    Used for subscription request, response etc
26    
27    ricActionID                                  RICactionID,
28    ricActionType                                RICactionType,
29    ricActionDefinition                  RICactionDefinition     OPTIONAL,
30    ricSubsequentAction                  RICsubsequentAction     OPTIONAL,
31    ricCause
32 */
33
34 #include <iostream>
35 #include <vector>
36 #include <memory>
37 #include "generic_helpers.hpp"
38
39
40 // Note : if no action definition specified, octet length of action definition  is NULL
41 // If no subsequent action specified, default is subsequent_action = 0, time to wait is 0
42 struct Action {
43
44 public:
45   
46   Action(int id, int type): _is_def(false), _is_subs_act(false), _id(id), _type(type), _next_action(0), _wait(0){};
47   Action(int id, int type, const void *def, size_t def_size, int next, int wait): _is_def(false), _is_subs_act(false), _id(id), _type(type){
48     
49     if (def_size > 0){
50       _is_def = true;
51       _action_definition.set_ref(def);
52       _action_definition.set_size(def_size);
53     }
54     
55     if(next >= 0 && wait >= 0){
56       _is_subs_act = true;
57       _next_action = next;
58       _wait = wait;
59     }
60   };
61
62   
63   int get_id() const{
64     return _id;
65   }
66
67   int get_type() const {
68     return _type;
69   }
70
71
72   const void * get_definition(void )  {
73     return _action_definition.get_ref();
74   }
75
76   int get_definition_size(void) const {
77     return _action_definition.get_size();
78   };
79   
80
81   int get_subsequent_action() const {
82     return _next_action;
83   };
84
85   int get_wait() const {
86     return _wait;
87   }
88
89   bool is_definition() const{
90
91     return _is_def;
92   }
93
94   bool is_subsequent_action() const{
95     return _is_subs_act;
96   }
97     
98 private:
99
100   bool _is_def;
101   bool _is_subs_act;
102   int _id, _type, _next_action, _wait, _cause, _sub_cause;
103   bool _is_admit;
104   octet_helper _action_definition;
105
106 };
107
108
109 /*
110  Helper class that stores subscription data 
111 */
112
113
114 struct subscription_helper {
115
116 public:
117
118   using action_t = std::vector<Action>;
119   
120   subscription_helper(){
121     _action_ref = std::make_unique<action_t>();
122     curr_index = 0;    
123   };
124   
125   action_t * get_list() const {return _action_ref.get();};
126
127   void clear(void){
128     _action_ref.get()->clear();
129   }
130   
131   void set_request(int id, int seq_no){
132     _req_id = id;
133     _req_seq_no = seq_no;
134     
135   };
136
137   void set_function_id(int id){
138     _func_id = id;
139   };
140
141   void set_event_def(const void *ref, size_t size){
142     _event_def.set_ref(ref);
143     _event_def.set_size(size);
144    };
145
146  
147   void add_action(int id, int type){
148     Action a(id, type) ;
149     _action_ref.get()->push_back(a);
150   };
151
152   void add_action(int id, int type, std::string action_def, int next_action, int wait_time){
153     Action a (id, type, action_def.c_str(), action_def.length(), next_action, wait_time);
154     _action_ref.get()->push_back(a);
155   };
156
157
158   int  get_request_id(void) const{
159     return _req_id;
160   }
161
162   int  get_req_seq(void) const {
163     return _req_seq_no;
164   }
165
166   int  get_function_id(void) const{
167     return _func_id;
168   }
169   
170   const void * get_event_def(void)  {
171     return _event_def.get_ref();
172   }
173
174   int get_event_def_size(void) const {
175     return _event_def.get_size();
176   }
177
178   void print_sub_info(void){
179     std::cout <<"Request ID = " << _req_id << std::endl;
180     std::cout <<"Request Sequence Number = " << _req_seq_no << std::endl;
181     std::cout <<"RAN Function ID = " << _func_id << std::endl;
182     for(auto const & e: *(_action_ref.get())){
183       std::cout <<"Action ID = " << e.get_id() << " Action Type = " << e.get_type() << std::endl;
184     }
185   };
186   
187 private:
188   
189   std::unique_ptr<action_t> _action_ref;
190   int curr_index;
191   int _req_id, _req_seq_no, _func_id;
192   octet_helper _event_def;
193 };
194
195 #endif