Skip to content

Commit

Permalink
fw: change golioth_fw_report_state() API to be synchronous
Browse files Browse the repository at this point in the history
This API does not take any callback, which means that it is not possible to
handle any communication errors or error responses from server. The main
reason why its implementation used golioth_coap_req_cb() (in [1]) was to
reduce breaking changes by allowing users to call this API from
system_client thread (which is not possible for synchronous APIs).

As right now samples/dfu/ has been updated to report FW state (i.e. call
golioth_fw_report_state() API) from main application thread, there is
little reason to keep golioth_fw_report_state() asynchronous.

If asynchronous API will be required in future, then such API would need to
take callback argument similar to other services (like LightDB and LightDB
Stream). Such API is not introduced now, as that would either require
second DFU sample with a slightly different flow or alternatively unit
tests for this new callback-based API.

[1] commit a540099 ("fw: rework on top of 'coap_req'")

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
  • Loading branch information
mniestroj committed Oct 19, 2022
1 parent 1660ba7 commit ef37756
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions net/golioth/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,6 @@ int golioth_fw_download(struct golioth_client *client,
return err;
}

static int golioth_fw_report_state_cb(struct golioth_req_rsp *rsp)
{
if (rsp->err) {
LOG_ERR("Failed to report FW state: %d", rsp->err);
} else {
LOG_INF("Successfully reported FW state");
}

return 0;
}

int golioth_fw_report_state(struct golioth_client *client,
const char *package_name,
const char *current_version,
Expand Down Expand Up @@ -224,10 +213,10 @@ int golioth_fw_report_state(struct golioth_client *client,
return qcbor_error_to_posix(qerr);
}

return golioth_coap_req_cb(client, COAP_METHOD_POST,
PATHV(GOLIOTH_FW_REPORT_STATE, package_name),
GOLIOTH_CONTENT_FORMAT_APP_CBOR,
encode_bufc.ptr, encoded_len,
golioth_fw_report_state_cb, NULL,
0);
return golioth_coap_req_sync(client, COAP_METHOD_POST,
PATHV(GOLIOTH_FW_REPORT_STATE, package_name),
GOLIOTH_CONTENT_FORMAT_APP_CBOR,
encode_bufc.ptr, encoded_len,
NULL, NULL,
0);
}

0 comments on commit ef37756

Please sign in to comment.