2 # ==================================================================================
3 # Copyright (c) 2020 HCL Technologies Limited.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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 # ==================================================================================
19 #include "xapp_config.hpp"
21 string& XappSettings::operator[](const SettingName& theName){
22 return theSettings[theName];
25 void XappSettings::loadCmdlineSettings(int argc, char **argv){
27 // Parse command line options to over ride
28 static struct option long_options[] =
30 {"xappname", required_argument, 0, 'n'},
31 {"xappid", required_argument, 0, 'x'},
32 {"port", required_argument, 0, 'p'},
33 {"threads", required_argument, 0, 't'},
34 {"ves-interval", required_argument, 0, 'i'},
35 {"gNodeB", required_argument, 0, 'g'}
43 char c = getopt_long(argc, argv, "n:p:t:s:g:a:v:u:i:c:x:", long_options, &option_index);
53 theSettings[XAPP_NAME].assign(optarg);
57 theSettings[BOUNCER_PORT].assign(optarg);
61 theSettings[THREADS].assign(optarg);
62 mdclog_write(MDCLOG_INFO, "Number of threads set to %s from command line e\n", theSettings[THREADS].c_str());
67 theSettings[XAPP_ID].assign(optarg);
68 mdclog_write(MDCLOG_INFO, "XAPP ID set to %s from command line ", theSettings[XAPP_ID].c_str());
83 void XappSettings::loadDefaultSettings(){
86 if(theSettings[XAPP_NAME].empty()){
87 theSettings[XAPP_NAME] = DEFAULT_XAPP_NAME;
90 if(theSettings[XAPP_ID].empty()){
91 theSettings[XAPP_ID] = DEFAULT_XAPP_NAME; //for now xapp_id is same as xapp_name since single xapp instance.
93 if(theSettings[LOG_LEVEL].empty()){
94 theSettings[LOG_LEVEL] = DEFAULT_LOG_LEVEL;
96 if(theSettings[BOUNCER_PORT].empty()){
97 theSettings[BOUNCER_PORT] = DEFAULT_PORT;
99 if(theSettings[MSG_MAX_BUFFER].empty()){
100 theSettings[MSG_MAX_BUFFER] = DEFAULT_MSG_MAX_BUFFER;
103 if(theSettings[THREADS].empty()){
104 theSettings[THREADS] = DEFAULT_THREADS;
110 void XappSettings::loadEnvVarSettings(){
112 if (const char *env_xname = std::getenv("XAPP_NAME")){
113 theSettings[XAPP_NAME].assign(env_xname);
114 mdclog_write(MDCLOG_INFO,"Xapp Name set to %s from environment variable", theSettings[XAPP_NAME].c_str());
116 if (const char *env_xid = std::getenv("XAPP_NAME")){
117 theSettings[XAPP_ID].assign(env_xid);
118 mdclog_write(MDCLOG_INFO,"Xapp ID set to %s from environment variable", theSettings[XAPP_ID].c_str());
121 if (const char *env_ports = std::getenv("BOUNCER_PORT")){
122 theSettings[BOUNCER_PORT].assign(env_ports);
123 mdclog_write(MDCLOG_INFO,"Ports set to %s from environment variable", theSettings[BOUNCER_PORT].c_str());
125 if (const char *env_ports = std::getenv("MSG_MAX_BUFFER")){
126 theSettings[MSG_MAX_BUFFER].assign(env_ports);
127 mdclog_write(MDCLOG_INFO,"Ports set to %s from environment variable", theSettings[MSG_MAX_BUFFER].c_str());
132 void XappSettings::usage(char *command){
133 std::cout <<"Usage : " << command << " " << std::endl;
134 std::cout <<" --name[-n] xapp_instance_name "<< std::endl;
135 std::cout <<" --port[-p] port to listen on e.g tcp:4561 "<< std::endl;
136 std::cout << "--threads[-t] number of listener threads "<< std::endl ;