Skip to content

Commit

Permalink
Event Dispatcher integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
sachinites committed Feb 5, 2021
1 parent ff42003 commit 64abd80
Show file tree
Hide file tree
Showing 25 changed files with 1,345 additions and 31,331 deletions.
Binary file modified CommandParser/LinuxLikeCommandLineInterface.docx
Binary file not shown.
18 changes: 9 additions & 9 deletions CommandParser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ CFLAGS=-g -Wall
INCLUDES=-I .
CLILIB=libcli.a
TARGET:exe ${CLILIB}
OBJ=cmd_hier.o parser.o serialize.o string_util.o clistd.o clicbext.o
OBJ=cmd_hier.o parser.o serialize.o string_util.o clistd.o clicbext.o ../EventDispatcher/event_dispatcher.o ../gluethread/glthread.o
exe:testapp.o ${CLILIB}
@echo "Building final executable"
@ ${CC} ${CFLAGS} ${INCLUDES} testapp.o -o exe -L . -lcli
@ ${CC} ${CFLAGS} ${INCLUDES} testapp.o -o exe -L . -lcli -lpthread
cmd_hier.o:cmd_hier.c
@echo "Building cmd_hier.o"
@ ${CC} ${CFLAGS} -c ${INCLUDES} cmd_hier.c -o cmd_hier.o
Expand All @@ -32,15 +32,15 @@ ${CLILIB}: ${OBJ}
@echo "Building Library ${CLILIB}"
ar rs ${CLILIB} ${OBJ}
clean:
rm exe
rm *.o
rm ${CLILIB}
rm CMD_HIST_RECORD_FILE.txt || true
rm -f exe
rm -f *.o
rm -f ${CLILIB}
rm -f CMD_HIST_RECORD_FILE.txt
install:
cp ${CLILIB} /usr/local/lib/
cp libcli.h /usr/include/
cp cmdtlv.h /usr/include/
uninstall:
rm /usr/local/lib/${CLILIB}
rm /usr/include/libcli.h
rm /usr/include/cmdtlv.h
rm -f /usr/local/lib/${CLILIB}
rm -f /usr/include/libcli.h
rm -f /usr/include/cmdtlv.h
6 changes: 3 additions & 3 deletions CommandParser/cliconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#define TERMINAL_NAME_SIZE CONS_INPUT_BUFFER_SIZE
#define TLV_MAX_BUFFER_SIZE 1024
#define POSSIBILITY_ARRAY_SIZE 10
#define DEFAULT_DEVICE_NAME "root@juniper"
#define DEFAULT_DEVICE_NAME "tcp-ip-stack"
#define MODE_CHARACTER "/"
#define SUBOPTIONS_CHARACTER "?"
#define CMD_EXPANSION_CHARACTER "."
#define MAX_OPTION_SIZE 64
#define MAX_OPTION_SIZE 16
#define CMD_HIST_RECORD_FILE "CMD_HIST_RECORD_FILE.txt"
#define FILE_CMD_SIZE_MAX (LEAF_VALUE_HOLDER_SIZE * MAX_CMD_TREE_DEPTH)
#define MODE_PARAM_INDEX 0
Expand Down Expand Up @@ -73,7 +73,7 @@ typedef enum{
#define CONFIG_SUPPORTSAVE_ENABLE 5
#define CONFIG_CONSOLEN_NAME_NAME 6
#define DEBUG_SHOW_CMDTREE 7

#define CONFIG_LOAD_FILE 8

typedef enum{
COMPLETE,
Expand Down
29 changes: 27 additions & 2 deletions CommandParser/clistd.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dump_all_commands(param_t *root, unsigned int index){
}
else if(IS_PARAM_LEAF(root)){
untokenize(index);
memset(temp, 0, LEAF_VALUE_HOLDER_SIZE + 2);
memset(temp, 0, sizeof(temp));
sprintf(temp, "<%s>", GET_LEAF_ID(root));
tokenize(temp, strlen(GET_LEAF_ID(root)) + 2, index);
}
Expand Down Expand Up @@ -314,6 +314,30 @@ config_mode_enter_handler(param_t *param, ser_buff_t *b, op_mode enable_or_disab
return 0;
}

extern void
parse_file(char *file_name);

int
load_file_handler(param_t *param, ser_buff_t *b, op_mode enable_or_disable){

char *file_name = NULL;
tlv_struct_t *tlv = NULL;

TLV_LOOP_BEGIN(b, tlv) {

if (strncmp(tlv->leaf_id, "file-name",
strlen("file-name")) == 0) {

file_name = tlv->value;
}
} TLV_LOOP_END;

assert(file_name);

parse_file(file_name);
return 0;
}

int
negate_callback(param_t *param, ser_buff_t *b, op_mode enable_or_disable){
printf("Command Negation - Type the cmd following to Negate\n");
Expand Down Expand Up @@ -358,7 +382,8 @@ show_help_handler(param_t *param, ser_buff_t *b, op_mode enable_or_disable){
printf(" f. debug show cmdtree - Show entire command tree\n");
printf(" g. show history - show history of commands triggered\n");
printf(" h. repeat - repeat the last command\n");
printf(ANSI_COLOR_YELLOW " Author : Abhishek Sagar, Juniper Networks\n" ANSI_COLOR_RESET);
printf(ANSI_COLOR_YELLOW " Author : Abhishek Sagar, Juniper Networks\n" ANSI_COLOR_RESET);
printf(ANSI_COLOR_YELLOW " Visit : www.csepracticals.com for more courses and projects\n" ANSI_COLOR_RESET);
return 0;
}

Expand Down
18 changes: 15 additions & 3 deletions CommandParser/cmd_hier.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ parse_input_cmd(char *input, unsigned int len);
extern void
place_console(char new_line);

extern int
load_file_handler(param_t *param, ser_buff_t *b, op_mode enable_or_disable);

void
libcli_register_display_callback(param_t *param,
display_possible_values_callback disp_callback){
Expand Down Expand Up @@ -307,6 +310,15 @@ init_libcli(){
init_param(&config, CMD, "config", config_mode_enter_handler, 0, INVALID, 0, "config cmds");
libcli_register_param(&root, &config);

static param_t load;
init_param(&load, CMD, "load", 0, 0, INVALID, 0, "load cmds");
libcli_register_param(&config, &load);

static param_t file_name;
init_param(&file_name, LEAF, 0, load_file_handler, 0, STRING, "file-name", "Name of the file");
libcli_register_param(&load, &file_name);
set_param_cmd_code(&file_name, CONFIG_LOAD_FILE);

static param_t supportsave;
init_param(&supportsave, CMD, "supportsave", 0 , 0, INVALID, 0, "Collect Support Save Data");
libcli_register_param(&config, &supportsave);
Expand Down Expand Up @@ -407,7 +419,7 @@ init_param(param_t *param, /* pointer to static pa
else if(param_type == NO_CMD){
GET_PARAM_CMD(param) = calloc(1, sizeof(cmd_t));
param->param_type = NO_CMD;
strncpy(GET_CMD_NAME(param), NEGATE_CHARACTER, strlen(NEGATE_CHARACTER));
memcpy(GET_CMD_NAME(param), NEGATE_CHARACTER, strlen(NEGATE_CHARACTER));
GET_CMD_NAME(param)[CMD_NAME_SIZE -1] = '\0';
}

Expand Down Expand Up @@ -465,7 +477,7 @@ support_cmd_negation(param_t *param){
}
break;
}

assert(i <= CHILDREN_END_INDEX);
param->options[i] = no_param;
no_param->parent = param;
Expand Down Expand Up @@ -625,7 +637,7 @@ go_one_level_up_cmd_tree(param_t *curr_cmd_tree_cursor){

if(IS_PARAM_LEAF(curr_cmd_tree_cursor)){
memset(GET_LEAF_VALUE_PTR(curr_cmd_tree_cursor), 0, LEAF_VALUE_HOLDER_SIZE);
serialize_buffer_skip(tlv_buff, -1 * sizeof(tlv_struct_t));/*Rewind*/
serialize_buffer_skip(tlv_buff, -1 * (int)sizeof(tlv_struct_t));/*Rewind*/
mark_checkpoint_serialize_buffer(tlv_buff);
}

Expand Down
6 changes: 5 additions & 1 deletion CommandParser/cmdtlv.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ typedef struct tlv_struct{
strncpy(tlvptr->leaf_id, leaf->leaf_id, MIN(LEAF_ID_SIZE, strlen(leaf->leaf_id)));

#define put_value_in_tlv(tlvptr, _val) \
strncpy(tlvptr->value, _val, MIN(LEAF_VALUE_HOLDER_SIZE, strlen(_val)));
{ \
const char *temp = _val; \
memcpy(tlvptr->value, temp, MIN(LEAF_VALUE_HOLDER_SIZE, strlen(temp))); \
}

static inline void
print_tlv_content(tlv_struct_t *tlv){
Expand Down Expand Up @@ -96,4 +99,5 @@ swap_tlv_units(tlv_struct_t *tlv1, tlv_struct_t *tlv2){
*tlv1 = *tlv2;
*tlv2 = tlv;
}

#endif /* __CMDTLV__H */
Loading

0 comments on commit 64abd80

Please sign in to comment.