1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020-2021] [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 defination of generic netconf utility function which can
20 * be used by any class*/
23 #include "NetconfUtils.hpp"
25 /*******************************************************************
27 * @brief print changes of given operation
31 * Function : printChange
34 * - print changes of given operation, old and new value
37 * @params[in] sysrepo::S_Change change
39 ******************************************************************/
41 void NetconfUtils::printChange(sysrepo::S_Change change) {
42 switch(change->oper()) {
44 if (nullptr != change->new_val()) {
45 O1_LOG("\nO1 NetconfUtils : CREATED: %s", \
46 change->new_val()->to_string().c_str());
50 if (nullptr != change->old_val()) {
51 O1_LOG("\nO1 NetconfUtils : DELETED: %s", \
52 change->old_val()->to_string().c_str());
56 if (nullptr != change->old_val() && nullptr != change->new_val()) {
57 O1_LOG("\nO1 NetconfUtils : MODIFIED: old value %s :new value %s", \
58 change->old_val()->to_string().c_str(), \
59 change->new_val()->to_string().c_str());
63 if (nullptr != change->old_val() && nullptr != change->new_val()) {
64 O1_LOG("\nO1 NetconfUtils : MOVED: %s :after %s ", \
65 change->new_val()->xpath(), \
66 change->old_val()->xpath());
68 else if (nullptr != change->new_val()) {
69 O1_LOG("\nO1 NetconfUtils : MOVED: %s : first", \
70 change->new_val()->xpath());
76 /*******************************************************************
78 * @brief convert event type to string
85 * - convert event type to string
88 * @params[in] sr_event_t event
89 * @return event name in string form
90 ******************************************************************/
92 /* Helper function for printing events. */
93 const char *NetconfUtils::evToStr(sr_event_t ev) {
105 /*******************************************************************
107 * @brief get the leaf name from xpath
111 * Function : getLeafInfo
114 * - extract the leaf name from xpath
117 * @params[in] xpath, output string
119 ******************************************************************/
121 void NetconfUtils::getLeafInfo(string xpath,string &parent, string &leaf ){
122 std::stringstream ssLeaf(xpath);
123 std::stringstream ssParent(xpath);
125 getline(ssLeaf, leaf, ch);
126 while(getline(ssLeaf, leaf, ch)){
127 getline(ssParent, parent, ch);
128 } //get leaf name after the last '/'
129 std::stringstream ss(leaf);
131 getline(ss, leaf, ch); //remove extra space
132 //O1_LOG("\nO1 NetconfUtils : parent = [%s]", parent.c_str());
133 //O1_LOG("\nO1 NetconfUtils : leaf = [%s]", leaf.c_str());
137 /**********************************************************************
139 **********************************************************************/