Squashed 'external/toxcore/c-toxcore/' changes from e29e185c03..f1df709b87

f1df709b87 feat: add ngc events
1b6c907235 refactor: Make event dispatch ordered by receive time.
b7f9367f6f test: Upgrade cppcheck, fix some warnings.
766e62bc89 chore: Use `pkg_search_module` directly in cmake.
00ff078f91 cleanup: Use target_link_libraries directly in cmake.
c58928cc89 chore: Add `IMPORTED_TARGET` to pkg-config packages.
895a6af122 cleanup: Remove NaCl support.
41dfb1c1c0 fix: unpack enum function names in event impl generator
447666d1a1 chore: Disable targets for cross-compilation.
572924e924 chore: Build a docker image with coverage info in it.
415cb78f5e cleanup: Some portability/warning fixes for Windows builds.
425216d9ec fix: Correct a use-after-free and fix some memory leaks.
4b1cfa3e08 refactor: Change all enum-like `#define` sequences into enums.
d3c2704fa9 chore: Fix make_single_file to support core-only.
0ce46b644e refactor: Change the `TCP_PACKET_*` defines into an enum.
22cd38ad50 adopt event impl generation tool to #2392
f31ea1088a add the event impl generation tool
4e603bb613 refactor: Use `enum-from-int` rule from tokstyle.
19d8f180d6 chore: Update github actions `uses`.
6a895be0c7 test: Make esp32 build actually try to instantiate tox.
65d09c9bfb cleanup: Remove test net support.
REVERT: e29e185c03 feat: add ngc events

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: f1df709b8792da4c0e946d826b11df77d565064d
This commit is contained in:
2023-12-27 12:37:22 +01:00
parent 83e200df43
commit b2ae9530a4
173 changed files with 9191 additions and 5633 deletions

View File

@ -28,19 +28,6 @@ struct Tox_Event_Group_Voice_State {
Tox_Group_Voice_State voice_state;
};
non_null()
static void tox_event_group_voice_state_construct(Tox_Event_Group_Voice_State *group_voice_state)
{
*group_voice_state = (Tox_Event_Group_Voice_State) {
0
};
}
non_null()
static void tox_event_group_voice_state_destruct(Tox_Event_Group_Voice_State *group_voice_state)
{
return;
}
non_null()
static void tox_event_group_voice_state_set_group_number(Tox_Event_Group_Voice_State *group_voice_state,
uint32_t group_number)
@ -68,7 +55,19 @@ Tox_Group_Voice_State tox_event_group_voice_state_get_voice_state(const Tox_Even
}
non_null()
static bool tox_event_group_voice_state_pack(
static void tox_event_group_voice_state_construct(Tox_Event_Group_Voice_State *group_voice_state)
{
*group_voice_state = (Tox_Event_Group_Voice_State) {
0
};
}
non_null()
static void tox_event_group_voice_state_destruct(Tox_Event_Group_Voice_State *group_voice_state, const Memory *mem)
{
return;
}
bool tox_event_group_voice_state_pack(
const Tox_Event_Group_Voice_State *event, Bin_Pack *bp)
{
assert(event != nullptr);
@ -80,7 +79,7 @@ static bool tox_event_group_voice_state_pack(
}
non_null()
static bool tox_event_group_voice_state_unpack(
static bool tox_event_group_voice_state_unpack_into(
Tox_Event_Group_Voice_State *event, Bin_Unpack *bu)
{
assert(event != nullptr);
@ -89,99 +88,126 @@ static bool tox_event_group_voice_state_unpack(
}
return bin_unpack_u32(bu, &event->group_number)
&& tox_unpack_group_voice_state(bu, &event->voice_state);
&& tox_group_voice_state_unpack(bu, &event->voice_state);
}
/*****************************************************
*
* :: add/clear/get
* :: new/free/add/get/size/unpack
*
*****************************************************/
non_null()
static Tox_Event_Group_Voice_State *tox_events_add_group_voice_state(Tox_Events *events)
const Tox_Event_Group_Voice_State *tox_event_get_group_voice_state(const Tox_Event *event)
{
if (events->group_voice_state_size == UINT32_MAX) {
return event->type == TOX_EVENT_GROUP_VOICE_STATE ? event->data.group_voice_state : nullptr;
}
Tox_Event_Group_Voice_State *tox_event_group_voice_state_new(const Memory *mem)
{
Tox_Event_Group_Voice_State *const group_voice_state =
(Tox_Event_Group_Voice_State *)mem_alloc(mem, sizeof(Tox_Event_Group_Voice_State));
if (group_voice_state == nullptr) {
return nullptr;
}
if (events->group_voice_state_size == events->group_voice_state_capacity) {
const uint32_t new_group_voice_state_capacity = events->group_voice_state_capacity * 2 + 1;
Tox_Event_Group_Voice_State *new_group_voice_state = (Tox_Event_Group_Voice_State *)
realloc(
events->group_voice_state,
new_group_voice_state_capacity * sizeof(Tox_Event_Group_Voice_State));
if (new_group_voice_state == nullptr) {
return nullptr;
}
events->group_voice_state = new_group_voice_state;
events->group_voice_state_capacity = new_group_voice_state_capacity;
}
Tox_Event_Group_Voice_State *const group_voice_state =
&events->group_voice_state[events->group_voice_state_size];
tox_event_group_voice_state_construct(group_voice_state);
++events->group_voice_state_size;
return group_voice_state;
}
void tox_events_clear_group_voice_state(Tox_Events *events)
void tox_event_group_voice_state_free(Tox_Event_Group_Voice_State *group_voice_state, const Memory *mem)
{
if (events == nullptr) {
return;
if (group_voice_state != nullptr) {
tox_event_group_voice_state_destruct(group_voice_state, mem);
}
for (uint32_t i = 0; i < events->group_voice_state_size; ++i) {
tox_event_group_voice_state_destruct(&events->group_voice_state[i]);
}
free(events->group_voice_state);
events->group_voice_state = nullptr;
events->group_voice_state_size = 0;
events->group_voice_state_capacity = 0;
mem_delete(mem, group_voice_state);
}
uint32_t tox_events_get_group_voice_state_size(const Tox_Events *events)
non_null()
static Tox_Event_Group_Voice_State *tox_events_add_group_voice_state(Tox_Events *events, const Memory *mem)
{
if (events == nullptr) {
return 0;
Tox_Event_Group_Voice_State *const group_voice_state = tox_event_group_voice_state_new(mem);
if (group_voice_state == nullptr) {
return nullptr;
}
return events->group_voice_state_size;
Tox_Event event;
event.type = TOX_EVENT_GROUP_VOICE_STATE;
event.data.group_voice_state = group_voice_state;
tox_events_add(events, &event);
return group_voice_state;
}
const Tox_Event_Group_Voice_State *tox_events_get_group_voice_state(const Tox_Events *events, uint32_t index)
{
assert(index < events->group_voice_state_size);
assert(events->group_voice_state != nullptr);
return &events->group_voice_state[index];
}
bool tox_events_pack_group_voice_state(const Tox_Events *events, Bin_Pack *bp)
{
const uint32_t size = tox_events_get_group_voice_state_size(events);
uint32_t group_voice_state_index = 0;
const uint32_t size = tox_events_get_size(events);
for (uint32_t i = 0; i < size; ++i) {
if (!tox_event_group_voice_state_pack(tox_events_get_group_voice_state(events, i), bp)) {
return false;
if (group_voice_state_index > index) {
return nullptr;
}
if (events->events[i].type == TOX_EVENT_GROUP_VOICE_STATE) {
const Tox_Event_Group_Voice_State *group_voice_state = events->events[i].data.group_voice_state;
if (group_voice_state_index == index) {
return group_voice_state;
}
++group_voice_state_index;
}
}
return true;
return nullptr;
}
bool tox_events_unpack_group_voice_state(Tox_Events *events, Bin_Unpack *bu)
uint32_t tox_events_get_group_voice_state_size(const Tox_Events *events)
{
Tox_Event_Group_Voice_State *event = tox_events_add_group_voice_state(events);
uint32_t group_voice_state_size = 0;
const uint32_t size = tox_events_get_size(events);
if (event == nullptr) {
for (uint32_t i = 0; i < size; ++i) {
if (events->events[i].type == TOX_EVENT_GROUP_VOICE_STATE) {
++group_voice_state_size;
}
}
return group_voice_state_size;
}
bool tox_event_group_voice_state_unpack(
Tox_Event_Group_Voice_State **event, Bin_Unpack *bu, const Memory *mem)
{
assert(event != nullptr);
*event = tox_event_group_voice_state_new(mem);
if (*event == nullptr) {
return false;
}
return tox_event_group_voice_state_unpack(event, bu);
return tox_event_group_voice_state_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Voice_State *tox_event_group_voice_state_alloc(void *user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);
if (state->events == nullptr) {
return nullptr;
}
Tox_Event_Group_Voice_State *group_voice_state = tox_events_add_group_voice_state(state->events, state->mem);
if (group_voice_state == nullptr) {
state->error = TOX_ERR_EVENTS_ITERATE_MALLOC;
return nullptr;
}
return group_voice_state;
}
@ -195,17 +221,9 @@ bool tox_events_unpack_group_voice_state(Tox_Events *events, Bin_Unpack *bu)
void tox_events_handle_group_voice_state(Tox *tox, uint32_t group_number, Tox_Group_Voice_State voice_state,
void *user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);
if (state->events == nullptr) {
return;
}
Tox_Event_Group_Voice_State *group_voice_state = tox_events_add_group_voice_state(state->events);
Tox_Event_Group_Voice_State *group_voice_state = tox_event_group_voice_state_alloc(user_data);
if (group_voice_state == nullptr) {
state->error = TOX_ERR_EVENTS_ITERATE_MALLOC;
return;
}