Skip to content

Commit 5cd8185

Browse files
author
daniel
committed
introduce hal_export_functf() similar to hal_*_newf() function family
1 parent 2217582 commit 5cd8185

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/hal/hal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,14 @@ extern int hal_get_param_value_by_name(
739739
extern int hal_export_funct(const char *name, void (*funct) (void *, long),
740740
void *arg, int uses_fp, int reentrant, int comp_id);
741741

742+
/** hal_export_functf is similar to hal_export_funct except that it also does
743+
printf-style formatting to compute the function name.
744+
If successful, it returns 0.
745+
On failure it returns a negative error code.
746+
*/
747+
extern int hal_export_functf(void (*funct) (void *, long),
748+
void *arg, int uses_fp, int reentrant, int comp_id, const char *fmt, ...);
749+
742750
/** hal_create_thread() establishes a realtime thread that will
743751
execute one or more HAL functions periodically.
744752
'name' is the name of the thread, which must be unique in

src/hal/hal_lib.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,32 @@ int hal_get_param_value_by_name(
18781878

18791879
#ifdef RTAPI
18801880

1881+
static int hal_export_functfv(void (*funct) (void *, long),
1882+
void *arg, int uses_fp, int reentrant, int comp_id, const char *fmt, va_list ap)
1883+
{
1884+
char name[HAL_NAME_LEN + 1];
1885+
int sz;
1886+
sz = rtapi_vsnprintf(name, sizeof(name), fmt, ap);
1887+
if(sz == -1 || sz > HAL_NAME_LEN) {
1888+
rtapi_print_msg(RTAPI_MSG_ERR,
1889+
"hal_export_functfv: length %d too long for name starting '%s'\n",
1890+
sz, name);
1891+
return -ENOMEM;
1892+
}
1893+
return hal_export_funct(name, funct, arg, uses_fp, reentrant, comp_id);
1894+
}
1895+
1896+
int hal_export_functf(void (*funct) (void *, long),
1897+
void *arg, int uses_fp, int reentrant, int comp_id, const char *fmt, ...)
1898+
{
1899+
va_list ap;
1900+
int ret;
1901+
va_start(ap, fmt);
1902+
ret = hal_export_functfv(funct, arg, uses_fp, reentrant, comp_id, fmt, ap);
1903+
va_end(ap);
1904+
return ret;
1905+
}
1906+
18811907
int hal_export_funct(const char *name, void (*funct) (void *, long),
18821908
void *arg, int uses_fp, int reentrant, int comp_id)
18831909
{
@@ -4361,6 +4387,7 @@ EXPORT_SYMBOL(hal_param_set);
43614387
EXPORT_SYMBOL(hal_set_constructor);
43624388

43634389
EXPORT_SYMBOL(hal_export_funct);
4390+
EXPORT_SYMBOL(hal_export_functf);
43644391

43654392
EXPORT_SYMBOL(hal_create_thread);
43664393

0 commit comments

Comments
 (0)