433f0ca2a7d2c74acb9128814b664a62330aac22
[ric-app/admin.git] / src / E2AP-c / subscription / 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 <generic_helpers.hpp>
35 #include <iostream>
36 #include <vector>
37 #include <memory>
38
39 struct Action {
40
41 public:
42   
43   Action(int id, int type): _is_def(false), _is_subs_act(false), _id(id), _type(type){};
44   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){
45     
46     if (def_size > 0){
47       _is_def = true;
48       _action_definition.set_ref(def);
49       _action_definition.set_size(def_size);
50     }
51     
52     if(next >= 0 && wait >= 0){
53       _is_subs_act = true;
54       _next_action = next;
55       _wait = wait;
56     }
57   };
58
59   
60   int get_id() const{
61     return _id;
62   }
63
64   int get_type() const {
65     return _type;
66   }
67
68
69   const void * get_definition(void )  {
70     return _action_definition.get_ref();
71   }
72
73   int get_definition_size(void) const {
74     return _action_definition.get_size();
75   };
76   
77
78   int get_subsequent_action() const {
79     return _next_action;
80   };
81
82   int get_wait() const {
83     return _wait;
84   }
85
86   bool is_definition() const{
87
88     return _is_def;
89   }
90
91   bool is_subsequent_action() const{
92     return _is_subs_act;
93   }
94     
95 private:
96
97   bool _is_def;
98   bool _is_subs_act;
99   int _id, _type, _next_action, _wait, _cause, _sub_cause;
100   bool _is_admit;
101   octet_helper _action_definition;
102
103 };
104
105
106 /*
107  Helper class that stores subscription data 
108 */
109
110
111 struct subscription_helper {
112
113 public:
114
115   using action_t = std::vector<Action>;
116   
117   subscription_helper(){
118     _action_ref = std::make_unique<action_t>();
119     curr_index = 0;    
120   };
121   
122   action_t * get_list() const {return _action_ref.get();};
123
124   void clear(void){
125     _action_ref.get()->clear();
126   }
127   
128   void set_request(int id, int seq_no){
129     _req_id = id;
130     _req_seq_no = seq_no;
131     
132   };
133
134   void set_function_id(int id){
135     _func_id = id;
136   };
137
138   void set_event_def(const void *ref, size_t size){
139     _event_def.set_ref(ref);
140     _event_def.set_size(size);
141    };
142
143  
144   void add_action(int id, int type){
145     Action a(id, type) ;
146     _action_ref.get()->push_back(a);
147   };
148
149   void add_action(int id, int type, std::string action_def, int next_action, int wait_time){
150     Action a (id, type, action_def.c_str(), action_def.length(), next_action, wait_time);
151     _action_ref.get()->push_back(a);
152   };
153
154
155   int  get_request_id(void) const{
156     return _req_id;
157   }
158
159   int  get_req_seq(void) const {
160     return _req_seq_no;
161   }
162
163   int  get_function_id(void) const{
164     return _func_id;
165   }
166   
167   const void * get_event_def(void)  {
168     return _event_def.get_ref();
169   }
170
171   int get_event_def_size(void) const {
172     return _event_def.get_size();
173   }
174
175   void print_sub_info(void){
176     std::cout <<"Request ID = " << _req_id << std::endl;
177     std::cout <<"Request Sequence Number = " << _req_seq_no << std::endl;
178     std::cout <<"RAN Function ID = " << _func_id << std::endl;
179     for(auto const & e: *(_action_ref.get())){
180       std::cout <<"Action ID = " << e.get_id() << " Action Type = " << e.get_type() << std::endl;
181     }
182   };
183   
184 private:
185   
186   std::unique_ptr<action_t> _action_ref;
187   int curr_index;
188   int _req_id, _req_seq_no, _func_id;
189   octet_helper _event_def;
190 };
191
192 #endif