Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
blaar
blibs
blc_program
Commits
3f05a49c
Commit
3f05a49c
authored
May 15, 2019
by
Arnaud Blanchard
Browse files
Update few funcitons for compatibility with old apps
parent
89991b1e
Changes
5
Hide whitespace changes
Inline
Side-by-side
include/blc_command.h
View file @
3f05a49c
...
...
@@ -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
...
...
include/blc_program.h
View file @
3f05a49c
...
...
@@ -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).
...
...
src/blc_command.cpp
View file @
3f05a49c
...
...
@@ -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
;
...
...
src/blc_loop.cpp
View file @
3f05a49c
...
...
@@ -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
;
}
src/blc_program.cpp
View file @
3f05a49c
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment