himeshshukla | ff20129 | 2021-05-11 13:40:12 +0530 | [diff] [blame] | 1 | /* |
| 2 | # ================================================================================== |
| 3 | # Copyright (c) 2020 HCL Technologies Limited. |
| 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 | #pragma once |
| 21 | |
| 22 | #ifndef SRC_XAPP_HPP_ |
| 23 | #define SRC_XAPP_HPP_ |
| 24 | |
| 25 | #include <iostream> |
| 26 | #include <string> |
| 27 | #include <memory> |
| 28 | #include <csignal> |
| 29 | #include <stdio.h> |
| 30 | #include <pthread.h> |
| 31 | #include <unordered_map> |
| 32 | #include "xapp_rmr.hpp" |
| 33 | #include "xapp_sdl.hpp" |
| 34 | #include "rapidjson/writer.h" |
| 35 | #include "rapidjson/document.h" |
| 36 | #include "rapidjson/error/error.h" |
| 37 | |
| 38 | #include "msgs_proc.hpp" |
| 39 | #include "subs_mgmt.hpp" |
| 40 | #include "xapp_config.hpp" |
| 41 | extern "C" { |
| 42 | #include "rnib/rnibreader.h" |
| 43 | } |
| 44 | using namespace std; |
| 45 | using namespace std::placeholders; |
| 46 | using namespace rapidjson; |
| 47 | |
| 48 | |
| 49 | class Xapp{ |
| 50 | public: |
| 51 | |
| 52 | Xapp(XappSettings &, XappRmr &); |
| 53 | |
| 54 | ~Xapp(void); |
| 55 | |
| 56 | void stop(void); |
| 57 | |
| 58 | void startup(SubscriptionHandler &); |
| 59 | void shutdown(void); |
| 60 | |
| 61 | void start_xapp_receiver(XappMsgHandler &); |
| 62 | void Run(); |
| 63 | |
| 64 | //void sdl_data(void); |
| 65 | |
| 66 | Xapp(Xapp const &)=delete; |
| 67 | Xapp& operator=(Xapp const &) = delete; |
| 68 | |
| 69 | void register_handler(XappMsgHandler &fn){ |
| 70 | _callbacks.emplace_back(fn); |
| 71 | } |
| 72 | |
| 73 | //getters/setters. |
| 74 | void set_rnib_gnblist(void); |
| 75 | std::vector<std::string> get_rnib_gnblist(){ return rnib_gnblist; } |
| 76 | |
| 77 | private: |
| 78 | void startup_subscribe_requests(void ); |
| 79 | void shutdown_subscribe_deletes(void); |
| 80 | void startup_get_policies(void ); |
| 81 | |
| 82 | |
| 83 | XappRmr * rmr_ref; |
| 84 | XappSettings * config_ref; |
| 85 | SubscriptionHandler *subhandler_ref; |
| 86 | |
| 87 | std::mutex *xapp_mutex; |
| 88 | std::vector<std::thread> xapp_rcv_thread; |
| 89 | std::vector<std::string> rnib_gnblist; |
| 90 | std::vector<XappMsgHandler> _callbacks; |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | #endif /* SRC_XAPP_HPP_ */ |