Incorporating RMR Health check code
[ric-app/hw.git] / src / xapp.hpp
1 /*
2 ==================================================================================
3
4         Copyright (c) 2018-2019 AT&T Intellectual Property.
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  *
21  *  Modified: Mar, 2020 (Shraboni Jana)
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>
35 #include <pthread.h>
36 #include <unordered_map>
37 #include "xapp_rmr.hpp"
38 #include "xapp_sdl.hpp"
39 #include "rapidjson/writer.h"
40 #include "rapidjson/document.h"
41 #include "msgs_proc.hpp"
42 #include "subs_mgmt.hpp"
43 #include "xapp_config.hpp"
44 extern "C" {
45 #include "rnib/rnibreader.h"
46 }
47 using namespace std;
48 using namespace std::placeholders;
49 using namespace rapidjson;
50
51 using callback_type = std::function< void(rmr_mbuf_t*,bool*) > ;
52
53 class Xapp{
54 public:
55
56   Xapp(XappSettings &, XappRmr &);
57   ~Xapp(void);
58
59   void startup();
60   void shutdown(void);
61   void init(void);
62   void start_xapp_receiver(XappMsgHandler &);
63   void sdl_data(void);
64
65   Xapp(Xapp const &)=delete;
66   Xapp& operator=(Xapp const &) = delete;
67
68   template<typename FunctionObject>
69   void register_handler(FunctionObject fn){
70           _callbacks.emplace_back(fn);
71   }
72
73   void callback_handler(){
74
75   }
76
77   void set_rnib_gnblist(void);
78   //getters/setters.
79   std::vector<std::string> get_rnib_gnblist(){ return rnib_gnblist; }
80
81 private:
82   void startup_subscribe_requests(void );
83   void shutdown_subscribe_deletes(void);
84   void startup_get_policies(void );
85
86
87   XappRmr * rmr_ref;
88   XappSettings * config_ref;
89
90   std::mutex *xapp_mutex;
91   std::vector<std::thread> xapp_rcv_thread;
92   std::vector<std::string> rnib_gnblist;
93
94   std::vector<callback_type> _callbacks;
95
96 };
97
98
99 #endif /* SRC_XAPP_HPP_ */