Adding new commiter to ODU-High repo
[o-du/l2.git] / src / o1 / AlarmOranYangModel.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 "AlarmOranYangModel.hpp"
22
23 using namespace std;
24
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 **********************************************************************/
32
33 int AlarmOranYangModel::oper_get_items(sysrepo::S_Session session, \
34                                        const char *module_name, \
35                                        const char *path, \
36                                        const char *request_xpath, \
37                                        uint32_t request_id, \
38                                        libyang::S_Data_Node &parent, \
39                                        void *private_data)
40 {
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);
44
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"));
48     
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;
55
56     //read the data from map
57     map<uint16_t,Alarm>::const_iterator it;
58
59     AlarmManager& alrmMgr = AlarmManager::instance();
60     const map<uint16_t,Alarm>& alrmList = alrmMgr.getAlarmList();
61     char alarmId[MAX_ALARM_ID_LEN];
62
63     for(it = alrmList.begin(); it !=alrmList.end(); it++)
64     {
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()));
73     }
74
75     return SR_ERR_OK;
76 }
77
78
79 /**********************************************************************
80          End of file
81 **********************************************************************/