Skip to content

Commit 8c35e0f

Browse files
Green-Skyiphydf
authored andcommitted
feat: add ngc events
1 parent 97bdd83 commit 8c35e0f

51 files changed

Lines changed: 5945 additions & 67 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ set(toxcore_SOURCES
248248
toxcore/events/friend_status_message.c
249249
toxcore/events/friend_typing.c
250250
toxcore/events/self_connection_status.c
251+
toxcore/events/group_custom_packet.c
252+
toxcore/events/group_custom_private_packet.c
253+
toxcore/events/group_invite.c
254+
toxcore/events/group_join_fail.c
255+
toxcore/events/group_message.c
256+
toxcore/events/group_moderation.c
257+
toxcore/events/group_password.c
258+
toxcore/events/group_peer_exit.c
259+
toxcore/events/group_peer_join.c
260+
toxcore/events/group_peer_limit.c
261+
toxcore/events/group_peer_name.c
262+
toxcore/events/group_peer_status.c
263+
toxcore/events/group_privacy_state.c
264+
toxcore/events/group_private_message.c
265+
toxcore/events/group_self_join.c
266+
toxcore/events/group_topic.c
267+
toxcore/events/group_topic_lock.c
268+
toxcore/events/group_voice_state.c
251269
toxcore/forwarding.c
252270
toxcore/forwarding.h
253271
toxcore/friend_connection.c

other/event_tooling/generate_event_c.cpp

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
2-
// Copyright © 2023 The TokTok team.
2+
// Copyright © 2023-2024 The TokTok team.
33

44
// this file can be used to generate event.c files
55
// requires c++17
@@ -119,22 +119,54 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
119119
exit(1);
120120
}
121121

122+
bool need_stdlib_h = false;
123+
bool need_string_h = false;
124+
bool need_tox_unpack_h = false;
125+
for (const auto& t : event_types) {
126+
std::visit(
127+
overloaded{
128+
[&](const EventTypeTrivial& t) {
129+
if (bin_unpack_name_from_type(t.type).rfind("tox_", 0) == 0) {
130+
need_tox_unpack_h = true;
131+
}
132+
},
133+
[&](const EventTypeByteRange&) {
134+
need_stdlib_h = true;
135+
need_string_h = true;
136+
}
137+
},
138+
t
139+
);
140+
}
141+
122142
f << R"(/* SPDX-License-Identifier: GPL-3.0-or-later
123-
* Copyright © 2023 The TokTok team.
143+
* Copyright © 2023-2024 The TokTok team.
124144
*/
125145
126146
#include "events_alloc.h"
127147
128-
#include <assert.h>
129-
#include <stdlib.h>
130-
#include <string.h>
148+
#include <assert.h>)";
149+
if (need_stdlib_h) {
150+
f << R"(
151+
#include <stdlib.h>)";
152+
}
153+
if (need_string_h) {
154+
f << R"(
155+
#include <string.h>)";
156+
}
157+
f << R"(
131158
132159
#include "../bin_pack.h"
133160
#include "../bin_unpack.h"
134161
#include "../ccompat.h"
162+
#include "../mem.h"
135163
#include "../tox.h"
136-
#include "../tox_events.h"
137-
#include "../tox_unpack.h"
164+
#include "../tox_events.h")";
165+
if (need_tox_unpack_h) {
166+
f << R"(
167+
#include "../tox_unpack.h")";
168+
}
169+
f << R"(
138170
139171
140172
/*****************************************************
@@ -205,10 +237,11 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
205237
f << " " << event_name_l << "->" << t.name_data << " = nullptr;\n";
206238
f << " " << event_name_l << "->" << t.name_length << " = 0;\n";
207239
f << " }\n\n";
208-
f << " " << event_name_l << "->" << t.name_data << " = (uint8_t *)malloc(" << t.name_length << ");\n\n";
209-
f << " if (" << event_name_l << "->" << t.name_data << " == nullptr) {\n";
240+
f << " uint8_t *" << t.name_data << "_copy = (uint8_t *)malloc(" << t.name_length << ");\n\n";
241+
f << " if (" << t.name_data << "_copy == nullptr) {\n";
210242
f << " return false;\n }\n\n";
211-
f << " memcpy(" << event_name_l << "->" << t.name_data << ", " << t.name_data << ", " << t.name_length << ");\n";
243+
f << " memcpy(" << t.name_data << "_copy, " << t.name_data << ", " << t.name_length << ");\n";
244+
f << " " << event_name_l << "->" << t.name_data << " = " << t.name_data << "_copy;\n";
212245
f << " " << event_name_l << "->" << t.name_length << " = " << t.name_length << ";\n";
213246
f << " return true;\n";
214247
}
@@ -626,7 +659,6 @@ int main(int argc, char** argv) {
626659
}
627660
},
628661

629-
#if 0 // not yet :)
630662
{
631663
"Group_Peer_Name",
632664
{
@@ -768,7 +800,6 @@ int main(int argc, char** argv) {
768800
EventTypeTrivial{"Tox_Group_Mod_Event", "mod_type"},
769801
}
770802
},
771-
#endif
772803
};
773804

774805
if (argc < 2) {

toxcore/Makefile.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \
3838
../toxcore/events/friend_status_message.c \
3939
../toxcore/events/friend_typing.c \
4040
../toxcore/events/self_connection_status.c \
41+
../toxcore/events/group_custom_packet.c \
42+
../toxcore/events/group_custom_private_packet.c \
43+
../toxcore/events/group_invite.c \
44+
../toxcore/events/group_join_fail.c \
45+
../toxcore/events/group_message.c \
46+
../toxcore/events/group_moderation.c \
47+
../toxcore/events/group_password.c \
48+
../toxcore/events/group_peer_exit.c \
49+
../toxcore/events/group_peer_join.c \
50+
../toxcore/events/group_peer_limit.c \
51+
../toxcore/events/group_peer_name.c \
52+
../toxcore/events/group_peer_status.c \
53+
../toxcore/events/group_privacy_state.c \
54+
../toxcore/events/group_private_message.c \
55+
../toxcore/events/group_self_join.c \
56+
../toxcore/events/group_topic.c \
57+
../toxcore/events/group_topic_lock.c \
58+
../toxcore/events/group_voice_state.c \
4159
../toxcore/DHT.h \
4260
../toxcore/DHT.c \
4361
../toxcore/mem.h \

toxcore/events/conference_connected.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later
2-
* Copyright © 2023 The TokTok team.
2+
* Copyright © 2023-2024 The TokTok team.
33
*/
44

55
#include "events_alloc.h"
66

77
#include <assert.h>
8-
#include <stdlib.h>
98

109
#include "../bin_pack.h"
1110
#include "../bin_unpack.h"
1211
#include "../ccompat.h"
12+
#include "../mem.h"
1313
#include "../tox.h"
1414
#include "../tox_events.h"
15-
#include "../tox_unpack.h"
1615

1716

1817
/*****************************************************

toxcore/events/conference_invite.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later
2-
* Copyright © 2023 The TokTok team.
2+
* Copyright © 2023-2024 The TokTok team.
33
*/
44

55
#include "events_alloc.h"
@@ -11,6 +11,7 @@
1111
#include "../bin_pack.h"
1212
#include "../bin_unpack.h"
1313
#include "../ccompat.h"
14+
#include "../mem.h"
1415
#include "../tox.h"
1516
#include "../tox_events.h"
1617
#include "../tox_unpack.h"

toxcore/events/conference_message.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later
2-
* Copyright © 2023 The TokTok team.
2+
* Copyright © 2023-2024 The TokTok team.
33
*/
44

55
#include "events_alloc.h"
@@ -11,6 +11,7 @@
1111
#include "../bin_pack.h"
1212
#include "../bin_unpack.h"
1313
#include "../ccompat.h"
14+
#include "../mem.h"
1415
#include "../tox.h"
1516
#include "../tox_events.h"
1617
#include "../tox_unpack.h"

toxcore/events/conference_peer_list_changed.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later
2-
* Copyright © 2023 The TokTok team.
2+
* Copyright © 2023-2024 The TokTok team.
33
*/
44

55
#include "events_alloc.h"
66

77
#include <assert.h>
8-
#include <stdlib.h>
98

109
#include "../bin_pack.h"
1110
#include "../bin_unpack.h"
1211
#include "../ccompat.h"
12+
#include "../mem.h"
1313
#include "../tox.h"
1414
#include "../tox_events.h"
15-
#include "../tox_unpack.h"
1615

1716

1817
/*****************************************************

toxcore/events/conference_peer_name.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later
2-
* Copyright © 2023 The TokTok team.
2+
* Copyright © 2023-2024 The TokTok team.
33
*/
44

55
#include "events_alloc.h"
@@ -11,9 +11,9 @@
1111
#include "../bin_pack.h"
1212
#include "../bin_unpack.h"
1313
#include "../ccompat.h"
14+
#include "../mem.h"
1415
#include "../tox.h"
1516
#include "../tox_events.h"
16-
#include "../tox_unpack.h"
1717

1818

1919
/*****************************************************

toxcore/events/conference_title.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later
2-
* Copyright © 2023 The TokTok team.
2+
* Copyright © 2023-2024 The TokTok team.
33
*/
44

55
#include "events_alloc.h"
@@ -11,9 +11,9 @@
1111
#include "../bin_pack.h"
1212
#include "../bin_unpack.h"
1313
#include "../ccompat.h"
14+
#include "../mem.h"
1415
#include "../tox.h"
1516
#include "../tox_events.h"
16-
#include "../tox_unpack.h"
1717

1818

1919
/*****************************************************

toxcore/events/events_alloc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#include "events_alloc.h"
66

77
#include <assert.h>
8-
#include <stdlib.h>
98

109
#include "../ccompat.h"
10+
#include "../mem.h"
11+
#include "../tox_event.h"
1112
#include "../tox_events.h"
1213

1314
Tox_Events_State *tox_events_alloc(void *user_data)

0 commit comments

Comments
 (0)