X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fxapp-mgmt%2Fsubs_mgmt.cc;h=dca9412a635d77fdbf550ec1910af6664e9bfba0;hb=ea129fa14c89d8f5cedacd9afc1e4dd7a30f1ae4;hp=4b17f5a887e3675b8b2b9d28703ae4e3c21f7214;hpb=0f5c234d5da8897f2f831e02ff03912e582ba6e9;p=ric-app%2Fhw.git diff --git a/src/xapp-mgmt/subs_mgmt.cc b/src/xapp-mgmt/subs_mgmt.cc index 4b17f5a..dca9412 100644 --- a/src/xapp-mgmt/subs_mgmt.cc +++ b/src/xapp-mgmt/subs_mgmt.cc @@ -21,10 +21,9 @@ * Author: Ashwin Shridharan, Shraboni Jana */ #include "subs_mgmt.hpp" - +#include #include - SubscriptionHandler::SubscriptionHandler(unsigned int timeout_seconds):_time_out(std::chrono::seconds(timeout_seconds)){ _data_lock = std::make_unique(); _cv = std::make_unique(); @@ -79,48 +78,63 @@ bool SubscriptionHandler::delete_request_entry(transaction_identifier id){ bool SubscriptionHandler::set_request_status(transaction_identifier id, transaction_status status){ // change status of a request only if it exists. - auto search = status_table.find(id); - if(search != status_table.end()){ - status_table[id] = status; - return true; - } - + for(auto &it:status_table){ + if(strcmp(it.first.c_str(), id.c_str())==0) { + it.second = status; + return true; + } + } return false; - + }; -int const SubscriptionHandler::get_request_status(transaction_identifier id){ - auto search = status_table.find(id); - if (search == status_table.end()){ - return -1; - } - - return search->second; +int SubscriptionHandler::get_request_status(transaction_identifier id){ + + for(auto it:status_table){ + if(strcmp(it.first.c_str(), id.c_str())==0) { + return it.second; + } + } + + + return -1; } bool SubscriptionHandler::is_request_entry(transaction_identifier id){ - auto search = status_table.find(id); - if (search != status_table.end()) - return true; - else + for(auto it:status_table){ + if(strcmp(it.first.c_str(), id.c_str())==0) { + return true; + } + } return false; } + + + // Handles subscription responses void SubscriptionHandler::manage_subscription_response(int message_type, transaction_identifier id){ + // Make This Thread sleep for 1 Second + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + { + std::unique_lock _local_lock(*(_data_lock.get())); + mdclog_write(MDCLOG_INFO,"Subscription Handler: Status for me id %s WAS: %d",id.c_str(),this->get_request_status(id)); - bool res; - std::cout << "In Manage subscription" << std::endl; + //from the message type we can know if its a success/failure etc. + if(message_type==RIC_SUB_RESP) + this->set_request_status(id, request_success); - // wake up all waiting users ... - if(is_request_entry(id)){ - std::cout << "In Manage subscription" << std::endl; - set_request_status(id, request_success); - _cv.get()->notify_all(); - } + if(message_type==RIC_SUB_FAILURE) + this->set_request_status(id,request_failed); + + mdclog_write(MDCLOG_INFO,"Subscription Handler: Status for me id %s IS: %d",id.c_str(),this->get_request_status(id)); + + //this->print_subscription_status(); + } + //_cv.get()->notify_all(); }