Skip to content

Commit

Permalink
cleanup: apply the same scheme to types
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Mar 8, 2024
1 parent aebbfab commit 0199c0f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion auto_tests/group_message_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static void group_private_message_handler(const Tox_Event_Group_Private_Message

const uint32_t groupnumber = tox_event_group_private_message_get_group_number(event);
const uint32_t peer_id = tox_event_group_private_message_get_peer_id(event);
const Tox_Message_Type type = tox_event_group_private_message_get_type(event);
const Tox_Message_Type type = tox_event_group_private_message_get_message_type(event);
const uint8_t *message = tox_event_group_private_message_get_message(event);
const size_t length = tox_event_group_private_message_get_message_length(event);
const Tox_Group_Message_Id pseudo_msg_id = tox_event_group_private_message_get_message_id(event);
Expand Down
4 changes: 2 additions & 2 deletions other/event_tooling/generate_event_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ int main(int argc, char** argv) {
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeTrivial{"Tox_Message_Type", "type"},
EventTypeTrivial{"Tox_Message_Type", "message_type"},
EventTypeByteRange{"message", "message_length", "message_length"},
EventTypeTrivial{"uint32_t", "message_id"},
}
Expand All @@ -755,7 +755,7 @@ int main(int argc, char** argv) {
{
EventTypeTrivial{"uint32_t", "group_number"},
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeTrivial{"Tox_Message_Type", "type"},
EventTypeTrivial{"Tox_Message_Type", "message_type"},
EventTypeByteRange{"message", "message_length", "message_length"},
EventTypeTrivial{"uint32_t", "message_id"},
}
Expand Down
20 changes: 10 additions & 10 deletions toxcore/events/group_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
struct Tox_Event_Group_Message {
uint32_t group_number;
uint32_t peer_id;
Tox_Message_Type type;
Tox_Message_Type message_type;
uint8_t *message;
uint32_t message_length;
uint32_t message_id;
Expand Down Expand Up @@ -60,16 +60,16 @@ uint32_t tox_event_group_message_get_peer_id(const Tox_Event_Group_Message *grou
}

non_null()
static void tox_event_group_message_set_type(Tox_Event_Group_Message *group_message,
Tox_Message_Type type)
static void tox_event_group_message_set_message_type(Tox_Event_Group_Message *group_message,
Tox_Message_Type message_type)
{
assert(group_message != nullptr);
group_message->type = type;
group_message->message_type = message_type;
}
Tox_Message_Type tox_event_group_message_get_type(const Tox_Event_Group_Message *group_message)
Tox_Message_Type tox_event_group_message_get_message_type(const Tox_Event_Group_Message *group_message)
{
assert(group_message != nullptr);
return group_message->type;
return group_message->message_type;
}

non_null(1) nullable(2)
Expand Down Expand Up @@ -143,7 +143,7 @@ bool tox_event_group_message_pack(
return bin_pack_array(bp, 5)
&& bin_pack_u32(bp, event->group_number)
&& bin_pack_u32(bp, event->peer_id)
&& tox_message_type_pack(event->type, bp)
&& tox_message_type_pack(event->message_type, bp)
&& bin_pack_bin(bp, event->message, event->message_length)
&& bin_pack_u32(bp, event->message_id);
}
Expand All @@ -159,7 +159,7 @@ static bool tox_event_group_message_unpack_into(

return bin_unpack_u32(bu, &event->group_number)
&& bin_unpack_u32(bu, &event->peer_id)
&& tox_message_type_unpack(&event->type, bu)
&& tox_message_type_unpack(&event->message_type, bu)
&& bin_unpack_bin(bu, &event->message, &event->message_length)
&& bin_unpack_u32(bu, &event->message_id);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ static Tox_Event_Group_Message *tox_event_group_message_alloc(void *user_data)
*****************************************************/

void tox_events_handle_group_message(
Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, const uint8_t *message, size_t message_length, uint32_t message_id,
Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type message_type, const uint8_t *message, size_t message_length, uint32_t message_id,
void *user_data)
{
Tox_Event_Group_Message *group_message = tox_event_group_message_alloc(user_data);
Expand All @@ -265,7 +265,7 @@ void tox_events_handle_group_message(

tox_event_group_message_set_group_number(group_message, group_number);
tox_event_group_message_set_peer_id(group_message, peer_id);
tox_event_group_message_set_type(group_message, type);
tox_event_group_message_set_message_type(group_message, message_type);
tox_event_group_message_set_message(group_message, message, message_length);
tox_event_group_message_set_message_id(group_message, message_id);
}
20 changes: 10 additions & 10 deletions toxcore/events/group_private_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
struct Tox_Event_Group_Private_Message {
uint32_t group_number;
uint32_t peer_id;
Tox_Message_Type type;
Tox_Message_Type message_type;
uint8_t *message;
uint32_t message_length;
uint32_t message_id;
Expand Down Expand Up @@ -60,16 +60,16 @@ uint32_t tox_event_group_private_message_get_peer_id(const Tox_Event_Group_Priva
}

non_null()
static void tox_event_group_private_message_set_type(Tox_Event_Group_Private_Message *group_private_message,
Tox_Message_Type type)
static void tox_event_group_private_message_set_message_type(Tox_Event_Group_Private_Message *group_private_message,
Tox_Message_Type message_type)
{
assert(group_private_message != nullptr);
group_private_message->type = type;
group_private_message->message_type = message_type;
}
Tox_Message_Type tox_event_group_private_message_get_type(const Tox_Event_Group_Private_Message *group_private_message)
Tox_Message_Type tox_event_group_private_message_get_message_type(const Tox_Event_Group_Private_Message *group_private_message)
{
assert(group_private_message != nullptr);
return group_private_message->type;
return group_private_message->message_type;
}

non_null(1) nullable(2)
Expand Down Expand Up @@ -143,7 +143,7 @@ bool tox_event_group_private_message_pack(
return bin_pack_array(bp, 5)
&& bin_pack_u32(bp, event->group_number)
&& bin_pack_u32(bp, event->peer_id)
&& tox_message_type_pack(event->type, bp)
&& tox_message_type_pack(event->message_type, bp)
&& bin_pack_bin(bp, event->message, event->message_length)
&& bin_pack_u32(bp, event->message_id);
}
Expand All @@ -159,7 +159,7 @@ static bool tox_event_group_private_message_unpack_into(

return bin_unpack_u32(bu, &event->group_number)
&& bin_unpack_u32(bu, &event->peer_id)
&& tox_message_type_unpack(&event->type, bu)
&& tox_message_type_unpack(&event->message_type, bu)
&& bin_unpack_bin(bu, &event->message, &event->message_length)
&& bin_unpack_u32(bu, &event->message_id);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ static Tox_Event_Group_Private_Message *tox_event_group_private_message_alloc(vo
*****************************************************/

void tox_events_handle_group_private_message(
Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, const uint8_t *message, size_t message_length, uint32_t message_id,
Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type message_type, const uint8_t *message, size_t message_length, uint32_t message_id,
void *user_data)
{
Tox_Event_Group_Private_Message *group_private_message = tox_event_group_private_message_alloc(user_data);
Expand All @@ -265,7 +265,7 @@ void tox_events_handle_group_private_message(

tox_event_group_private_message_set_group_number(group_private_message, group_number);
tox_event_group_private_message_set_peer_id(group_private_message, peer_id);
tox_event_group_private_message_set_type(group_private_message, type);
tox_event_group_private_message_set_message_type(group_private_message, message_type);
tox_event_group_private_message_set_message(group_private_message, message, message_length);
tox_event_group_private_message_set_message_id(group_private_message, message_id);
}
8 changes: 4 additions & 4 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -3932,7 +3932,7 @@ bool tox_group_get_password(const Tox *tox, uint32_t group_number, uint8_t *pass
}

Tox_Group_Message_Id tox_group_send_message(
const Tox *tox, uint32_t group_number, Tox_Message_Type type, const uint8_t *message,
const Tox *tox, uint32_t group_number, Tox_Message_Type message_type, const uint8_t *message,
size_t length, Tox_Err_Group_Send_Message *error)
{
assert(tox != nullptr);
Expand All @@ -3953,7 +3953,7 @@ Tox_Group_Message_Id tox_group_send_message(
}

uint32_t message_id = 0;
const int ret = gc_send_message(chat, message, length, type, &message_id);
const int ret = gc_send_message(chat, message, length, message_type, &message_id);
tox_unlock(tox);

switch (ret) {
Expand Down Expand Up @@ -3995,7 +3995,7 @@ Tox_Group_Message_Id tox_group_send_message(
}

Tox_Group_Message_Id tox_group_send_private_message(const Tox *tox, uint32_t group_number, uint32_t peer_id,
Tox_Message_Type type, const uint8_t *message, size_t length, Tox_Err_Group_Send_Private_Message *error)
Tox_Message_Type message_type, const uint8_t *message, size_t length, Tox_Err_Group_Send_Private_Message *error)
{
assert(tox != nullptr);

Expand All @@ -4015,7 +4015,7 @@ Tox_Group_Message_Id tox_group_send_private_message(const Tox *tox, uint32_t gro
}

uint32_t message_id = 0;
const int ret = gc_send_private_message(chat, gc_peer_id_from_int(peer_id), type, message, length, &message_id);
const int ret = gc_send_private_message(chat, gc_peer_id_from_int(peer_id), message_type, message, length, &message_id);
tox_unlock(tox);

switch (ret) {
Expand Down
14 changes: 8 additions & 6 deletions toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -4493,7 +4493,7 @@ const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message valu
* then reassemble the fragments. Messages may not be empty.
*
* @param group_number The group number of the group the message is intended for.
* @param type Message type (normal, action, ...).
* @param message_type Message type (normal, action, ...).
* @param message A non-NULL pointer to the first element of a byte array
* containing the message text.
* @param length Length of the message to be sent.
Expand All @@ -4502,7 +4502,7 @@ const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message valu
* returned message ID value will be undefined.
*/
Tox_Group_Message_Id tox_group_send_message(
const Tox *tox, Tox_Group_Number group_number, Tox_Message_Type type,
const Tox *tox, Tox_Group_Number group_number, Tox_Message_Type message_type,
const uint8_t message[], size_t length,
Tox_Err_Group_Send_Message *error);

Expand Down Expand Up @@ -4569,14 +4569,15 @@ const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Priv
*
* @param group_number The group number of the group the message is intended for.
* @param peer_id The ID of the peer the message is intended for.
* @param message_type The type of message (normal, action, ...).
* @param message A non-NULL pointer to the first element of a byte array
* containing the message text.
* @param length Length of the message to be sent.
*
* @return true on success.
*/
Tox_Group_Message_Id tox_group_send_private_message(
const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type,
const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type message_type,
const uint8_t message[], size_t length,
Tox_Err_Group_Send_Private_Message *error);

Expand Down Expand Up @@ -4729,13 +4730,13 @@ bool tox_group_send_custom_private_packet(const Tox *tox, Tox_Group_Number group
/**
* @param group_number The group number of the group the message is intended for.
* @param peer_id The ID of the peer who sent the message.
* @param type The type of message (normal, action, ...).
* @param message_type The type of message (normal, action, ...).
* @param message The message data.
* @param message_length The length of the message.
* @param message_id A pseudo message id that clients can use to uniquely identify this group message.
*/
typedef void tox_group_message_cb(
Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type,
Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type message_type,
const uint8_t message[], size_t message_length, Tox_Group_Message_Id message_id, void *user_data);

/**
Expand All @@ -4748,12 +4749,13 @@ void tox_callback_group_message(Tox *tox, tox_group_message_cb *callback);
/**
* @param group_number The group number of the group the private message is intended for.
* @param peer_id The ID of the peer who sent the private message.
* @param message_type The type of message (normal, action, ...).
* @param message The message data.
* @param message_length The length of the message.
* @param message_id A pseudo message id that clients can use to uniquely identify this group message.
*/
typedef void tox_group_private_message_cb(
Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type,
Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type message_type,
const uint8_t message[], size_t message_length, Tox_Group_Message_Id message_id, void *user_data);

/**
Expand Down
4 changes: 2 additions & 2 deletions toxcore/tox_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ uint32_t tox_event_group_message_get_group_number(
const Tox_Event_Group_Message *group_message);
uint32_t tox_event_group_message_get_peer_id(
const Tox_Event_Group_Message *group_message);
Tox_Message_Type tox_event_group_message_get_type(
Tox_Message_Type tox_event_group_message_get_message_type(
const Tox_Event_Group_Message *group_message);
const uint8_t *tox_event_group_message_get_message(
const Tox_Event_Group_Message *group_message);
Expand All @@ -262,7 +262,7 @@ uint32_t tox_event_group_private_message_get_group_number(
const Tox_Event_Group_Private_Message *group_private_message);
uint32_t tox_event_group_private_message_get_peer_id(
const Tox_Event_Group_Private_Message *group_private_message);
Tox_Message_Type tox_event_group_private_message_get_type(
Tox_Message_Type tox_event_group_private_message_get_message_type(
const Tox_Event_Group_Private_Message *group_private_message);
const uint8_t *tox_event_group_private_message_get_message(
const Tox_Event_Group_Private_Message *group_private_message);
Expand Down

0 comments on commit 0199c0f

Please sign in to comment.