Skip to content

Commit

Permalink
Rename TOIT_ERR_SUCCESS to TOIT_OK. (#2314)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed May 16, 2024
1 parent 95bc834 commit f5534eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions include/toit/toit.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C" {
* @brief Toit error constants.
*/
typedef enum {
TOIT_ERR_SUCCESS = 0, /*!< The operation succeeded (no error). */
TOIT_OK = 0, /*!< The operation succeeded (no error). */
TOIT_ERR_OOM, /*!< Out of memory. */
TOIT_ERR_NO_SUCH_RECEIVER, /*!< The receiver of a system message didn't exist. */
TOIT_ERR_NOT_FOUND, /*!< The corresponding resource was not found. */
Expand Down Expand Up @@ -51,7 +51,7 @@ typedef struct {
*
* @param user_data The user data passed to `toit_msg_add_handler`.
* @param context The context of the message handler.
* @return toit_err_t The result of the callback. Must be `TOIT_ERR_SUCCESS`.
* @return toit_err_t The result of the callback. Must be `TOIT_OK`.
*/
typedef toit_err_t (*toit_msg_on_created_cb_t)(void* user_data, toit_msg_context_t* context);

Expand All @@ -67,7 +67,7 @@ typedef toit_err_t (*toit_msg_on_created_cb_t)(void* user_data, toit_msg_context
* @param sender The PID of the sender.
* @param data The data of the message. Must be freed by the receiver.
* @param length The length of the data.
* @return toit_err_t The result of the callback. Must be `TOIT_ERR_SUCCESS`.
* @return toit_err_t The result of the callback. Must be `TOIT_OK`.
*/
typedef toit_err_t (*toit_msg_on_message_cb_t)(void* user_data, int sender, uint8_t* data, int length);

Expand All @@ -92,7 +92,7 @@ typedef toit_err_t (*toit_msg_on_message_cb_t)(void* user_data, int sender, uint
* @param rpc_handle The handle to the request.
* @param data The data of the request. Must be freed by the receiver.
* @param length The length of the data.
* @return toit_err_t The result of the callback. Must be `TOIT_ERR_SUCCESS`.
* @return toit_err_t The result of the callback. Must be `TOIT_OK`.
*/
typedef toit_err_t (*toit_msg_on_request_cb_t)(void* user_data,
int sender,
Expand All @@ -107,7 +107,7 @@ typedef toit_err_t (*toit_msg_on_request_cb_t)(void* user_data,
* point, the user data is no longer needed and can be freed.
*
* @param user_data The user data passed to `toit_msg_add_handler`.
* @return toit_err_t The result of the callback. Must be `TOIT_ERR_SUCCESS`.
* @return toit_err_t The result of the callback. Must be `TOIT_OK`.
*/
typedef toit_err_t (*toit_msg_on_removed_cb_t)(void* user_data);

Expand Down
8 changes: 4 additions & 4 deletions src/messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ toit_err_t toit_msg_add_handler(const char* id,
list->registered_handler.user_context = user_context;
list->registered_handler.callbacks = cbs;
toit::registered_message_handlers = list;
return TOIT_ERR_SUCCESS;
return TOIT_OK;
}

toit_err_t toit_msg_remove_handler(toit_msg_context_t* context) {
Expand All @@ -1110,15 +1110,15 @@ toit_err_t toit_msg_remove_handler(toit_msg_context_t* context) {
auto handler = entry.handler;
toit::id_handler_entry_mapping[i].handler = null;
delete handler;
return TOIT_ERR_SUCCESS;
return TOIT_OK;
}
}
return TOIT_ERR_NOT_FOUND;
}

static toit_err_t message_err_to_toit_err(toit::message_err_t err) {
switch (err) {
case toit::MESSAGE_OK: return TOIT_ERR_SUCCESS;
case toit::MESSAGE_OK: return TOIT_OK;
case toit::MESSAGE_OOM: return TOIT_ERR_OOM;
case toit::MESSAGE_NO_SUCH_RECEIVER: return TOIT_ERR_NO_SUCH_RECEIVER;
}
Expand Down Expand Up @@ -1164,7 +1164,7 @@ toit_err_t toit_msg_request_reply(toit_msg_request_handle_t rpc_handle, uint8_t*
// TODO(florian): this isn't really a messaging function. It should probably be somewhere else.
toit_err_t toit_gc() {
toit::VM::current()->scheduler()->gc(NULL, true, true);
return TOIT_ERR_SUCCESS;
return TOIT_OK;
}

void* toit_malloc(size_t size) {
Expand Down
12 changes: 6 additions & 6 deletions tests/ctest/external-messaging2-toit-run-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ static toit_err_t on_created(void* user_data, toit_msg_context_t* context) {
test_service_t* test_service = (test_service_t*)user_data;
printf("created external message handler %d\n", test_service->id);
test_service->msg_context = context;
return TOIT_ERR_SUCCESS;
return TOIT_OK;
}

static toit_err_t on_message(void* user_data, int sender, uint8_t* data, int length) {
test_service_t* test_service = (test_service_t*)user_data;
printf("received message in C %d\n", test_service->id);
toit_msg_context_t* context = ((test_service_t*)(user_data))->msg_context;
if (toit_msg_notify(context, sender, data, length, true) != TOIT_ERR_SUCCESS) {
if (toit_msg_notify(context, sender, data, length, true) != TOIT_OK) {
printf("unable to send\n");
}
if (length == 2 && ((char*)data)[0] == 99 && ((char*)data)[1] == 99) {
toit_msg_remove_handler(context);
}
return TOIT_ERR_SUCCESS;
return TOIT_OK;
}

static toit_err_t on_rpc_request(void* user_data, int sender, int function, toit_msg_request_handle_t handle, uint8_t* data, int length) {
Expand All @@ -47,18 +47,18 @@ static toit_err_t on_rpc_request(void* user_data, int sender, int function, toit
toit_gc();
data[0] = 0;
}
if (toit_msg_request_reply(handle, data, length, true) != TOIT_ERR_SUCCESS) {
if (toit_msg_request_reply(handle, data, length, true) != TOIT_OK) {
printf("unable to reply\n");
}
}
return TOIT_ERR_SUCCESS;
return TOIT_OK;
}

static toit_err_t on_removed(void* user_data) {
test_service_t* test_service = (test_service_t*)user_data;
printf("freeing user data %d\n", test_service->id);
free(user_data);
return TOIT_ERR_SUCCESS;
return TOIT_OK;
}

static void __attribute__((constructor)) init() {
Expand Down

0 comments on commit f5534eb

Please sign in to comment.