2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
22 * Created on: Mar, 2020
23 * Author: Shraboni Jana
28 Xapp::Xapp(XappSettings &config, XappRmr &rmr){
36 Xapp::Xapp(XappSettings &config, XappRmr &rmr, XappSDL &sdl){
40 //sdl_ref.insert_data();
48 int threadcnt = xapp_rcv_thread.size();
49 for(int i=0; i<threadcnt; i++){
50 if(xapp_rcv_thread[i].joinable())
51 xapp_rcv_thread[i].join();
55 void Xapp::startup() {
56 //send subscriptions and read A1 policies.
57 startup_subscribe_requests();
58 startup_get_policies();
62 void Xapp::start_xapp_receiver(){
63 //start a receiver thread. Can be multiple receiver threads for more than 1 listening port.
65 xapp_mutex = new std::mutex();
67 std::vector<std::unique_ptr <XappMsgHandler>> message_procs;
68 mdclog_write(MDCLOG_INFO,"Receiver Thread file= %s, line=%d",__FILE__,__LINE__);
69 std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>();
70 std::lock_guard<std::mutex> guard(*xapp_mutex);
71 std::thread th_recv([&](){ rmr_ref->xapp_rmr_receive(std::move(*mp_handler.get()), rmr_ref);});
72 xapp_rcv_thread.push_back(std::move(th_recv));
80 void Xapp::shutdown(){
87 void Xapp::startup_subscribe_requests(void ){
88 size_t data_size = ASN_BUFF_MAX_SIZE;
89 unsigned char data[data_size];
91 std::vector<std::string> gNodeBs;
92 gNodeBs.push_back("GNB1001"); //this line should come from RNIB
95 for(auto &it: gNodeBs){
99 /* bool res_encode = msg.encode_subscription_request(data, &data_size);
100 if(!res_encode) exit(0);*/
101 char *strMsg = "HelloWorld\0";
102 strncpy((char *)data,strMsg,strlen(strMsg));
103 data_size = sizeof(data);
105 xapp_rmr_header rmr_header;
106 rmr_header.message_type = RIC_SUB_RESP;
107 rmr_header.payload_length = data_size;
110 auto transmitter = std::bind(&XappRmr::xapp_rmr_send,rmr_ref, &rmr_header, (void*)data);
111 transmitter(); //this will go to subscription manager.
117 void Xapp::startup_get_policies(void){
119 int policy_id = HELLOWORLD_POLICY_ID;
121 std::string policy_query = "{\"policy_id\":" + std::to_string(policy_id) + "}";
122 unsigned char * message = (unsigned char *)calloc(policy_query.length(), sizeof(unsigned char));
123 memcpy(message, policy_query.c_str(), policy_query.length());
124 xapp_rmr_header header;
125 header.payload_length = policy_query.length();
126 header.message_type = A1_POLICY_QUERY;
127 mdclog_write(MDCLOG_INFO, "Sending request for policy id %d\n", policy_id);
128 rmr_ref->xapp_rmr_send(&header, (void *)message);
132 void Xapp::sdl_data(void) {
133 sdl_ref->insert_data();
135 /*void Xapp::rnib_data(void) {
137 printf("Using rnibreader lib from C:\n");
139 void *result = getListGnbIds();
142 printf("ERROR: no data from getListGnbIds\n");
145 printf("getListGnbIds response: %s\n", (char *)result);