libamxp
1.4.0
Patterns C Implementation
|
Data Structures | |
struct | _cron_expr |
Structure containing parsed cron expression. More... | |
Typedefs | |
typedef struct _cron_expr | amxp_cron_expr_t |
Structure containing parsed cron expression. More... | |
Functions | |
int | amxp_cron_new (amxp_cron_expr_t **cron_expr) |
Allocates an amxp_cron_expr_t structures and initializes it to every second. More... | |
void | amxp_cron_delete (amxp_cron_expr_t **cron_expr) |
Frees the previously allocated amxp_cron_expr_t structure. More... | |
int | amxp_cron_init (amxp_cron_expr_t *cron_expr) |
Initializes an amxp_cron_expr_t structures to every second. More... | |
void | amxp_cron_clean (amxp_cron_expr_t *cron_expr) |
Resets the amxp_cron_expr_t structure to the initialized state. More... | |
int | amxp_cron_parse_expr (amxp_cron_expr_t *target, const char *expression, const char **error) |
Allocates and initializes an amxp_cron_expr_t structures and parses the given cron expression. More... | |
int | amxp_cron_build_weekly (amxp_cron_expr_t *target, const char *time, const char *days_of_week) |
Builds a weekly cron expression that is triggered at a certain time on certain days of the week. More... | |
int | amxp_cron_prev (const amxp_cron_expr_t *expr, const amxc_ts_t *ref, amxc_ts_t *next) |
Calculates the previous trigger time for a parsed cron expression. More... | |
int | amxp_cron_next (const amxp_cron_expr_t *expr, const amxc_ts_t *ref, amxc_ts_t *next) |
Calculates the next trigger time for a parsed cron expression. More... | |
int64_t | amxp_cron_time_until_next (const amxp_cron_expr_t *expr, bool local) |
Calculates the time in seconds until next trigger of a parsed cron expression occurs. More... | |
Ambiorix cron expression parser.
typedef struct _cron_expr amxp_cron_expr_t |
Structure containing parsed cron expression.
This structure contains a member for each cron expression field. Each member will have bits set. Each set bit indicates an active position in time for which the cron expression can be trigger.
int amxp_cron_build_weekly | ( | amxp_cron_expr_t * | target, |
const char * | time, | ||
const char * | days_of_week | ||
) |
Builds a weekly cron expression that is triggered at a certain time on certain days of the week.
Passing the time "15:10" and list of week days "saterday, sunday" will build the cron expression "0 10 15 * * SAT,SUN" and initializes the provided amxp_cron_expr_t structure with it.
The time must be provided in "HH:MM:SS" format, The seconds are optional, when not provided the seconds will be set to "00".
The days of week argument must be a comma separated list of week day names:
The name of the days is case insensitive. It is allowed to provide a range like "monday-friday".
target | pointer to amxp_cron_expr_t. |
time | a string containing the time in "HH:MM:SS" format, seconds are optional. |
days_of_week | comma separated list of week days or a range of week days. |
Definition at line 531 of file amxp_cron.c.
void amxp_cron_clean | ( | amxp_cron_expr_t * | cron_expr | ) |
Resets the amxp_cron_expr_t structure to the initialized state.
Resets the amxp_cron_expr_t structure to the "* * * * * *" cron expression.
cron_expr | pointer to an amxp_cron_expr_t structure |
Definition at line 477 of file amxp_cron.c.
void amxp_cron_delete | ( | amxp_cron_expr_t ** | cron_expr | ) |
Frees the previously allocated amxp_cron_expr_t structure.
Frees the allocated memory and sets the pointer to NULL.
cron_expr | pointer to a pointer that points to the allocated amxp_cron_expr_t structure |
Definition at line 453 of file amxp_cron.c.
int amxp_cron_init | ( | amxp_cron_expr_t * | cron_expr | ) |
Initializes an amxp_cron_expr_t structures to every second.
This function initializes a amxp_cron_expr_t structure using following cron expression "* * * * * *". This cron expression triggers every second.
Call amxp_cron_parse_expr to set another schedule for the cron expression.
cron_expr | pointer to a amxp_cron_expr_t structure that must be initialized. |
Definition at line 466 of file amxp_cron.c.
int amxp_cron_new | ( | amxp_cron_expr_t ** | cron_expr | ) |
Allocates an amxp_cron_expr_t structures and initializes it to every second.
This function allocates memory on the heap for an amxp_cron_expr_t structure and initializes it using following cron expression "* * * * * *". This cron expression triggers every second.
Call amxp_cron_parse_expr to set another schedule for the cron expression.
cron_expr | pointer to a pointer that points to the new allocated amxp_cron_expr_t structure |
Definition at line 440 of file amxp_cron.c.
int amxp_cron_next | ( | const amxp_cron_expr_t * | expr, |
const amxc_ts_t * | ref, | ||
amxc_ts_t * | next | ||
) |
Calculates the next trigger time for a parsed cron expression.
Given a parsed cron expression and a reference time, calculates the next trigger time for the cron expression.
Typically the reference time will be the current time.
Example:
Calling the above function will provide this output:
expr | A parsed cron expression. |
ref | The reference time. |
next | The calculated next trigger time. |
Definition at line 631 of file amxp_cron.c.
int amxp_cron_parse_expr | ( | amxp_cron_expr_t * | target, |
const char * | expression, | ||
const char ** | error | ||
) |
Allocates and initializes an amxp_cron_expr_t structures and parses the given cron expression.
This function allocates memory for an amxp_cron_expr_t structure. This memory must be freed when not needed anymore.
When an invalid expression is provided, no memory will be allocated and an error string is put in error.
A valid cron expression contains 6 fields:
Each field can contain a single value, a list of values, a range, and an incrementor.
To indicate all possible value for that field the * symbol can be used.
Months can be specified using ordinals: "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
Days of week can be specified using ordinals: "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"
When using "SUN" to indicate sunday, index 0 for the day of week will be used.
Examples:
target | pointer to amxp_cron_expr_t. |
expression | the cron expression that needs to be parsed. |
error | (optional) if provided a human readable error string will be placed here. |
Definition at line 486 of file amxp_cron.c.
int amxp_cron_prev | ( | const amxp_cron_expr_t * | expr, |
const amxc_ts_t * | ref, | ||
amxc_ts_t * | next | ||
) |
Calculates the previous trigger time for a parsed cron expression.
Given a parsed cron expression and a reference time, calculates the previous trigger time for the cron expression.
Typically the reference time will be the current time.
Example:
Calling the above function will provide this output:
expr | A parsed cron expression. |
ref | The reference time. |
next | The calculated next trigger time. |
Definition at line 588 of file amxp_cron.c.
int64_t amxp_cron_time_until_next | ( | const amxp_cron_expr_t * | expr, |
bool | local | ||
) |
Calculates the time in seconds until next trigger of a parsed cron expression occurs.
Calculates the time in seconds, from the current time until the next trigger of the parsed cron expression occurs.
When local is set to true, the local time is used, otherwise the UTC time is used.
expr | A parsed cron expression. |
local | Set to true to use local time. |
Definition at line 673 of file amxp_cron.c.