libamxp
1.4.0
Patterns C Implementation
|
Data Structures | |
struct | _amxp_proc_ctrl |
Structure containing the child process control. More... | |
Typedefs | |
typedef int(* | amxp_proc_ctrl_cmd_t) (amxc_array_t *cmd, amxc_var_t *settings) |
Command builder callback function signature. More... | |
typedef struct _amxp_proc_ctrl | amxp_proc_ctrl_t |
Structure containing the child process control. More... | |
Functions | |
int | amxp_proc_ctrl_new (amxp_proc_ctrl_t **proc, amxp_proc_ctrl_cmd_t cmd_build_fn) |
Allocates and initializes an amxp_proc_ctrl_t. More... | |
void | amxp_proc_ctrl_delete (amxp_proc_ctrl_t **proc) |
Clean-up and frees previously allocated memory. More... | |
int | amxp_proc_ctrl_start (amxp_proc_ctrl_t *proc, uint32_t minutes, amxc_var_t *settings) |
Launches the child process. More... | |
int | amxp_proc_ctrl_stop (amxp_proc_ctrl_t *proc) |
Stops the child process. More... | |
void | amxp_proc_ctrl_set_active_duration (amxp_proc_ctrl_t *proc, uint32_t minutes) |
Sets the active time durations. More... | |
void | amxp_proc_ctrl_stop_childs (amxp_proc_ctrl_t *proc) |
Stop all child processes of the child process. More... | |
int | amxp_proc_ctrl_get_child_pids (amxp_proc_ctrl_t *proc) |
Fetches the process ids of the children of the launched child process. More... | |
Child Process Control and monitor
typedef int(* amxp_proc_ctrl_cmd_t) (amxc_array_t *cmd, amxc_var_t *settings) |
Command builder callback function signature.
A callback function is used to build the command that must be launched.
In the callback function a configuration file can be built.
An array must be filled with the command and the command arguments.
Definition at line 87 of file amxp_proc_ctrl.h.
typedef struct _amxp_proc_ctrl amxp_proc_ctrl_t |
Structure containing the child process control.
void amxp_proc_ctrl_delete | ( | amxp_proc_ctrl_t ** | proc | ) |
Clean-up and frees previously allocated memory.
Each allocated amxp_proc_trl_t structure with amxp_proc_ctrl_new must be freed when not needed anymore using this function.
proc | pointer to previously allocated amxp_proc_ctrl_t struct, will be set to NULL. |
Definition at line 201 of file amxp_proc_ctrl.c.
int amxp_proc_ctrl_get_child_pids | ( | amxp_proc_ctrl_t * | proc | ) |
Fetches the process ids of the children of the launched child process.
The list of found process ids is stored in the amxp_proc_ctrl_t structure.
The function returns the number of children found.
Two methods are used to find the list of children:
proc | pointer to amxp_proc_trl_t structure, previously allocated with amxp_proc_ctrl_new |
Definition at line 294 of file amxp_proc_ctrl.c.
int amxp_proc_ctrl_new | ( | amxp_proc_ctrl_t ** | proc, |
amxp_proc_ctrl_cmd_t | cmd_build_fn | ||
) |
Allocates and initializes an amxp_proc_ctrl_t.
Allocates memory on the heap for an amxp_proc_ctrl_t structure and initializes it.
The pointer to the allocated memory will be stored in the proc argument. The *proc must be initialized to NULL before calling this function.
To free all allocated memory use amxp_proc_ctrl_delete.
proc | will be filled with the pointer to the new allocated amxp_proc_ctrl_t structure |
cmd_build_fn | callback function that fills the command array |
Definition at line 170 of file amxp_proc_ctrl.c.
void amxp_proc_ctrl_set_active_duration | ( | amxp_proc_ctrl_t * | proc, |
uint32_t | minutes | ||
) |
Sets the active time durations.
Sets or changes the active duration.
If the process was already started with an active time (see amxp_proc_ctrl_start), the running timer is stopped and restarted with the new provided time.
If the process was running without an active time set, the timer is started with the given time and the child process will be stopped when the timer expires.
When the new time is set to 0 the timer is stopped and the child process will keep running until stopped manually.
proc | pointer to amxp_proc_ctrl_t structure, previously allocated with amxp_proc_ctrl_new |
minutes | new active time |
Definition at line 264 of file amxp_proc_ctrl.c.
int amxp_proc_ctrl_start | ( | amxp_proc_ctrl_t * | proc, |
uint32_t | minutes, | ||
amxc_var_t * | settings | ||
) |
Launches the child process.
Will call the amxp_proc_ctrl_cmd_t callback function. That callback function must fill the command array. The provided variant containing child process settings will be passed to the callback function as is.
When an active time is provided in the argument minutes, a timer is started. When the timer expires, the launched process is stopped.
When the time in minutes is set to 0, no timer is started and the child process will keep runnning until stopped.
proc | pointer to amxp_proc_ctrl_t structure, previously allocated with amxp_proc_ctrl_new |
minutes | time in minutes the launched process can keep running |
settings | a variant containing settings, passed to the callback function as is. |
Definition at line 220 of file amxp_proc_ctrl.c.
int amxp_proc_ctrl_stop | ( | amxp_proc_ctrl_t * | proc | ) |
Stops the child process.
Stops the child process and the children of the child process.
proc | pointer to amxp_proc_trl_t structure, previously allocated with amxp_proc_ctrl_new |
Definition at line 242 of file amxp_proc_ctrl.c.
void amxp_proc_ctrl_stop_childs | ( | amxp_proc_ctrl_t * | proc | ) |
Stop all child processes of the child process.
A child process monitored with the amxp_proc_ctrl can launch its own children. These child processes can be stopped using this function.
proc | pointer to amxp_proc_trl_t structure, previously allocated with amxp_proc_ctrl_new |
Definition at line 280 of file amxp_proc_ctrl.c.