Adding initial code jy.oak@samsung.com
[ric-app/kpimon.git] / src / E2AP-c / subscription / subscription_helper.hpp
diff --git a/src/E2AP-c/subscription/subscription_helper.hpp b/src/E2AP-c/subscription/subscription_helper.hpp
new file mode 100755 (executable)
index 0000000..cc35816
--- /dev/null
@@ -0,0 +1,192 @@
+/*\r
+==================================================================================\r
+        Copyright (c) 2018-2019 AT&T Intellectual Property.\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================================\r
+*/\r
+\r
+\r
+#ifndef SUB_HELPER_\r
+#define SUB_HELPER_\r
+\r
+/* \r
+   Simple structure to store action related information based on E2 v0.22\r
+   Used for subscription request, response etc\r
+   \r
+   ricActionID                                 RICactionID,\r
+   ricActionType                               RICactionType,\r
+   ricActionDefinition                 RICactionDefinition     OPTIONAL,\r
+   ricSubsequentAction                 RICsubsequentAction     OPTIONAL,\r
+   ricCause\r
+*/\r
+\r
+#include <generic_helpers.hpp>\r
+#include <iostream>\r
+#include <vector>\r
+#include <memory>\r
+\r
+struct Action {\r
+\r
+public:\r
+  \r
+  Action(int id, int type): _is_def(false), _is_subs_act(false), _id(id), _type(type){};\r
+  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
+    \r
+    if (def_size > 0){\r
+      _is_def = true;\r
+      _action_definition.set_ref(def);\r
+      _action_definition.set_size(def_size);\r
+    }\r
+    \r
+    if(next >= 0 && wait >= 0){\r
+      _is_subs_act = true;\r
+      _next_action = next;\r
+      _wait = wait;\r
+    }\r
+  };\r
+\r
+  \r
+  int get_id() const{\r
+    return _id;\r
+  }\r
+\r
+  int get_type() const {\r
+    return _type;\r
+  }\r
+\r
+\r
+  const void * get_definition(void )  {\r
+    return _action_definition.get_ref();\r
+  }\r
+\r
+  int get_definition_size(void) const {\r
+    return _action_definition.get_size();\r
+  };\r
+  \r
+\r
+  int get_subsequent_action() const {\r
+    return _next_action;\r
+  };\r
+\r
+  int get_wait() const {\r
+    return _wait;\r
+  }\r
+\r
+  bool is_definition() const{\r
+\r
+    return _is_def;\r
+  }\r
+\r
+  bool is_subsequent_action() const{\r
+    return _is_subs_act;\r
+  }\r
+    \r
+private:\r
+\r
+  bool _is_def;\r
+  bool _is_subs_act;\r
+  int _id, _type, _next_action, _wait, _cause, _sub_cause;\r
+  bool _is_admit;\r
+  octet_helper _action_definition;\r
+\r
+};\r
+\r
+\r
+/*\r
+ Helper class that stores subscription data \r
+*/\r
+\r
+\r
+struct subscription_helper {\r
+\r
+public:\r
+\r
+  using action_t = std::vector<Action>;\r
+  \r
+  subscription_helper(){\r
+    _action_ref = std::make_unique<action_t>();\r
+    curr_index = 0;    \r
+  };\r
+  \r
+  action_t * get_list() const {return _action_ref.get();};\r
+\r
+  void clear(void){\r
+    _action_ref.get()->clear();\r
+  }\r
+  \r
+  void set_request(int id, int seq_no){\r
+    _req_id = id;\r
+    _req_seq_no = seq_no;\r
+    \r
+  };\r
+\r
+  void set_function_id(int id){\r
+    _func_id = id;\r
+  };\r
+\r
+  void set_event_def(const void *ref, size_t size){\r
+    _event_def.set_ref(ref);\r
+    _event_def.set_size(size);\r
+   };\r
+\r
\r
+  void add_action(int id, int type){\r
+    Action a(id, type) ;\r
+    _action_ref.get()->push_back(a);\r
+  };\r
+\r
+  void add_action(int id, int type, std::string action_def, int next_action, int wait_time){\r
+    Action a (id, type, action_def.c_str(), action_def.length(), next_action, wait_time);\r
+    _action_ref.get()->push_back(a);\r
+  };\r
+\r
+\r
+  int  get_request_id(void) const{\r
+    return _req_id;\r
+  }\r
+\r
+  int  get_req_seq(void) const {\r
+    return _req_seq_no;\r
+  }\r
+\r
+  int  get_function_id(void) const{\r
+    return _func_id;\r
+  }\r
+  \r
+  const void * get_event_def(void)  {\r
+    return _event_def.get_ref();\r
+  }\r
+\r
+  int get_event_def_size(void) const {\r
+    return _event_def.get_size();\r
+  }\r
+\r
+  void print_sub_info(void){\r
+    std::cout <<"Request ID = " << _req_id << std::endl;\r
+    std::cout <<"Request Sequence Number = " << _req_seq_no << std::endl;\r
+    std::cout <<"RAN Function ID = " << _func_id << std::endl;\r
+    for(auto const & e: *(_action_ref.get())){\r
+      std::cout <<"Action ID = " << e.get_id() << " Action Type = " << e.get_type() << std::endl;\r
+    }\r
+  };\r
+  \r
+private:\r
+  \r
+  std::unique_ptr<action_t> _action_ref;\r
+  int curr_index;\r
+  int _req_id, _req_seq_no, _func_id;\r
+  octet_helper _event_def;\r
+};\r
+\r
+#endif\r