Skip to content

Commit

Permalink
hawkbit-client/rauc-hawkbit-updater: Confirmation implementaion
Browse files Browse the repository at this point in the history
Initial implementation of Hawkbit's confirmationBase end point. This
version allows to send a request to a custon user backend/software,
which is supposed to implement RaucInstallConfirmation DBus interface
and be capable to make a decision whether an installation of new version
is possible/desired at the moment and accept or decline it.

See
https://eclipse.dev/hawkbit/rest-api/rootcontroller-api-guide.html#_get_tenantcontrollerv1controlleridconfirmationbase
for more into on the API end point.

Signed-off-by: Vyacheslav Yurkov <[email protected]>
  • Loading branch information
UVV-gh committed Sep 4, 2023
1 parent 056b327 commit 359aba3
Show file tree
Hide file tree
Showing 3 changed files with 341 additions and 4 deletions.
57 changes: 56 additions & 1 deletion include/hawkbit-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ enum ActionState {
ACTION_STATE_CANCEL_REQUESTED,
};

enum ConfirmationState {
CONFIRMATION_STATE_NONE,
CONFIRMATION_STATE_REQUESTED,
CONFIRMATION_STATE_CONFIRMED,
CONFIRMATION_STATE_DENIED,
};

/**
* @brief struct that contains the context of an HawkBit action.
*/
Expand All @@ -72,6 +79,16 @@ struct HawkbitAction {
GCond cond; /**< condition on state */
};

/**
* @brief struct that contains the context of a confirmation action.
*/
struct ConfirmationAction {
gchar *id; /**< HawkBit action id */
GMutex mutex; /**< mutex used for synchronization of the state */
GCond cond; /**< condition on confirmation */
enum ConfirmationState state; /**< current confirmation state */
};

/**
* @brief struct containing the payload and size of REST body.
*/
Expand All @@ -94,6 +111,14 @@ typedef struct Artifact_ {
gboolean do_install; /**< whether the installation should be started or not */
} Artifact;

/**
* @brief struct used to store active confirmation info
*/
typedef struct Confirmation_ {
gchar *action_id; /**< Hawkbit's ID of the request */
gchar *version; /**< software version */
} Confirmation;

/**
* @brief struct containing the new downloaded file.
*/
Expand All @@ -113,15 +138,37 @@ struct on_install_complete_userdata {
gboolean install_success; /**< status of installation */
};

/**
* @brief struct containing a confirmation request.
*/
struct on_install_confirmation_request_userdata {
GSourceFunc response_callback; /**< callback function to be called when response is received */
gchar *action_id; /**< Hawkbit's ID of the request */
gchar *version; /**< software version */
};

/**
* @brief struct containing a confirmation response from a user software
*/
struct on_install_confirmed_userdata {
gchar *action_id; /**< Hawkbit's ID of the request */
gboolean confirmed; /**< True - confirmed, False - denied */
gchar *details; /**< Explanation about confirmation status (if any) */
gint error_code; /**< Code to be returned to Hawkbit */
};

/**
* @brief Pass config, callback for installation ready and initialize libcurl.
* Intended to be called from program's main().
*
* @param[in] config Config* to make global
* @param[in] on_install_ready GSourceFunc to call after artifact download, to
* trigger RAUC installation
* @param[in] on_install_confirm GSourceFunc to call when confirmation status
* is received from a user
*/
void hawkbit_init(Config *config, GSourceFunc on_install_ready);
void hawkbit_init(Config *config, GSourceFunc on_install_ready,
GSourceFunc on_install_confirmed);

/**
* @brief Sets up timeout and event sources, initializes and runs main loop.
Expand Down Expand Up @@ -161,7 +208,15 @@ void rest_payload_free(RestPayload *payload);
*/
void artifact_free(Artifact *artifact);

/**
* @brief Frees the memory allocated by a Confirmation
*
* @param[in] confirmation Confirmation to free
*/
void confirmation_free(Confirmation *confirmation);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(RestPayload, rest_payload_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(Artifact, artifact_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(Confirmation, confirmation_free)

#endif // __HAWKBIT_CLIENT_H__
Loading

0 comments on commit 359aba3

Please sign in to comment.