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 class is the netconf manager class. It will handle netopeer-server start and stop along with session handler init. Additionally it will provide the
22 #include "NetconfManager.hpp"
24 /* Default constructor */
25 NetconfManager::NetconfManager()
31 NetconfManager::~NetconfManager()
33 if( NULL != mSessHndl)
39 /**********************************************************************
40 Description : This function will start the netopeer2-server and
41 redirect logs to the /etc/netopeer2-server.log file
43 Return : true - started successful
45 **********************************************************************/
47 bool NetconfManager::startNetopeerServer ()
49 int status = system("netopeer2-server -d -v3 > /etc/netopeer2-server.log 2>&1 &");
52 O1_LOG("\nO1 NetconfManager : Error during netopeer server start status : %s",\
57 if (WIFEXITED(status))
58 O1_LOG("\nO1 NetconfManager : netopeer server started normally with status : %d",\
61 O1_LOG("\nO1 NetconfManager : netopeer server started abnormally with status : %d",\
68 /**********************************************************************
69 Description : This function will stop the netopeer2-server
71 Return : true - started successful
73 **********************************************************************/
74 bool NetconfManager::stopNetopeerServer(void)
76 int status = system("kill -9 `pidof netopeer2-server`");
79 O1_LOG("\nO1 NetconfManager : Error during Netopeer server stopped status : %s\n",\
84 if (WIFEXITED(status))
86 O1_LOG("\nO1 NetconfManager : Netopeer server stopped normally with status : %d\n",\
91 O1_LOG("\nO1 NetconfManager : Netopeer server stopped abnormally with status : %d\n",\
99 /**********************************************************************
100 Description : catch and handle the SIGINT signal
103 **********************************************************************/
104 void NetconfManager::sigintHandler(int signum)
106 if (true != NetconfManager::stopNetopeerServer())
108 O1_LOG("\nO1 NetconfManager : Error stopping Netopeer server");
113 /**********************************************************************
114 Description : This function will start the netopeer2-server and
117 Return : true - started successful
119 **********************************************************************/
120 bool NetconfManager::init(void)
122 /* if(startNetopeerServer())
124 O1_LOG("\nO1 NetconfManager : netopeer server started");
129 mSessHndl = new SessionHandler;
131 O1_LOG("\nO1 NetconfManager : SessionHandler created ");
133 if( !mSessHndl->init())
135 O1_LOG("\nO1 NetconfManager : SessionHandler init failed \n");
140 catch( const std::exception& e )
142 O1_LOG("\nO1 O1_main : Exception : %s", e.what());
148 /**********************************************************************
150 **********************************************************************/