HelloWorld E2SM source
[ric-app/hw.git] / src / hw_xapp_main.cc
index 624d88f..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.
@@ -51,45 +51,52 @@ int main(int argc, char *argv[]){
        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>(port);
-       rmr->xapp_rmr_init();
+       std::unique_ptr<XappRmr> rmr = std::make_unique<XappRmr>(port);
+       rmr->xapp_rmr_init(true);
 
 
-       std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
+       //Create Subscription Handler if Xapp deals with Subscription.
+       bool sub_required = true;
+       std::unique_ptr<SubscriptionHandler> sub_handler = std::make_unique<SubscriptionHandler>();
 
-       //register MsgHandler plugin for a received rmr_buffer
-        std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>();
-        hw_xapp->register_handler(std::bind(&XappMsgHandler::operator (),mp_handler.get(),std::placeholders::_1,std::placeholders::_2));
+       //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));
 
-        rmr->set_listen(true);
-        hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
+       mdclog_write(MDCLOG_INFO, "Created Hello World Xapp Instance");
 
-        sleep(5);
+       sleep(1);
+       //Startup E2 subscription and A1 policy
+       hw_xapp->startup();
 
 
-       //Delete all subscriptions if any based on Xapp Mode.
-       //xapp->shutdown();
+       //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]);
 
-       xapp_rmr_header hdr;
-       hdr.message_type = RIC_HEALTH_CHECK_REQ;
+               hw_xapp->register_handler(std::ref(*mp_handler));
+       }
 
-       char *strMsg = "HelloWorld: RMR Health Check\0";
+       mdclog_write(MDCLOG_INFO, "Starting Listener Threads. Number of Workers = %d", num_threads);
 
-       clock_gettime(CLOCK_REALTIME, &(hdr.ts));
-       hdr.payload_length = strlen(strMsg);
+       hw_xapp->Run();
 
-       bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
+       //Delete all subscriptions if any based on Xapp Mode.
+       //xapp->shutdown();
 
-       if (!res){
-          std::cout << "Xapp RMR Send Failure";
-       }
-       usleep(10);
-        while(1){
+       while(1){
                                sleep(1);
                         }