blob: a769b43ba920281b7dd8aea9daa5488d43f6288e [file] [log] [blame]
sjana6df19a42020-03-19 12:06:12 -04001/*
2==================================================================================
3
sjana0f5c2342020-05-07 18:02:09 -04004 Copyright (c) 2019-2020 AT&T Intellectual Property.
sjana6df19a42020-03-19 12:06:12 -04005
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 *
sjana0f5c2342020-05-07 18:02:09 -040021 * Mar, 2020 (Shraboni Jana)
sjana6df19a42020-03-19 12:06:12 -040022 *
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>
sjanab85024c2020-03-24 13:57:25 -040035#include <pthread.h>
36#include <unordered_map>
sjana6df19a42020-03-19 12:06:12 -040037#include "xapp_rmr.hpp"
38#include "xapp_sdl.hpp"
39#include "rapidjson/writer.h"
sjanab85024c2020-03-24 13:57:25 -040040#include "rapidjson/document.h"
sjana0f5c2342020-05-07 18:02:09 -040041#include "rapidjson/error/error.h"
42
sjana6df19a42020-03-19 12:06:12 -040043#include "msgs_proc.hpp"
44#include "subs_mgmt.hpp"
45#include "xapp_config.hpp"
sjanab85024c2020-03-24 13:57:25 -040046extern "C" {
sjana0f5c2342020-05-07 18:02:09 -040047#include "rnib/rnibreader.h"
sjanab85024c2020-03-24 13:57:25 -040048}
sjana6df19a42020-03-19 12:06:12 -040049using namespace std;
50using namespace std::placeholders;
sjanab85024c2020-03-24 13:57:25 -040051using namespace rapidjson;
52
sjana6df19a42020-03-19 12:06:12 -040053
54class Xapp{
55public:
56
57 Xapp(XappSettings &, XappRmr &);
sjana0f5c2342020-05-07 18:02:09 -040058 Xapp(XappSettings &, XappRmr &, SubscriptionHandler &);
59
sjana6df19a42020-03-19 12:06:12 -040060 ~Xapp(void);
sjana0f5c2342020-05-07 18:02:09 -040061
sjana91d30a62020-03-31 12:14:06 -040062 void stop(void);
sjana0f5c2342020-05-07 18:02:09 -040063
sjana6df19a42020-03-19 12:06:12 -040064 void startup();
65 void shutdown(void);
sjana0f5c2342020-05-07 18:02:09 -040066
sjanab85024c2020-03-24 13:57:25 -040067 void start_xapp_receiver(XappMsgHandler &);
sjana0f5c2342020-05-07 18:02:09 -040068 void Run();
69
sjanab85024c2020-03-24 13:57:25 -040070 void sdl_data(void);
sjana6df19a42020-03-19 12:06:12 -040071
72 Xapp(Xapp const &)=delete;
73 Xapp& operator=(Xapp const &) = delete;
74
sjana0f5c2342020-05-07 18:02:09 -040075 void register_handler(XappMsgHandler &fn){
sjanab85024c2020-03-24 13:57:25 -040076 _callbacks.emplace_back(fn);
77 }
78
sjanab85024c2020-03-24 13:57:25 -040079 //getters/setters.
sjana0f5c2342020-05-07 18:02:09 -040080 void set_rnib_gnblist(void);
sjanab85024c2020-03-24 13:57:25 -040081 std::vector<std::string> get_rnib_gnblist(){ return rnib_gnblist; }
82
sjana6df19a42020-03-19 12:06:12 -040083private:
84 void startup_subscribe_requests(void );
85 void shutdown_subscribe_deletes(void);
86 void startup_get_policies(void );
sjanab85024c2020-03-24 13:57:25 -040087
sjana6df19a42020-03-19 12:06:12 -040088
89 XappRmr * rmr_ref;
90 XappSettings * config_ref;
sjana0f5c2342020-05-07 18:02:09 -040091 SubscriptionHandler *subhandler_ref;
sjanab85024c2020-03-24 13:57:25 -040092
sjana6df19a42020-03-19 12:06:12 -040093 std::mutex *xapp_mutex;
94 std::vector<std::thread> xapp_rcv_thread;
sjanab85024c2020-03-24 13:57:25 -040095 std::vector<std::string> rnib_gnblist;
sjana0f5c2342020-05-07 18:02:09 -040096 std::vector<XappMsgHandler> _callbacks;
sjanab85024c2020-03-24 13:57:25 -040097
sjana6df19a42020-03-19 12:06:12 -040098};
99
100
101#endif /* SRC_XAPP_HPP_ */