b4cfbde2cbe3db13f056e5342f242390821dc063
[o-du/l2.git] / src / o1 / O1App.cpp
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020-2021] [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 the O1App class which is responsible for running/starting
20    all the O1 modules in a thread. It inherits the Thread class and Singleton
21    class.
22 */
23
24 #include "O1App.hpp"
25 #include "GlobalDefs.hpp"
26 #include "SessionHandler.hpp"
27 #include "ConfigInterface.h"
28 #include <unistd.h>
29
30 /*******************************************************************
31  *
32  * @brief Constructor
33  *
34  * @details
35  *
36  *    Function : O1App
37  *
38  *    Functionality:
39  *      - Constructor intialization
40  *
41  * @params[in] None
42  * @return None
43  ******************************************************************/
44
45 O1App::O1App() : mUxSocketServer(O1::ALARM_SOCK_PATH)
46 {
47
48 }
49
50 /*******************************************************************
51  *
52  * @brief Destructor
53  *
54  * @details
55  *
56  *    Function : ~O1App
57  *
58  *    Functionality:
59  *      - Destructor
60  *
61  * @params[in] None
62  * @return None
63  ******************************************************************/
64
65 O1App::~O1App()
66 {
67
68 }
69
70 /*******************************************************************
71  *
72  * @brief Runs the O1 modules as a thread 
73  *
74  * @details
75  *
76  *    Function : run
77  *
78  *    Functionality:
79  *      - Implements the "run" function of Thread class.
80  *        Starts all the O1 modules.
81  *
82  *
83  * @params[in] void
84  * @return true  : success
85  *         false : failure
86  ******************************************************************/
87
88 bool O1App::run()
89 {
90     
91    SessionHandler sessHdlr;
92    /* Start Netconf session and subscribe to yang modules */
93    try
94    {
95       if( !sessHdlr.init() )
96       {
97          O1_LOG("\nO1 O1App : SessionHandler initialization failed ");         
98          return false;
99       }
100    }
101    catch( const std::exception& e ) 
102    {
103       O1_LOG("\nO1 O1App : Exception : %s", e.what());
104       return false;
105    }
106    
107    /* Start the Unix Socket Server to listen for alarm messages */
108    if( mUxSocketServer.start() )
109    {  
110       
111       if(mUxSocketServer.setAffinity(O1::CPU_CORE))
112       {
113          O1_LOG("\nO1 O1App : CPU affinity set " );
114          mUxSocketServer.printAffinity();
115       }
116       
117       sleep(2);
118       if( mUxSocketServer.isRunning() )  
119       {
120          mStartupStatus = true;
121          O1_LOG("\nO1 O1App : Unix Socket server started\n");
122       }
123       else
124       {
125          O1_LOG("\nO1 O1App : Unix Socket server failed to start\n");
126          return false;
127       }
128       /* Wait for the Unix Socket Server thread to end*/
129       mUxSocketServer.join();
130    }
131    else
132    {
133       O1_LOG("\nO1 O1App : Unix Socket server failed to start\n");
134       return false;
135    }
136    return true;
137 }
138
139 /*******************************************************************
140  *
141  * @brief Check if the O1 Module is fully up and running
142  *
143  * @details
144  *
145  *    Function : getStartupStatus
146  *
147  *    Functionality:
148  *      - Returns the status of O1App whether it is fully up
149  *
150  *
151  * @params[in] void
152  * @return true  : started
153  *         false : not started
154  ******************************************************************/
155
156 bool O1App::getStartupStatus() const
157 {
158    return mStartupStatus;
159 }
160
161 /*******************************************************************
162  *
163  * @brief Cleanup O1App
164  *
165  * @details
166  *
167  *    Function : cleanUp
168  *
169  *    Functionality:
170  *      - Implements the "cleanUp" function of Thread class to
171  *        take care of any clean up required for O1 components 
172  *        before stopping the thread.
173  *
174  * @params[in] void
175  * @return void
176  ******************************************************************/
177
178 void O1App::cleanUp(void)
179 {
180    /* Stop the socket server thread */
181    mUxSocketServer.stop();   
182 }