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