HelloWorld E2SM unit tests
[ric-app/hw.git] / src / hw_xapp_main.cc
index 3c45e6a..655f452 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ==================================================================================
-        Copyright (c) 2018-2019 AT&T Intellectual Property.
+        Copyright (c) 2019-2020 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -22,8 +22,6 @@
  */
 
 #include "xapp.hpp"
-#include "subscription_request.hpp"
-#include "xapp_sdl.hpp"
 
 void signalHandler( int signum ) {
    cout << "Interrupt signal (" << signum << ") received.\n";
@@ -32,6 +30,15 @@ void signalHandler( int signum ) {
 
 int main(int argc, char *argv[]){
 
+       // Get the thread id
+       std::thread::id my_id = std::this_thread::get_id();
+       std::stringstream thread_id;
+       std::stringstream ss;
+
+       thread_id << my_id;
+
+       mdclog_write(MDCLOG_INFO, "Starting thread %s",  thread_id.str().c_str());
+
        //get configuration
        XappSettings config;
        //change the priority depending upon application requirement
@@ -39,53 +46,57 @@ int main(int argc, char *argv[]){
        config.loadEnvVarSettings();
        config.loadCmdlineSettings(argc, argv);
 
+       //Register signal handler to stop
+       signal(SIGINT, signalHandler);
+       signal(SIGTERM, signalHandler);
+
        //getting the listening port and xapp name info
-       std::string  port = config[XappSettings::SettingName::HW_PORTS];
+       std::string  port = config[XappSettings::SettingName::HW_PORT];
        std::string  name = config[XappSettings::SettingName::XAPP_NAME];
 
-
        //initialize rmr
-       std::unique_ptr<XappRmr> rmr;
-       rmr = std::make_unique<XappRmr>(name,port);
-       rmr->xapp_rmr_init();
+       std::unique_ptr<XappRmr> rmr = std::make_unique<XappRmr>(port);
+       rmr->xapp_rmr_init(true);
 
-       //Register signal handler to stop
-       signal(SIGINT, signalHandler);
-       signal(SIGTERM, signalHandler);
 
-       //Test SDL.
-       XappSDL sdl = XappSDL("hw-xapp");
+       //Create Subscription Handler if Xapp deals with Subscription.
+       bool sub_required = true;
+       std::unique_ptr<SubscriptionHandler> sub_handler = std::make_unique<SubscriptionHandler>();
 
-       //Initiate the Xapp functionality
-       std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config), std::ref(*rmr),std::ref(sdl));
+       //create HelloWorld Xapp Instance.
+       std::unique_ptr<Xapp> hw_xapp;
+       if(sub_required)
+               hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr), std::ref(*sub_handler));
+       else
+               hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
 
+       mdclog_write(MDCLOG_INFO, "Created Hello World Xapp Instance");
 
-       //define the startup mode.
+       sleep(1);
+       //Startup E2 subscription and A1 policy
        hw_xapp->startup();
 
-       //Register Callback Handlers
-       //Register E2 Msg Handlers - Subscription/Indication.
-       //Register A1 Msg Handlers.
-       //Register Callback Handlers
-
-
-       //start the receiver thread listening at HW_PORT
-       //currently only one receiver thread. In total how many receiver threads depend on the xapp developer.
-       //Register all the handlers required and start the receiver
 
-       //register_msgproc(RIC_SUB_RESP, sub_handler);
-       //register_msgproc(RIC_SUB_DEL_RESP, sub_handler);
-       //register_msgproc(RIC_SUB_FAILURE, sub_handler);
+       //start listener threads and register message handlers.
+       int num_threads = std::stoi(config[XappSettings::SettingName::THREADS]);
+       for(int j=0; j < num_threads; j++) {
+               std::unique_ptr<XappMsgHandler> mp_handler;
+               if(sub_required)
+                       mp_handler = std::make_unique<XappMsgHandler>(config[XappSettings::SettingName::XAPP_ID], std::ref(*sub_handler));
+               else
+                       mp_handler = std::make_unique<XappMsgHandler>(config[XappSettings::SettingName::XAPP_ID]);
 
+               hw_xapp->register_handler(std::ref(*mp_handler));
+       }
 
-       hw_xapp->start_xapp_receiver();
-       sleep(5);
+       mdclog_write(MDCLOG_INFO, "Starting Listener Threads. Number of Workers = %d", num_threads);
 
+       hw_xapp->Run();
 
        //Delete all subscriptions if any based on Xapp Mode.
        //xapp->shutdown();
 
-        while(1){
+       while(1){
                                sleep(1);
                         }