279f0573a5a55c41b6cdea47d166b893cb4c8c5d
[ric-app/kpimon.git] / src / E2AP-c / subscription / response_helper.hpp
1 /*\r
2 ==================================================================================\r
3         Copyright (c) 2018-2019 SAMSUNG 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 #pragma once\r
20 \r
21 #ifndef S_RESPONSE_HELPER_\r
22 #define S_RESPONSE_HELPER_\r
23 \r
24 #include <vector>\r
25 #include <memory>\r
26 \r
27 /* Simple structure to store action for RICaction of the Subscription response based on E2 v0.22 */\r
28 struct ActionResponse {\r
29 public:\r
30   ActionResponse(int id): _is_admit(true), _id(id), _cause(-1), _sub_cause(-1){};\r
31   ActionResponse(int id, int cause, int sub_cause): _is_admit(false), _id(id), _cause(cause), _sub_cause(sub_cause){};\r
32   \r
33   int get_id() const{\r
34     return _id;\r
35   };\r
36 \r
37   int get_cause() const{\r
38     return _cause;\r
39   };\r
40 \r
41   int get_sub_cause() const{\r
42     return _sub_cause;\r
43   };\r
44 \r
45   bool is_admitted(void){\r
46     return _is_admit;\r
47   };\r
48   \r
49 private:\r
50 \r
51   bool _is_admit;\r
52   int _id, _cause, _sub_cause;\r
53   \r
54 };\r
55 \r
56 \r
57 struct subscription_response_helper {\r
58   \r
59 public:\r
60 \r
61   using action_t = std::vector<ActionResponse>;\r
62   \r
63   subscription_response_helper(void){\r
64     _action_admitted_ref = std::make_unique<action_t>();\r
65     _action_not_admitted_ref = std::make_unique<action_t>();\r
66     \r
67   };\r
68   \r
69   // copy operator\r
70   subscription_response_helper(const subscription_response_helper &he ){\r
71     _action_admitted_ref = std::make_unique<action_t>();\r
72     _action_not_admitted_ref = std::make_unique<action_t>();\r
73     \r
74     _req_id = he.get_request_id();\r
75     _req_seq_no = he.get_req_seq();\r
76     _func_id = he.get_function_id();\r
77     \r
78     // Take care of the actions\r
79     for (auto const & e: *(he.get_admitted_list())){\r
80       add_action(e.get_id());\r
81     }\r
82     \r
83     for(auto const  & e: *(he.get_not_admitted_list())){\r
84       add_action(e.get_id(), e.get_cause(), e.get_sub_cause());\r
85     };\r
86   }\r
87   \r
88 \r
89   // assignment operator\r
90   void operator=(const subscription_response_helper & he){\r
91     _action_admitted_ref = std::make_unique<action_t>();\r
92     _action_not_admitted_ref = std::make_unique<action_t>();\r
93     \r
94     _req_id = he.get_request_id();\r
95     _req_seq_no = he.get_req_seq();\r
96     _func_id = he.get_function_id();\r
97     \r
98     \r
99     // Take care of the actions\r
100     for (auto  const & e: *(he.get_admitted_list())){\r
101       add_action(e.get_id());\r
102     }\r
103   \r
104     for(auto const  & e: *(he.get_not_admitted_list())){\r
105       add_action(e.get_id(), e.get_cause(), e.get_sub_cause());\r
106     };\r
107     \r
108   }\r
109   \r
110   action_t * get_admitted_list (void ) const {return _action_admitted_ref.get();};\r
111   action_t * get_not_admitted_list (void ) const{return _action_not_admitted_ref.get();};\r
112   \r
113   void set_request(int id, int seq_no){\r
114     _req_id = id;\r
115     _req_seq_no = seq_no;\r
116     \r
117   };\r
118 \r
119   void clear(void){\r
120     _action_admitted_ref.get()->clear();\r
121     _action_not_admitted_ref.get()->clear();\r
122   }\r
123 \r
124   \r
125   void set_function_id(int id){\r
126     _func_id = id;\r
127   };\r
128 \r
129   void add_action(int id){\r
130     ActionResponse a(id) ;\r
131     _action_admitted_ref.get()->push_back(a);\r
132   };\r
133 \r
134   void add_action(int id, int cause, int sub_cause){\r
135     ActionResponse a (id, cause, sub_cause);\r
136     _action_not_admitted_ref.get()->push_back(a);\r
137   };\r
138 \r
139 \r
140   int  get_request_id(void) const{\r
141     return _req_id;\r
142   }\r
143   \r
144   int get_req_seq(void) const{\r
145     return _req_seq_no;\r
146   }\r
147 \r
148   int  get_function_id(void) const{\r
149     return _func_id;\r
150   }\r
151  \r
152   std::string  to_string(void){\r
153     std::string Info;\r
154     Info += "Request ID = " + std::to_string(_req_id) + "\n";\r
155     Info += "Request Sequence No = "  + std::to_string(_req_seq_no) + "\n";\r
156     Info += "RAN Function ID = " + std::to_string(_func_id) + "\n";\r
157     Info += "Actions Admitted =\n";\r
158     int i = 0;\r
159     for(auto & e: *(_action_admitted_ref)){\r
160         Info += std::to_string(i)  + ": ID=" + std::to_string(e.get_id()) + "\n";\r
161         i++;\r
162     }    \r
163     Info += "Actions Not Admitted =\n";\r
164     i = 0;\r
165     for(auto & e: *(_action_not_admitted_ref)){\r
166       Info += std::to_string(i)  + ": ID=" + std::to_string(e.get_id()) +  ": Cause =" + std::to_string(e.get_cause()) + ": Sub-Cause=" + std::to_string(e.get_sub_cause()) + "\n";\r
167       i++;\r
168     }    \r
169   \r
170     return Info;\r
171   } \r
172 \r
173 private:\r
174   int _req_id, _req_seq_no, _func_id;\r
175   std::unique_ptr<action_t> _action_admitted_ref;\r
176   std::unique_ptr<action_t> _action_not_admitted_ref;\r
177   \r
178 };\r
179   \r
180 \r
181 #endif\r