Adding new commiter to ODU-High repo
[o-du/l2.git] / src / o1 / Alarm3GPPYangModel.cpp
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 /* This file contains Alarm Yang model data filling and sending related methods */
20
21 #include "Alarm3GPPYangModel.hpp"
22
23 using namespace std;
24
25
26 /********************************************************************** 
27    Description : It is a callback function, called on get request of
28                  alarm-list (overridden function of sysrepo::Callback )
29    Params[In]  : (sysrepo::S_Session, module_name, path,
30                  request_xpath, request_id, &parent, private_data)
31    Return      : SR_ERR_OK - success
32 **********************************************************************/
33
34 int Alarm3GPPYangModel::oper_get_items(sysrepo::S_Session session,
35                                        const char         *module_name,
36                                        const char         *path,
37                                        const char         *request_xpath,
38                                        uint32_t           request_id,
39                                        libyang::S_Data_Node &parent,
40                                        void *private_data) 
41 {
42     O1_LOG("\n\n ========== CALLBACK CALLED TO PROVIDE \" %s DATA ==========\n", path); 
43
44     libyang::S_Context ctx = session->get_context();
45     libyang::S_Module mod = ctx->get_module(module_name);
46
47     parent.reset(new libyang::Data_Node(ctx, ALARM_MODULE_PATH_3GPP, nullptr, LYD_ANYDATA_CONSTSTRING, 0));
48     //read the data from map
49     //tree of alarmRecord  : AlarmList/AlarmListGrp/alarmRecordList/AlarmRecordGrp
50
51     libyang::S_Data_Node alarms(new libyang::Data_Node(parent, mod, "AlarmList"));
52     libyang::S_Data_Node alarm(new libyang::Data_Node(alarms, mod, "AlarmListGrp"));
53     libyang::S_Data_Node ifc3(new libyang::Data_Node(parent, mod, "alarmRecordList"));
54     libyang::S_Data_Node ifc4(new libyang::Data_Node(ifc3, mod, "AlarmRecordGrp"));
55     
56
57     libyang::S_Data_Node id;
58     libyang::S_Data_Node text;
59     libyang::S_Data_Node severity;
60     libyang::S_Data_Node status;
61     libyang::S_Data_Node add_info;
62
63     //read the data from map
64     map<uint16_t,Alarm>::const_iterator it;
65
66     AlarmManager& alrmMgr = AlarmManager::instance();
67     const map<uint16_t,Alarm>& alrmList = alrmMgr.getAlarmList();
68
69     for(it = alrmList.begin(); it !=alrmList.end(); it++)
70     {
71         O1_LOG("\nAlarm ID %hu", it->second.getAlarmId());
72         alarm.reset(new libyang::Data_Node(alarms, mod, "alarm"));
73         id.reset(new libyang::Data_Node(alarm, mod, "alarm-id", to_string(it->second.getAlarmId()).c_str()));
74         text.reset(new libyang::Data_Node(alarm, mod, "alarm-text", it->second.getAdditionalText().c_str()));
75         severity.reset(new libyang::Data_Node(alarm, mod, "severity", to_string(it->second.getEventType()).c_str()));
76         status.reset(new libyang::Data_Node(alarm, mod, "status", it->second.getSpecificProblem().c_str()));
77         add_info.reset(new libyang::Data_Node(alarm, mod, "additional-info", it->second.getAdditionalInfo().c_str()));
78     }
79     return SR_ERR_OK;
80 }
81
82 /**********************************************************************
83          End of file
84 **********************************************************************/