Skip to content

Commit

Permalink
Fix runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffMboya committed Jan 16, 2025
1 parent f3d03c6 commit 0b32764
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
22 changes: 9 additions & 13 deletions embed-proplet/src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ static const struct json_obj_descr registry_response_descr[] = {
JSON_OBJ_DESCR_PRIM(struct registry_response, data, JSON_TOK_STRING),
};

static struct chunk_tracker *app_chunk_tracker = NULL;

static void prepare_fds(struct mqtt_client *client)
{
if (client->transport.type == MQTT_TRANSPORT_NON_SECURE) {
Expand Down Expand Up @@ -531,14 +529,14 @@ void publish_results(const char *channel_id, const char *task_id, const char *re
}
}

void handle_registry_response(const char *payload) {
int handle_registry_response(const char *payload) {
struct registry_response resp;
int ret;

ret = json_obj_parse((char *)payload, strlen(payload), registry_response_descr, ARRAY_SIZE(registry_response_descr), &resp);
if (ret < 0) {
LOG_ERR("Failed to parse registry response, error: %d", ret);
return;
return -1;
}

LOG_INF("Registry response received:");
Expand All @@ -548,27 +546,25 @@ void handle_registry_response(const char *payload) {
uint8_t *binary_data = malloc(decoded_len);
if (!binary_data) {
LOG_ERR("Failed to allocate memory for decoded binary");
return;
return -1;
}

size_t binary_data_len = decoded_len;
ret = base64_decode(binary_data, decoded_len, &binary_data_len, (const uint8_t *)resp.data, strlen(resp.data));
if (ret < 0) {
LOG_ERR("Failed to decode Base64 data, error: %d", ret);
free(binary_data);
return;
return -1;
}

LOG_INF("Successfully decoded Wasm binary. Executing now...");

ret = execute_wasm_from_memory(binary_data, binary_data_len);
if (ret < 0) {
LOG_ERR("Failed to execute Wasm binary, error: %d", ret);
} else {
LOG_INF("Wasm binary executed successfully");
}

execute_wasm_module(binary_data, binary_data_len);
free(binary_data);

LOG_INF("Wasm binary executed");

return 0;
}

void mqtt_client_process(void)
Expand Down
2 changes: 1 addition & 1 deletion embed-proplet/src/mqtt_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ void handle_stop_command(const char *payload);
*
* @param payload The JSON payload containing the chunk details.
*/
void handle_registry_response(const char *payload);
int handle_registry_response(const char *payload);

#endif /* MQTT_CLIENT_H */
2 changes: 1 addition & 1 deletion embed-proplet/src/wasm_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

LOG_MODULE_REGISTER(wasm_handler);

void execute_wasm_from_memory(const uint8_t *wasm_data, size_t wasm_size)
void execute_wasm_module(const uint8_t *wasm_data, size_t wasm_size)
{
RuntimeInitArgs init_args = { .mem_alloc_type = Alloc_With_System_Allocator };
if (!wasm_runtime_full_init(&init_args)) {
Expand Down
2 changes: 1 addition & 1 deletion embed-proplet/src/wasm_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* @param wasm_data Pointer to the Wasm file data in memory.
* @param wasm_size Size of the Wasm file data in bytes.
*/
void execute_wasm_from_memory(const uint8_t *wasm_data, size_t wasm_size);
void execute_wasm_module(const uint8_t *wasm_data, size_t wasm_size);

#endif /* WASM_HANDLER_H */

0 comments on commit 0b32764

Please sign in to comment.