sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 3 | Copyright (c) 2019-2020 AT&T Intellectual Property. |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 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> |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 37 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 38 | #include "generic_helpers.hpp" |
| 39 | |
| 40 | |
| 41 | // Note : if no action definition specified, octet length of action definition is NULL |
| 42 | // If no subsequent action specified, default is subsequent_action = 0, time to wait is 0 |
| 43 | struct Action { |
| 44 | |
| 45 | public: |
| 46 | |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 47 | Action(int id, int type): _is_def(false), _is_subs_act(false), _id(id), _type(type), _next_action(0){}; |
| 48 | Action(int id, int type, const void *def, size_t def_size, int next_action): _is_def(false), _is_subs_act(false), _id(id), _type(type){ |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 49 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 50 | _is_def = true; |
| 51 | _action_definition.set_ref(def); |
| 52 | _action_definition.set_size(def_size); |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 53 | _is_subs_act = true; |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 54 | _next_action = next_action; |
| 55 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | |
| 59 | int get_id() const{ |
| 60 | return _id; |
| 61 | } |
| 62 | |
| 63 | int get_type() const { |
| 64 | return _type; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | const void * get_definition(void ) { |
| 69 | return _action_definition.get_ref(); |
| 70 | } |
| 71 | |
| 72 | int get_definition_size(void) const { |
| 73 | return _action_definition.get_size(); |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | int get_subsequent_action() const { |
| 78 | return _next_action; |
| 79 | }; |
| 80 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 81 | bool is_definition() const{ |
| 82 | |
| 83 | return _is_def; |
| 84 | } |
| 85 | |
| 86 | bool is_subsequent_action() const{ |
| 87 | return _is_subs_act; |
| 88 | } |
| 89 | |
| 90 | private: |
| 91 | |
| 92 | bool _is_def; |
| 93 | bool _is_subs_act; |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 94 | int _id, _type, _next_action, _cause, _sub_cause; |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 95 | bool _is_admit; |
| 96 | octet_helper _action_definition; |
| 97 | |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | /* |
| 102 | Helper class that stores subscription data |
| 103 | */ |
| 104 | |
| 105 | |
| 106 | struct subscription_helper { |
| 107 | |
| 108 | public: |
| 109 | |
| 110 | using action_t = std::vector<Action>; |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 111 | subscription_helper(){ |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 112 | _action_ref = std::make_unique<action_t>(); |
| 113 | }; |
| 114 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 115 | action_t * get_list() const {return _action_ref.get();}; |
| 116 | |
| 117 | void clear(void){ |
| 118 | _action_ref.get()->clear(); |
| 119 | } |
| 120 | |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 121 | void set_request(int id){ |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 122 | _req_id = id; |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 123 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | void set_function_id(int id){ |
| 127 | _func_id = id; |
| 128 | }; |
| 129 | |
| 130 | void set_event_def(const void *ref, size_t size){ |
| 131 | _event_def.set_ref(ref); |
| 132 | _event_def.set_size(size); |
| 133 | }; |
| 134 | |
| 135 | |
| 136 | void add_action(int id, int type){ |
| 137 | Action a(id, type) ; |
| 138 | _action_ref.get()->push_back(a); |
| 139 | }; |
| 140 | |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 141 | void add_action(int id, int type, const void *action_def, size_t size, int next_action){ |
| 142 | Action a (id, type, action_def, size, next_action); |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 143 | _action_ref.get()->push_back(a); |
| 144 | }; |
| 145 | |
| 146 | |
| 147 | int get_request_id(void) const{ |
| 148 | return _req_id; |
| 149 | } |
| 150 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 151 | |
| 152 | int get_function_id(void) const{ |
| 153 | return _func_id; |
| 154 | } |
| 155 | |
| 156 | const void * get_event_def(void) { |
| 157 | return _event_def.get_ref(); |
| 158 | } |
| 159 | |
| 160 | int get_event_def_size(void) const { |
| 161 | return _event_def.get_size(); |
| 162 | } |
| 163 | |
| 164 | void print_sub_info(void){ |
| 165 | std::cout <<"Request ID = " << _req_id << std::endl; |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 166 | std::cout <<"RAN Function ID = " << _func_id << std::endl; |
| 167 | for(auto const & e: *(_action_ref.get())){ |
| 168 | std::cout <<"Action ID = " << e.get_id() << " Action Type = " << e.get_type() << std::endl; |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | private: |
| 173 | |
| 174 | std::unique_ptr<action_t> _action_ref; |
| 175 | int curr_index; |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 176 | int _req_id, _func_id; |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 177 | octet_helper _event_def; |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 178 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | #endif |