2 ==================================================================================
4 Copyright (c) 2019-2020 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
22 * Author: Ashwin Shridharan, Shraboni Jana
25 #include "xapp_config.hpp"
27 string& XappSettings::operator[](const SettingName& theName){
28 return theSettings[theName];
31 void XappSettings::loadCmdlineSettings(int argc, char **argv){
33 // Parse command line options to over ride
34 static struct option long_options[] =
36 {"xappname", required_argument, 0, 'n'},
37 {"xappid", required_argument, 0, 'x'},
38 {"port", required_argument, 0, 'p'},
39 {"threads", required_argument, 0, 't'},
40 {"ves-interval", required_argument, 0, 'i'},
41 {"gNodeB", required_argument, 0, 'g'}
49 char c = getopt_long(argc, argv, "n:p:t:s:g:a:v:u:i:c:x:", long_options, &option_index);
59 theSettings[XAPP_NAME].assign(optarg);
63 theSettings[HW_PORT].assign(optarg);
67 theSettings[THREADS].assign(optarg);
68 mdclog_write(MDCLOG_INFO, "Number of threads set to %s from command line e\n", theSettings[THREADS].c_str());
73 theSettings[XAPP_ID].assign(optarg);
74 mdclog_write(MDCLOG_INFO, "XAPP ID set to %s from command line ", theSettings[XAPP_ID].c_str());
89 void XappSettings::loadDefaultSettings(){
92 if(theSettings[XAPP_NAME].empty()){
93 theSettings[XAPP_NAME] = DEFAULT_XAPP_NAME;
96 if(theSettings[XAPP_ID].empty()){
97 theSettings[XAPP_ID] = DEFAULT_XAPP_NAME; //for now xapp_id is same as xapp_name since single xapp instance.
99 if(theSettings[LOG_LEVEL].empty()){
100 theSettings[LOG_LEVEL] = DEFAULT_LOG_LEVEL;
102 if(theSettings[HW_PORT].empty()){
103 theSettings[HW_PORT] = DEFAULT_PORT;
105 if(theSettings[MSG_MAX_BUFFER].empty()){
106 theSettings[MSG_MAX_BUFFER] = DEFAULT_MSG_MAX_BUFFER;
109 if(theSettings[THREADS].empty()){
110 theSettings[THREADS] = DEFAULT_THREADS;
116 void XappSettings::loadEnvVarSettings(){
118 if (const char *env_xname = std::getenv("XAPP_NAME")){
119 theSettings[XAPP_NAME].assign(env_xname);
120 mdclog_write(MDCLOG_INFO,"Xapp Name set to %s from environment variable", theSettings[XAPP_NAME].c_str());
122 if (const char *env_xid = std::getenv("XAPP_ID")){
123 theSettings[XAPP_ID].assign(env_xid);
124 mdclog_write(MDCLOG_INFO,"Xapp ID set to %s from environment variable", theSettings[XAPP_ID].c_str());
127 if (const char *env_ports = std::getenv("HW_PORT")){
128 theSettings[HW_PORT].assign(env_ports);
129 mdclog_write(MDCLOG_INFO,"Ports set to %s from environment variable", theSettings[HW_PORT].c_str());
131 if (const char *env_ports = std::getenv("MSG_MAX_BUFFER")){
132 theSettings[MSG_MAX_BUFFER].assign(env_ports);
133 mdclog_write(MDCLOG_INFO,"Ports set to %s from environment variable", theSettings[MSG_MAX_BUFFER].c_str());
138 void XappSettings::usage(char *command){
139 std::cout <<"Usage : " << command << " " << std::endl;
140 std::cout <<" --name[-n] xapp_instance_name "<< std::endl;
141 std::cout <<" --port[-p] port to listen on e.g tcp:4561 "<< std::endl;
142 std::cout << "--threads[-t] number of listener threads "<< std::endl ;