Skip to content
Snippets Groups Projects
Commit 2d596d65 authored by Stefan Spettel's avatar Stefan Spettel
Browse files

refact(pcf): Move command line options to utils and add namespace

parent 795baa81
No related branches found
No related tags found
1 merge request!11Refactor main and app class
################################################################################
# Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The OpenAirInterface Software Alliance licenses this file to You under
# the OAI Public License, Version 1.1 (the "License"); you may not use this file
# except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.openairinterface.org/?page_id=698
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
# For more information about the OpenAirInterface (OAI) Software Alliance:
# contact@openairinterface.org
################################################################################
## This file is used to specify the common models and utils this library is using
## DO NOT JUST COPY THIS FILE FROM OTHER NFs. The reasoning behind this is to only compile used files to optimize
## build speed
SET(UTILS_COMMON_DIR ${SRC_TOP_DIR}/common/utils)
## UTILS used in PCF
target_include_directories(pcf PUBLIC ${UTILS_COMMON_DIR})
target_sources(pcf PRIVATE ${UTILS_COMMON_DIR}/options.cpp)
......@@ -19,13 +19,14 @@
#include "options.hpp"
int Options::options;
using namespace oai::utils;
std::string Options::m_libconfigcfg;
bool Options::m_log_rot_file_log;
bool Options::m_log_stdout;
int options::m_options;
std::string options::m_libconfigcfg;
bool options::m_log_rot_file_log;
bool options::m_log_stdout;
void Options::help() {
void options::help() {
std::cout << std::endl
<< "Usage: pcf [OPTIONS]..." << std::endl
<< " -h, --help Print help and exit" << std::endl
......@@ -40,19 +41,19 @@ void Options::help() {
<< std::endl;
}
bool Options::parse(int argc, char** argv) {
bool ret = true;
bool options::parse(int argc, char** argv) {
bool ret;
ret = parseInputOptions(argc, argv);
ret &= validateOptions();
return ret;
}
bool Options::validateOptions() {
return ((options & libconfigcfg));
bool options::validateOptions() {
return ((m_options & libconfigcfg));
}
bool Options::parseInputOptions(int argc, char** argv) {
bool options::parseInputOptions(int argc, char** argv) {
int c;
int option_index = 0;
bool result = true;
......@@ -76,17 +77,17 @@ bool Options::parseInputOptions(int argc, char** argv) {
}
case 'c': {
m_libconfigcfg = optarg;
options |= libconfigcfg;
m_options |= libconfigcfg;
break;
}
case 'o': {
m_log_stdout = true;
options |= log_stdout;
m_options |= log_stdout;
break;
}
case 'r': {
m_log_rot_file_log = true;
options |= log_rot_file_log;
m_options |= log_rot_file_log;
break;
}
......@@ -98,13 +99,13 @@ bool Options::parseInputOptions(int argc, char** argv) {
break;
}
case 'o': {
std::cout << "Option -o does not requires an argument, can be also "
std::cout << "Option -o does not require an argument, can be also "
"set with option -r."
<< std::endl;
break;
}
case 'r': {
std::cout << "Option -r does not requires an argument, can be also "
std::cout << "Option -r does not require an argument, can be also "
"set with option -o."
<< std::endl;
break;
......
......@@ -20,7 +20,9 @@
#include <cstdint>
#include <string>
class Options {
namespace oai::utils {
class options {
public:
static bool parse(int argc, char** argv);
static bool parseInputOptions(int argc, char** argv);
......@@ -39,11 +41,12 @@ class Options {
static void help();
static int options;
static int m_options;
static bool m_log_rot_file_log;
static bool m_log_stdout;
static std::string m_libconfigcfg;
};
} // namespace oai::utils
#endif // #define __OPTIONS_H
......@@ -158,12 +158,14 @@ add_definitions(-DBSTRLIB_CAN_USE_STL=1 -DBSTRLIB_CAN_USE_IOSTREAM=1 -DBSTRLIB_T
# CMAKE_C_FLAGS_DEBUG: -fsanitize=address not compatible with valgrind
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -fstack-protector-all -DMALLOC_CHECK_=3 -DINFO_IS_ON=1 -DDEBUG_IS_ON=1 -DTRACE_IS_ON=1 -O0 -fno-omit-frame-pointer")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -fstack-protector-all -DMALLOC_CHECK_=3 -DINFO_IS_ON=1 -DDEBUG_IS_ON=1 -DTRACE_IS_ON=1 -O0 -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2 -fno-omit-frame-pointer -s -DINFO_IS_ON=1")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g -O1 -DINFO_IS_ON=1 ")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -Os -s")
# CMAKE_CXX_FLAGS_DEBUG: -fsanitize=address not compatible with valgrind
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -std=c++17 -g -fstack-protector-all -DMALLOC_CHECK_=3 -DINFO_IS_ON=1 -DDEBUG_IS_ON=1 -DTRACE_IS_ON=1 -O0 -fno-omit-frame-pointer")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -std=c++17 -g -fstack-protector-all -DMALLOC_CHECK_=3 -DINFO_IS_ON=1 -DDEBUG_IS_ON=1 -DTRACE_IS_ON=1 -O0 -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -std=c++17 -O2 -fno-omit-frame-pointer -s -DINFO_IS_ON=1")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -std=c++17 -g -O1 -DINFO_IS_ON=1")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -std=c++17 -Os -s")
......@@ -281,9 +283,10 @@ include_directories(${SRC_TOP_DIR}/api-server/model)
add_executable(pcf
${SRC_TOP_DIR}/oai_pcf/main.cpp
${SRC_TOP_DIR}/oai_pcf/options.cpp
)
include(${BUILD_TOP_DIR}/pcf/used_common_files.cmake)
IF(STATIC_LINKING)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
SET_TARGET_PROPERTIES(pcf PROPERTIES LINK_SEARCH_END_STATIC 1)
......
......@@ -109,13 +109,13 @@ int main(int argc, char** argv) {
}
// Command line options
if (!Options::parse(argc, argv)) {
if (!oai::utils::options::parse(argc, argv)) {
std::cout << "Options::parse() failed" << std::endl;
return 1;
}
// Logger
Logger::init("pcf", Options::getlogStdout(), Options::getlogRotFilelog());
Logger::init("pcf", oai::utils::options::getlogStdout(), oai::utils::options::getlogRotFilelog());
struct sigaction sigIntHandler {};
sigIntHandler.sa_handler = my_app_signal_handler;
......@@ -127,7 +127,7 @@ int main(int argc, char** argv) {
pcf_event ev;
// Config
if (pcf_cfg->load(Options::getlibconfigConfig()) == RETURNerror) {
if (pcf_cfg->load(oai::utils::options::getlibconfigConfig()) == RETURNerror) {
exit(-1);
}
pcf_cfg->display();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment