c3135b53a54e6ab3e9394bd5d044db8c2b7a8381
[o-du/l2.git] / src / o1 / O1Interface.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 C interface for ODU to start the O1 module */
20
21 #include "O1Interface.h"
22 #include "O1App.hpp"
23 #include "GlobalDefs.hpp"
24 #include <signal.h>
25 #include <unistd.h>
26
27
28 /*******************************************************************
29  *
30  * @brief Wait for the O1 Module to start
31  *
32  * @details
33  *
34  *    Function : check_O1_module_status
35  *
36  *    Functionality:
37  *      - Checks if the O1App has started
38  *
39  *
40  * @params[in] void
41  * @return O1::SUCCESS - success
42  *         O1::FAILURE - failure
43  ******************************************************************/
44
45 int static check_O1_module_status(void){
46    for( int i = 0; i < 5 ; i++)
47    {
48       if( O1App::instance().getStartupStatus() == true)
49       {
50          return O1::SUCCESS;
51       }
52       else
53       {
54          sleep(1);
55       }
56    }
57
58    return O1::FAILURE;
59 }
60
61 /*******************************************************************
62  *
63  * @brief Starts the O1 Module
64  *
65  * @details
66  *
67  *    Function : start_O1_module
68  *
69  *    Functionality:
70  *      - Starts the O1 module by instantiating the O1App instance
71  *        Invoked from the ODU-High main function
72  *
73  *
74  * @params[in] void
75  * @return O1::SUCCESS - success
76  *         O1::FAILURE - failure
77  ******************************************************************/
78
79 int start_O1_module(void)
80 {
81
82    if(O1App::instance().start() == false){
83          O1_LOG("\nO1 O1Interface : Failed to start");
84       return O1::FAILURE;
85    }
86    
87    if(O1App::instance().setAffinity(O1::CPU_CORE))
88    {
89       O1_LOG("\nO1 O1Interface : CPU affinity set " );
90       O1App::instance().printAffinity();
91    }
92    return check_O1_module_status();
93 }
94
95
96 /**********************************************************************
97          End of file
98 **********************************************************************/