From 3f05a49cd5c25be5ff3ab8b4357fc1a351879192 Mon Sep 17 00:00:00 2001 From: Arnaud Blanchard <arnaud.blanchard@ensea.fr> Date: Wed, 15 May 2019 16:15:18 +0200 Subject: [PATCH] Update few funcitons for compatibility with old apps --- include/blc_command.h | 6 ++++++ include/blc_program.h | 1 + src/blc_command.cpp | 5 +++++ src/blc_loop.cpp | 10 ++++++++++ src/blc_program.cpp | 1 + 5 files changed, 23 insertions(+) diff --git a/include/blc_command.h b/include/blc_command.h index 84cc23d..d0da62c 100644 --- a/include/blc_command.h +++ b/include/blc_command.h @@ -28,6 +28,8 @@ Few functions helping for pseudo realtime applications. #include "blc_tools.h" +#define BLC_COMMAND_LOOP_THREAD() for(blc_command_loop_init(-2); blc_command_loop_start();blc_command_loop_end()) + /** period in microseconds 0 for system as fast as possible, -1 for blocking on keyborad, -2 blocking after first iteration. @@ -126,6 +128,10 @@ void blc_command_loop_init(long loop_period); int blc_command_loop_start(); void blc_command_loop_end(); +/**Wait until the blc_loop_stop. + Return the loop_thred pointer (always NULL for now)*/ +void *blc_loop_wait_stop(); + /** Stop a textual program * - Send a quitting message with the name of the app on stderr. * - Send 'q' and flush on stdout if it is a piped output diff --git a/include/blc_program.h b/include/blc_program.h index d6ced8b..3ab7eaa 100644 --- a/include/blc_program.h +++ b/include/blc_program.h @@ -29,6 +29,7 @@ #include "blc_core.h" #include "blc_command.h" + START_EXTERN_C ///Set the desciption of the program used for help. A copy of desciption is done (strdup). diff --git a/src/blc_command.cpp b/src/blc_command.cpp index 43751df..9fd6e79 100644 --- a/src/blc_command.cpp +++ b/src/blc_command.cpp @@ -33,6 +33,7 @@ #include "blc_tools.h" #include "blc_program.h" + //Identical to argparse in Python #define POSITIONAL_ARGUMENTS_TITLE "\npositional arguments:\n" #define OPTIONAL_ARGUMENTS_TITLE "\noptional arguments:\n" @@ -48,6 +49,7 @@ typedef struct void *user_data; }blc_command; + // Static means it is only existing in this file static blc_command *blc_commands = NULL; static int blc_commands_nb = 0; @@ -102,6 +104,7 @@ void blc_command_add(const char *command_name, type_blc_command_cb callback, con APPEND_ITEM(&blc_commands, &blc_commands_nb, &tmp_command); } + void blc_command_remove(const char *command_name){ int i; @@ -113,6 +116,8 @@ void blc_command_remove(const char *command_name){ REMOVE_ITEM_POSITION(&blc_commands, &blc_commands_nb, i); } + + void blc_command_interpret_string(char const *input_string, size_t size){ char const*parameter; char *parameter2; diff --git a/src/blc_loop.cpp b/src/blc_loop.cpp index 09f683b..dd895d0 100644 --- a/src/blc_loop.cpp +++ b/src/blc_loop.cpp @@ -14,8 +14,10 @@ struct timeval blc_loop_timer; static uint blc_period=0; static uint blc_duration=0; static uint blc_duration_min=UINT_MAX, blc_duration_max=0; + static long blc_current_duration; static int intermediate_iteration; + long blc_command_loop_period=-2; //unitialised uint64_t blc_loop_iteration_limit=UINT64_MAX; uint64_t blc_loop_iteration=0; @@ -190,6 +192,7 @@ static void *command_thread_interpret_loop(void *){ while(blc_status!=BLC_QUIT){ blc_command_interpret_block(); if (blc_command_loop_period==-1) BLC_PTHREAD_CHECK(pthread_mutex_unlock(&mutex_lock_keyboard), NULL); + //blc_command_interpret(); } return NULL; } @@ -229,6 +232,7 @@ void blc_command_loop_init(long loop_period){ int blc_command_loop_start(){ int continue_value; int i; + //We wait before counting the duration time as the time for waiting does not matter if (blc_profile_file) gettimeofday(&profile_timer, NULL); //this is only for profiling @@ -294,3 +298,9 @@ void blc_command_loop_end(){ intermediate_iteration++; blc_loop_iteration++; } + +void *blc_loop_wait_stop(){ + void *result; + SYSTEM_ERROR_CHECK(pthread_join(loop_thread, &result), -1, NULL); + return result; +} diff --git a/src/blc_program.cpp b/src/blc_program.cpp index 6202f18..627c3d2 100644 --- a/src/blc_program.cpp +++ b/src/blc_program.cpp @@ -176,6 +176,7 @@ static void blc_program_option_interpret(int *argc, char **argv[]) type_program_option *program_option; char pipe_name[PATH_MAX+1]; + blc_program_name = basename(*argv[0]); //We store enough room for all the optional letters + ':' + terminating null char optstring = MANY_ALLOCATIONS(blc_program_options_nb*2+1, char); -- GitLab