1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020] [HCL Technologies Ltd.] #
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 ################################################################################
17 *******************************************************************************/
19 /* This file contains Alarm Yang model data filling and sending related methods */
21 #include "AlarmOranYangModel.hpp"
25 /**********************************************************************
26 Description : It is a callback function, called on get request of
27 alarm-list (overridden function of sysrepo::Callback )
28 Params[In] : (sysrepo::S_Session, module_name, path,
29 request_xpath, request_id, &parent, private_data)
30 Return : SR_ERR_OK - success
31 **********************************************************************/
33 int AlarmOranYangModel::oper_get_items(sysrepo::S_Session session, \
34 const char *module_name, \
36 const char *request_xpath, \
37 uint32_t request_id, \
38 libyang::S_Data_Node &parent, \
41 O1_LOG("\n\n ========== CALLBACK CALLED TO PROVIDE \" %s DATA ==========\n", path);
42 libyang::S_Context ctx = session->get_context();
43 libyang::S_Module mod = ctx->get_module(module_name);
45 //first create root of the tree then add nodes and leaves and fill data
46 parent.reset(new libyang::Data_Node(ctx, ALARM_MODULE_PATH_ORAN, nullptr, LYD_ANYDATA_CONSTSTRING, 0));
47 libyang::S_Data_Node alarms(new libyang::Data_Node(parent, mod, "alarms"));
49 libyang::S_Data_Node alarm;
50 libyang::S_Data_Node id;
51 libyang::S_Data_Node text;
52 libyang::S_Data_Node severity;
53 libyang::S_Data_Node status;
54 libyang::S_Data_Node add_info;
56 //read the data from map
57 map<uint16_t,Alarm>::const_iterator it;
59 AlarmManager& alrmMgr = AlarmManager::instance();
60 const map<uint16_t,Alarm>& alrmList = alrmMgr.getAlarmList();
61 char alarmId[MAX_ALARM_ID_LEN];
63 for(it = alrmList.begin(); it !=alrmList.end(); it++)
65 strcpy(alarmId, to_string(it->second.getAlarmId()).c_str());
66 O1_LOG("\nAlarm ID %s",alarmId);
67 alarm.reset(new libyang::Data_Node(alarms, mod, "alarm"));
68 id.reset(new libyang::Data_Node(alarm, mod, "alarm-id", alarmId));
69 text.reset(new libyang::Data_Node(alarm, mod, "alarm-text", it->second.getAdditionalText().c_str()));
70 severity.reset(new libyang::Data_Node(alarm, mod, "severity", to_string(it->second.getEventType()).c_str()));
71 status.reset(new libyang::Data_Node(alarm, mod, "status", it->second.getSpecificProblem().c_str()));
72 add_info.reset(new libyang::Data_Node(alarm, mod, "additional-info", it->second.getAdditionalInfo().c_str()));
79 /**********************************************************************
81 **********************************************************************/