2 ==================================================================================
3 Copyright (c) 2019-2020 AT&T Intellectual Property.
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
9 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
20 * Created on: Dec, 2019
21 * Author: Shraboni Jana
26 void signalHandler( int signum ) {
27 cout << "Interrupt signal (" << signum << ") received.\n";
31 int main(int argc, char *argv[]){
34 std::thread::id my_id = std::this_thread::get_id();
35 std::stringstream thread_id;
40 mdclog_write(MDCLOG_INFO, "Starting thread %s", thread_id.str().c_str());
44 //change the priority depending upon application requirement
45 config.loadDefaultSettings();
46 config.loadEnvVarSettings();
47 config.loadCmdlineSettings(argc, argv);
49 //Register signal handler to stop
50 signal(SIGINT, signalHandler);
51 signal(SIGTERM, signalHandler);
53 //getting the listening port and xapp name info
54 std::string port = config[XappSettings::SettingName::HW_PORT];
55 std::string name = config[XappSettings::SettingName::XAPP_NAME];
58 std::unique_ptr<XappRmr> rmr = std::make_unique<XappRmr>(port);
59 rmr->xapp_rmr_init(true);
62 //Create Subscription Handler if Xapp deals with Subscription.
63 std::unique_ptr<SubscriptionHandler> sub_handler = std::make_unique<SubscriptionHandler>();
65 //create HelloWorld Xapp Instance.
66 std::unique_ptr<Xapp> hw_xapp;
67 hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
69 mdclog_write(MDCLOG_INFO, "Created Hello World Xapp Instance");
72 //Startup E2 subscription and A1 policy
73 hw_xapp->startup(std::ref(*sub_handler));
76 //start listener threads and register message handlers.
77 int num_threads = std::stoi(config[XappSettings::SettingName::THREADS]);
78 bool sub_required = true;
79 for(int j=0; j < num_threads; j++) {
80 std::unique_ptr<XappMsgHandler> mp_handler;
82 mp_handler = std::make_unique<XappMsgHandler>(config[XappSettings::SettingName::XAPP_ID], std::ref(*sub_handler));
84 mp_handler = std::make_unique<XappMsgHandler>(config[XappSettings::SettingName::XAPP_ID]);
86 hw_xapp->register_handler(std::ref(*mp_handler));
89 mdclog_write(MDCLOG_INFO, "Starting Listener Threads. Number of Workers = %d", num_threads);
93 //Delete all subscriptions if any based on Xapp Mode.