sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 4 | Copyright (c) 2019-2020 AT&T Intellectual Property. |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 5 | |
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | you may not use this file except in compliance with the License. |
| 8 | You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, software |
| 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | See the License for the specific language governing permissions and |
| 16 | limitations under the License. |
| 17 | ================================================================================== |
| 18 | *//* |
| 19 | * xapp.hpp |
| 20 | * |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 21 | * Mar, 2020 (Shraboni Jana) |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 22 | * |
| 23 | */ |
| 24 | |
| 25 | #pragma once |
| 26 | |
| 27 | #ifndef SRC_XAPP_HPP_ |
| 28 | #define SRC_XAPP_HPP_ |
| 29 | |
| 30 | #include <iostream> |
| 31 | #include <string> |
| 32 | #include <memory> |
| 33 | #include <csignal> |
| 34 | #include <stdio.h> |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 35 | #include <pthread.h> |
| 36 | #include <unordered_map> |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 37 | #include "xapp_rmr.hpp" |
| 38 | #include "xapp_sdl.hpp" |
| 39 | #include "rapidjson/writer.h" |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 40 | #include "rapidjson/document.h" |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 41 | #include "rapidjson/error/error.h" |
| 42 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 43 | #include "msgs_proc.hpp" |
| 44 | #include "subs_mgmt.hpp" |
| 45 | #include "xapp_config.hpp" |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 46 | extern "C" { |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 47 | #include "rnib/rnibreader.h" |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 48 | } |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 49 | using namespace std; |
| 50 | using namespace std::placeholders; |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 51 | using namespace rapidjson; |
| 52 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 53 | |
| 54 | class Xapp{ |
| 55 | public: |
| 56 | |
| 57 | Xapp(XappSettings &, XappRmr &); |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 58 | Xapp(XappSettings &, XappRmr &, SubscriptionHandler &); |
| 59 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 60 | ~Xapp(void); |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 61 | |
sjana | 91d30a6 | 2020-03-31 12:14:06 -0400 | [diff] [blame] | 62 | void stop(void); |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 63 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 64 | void startup(); |
| 65 | void shutdown(void); |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 66 | |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 67 | void start_xapp_receiver(XappMsgHandler &); |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 68 | void Run(); |
| 69 | |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 70 | void sdl_data(void); |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 71 | |
| 72 | Xapp(Xapp const &)=delete; |
| 73 | Xapp& operator=(Xapp const &) = delete; |
| 74 | |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 75 | void register_handler(XappMsgHandler &fn){ |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 76 | _callbacks.emplace_back(fn); |
| 77 | } |
| 78 | |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 79 | //getters/setters. |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 80 | void set_rnib_gnblist(void); |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 81 | std::vector<std::string> get_rnib_gnblist(){ return rnib_gnblist; } |
| 82 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 83 | private: |
| 84 | void startup_subscribe_requests(void ); |
| 85 | void shutdown_subscribe_deletes(void); |
| 86 | void startup_get_policies(void ); |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 87 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 88 | |
| 89 | XappRmr * rmr_ref; |
| 90 | XappSettings * config_ref; |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 91 | SubscriptionHandler *subhandler_ref; |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 92 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 93 | std::mutex *xapp_mutex; |
| 94 | std::vector<std::thread> xapp_rcv_thread; |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 95 | std::vector<std::string> rnib_gnblist; |
sjana | 0f5c234 | 2020-05-07 18:02:09 -0400 | [diff] [blame^] | 96 | std::vector<XappMsgHandler> _callbacks; |
sjana | b85024c | 2020-03-24 13:57:25 -0400 | [diff] [blame] | 97 | |
sjana | 6df19a4 | 2020-03-19 12:06:12 -0400 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | |
| 101 | #endif /* SRC_XAPP_HPP_ */ |