42d2d3eaf98e5fed06644a61b5ee854ad21e055c
[ric-app/bouncer.git] / Bouncer / src / b_xapp_main.cc
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 #include "xapp.hpp"
20
21 void signalHandler( int signum ) {
22    cout << "Interrupt signal (" << signum << ") received.\n";
23    exit(signum);
24 }
25
26 int main(int argc, char *argv[]){
27
28         // Get the thread id
29         std::thread::id my_id = std::this_thread::get_id();
30         std::stringstream thread_id;
31         std::stringstream ss;
32
33         thread_id << my_id;
34
35         mdclog_write(MDCLOG_INFO, "Starting thread %s",  thread_id.str().c_str());
36
37         //get configuration
38         XappSettings config;
39         //change the priority depending upon application requirement
40         config.loadDefaultSettings();
41         config.loadEnvVarSettings();
42         config.loadCmdlineSettings(argc, argv);
43
44         //Register signal handler to stop
45         signal(SIGINT, signalHandler);
46         signal(SIGTERM, signalHandler);
47
48         //getting the listening port and xapp name info
49         std::string  port = config[XappSettings::SettingName::BOUNCER_PORT];
50         std::string  name = config[XappSettings::SettingName::XAPP_NAME];
51
52         //initialize rmr
53         std::unique_ptr<XappRmr> rmr = std::make_unique<XappRmr>(port);
54         rmr->xapp_rmr_init(true);
55
56
57         //Create Subscription Handler if Xapp deals with Subscription.
58         //std::unique_ptr<SubscriptionHandler> sub_handler = std::make_unique<SubscriptionHandler>();
59
60         SubscriptionHandler sub_handler;
61
62         //create Bouncer Xapp Instance.
63         std::unique_ptr<Xapp> b_xapp;
64         b_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
65
66         mdclog_write(MDCLOG_INFO, "Created Bouncer Xapp Instance");
67         //Startup E2 subscription
68         b_xapp->startup(sub_handler);
69
70         sleep(10);
71
72
73         //start listener threads and register message handlers.
74         int num_threads = std::stoi(config[XappSettings::SettingName::THREADS]);
75         mdclog_write(MDCLOG_INFO, "Starting Listener Threads. Number of Workers = %d", num_threads);
76
77         std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>(config[XappSettings::SettingName::XAPP_ID], sub_handler);
78
79         b_xapp->start_xapp_receiver(std::ref(*mp_handler));
80
81         sleep(1);
82
83
84
85         while(1){
86                                 sleep(1);
87                          }
88
89         return 0;
90 }
91
92
93