From e7f67702008135f8f7c14e8c8a4c7f4401412ecf Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Thu, 28 Sep 2023 23:55:41 +0200 Subject: [PATCH] client: allow applications to trigger works --- add-ons/src/mender-configure.c | 14 ++++++++++++++ add-ons/src/mender-inventory.c | 14 ++++++++++++++ core/src/mender-client.c | 14 ++++++++++++++ include/mender-client.h | 24 ++++++++++++++++-------- include/mender-configure.h | 10 +++++++++- include/mender-inventory.h | 10 +++++++++- include/mender-rtos.h | 4 ++-- include/mender-troubleshoot.h | 2 +- 8 files changed, 79 insertions(+), 13 deletions(-) mode change 100644 => 100755 core/src/mender-client.c mode change 100755 => 100644 include/mender-client.h mode change 100755 => 100644 include/mender-rtos.h diff --git a/add-ons/src/mender-configure.c b/add-ons/src/mender-configure.c index 5e20612..725584b 100755 --- a/add-ons/src/mender-configure.c +++ b/add-ons/src/mender-configure.c @@ -213,6 +213,20 @@ mender_configure_set(mender_keystore_t *configuration) { return ret; } +mender_err_t +mender_configure_execute(void) { + + mender_err_t ret; + + /* Trigger execution of the work */ + if (MENDER_OK != (ret = mender_rtos_work_execute(mender_configure_work_handle))) { + mender_log_error("Unable to trigger configure work"); + return ret; + } + + return MENDER_OK; +} + mender_err_t mender_configure_exit(void) { diff --git a/add-ons/src/mender-inventory.c b/add-ons/src/mender-inventory.c index 2e8806a..fff9fc5 100755 --- a/add-ons/src/mender-inventory.c +++ b/add-ons/src/mender-inventory.c @@ -138,6 +138,20 @@ mender_inventory_set(mender_keystore_t *inventory) { return ret; } +mender_err_t +mender_inventory_execute(void) { + + mender_err_t ret; + + /* Trigger execution of the work */ + if (MENDER_OK != (ret = mender_rtos_work_execute(mender_inventory_work_handle))) { + mender_log_error("Unable to trigger inventory work"); + return ret; + } + + return MENDER_OK; +} + mender_err_t mender_inventory_exit(void) { diff --git a/core/src/mender-client.c b/core/src/mender-client.c old mode 100644 new mode 100755 index 83988ec..ca0f59d --- a/core/src/mender-client.c +++ b/core/src/mender-client.c @@ -247,6 +247,20 @@ mender_client_init(mender_client_config_t *config, mender_client_callbacks_t *ca return ret; } +mender_err_t +mender_client_execute(void) { + + mender_err_t ret; + + /* Trigger execution of the work */ + if (MENDER_OK != (ret = mender_rtos_work_execute(mender_client_work_handle))) { + mender_log_error("Unable to trigger update work"); + return ret; + } + + return MENDER_OK; +} + mender_err_t mender_client_exit(void) { diff --git a/include/mender-client.h b/include/mender-client.h old mode 100755 new mode 100644 index 4852927..401f65e --- a/include/mender-client.h +++ b/include/mender-client.h @@ -38,14 +38,14 @@ extern "C" { * @brief Mender client configuration */ typedef struct { - char * mac_address; /**< MAC address of the device */ - char * artifact_name; /**< Artifact name */ - char * device_type; /**< Device type */ - char * host; /**< URL of the mender server */ - char * tenant_token; /**< Tenant token used to authenticate on the mender server (optional) */ - uint32_t authentication_poll_interval; /**< Authentication poll interval, default is 60 seconds */ - uint32_t update_poll_interval; /**< Update poll interval, default is 1800 seconds */ - bool recommissioning; /**< Used to force creation of new authentication keys */ + char * mac_address; /**< MAC address of the device */ + char * artifact_name; /**< Artifact name */ + char * device_type; /**< Device type */ + char * host; /**< URL of the mender server */ + char * tenant_token; /**< Tenant token used to authenticate on the mender server (optional) */ + int32_t authentication_poll_interval; /**< Authentication poll interval, default is 60 seconds, -1 permits to disable periodic execution */ + int32_t update_poll_interval; /**< Update poll interval, default is 1800 seconds, -1 permits to disable periodic execution */ + bool recommissioning; /**< Used to force creation of new authentication keys */ } mender_client_config_t; /** @@ -71,6 +71,14 @@ typedef struct { */ mender_err_t mender_client_init(mender_client_config_t *config, mender_client_callbacks_t *callbacks); +/** + * @brief Function used to trigger execution of the authentication and update work + * @note Calling this function is optional when the periodic execution of the work is configured + * @note It only permits to execute the work as soon as possible to synchronize updates + * @return MENDER_OK if the function succeeds, error code otherwise + */ +mender_err_t mender_client_execute(void); + /** * @brief Release mender client * @return MENDER_OK if the function succeeds, error code otherwise diff --git a/include/mender-configure.h b/include/mender-configure.h index 4a645c0..b0d2460 100755 --- a/include/mender-configure.h +++ b/include/mender-configure.h @@ -40,7 +40,7 @@ extern "C" { * @brief Mender configure configuration */ typedef struct { - uint32_t refresh_interval; /**< Configure refresh interval, default is 28800 seconds */ + int32_t refresh_interval; /**< Configure refresh interval, default is 28800 seconds, -1 permits to disable periodic execution */ } mender_configure_config_t; /** @@ -80,6 +80,14 @@ mender_err_t mender_configure_get(mender_keystore_t **configuration); */ mender_err_t mender_configure_set(mender_keystore_t *configuration); +/** + * @brief Function used to trigger execution of the configure work + * @note Calling this function is optional when the periodic execution of the work is configured + * @note It only permits to execute the work as soon as possible to synchronize configuration + * @return MENDER_OK if the function succeeds, error code otherwise + */ +mender_err_t mender_configure_execute(void); + /** * @brief Release mender configure add-on * @return MENDER_OK if the function succeeds, error code otherwise diff --git a/include/mender-inventory.h b/include/mender-inventory.h index f14916c..e0b753f 100755 --- a/include/mender-inventory.h +++ b/include/mender-inventory.h @@ -40,7 +40,7 @@ extern "C" { * @brief Mender inventory configuration */ typedef struct { - uint32_t refresh_interval; /**< Inventory refresh interval, default is 28800 seconds */ + int32_t refresh_interval; /**< Inventory refresh interval, default is 28800 seconds, -1 permits to disable periodic execution */ } mender_inventory_config_t; /** @@ -63,6 +63,14 @@ mender_err_t mender_inventory_activate(void); */ mender_err_t mender_inventory_set(mender_keystore_t *inventory); +/** + * @brief Function used to trigger execution of the inventory work + * @note Calling this function is optional when the periodic execution of the work is configured + * @note It only permits to execute the work as soon as possible to synchronize inventory + * @return MENDER_OK if the function succeeds, error code otherwise + */ +mender_err_t mender_inventory_execute(void); + /** * @brief Release mender inventory add-on * @return MENDER_OK if the function succeeds, error code otherwise diff --git a/include/mender-rtos.h b/include/mender-rtos.h old mode 100755 new mode 100644 index 3d50e56..42f7fa0 --- a/include/mender-rtos.h +++ b/include/mender-rtos.h @@ -39,8 +39,8 @@ extern "C" { */ typedef struct { mender_err_t (*function)(void); /**< Work function */ - uint32_t period; /**< Work period (seconds), null value permits to disable periodic execution */ - char * name; /**< Work name */ + int32_t period; /**< Work period (seconds), negative or null value permits to disable periodic execution */ + char * name; /**< Work name */ } mender_rtos_work_params_t; /** diff --git a/include/mender-troubleshoot.h b/include/mender-troubleshoot.h index 8d3009c..4e21fb7 100644 --- a/include/mender-troubleshoot.h +++ b/include/mender-troubleshoot.h @@ -40,7 +40,7 @@ extern "C" { * @brief Mender troubleshoot configuration */ typedef struct { - uint32_t healthcheck_interval; /**< Troubleshoot healthcheck interval, default is 30 seconds */ + int32_t healthcheck_interval; /**< Troubleshoot healthcheck interval, default is 30 seconds, -1 permits to disable periodic execution */ } mender_troubleshoot_config_t; /**