config_load_configmodule.h 4.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/*
 * 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.0  (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
 */

/*! \file common/config/config_load_configmodule.h
 * \brief: configuration module, include file to be used by the source code calling the 
 *  configuration module initialization 
 * \author Francois TABURET
 * \date 2017
 * \version 0.1
 * \company NOKIA BellLabs France
 * \email: francois.taburet@nokia-bell-labs.com
 * \note
 * \warning
 */
#ifndef INCLUDE_CONFIG_LOADCONFIGMODULE_H
#define INCLUDE_CONFIG_LOADCONFIGMODULE_H 


#include <string.h>
#include <stdlib.h>
#include "common/config/config_paramdesc.h"
#define CONFIG_MAX_OOPT_PARAMS    10     // maximum number of parameters in the -O option (-O <cfgmode>:P1:P2...
41
#define CONFIG_MAX_ALLOCATEDPTRS  1024   // maximum number of parameters that can be dynamicaly allocated in the config module
42 43 44 45 46

/* rtflags bit position definitions */
#define CONFIG_PRINTPARAMS    1        // print parameters values while processing
#define CONFIG_DEBUGPTR       2        // print memory allocation/free debug messages
#define CONFIG_DEBUGCMDLINE   4        // print command line processing messages
47 48
#define CONFIG_HELP           8        // print help message
#define CONFIG_ABORT          16       // config failed,abort execution 
49
#define CONFIG_NOOOPT         32       // no -O option found when parsing command line 
50

51

52 53 54 55 56 57
typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP);
typedef int(*configmodule_getfunc_t)(paramdef_t *,int numparams, char *prefix);
typedef int(*configmodule_getlistfunc_t)(paramlist_def_t *, paramdef_t *,int numparams, char *prefix);
typedef void(*configmodule_endfunc_t)(void);
typedef struct configmodule_interface
{
58 59 60 61 62
  int      argc;
  char     **argv;
  char     *cfgmode;
  int      num_cfgP;
  char     *cfgP[CONFIG_MAX_OOPT_PARAMS];
63 64 65 66
  configmodule_initfunc_t         init;
  configmodule_getfunc_t          get;
  configmodule_getlistfunc_t      getlist;
  configmodule_endfunc_t          end;
67 68 69
  uint32_t numptrs;
  uint32_t rtflags;
  char     *ptrs[CONFIG_MAX_ALLOCATEDPTRS];  
70 71 72 73 74
} configmodule_interface_t;

#ifdef CONFIG_LOADCONFIG_MAIN
configmodule_interface_t *cfgptr=NULL;

75 76 77 78 79
static char config_helpstr [] = "\n lte-softmodem -O [config mode]<:dbg[debugflags]> \n \
          debugflags can also be defined in the config_libconfig section of the config file\n \
          debugflags: mask,    1->print parameters, 2->print memory allocations debug messages\n \
                               4->print command line processing debug messages\n ";
			       
80 81
#define CONFIG_SECTIONNAME "config"
#define CONFIGPARAM_DEBUGFLAGS_IDX        0
82 83


84
static paramdef_t Config_Params[] = {
85 86 87 88 89
/*-----------------------------------------------------------------------------------------------------------------------*/
/*                                            config parameters for config module                                        */
/*   optname              helpstr           paramflags     XXXptr       defXXXval            type       numelt           */
/*-----------------------------------------------------------------------------------------------------------------------*/
{"debugflags",            config_helpstr,   0,             uptr:NULL,   defintval:0,        TYPE_MASK,  0}, 
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
};

#else
extern configmodule_interface_t *cfgptr;
#endif


#define printf_params(...) if ( (cfgptr->rtflags & CONFIG_PRINTPARAMS) != 0 )  { printf ( __VA_ARGS__ ); }
#define printf_ptrs(...)   if ( (cfgptr->rtflags & CONFIG_DEBUGPTR) != 0 )     { printf ( __VA_ARGS__ ); }     
#define printf_cmdl(...)   if ( (cfgptr->rtflags & CONFIG_DEBUGCMDLINE) != 0 ) { printf ( __VA_ARGS__ ); }
 
extern configmodule_interface_t *load_configmodule(int argc, char **argv);
extern void end_configmodule(void);

#endif  /* INCLUDE_CONFIG_LOADCONFIGMODULE_H */