Skip to content

Commit

Permalink
port: GenMessageParseOk -> GenCallMessage
Browse files Browse the repository at this point in the history
Future proof #2: return the type of message instead of a generic Ok
value. Right now we support only calls.

Signed-off-by: Davide Bettio <davide@uninstall.it>
  • Loading branch information
bettio committed Dec 25, 2023
1 parent 28b374c commit 14197e2
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/libAtomVM/nifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ static NativeHandlerResult process_console_message(Context *ctx, term msg)
}
}

} else if (port_parse_gen_message(msg, &gen_message) == GenMessageParseOk) {
} else if (port_parse_gen_message(msg, &gen_message) == GenCallMessage) {
term pid = gen_message.pid;
term ref = gen_message.ref;
term cmd = gen_message.req;
Expand Down
2 changes: 1 addition & 1 deletion src/libAtomVM/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ enum GenMessageParseResult port_parse_gen_message(term msg, GenMessage *gen_mess
return GenMessageParseError;
}

return GenMessageParseOk;
return GenCallMessage;
}
2 changes: 1 addition & 1 deletion src/libAtomVM/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ typedef struct

enum GenMessageParseResult
{
GenMessageParseOk,
GenCallMessage,
GenMessageParseError
};

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/esp32/components/avm_builtins/gpio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ static NativeHandlerResult consume_gpio_mailbox(Context *ctx)
{
Message *message = mailbox_first(&ctx->mailbox);
GenMessage gen_message;
if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenMessageParseOk)) {
if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenCallMessage)) {
ESP_LOGW(TAG, "Received invalid message.");
mailbox_remove_message(&ctx->mailbox, &ctx->heap);
return NativeContinue;
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/esp32/components/avm_builtins/i2c_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ static NativeHandlerResult i2cdriver_consume_mailbox(Context *ctx)
{
Message *message = mailbox_first(&ctx->mailbox);
GenMessage gen_message;
if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenMessageParseOk)) {
if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenCallMessage)) {
ESP_LOGW(TAG, "Received invalid message.");
mailbox_remove_message(&ctx->mailbox, &ctx->heap);
return NativeContinue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ static NativeHandlerResult socket_consume_mailbox(Context *ctx)
}

GenMessage gen_message;
if (UNLIKELY((port_parse_gen_message(msg, &gen_message) != GenMessageParseOk)
if (UNLIKELY((port_parse_gen_message(msg, &gen_message) != GenCallMessage)
|| !term_is_tuple(gen_message.req) || term_get_tuple_arity(gen_message.req) < 1)) {
ESP_LOGW(TAG, "Received invalid message.");
mailbox_remove_message(&ctx->mailbox, &ctx->heap);
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/esp32/components/avm_builtins/spi_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ static NativeHandlerResult spidriver_consume_mailbox(Context *ctx)
{
Message *message = mailbox_first(&ctx->mailbox);
GenMessage gen_message;
if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenMessageParseOk)) {
if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenCallMessage)) {
ESP_LOGW(TAG, "Received invalid message.");
mailbox_remove_message(&ctx->mailbox, &ctx->heap);
return NativeContinue;
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/esp32/components/avm_builtins/uart_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ static NativeHandlerResult uart_driver_consume_mailbox(Context *ctx)
Message *message = mailbox_first(&ctx->mailbox);
term msg = message->message;
GenMessage gen_message;
if (UNLIKELY(port_parse_gen_message(msg, &gen_message) != GenMessageParseOk)) {
if (UNLIKELY(port_parse_gen_message(msg, &gen_message) != GenCallMessage)) {
ESP_LOGW(TAG, "Received invalid message.");
mailbox_remove_message(&ctx->mailbox, &ctx->heap);
return NativeContinue;
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/generic_unix/lib/socket_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ static NativeHandlerResult socket_consume_mailbox(Context *ctx)
}

GenMessage gen_message;
if (UNLIKELY((port_parse_gen_message(msg, &gen_message) != GenMessageParseOk)
if (UNLIKELY((port_parse_gen_message(msg, &gen_message) != GenCallMessage)
|| !term_is_tuple(gen_message.req) || term_get_tuple_arity(gen_message.req) < 1)) {
fprintf(stderr, "Received invalid socket message.\n");
mailbox_remove_message(&ctx->mailbox, &ctx->heap);
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/stm32/src/lib/gpio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ static NativeHandlerResult consume_gpio_mailbox(Context *ctx)
{
Message *message = mailbox_first(&ctx->mailbox);
GenMessage gen_message;
if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenMessageParseOk)
if (UNLIKELY(port_parse_gen_message(message->message, &gen_message) != GenCallMessage)
|| !term_is_tuple(gen_message.req) || term_get_tuple_arity(gen_message.req) < 1) {
AVM_LOGW(TAG, "Received invalid message.");
mailbox_remove_message(&ctx->mailbox, &ctx->heap);
Expand Down

0 comments on commit 14197e2

Please sign in to comment.