f4108c003a86ff9188236ffaa497019ee88f4ab8
[o-du/l2.git] / src / o1 / SessionHandler.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 methods of Session/Connection creation and Subscription to
20    YANG modules */
21
22 #include "SessionHandler.hpp"
23
24
25 /* Default constructor */
26 SessionHandler::SessionHandler()
27 {    
28 }
29
30
31 /* Destructor */
32 SessionHandler::~SessionHandler()
33 {  
34 }
35
36 /********************************************************************** 
37    Description : This function will create Connection, Session, and 
38                  subscribe. These sysrepo class provide netconf connection
39                  related services.
40    Params[In]  : void
41    Return      : true  - started successful
42                  false - start failed
43 **********************************************************************/
44 bool SessionHandler::init()
45 {
46    try
47    {
48       mConn = createConnection();
49       mSess = createSession(mConn);
50       mSub  = createSubscribe(mSess);
51       O1_LOG("\nO1 SessionHandler : Initialization done");
52       return true;
53    }
54    catch( const std::exception& e )
55    {
56       O1_LOG("\nO1 SessionHandler : Exception : %s", e.what());
57       return false;
58    }
59 }
60
61 /********************************************************************** 
62    Description : This function will create Connection instance and 
63                  return the same  
64    Params[In]  : void
65    Return      : sysrepo::S_Connection instance
66 **********************************************************************/
67 sysrepo::S_Connection SessionHandler::createConnection()
68 {
69    sysrepo::S_Connection conn(new sysrepo::Connection());
70    return conn;
71 }
72
73
74 /********************************************************************** 
75    Description : This function will create Session instance and
76                  return the same
77    Params[In]  : sysrepo::S_Connection
78    Return      : sysrepo::S_Session instance
79 **********************************************************************/
80 sysrepo::S_Session SessionHandler::createSession(sysrepo::S_Connection conn)
81 {
82    sysrepo::S_Session sess(new sysrepo::Session(conn));
83    return sess;
84 }
85
86
87
88 /**********************************************************************
89    Description : This function will create Subscribe instance and
90                  return the same
91    Params[In]  : sysrepo::S_Session
92    Return      : sysrepo::S_Subscribe instance
93 **********************************************************************/
94 sysrepo::S_Subscribe SessionHandler::createSubscribe(sysrepo::S_Session sess)
95 {
96    sysrepo::S_Subscribe subscrb(new sysrepo::Subscribe(sess));
97    if(subscribeModule(subscrb))
98    {
99       O1_LOG("\nO1 SessionHandler : Subscription done successfully");
100    }
101    return subscrb;
102 }
103
104
105 /********************************************************************** 
106    Description : This function will create a callback object and register
107                  it for callback. 
108    Params[In]  : sysrepo::S_Subscribe
109    Return      : true   - on success
110 **********************************************************************/
111 bool SessionHandler::subscribeModule(sysrepo::S_Subscribe subscrb)
112 {
113    sysrepo::S_Callback alarmOranCb(new AlarmOranYangModel());
114
115    subscrb->oper_get_items_subscribe(ALARM_MODULE_NAME_ORAN, \
116                                      ALARM_MODULE_PATH_ORAN, \
117                                      alarmOranCb);
118    return true;
119 }
120
121 /**********************************************************************
122          End of file
123 **********************************************************************/