astyle --recursive --indent=spaces=2 --style=kr --indent-col1-comments --break-blocks --convert-tabs --max-code-length=200

This is done for better merging branch/LG_PRE_RELEASE_0.3 into trunk (same process is applied on this branch)

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7073 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
Lionel Gauthier
2015-04-09 09:29:12 +00:00
parent f0a8a0b3b5
commit 059a0a3fdc
2044 changed files with 1182666 additions and 1145123 deletions
+139 -108
View File
@@ -47,78 +47,84 @@
extern cli_config *cli_cfg;
#define NEXT_OPT do {optv++;optc--; } while (0)
#define CHECK_OPTC do { if(!optc) { \
if((optc - 1) == 1){ \
fprintf(stderr, "[CLI]Error parsing command line options!\n"); \
} else { \
optv--; \
fprintf(stderr, "[CLI]You must provide a parameter when using the %s switch!\n", *optv); \
} \
} } while (0)
#define CHECK_OPTC do { if(!optc) { \
if((optc - 1) == 1){ \
fprintf(stderr, "[CLI]Error parsing command line options!\n"); \
} else { \
optv--; \
fprintf(stderr, "[CLI]You must provide a parameter when using the %s switch!\n", *optv); \
} \
} } while (0)
mapping log_comp[] = {
{"phy", 2},
{"mac", 3},
{"emu", 4},
{"ocg", 5},
{"omg", 6},
{NULL, -1}
{"phy", 2},
{"mac", 3},
{"emu", 4},
{"ocg", 5},
{"omg", 6},
{NULL, -1}
};
mapping log_level[] = {
{"error", 3},
{"warn", 4},
{"info", 6},
{"debug", 7},
{NULL, -1}
{"error", 3},
{"warn", 4},
{"info", 6},
{"debug", 7},
{NULL, -1}
};
mapping log_flag[] = {
{"none", 0x0},
{"low", 0x04},
{"med", 0x34},
{"full", 0x74},
{NULL, -1}
{"none", 0x0},
{"low", 0x04},
{"med", 0x34},
{"full", 0x74},
{NULL, -1}
};
/* ************************ CLI COMMANDS ************************** */
/* The user wishes to quit using this program. Just set DONE non-zero. */
int com_exit (char *arg) {
int com_exit (char *arg)
{
//set the xit value for the threads
cli_cfg->exit = 1;
cli_cfg->promptchar='\0';
cli_cfg->prompt[0]='\0';
snprintf(cli_cfg->prompt,200,"%s","oaicli");
snprintf(cli_cfg->prompt,200,"%s","oaicli");
close(cli_cfg->cfd);
return (0);
}
/* CLI error Function . */
void cli_error (char *caller) {
void cli_error (char *caller)
{
fprintf (stderr,"[CLI]an error running occured during the execution of %s function\n",
caller);
}
int prompt (char *arg) {
int prompt (char *arg)
{
// char buf[200];
if (cli_help("prompt", arg) == OK)
return 0;
if (!arg || !*arg){ // no arg is provided, run get func
if (!arg || !*arg) { // no arg is provided, run get func
snprintf(buffer,200,"%s\n", cli_cfg->prompt);
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
// send(cli_cfg->cfd, cli_cfg->prompt, strlen(cli_cfg->prompt), 0);
}else {// set func
} else {// set func
snprintf(cli_cfg->prompt,200,"%s",arg);
sprintf( cli_cfg->prompt,"%s%c ", cli_prompt(), cli_cfg->promptchar);
}
return (0);
}
int info (char *arg) {
int info (char *arg)
{
sprintf(buffer, "CLI by user %s from host %s\n", username, host);
send(cli_cfg->cfd,buffer, strlen(buffer),0);
@@ -126,37 +132,40 @@ int info (char *arg) {
}
int start (char *arg) {
int start (char *arg)
{
// char buf[200];
char* optv[20];
int optc=0;
if (cli_help("start", arg) == OK)
return OK;
if (valid_argument ("start", arg) == ERR){
if (valid_argument ("start", arg) == ERR) {
start_usage("");
return ERR;
}
optc = token_argument(arg, optv);
process_argument(optc, optv);
return (0);
}
int set(char *arg){
int set(char *arg)
{
char* optv[20];
int optc=0;
if (cli_help("set", arg) == OK)
return OK;
if (valid_argument ("set", arg) == ERR){
if (valid_argument ("set", arg) == ERR) {
set_usage();
return ERR;
}
optc = token_argument(arg, optv);
process_argument(optc, optv);
return OK;
@@ -164,138 +173,160 @@ int set(char *arg){
}
/* Return non-zero if ARG is a valid argument for CALLER, else print
an error message and return zero. */
int valid_argument (char *caller, char *arg) {
int valid_argument (char *caller, char *arg)
{
if (!arg || !*arg) {
snprintf(buffer,200,"%s: argument required\n", caller);
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
fprintf (stderr, "%s: argument required\n", caller);
return (ERR);
}
snprintf(buffer,200,"%s: argument required\n", caller);
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
fprintf (stderr, "%s: argument required\n", caller);
return (ERR);
}
return (OK);
}
int cli_help(char *caller, char * arg) {
int cli_help(char *caller, char * arg)
{
command *command;
if ((strcmp(arg, "-h") == 0 ) || (strcmp(arg, "?") == 0 ) || (strcmp(arg, "help") == 0 ) ||
(strcmp(arg, "-help") == 0 ) ||(strcmp(arg, "--help") == 0 )) {
command = find_command (caller); // we are sure that the command exists so no check is done
return ((*(command->help))(caller)); // return zero after calling help func
}
return ERR; // no help is requested bu the user
}
int token_argument(char *arg, char* optv[]) {
int token_argument(char *arg, char* optv[])
{
int tokc;
tokc = 0;
optv[tokc] = strtok(arg, " "); // get the first token
while (optv[tokc]!=NULL) {
tokc++;
optv[tokc] = strtok(NULL, " ");
optv[tokc] = strtok(NULL, " ");
}
return tokc;
return tokc;
}
int process_argument(int optc, char* optv[]) {
int process_argument(int optc, char* optv[])
{
int index;
int state;
int comp=0, level=0, flag=0x34, interval=0;
while (optc > 0) {
/* add an RB */
/* add an RB */
if ((strcmp(*optv, "ue") == 0) || (strcmp(*optv, "UE") == 0) ) {
NEXT_OPT; CHECK_OPTC;
index = atoi (*optv);
if (optc > 0){
NEXT_OPT; CHECK_OPTC;
state = atoi (*optv);
printf("[CLI] UE %d state %d\n", index, state);
oai_emulation.info.cli_start_ue[index]=state;
}
else
return ERR;
}
if ((strcmp(*optv, "enb") == 0) || (strcmp(*optv, "eNB") == 0) ) {
NEXT_OPT; CHECK_OPTC;
NEXT_OPT;
CHECK_OPTC;
index = atoi (*optv);
if (optc > 0) {
NEXT_OPT;CHECK_OPTC;
state = atoi (*optv);
printf("[CLI] eNB %d state %d\n", index, state);
oai_emulation.info.cli_start_enb[index]= state;
}
else
return ERR;
NEXT_OPT;
CHECK_OPTC;
state = atoi (*optv);
printf("[CLI] UE %d state %d\n", index, state);
oai_emulation.info.cli_start_ue[index]=state;
} else
return ERR;
}
if ((strcmp(*optv, "enb") == 0) || (strcmp(*optv, "eNB") == 0) ) {
NEXT_OPT;
CHECK_OPTC;
index = atoi (*optv);
if (optc > 0) {
NEXT_OPT;
CHECK_OPTC;
state = atoi (*optv);
printf("[CLI] eNB %d state %d\n", index, state);
oai_emulation.info.cli_start_enb[index]= state;
} else
return ERR;
}
// fixme
if ((strcmp(*optv, "log") == 0) || (strcmp(*optv, "LOG") == 0) ) {
NEXT_OPT; CHECK_OPTC;
NEXT_OPT;
CHECK_OPTC;
comp = map_str_to_int(log_comp, *optv);
NEXT_OPT;
if (optc > 0) {
CHECK_OPTC;
level = map_str_to_int(log_level, *optv);
}
else
return ERR;
NEXT_OPT;
if (optc > 0) {
CHECK_OPTC;
flag = map_str_to_int (log_flag, *optv);
}
CHECK_OPTC;
level = map_str_to_int(log_level, *optv);
} else
return ERR;
NEXT_OPT;
if (optc > 0) {
CHECK_OPTC;
interval = atoi (*optv);
CHECK_OPTC;
flag = map_str_to_int (log_flag, *optv);
}
printf("[CLI] OMG set log for comp %d level %d flag 0x%x interval %d\n",
comp, level, flag, interval);
NEXT_OPT;
if (optc > 0) {
CHECK_OPTC;
interval = atoi (*optv);
}
printf("[CLI] OMG set log for comp %d level %d flag 0x%x interval %d\n",
comp, level, flag, interval);
set_comp_log(comp, level, flag, interval);
}
NEXT_OPT;
}
return OK;
}
int prompt_usage(char *arg) {
int prompt_usage(char *arg)
{
sprintf(buffer, "Usage: prompt [value]\n");
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
return 0;
}
int start_usage(char *arg) {
int start_usage(char *arg)
{
sprintf(buffer, "Usage: start [enb|UE] [enb_index][0: stop, 1: start] \n");
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
sprintf(buffer, "Example to start enb 0: start enb 0 1 \n");
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
sprintf(buffer, "Example to stop ue &: start ue 1 0 \n");
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
return 0;
}
int set_usage(void) {
int set_usage(void)
{
sprintf(buffer, "Usage: set log [comp] [level:debug,info,warn,error][flag:none,low,med,full][intervale: 1-100] \n");
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
sprintf(buffer, "Example 1: set log omg debug\n");
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
sprintf(buffer, "Example 1: set log omg info med 10\n");
send(cli_cfg->cfd, buffer, strlen(buffer), 0);
return 0;
}