[ Jira id - ODUHIGH-593 ] Pack and unpack function nomenclature correction
[o-du/l2.git] / src / o1 / VesConfigFile.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 /* This class defines functions to read Ves Config files */
19
20 #include "VesConfigFile.hpp"
21 #include "JsonHelper.hpp"
22 #include "GlobalDefs.hpp"
23
24
25 /* Constructor */
26 VesConfigFile::VesConfigFile(string filepath)
27     :ConfigFile(filepath) 
28 {
29 }
30 /* Default Destructor */
31 VesConfigFile::~VesConfigFile()
32 {
33 }
34
35 //Getters
36 string VesConfigFile::getVesServerIp() const
37 {
38     return mVesServerIp;
39 }
40 string VesConfigFile::getVesServerPort() const
41 {
42     return mVesServerPort;
43 }
44 string VesConfigFile::getVesServerUsername() const
45 {
46     return mVesServerUsername;
47 }
48 string VesConfigFile::getVesServerPassword() const
49 {
50     return mVesServerPassword;
51 }
52
53 /*******************************************************************
54 *
55 * @brief load Ves config file
56 *
57 * @details
58 *
59 * Function : loadConfigFile
60 *
61 * Functionality:
62 * - read Ves Config file and store its contents
63 *
64 * @params[in] IN - NULL
65 * @return true - success
66 *         false - failure
67 *
68 * ****************************************************************/
69
70 bool VesConfigFile::loadConfigFile()
71 {
72     cJSON *json = JsonHelper::read(mFilepath.c_str());
73     if (json == NULL)
74     {
75         O1_LOG("\nO1 VesEvent : Error reading config file  :%s", JsonHelper::getError());
76         return false;
77     }
78     else
79     {
80         cJSON *rootNode = NULL;
81         rootNode = JsonHelper::getNode(json, "vesConfig");
82         if (rootNode)
83         {
84             O1_LOG("\nO1 VesEvent : Reading Config.json file\n");
85             mVesServerIp = JsonHelper::getValue(rootNode, "vesV4IpAddress");
86             mVesServerPort = JsonHelper::getValue(rootNode, "vesPort");
87             mVesServerUsername = JsonHelper::getValue(rootNode, "username");
88             mVesServerPassword = JsonHelper::getValue(rootNode, "password");
89         }
90         else
91         {
92             O1_LOG("\nO1 VesEvent : Config Object is not available in config file");
93             return false;
94         }
95     }
96     JsonHelper::deleteNode(json);
97     return true;
98 }
99
100 /**********************************************************************
101   End of file
102  **********************************************************************/