Skip to content

Commit 3498bb1

Browse files
committed
refactor: Move some OS-specifics into tox_system.
1 parent 5ab42d4 commit 3498bb1

File tree

147 files changed

+4139
-2182
lines changed

Some content is hidden

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

147 files changed

+4139
-2182
lines changed

BUILD.bazel

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,76 @@ load("//tools/project:build_defs.bzl", "project")
33

44
project(license = "gpl3-https")
55

6+
genrule(
7+
name = "toxcore_headers",
8+
srcs = ["//c-toxcore/toxcore:public"],
9+
outs = [
10+
"tox/toxcore/os_log.h",
11+
"tox/toxcore/os_memory.h",
12+
"tox/toxcore/os_network.h",
13+
"tox/toxcore/os_random.h",
14+
"tox/toxcore/os_system.h",
15+
"tox/toxcore/tox.h",
16+
"tox/toxcore/tox_attributes.h",
17+
"tox/toxcore/tox_dispatch.h",
18+
"tox/toxcore/tox_events.h",
19+
"tox/toxcore/tox_log.h",
20+
"tox/toxcore/tox_log_impl.h",
21+
"tox/toxcore/tox_log_level.h",
22+
"tox/toxcore/tox_memory.h",
23+
"tox/toxcore/tox_memory_impl.h",
24+
"tox/toxcore/tox_network.h",
25+
"tox/toxcore/tox_network_impl.h",
26+
"tox/toxcore/tox_options.h",
27+
"tox/toxcore/tox_random.h",
28+
"tox/toxcore/tox_random_impl.h",
29+
"tox/toxcore/tox_system.h",
30+
"tox/toxcore/tox_system_impl.h",
31+
"tox/toxcore/tox_time.h",
32+
"tox/toxcore/tox_time_impl.h",
33+
],
34+
cmd = "cp $(locations //c-toxcore/toxcore:public) $(GENDIR)/c-toxcore/tox/toxcore/",
35+
visibility = ["//visibility:public"],
36+
)
37+
638
genrule(
739
name = "public_headers",
840
srcs = [
41+
"tox.h",
42+
"toxav.h",
43+
"toxencryptsave.h",
944
"//c-toxcore/toxav:toxav.h",
10-
"//c-toxcore/toxcore:tox.h",
11-
"//c-toxcore/toxcore:tox_dispatch.h",
12-
"//c-toxcore/toxcore:tox_events.h",
13-
"//c-toxcore/toxcore:tox_private.h",
1445
"//c-toxcore/toxencryptsave:toxencryptsave.h",
1546
],
1647
outs = [
17-
"tox/toxav.h",
1848
"tox/tox.h",
19-
"tox/tox_dispatch.h",
20-
"tox/tox_events.h",
21-
"tox/tox_private.h",
49+
"tox/toxav.h",
50+
"tox/toxav/toxav.h",
2251
"tox/toxencryptsave.h",
52+
"tox/toxencryptsave/toxencryptsave.h",
2353
],
2454
cmd = """
25-
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
26-
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
27-
cp $(location //c-toxcore/toxcore:tox_dispatch.h) $(GENDIR)/c-toxcore/tox/tox_dispatch.h
28-
cp $(location //c-toxcore/toxcore:tox_events.h) $(GENDIR)/c-toxcore/tox/tox_events.h
29-
cp $(location //c-toxcore/toxcore:tox_private.h) $(GENDIR)/c-toxcore/tox/tox_private.h
30-
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
55+
cp $(location toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
56+
cp $(location tox.h) $(GENDIR)/c-toxcore/tox/tox.h
57+
cp $(location toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
58+
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav/toxav.h
59+
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave/toxencryptsave.h
3160
""",
3261
visibility = ["//visibility:public"],
3362
)
3463

64+
filegroup(
65+
name = "public",
66+
srcs = [
67+
":public_headers",
68+
":toxcore_headers",
69+
],
70+
visibility = ["//visibility:public"],
71+
)
72+
3573
cc_library(
3674
name = "c-toxcore",
37-
hdrs = [":public_headers"],
75+
hdrs = [":public"],
3876
includes = ["."],
3977
visibility = ["//visibility:public"],
4078
deps = [

CMakeLists.txt

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ endif()
3030
set_source_files_properties(
3131
toxcore/mono_time.c
3232
toxcore/network.c
33+
toxcore/os_time.c
3334
toxcore/tox.c
3435
toxcore/util.c
3536
PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
@@ -319,6 +320,19 @@ set(toxcore_SOURCES
319320
toxcore/onion_client.c
320321
toxcore/onion_client.h
321322
toxcore/onion.h
323+
toxcore/os_log.c
324+
toxcore/os_log.h
325+
toxcore/os_memory.c
326+
toxcore/os_memory.h
327+
toxcore/os_network.c
328+
toxcore/os_network.h
329+
toxcore/os_network_impl.h
330+
toxcore/os_random.c
331+
toxcore/os_random.h
332+
toxcore/os_system.c
333+
toxcore/os_system.h
334+
toxcore/os_time.c
335+
toxcore/os_time.h
322336
toxcore/ping_array.c
323337
toxcore/ping_array.h
324338
toxcore/ping.c
@@ -341,13 +355,35 @@ set(toxcore_SOURCES
341355
toxcore/timed_auth.h
342356
toxcore/tox_api.c
343357
toxcore/tox.c
358+
toxcore/tox.h
344359
toxcore/tox_dispatch.c
345360
toxcore/tox_dispatch.h
346361
toxcore/tox_event.c
347362
toxcore/tox_event.h
348363
toxcore/tox_events.c
349364
toxcore/tox_events.h
350-
toxcore/tox.h
365+
toxcore/tox_log.c
366+
toxcore/tox_log.h
367+
toxcore/tox_log_impl.h
368+
toxcore/tox_log_level.c
369+
toxcore/tox_log_level.h
370+
toxcore/tox_memory.c
371+
toxcore/tox_memory.h
372+
toxcore/tox_memory_impl.h
373+
toxcore/tox_network.c
374+
toxcore/tox_network.h
375+
toxcore/tox_network_impl.h
376+
toxcore/tox_options.c
377+
toxcore/tox_options.h
378+
toxcore/tox_random.c
379+
toxcore/tox_random.h
380+
toxcore/tox_random_impl.h
381+
toxcore/tox_system.c
382+
toxcore/tox_system.h
383+
toxcore/tox_system_impl.h
384+
toxcore/tox_time.c
385+
toxcore/tox_time.h
386+
toxcore/tox_time_impl.h
351387
toxcore/tox_private.c
352388
toxcore/tox_private.h
353389
toxcore/tox_pack.c
@@ -368,13 +404,25 @@ else()
368404
endif()
369405
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
370406
set(toxcore_API_HEADERS
407+
${toxcore_SOURCE_DIR}/tox.h^tox
408+
${toxcore_SOURCE_DIR}/toxcore/os_log.h^os
409+
${toxcore_SOURCE_DIR}/toxcore/os_memory.h^os
410+
${toxcore_SOURCE_DIR}/toxcore/os_network.h^os
411+
${toxcore_SOURCE_DIR}/toxcore/os_random.h^os
412+
${toxcore_SOURCE_DIR}/toxcore/os_system.h^os
371413
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
414+
${toxcore_SOURCE_DIR}/toxcore/tox_attributes.h^tox
415+
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox
372416
${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox
373-
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox)
374-
if(EXPERIMENTAL_API)
375-
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
376-
${toxcore_SOURCE_DIR}/toxcore/tox_private.h^tox)
377-
endif()
417+
${toxcore_SOURCE_DIR}/toxcore/tox_log.h^tox
418+
${toxcore_SOURCE_DIR}/toxcore/tox_log_level.h^tox
419+
${toxcore_SOURCE_DIR}/toxcore/tox_memory.h^tox
420+
${toxcore_SOURCE_DIR}/toxcore/tox_network.h^tox
421+
${toxcore_SOURCE_DIR}/toxcore/tox_options.h^tox
422+
${toxcore_SOURCE_DIR}/toxcore/tox_random.h^tox
423+
${toxcore_SOURCE_DIR}/toxcore/tox_system.h^tox
424+
${toxcore_SOURCE_DIR}/toxcore/tox_system_impl.h^tox
425+
${toxcore_SOURCE_DIR}/toxcore/tox_time.h^tox)
378426

379427
################################################################################
380428
#
@@ -403,6 +451,7 @@ if(BUILD_TOXAV)
403451
toxav/video.c
404452
toxav/video.h)
405453
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
454+
${toxcore_SOURCE_DIR}/toxav.h^toxav
406455
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
407456

408457
if(TARGET Opus::opus AND TARGET libvpx::libvpx)
@@ -428,6 +477,7 @@ set(toxcore_SOURCES ${toxcore_SOURCES}
428477
toxencryptsave/toxencryptsave.c
429478
toxencryptsave/toxencryptsave.h)
430479
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
480+
${toxcore_SOURCE_DIR}/toxencryptsave.h^tox
431481
${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
432482

433483
################################################################################

auto_tests/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cc_library(
1919
"//c-toxcore/toxcore:tox",
2020
"//c-toxcore/toxcore:tox_dispatch",
2121
"//c-toxcore/toxcore:tox_events",
22+
"//c-toxcore/toxcore:tox_time",
2223
],
2324
)
2425

@@ -75,10 +76,14 @@ extra_data = {
7576
"//c-toxcore/toxcore:onion",
7677
"//c-toxcore/toxcore:onion_announce",
7778
"//c-toxcore/toxcore:onion_client",
79+
"//c-toxcore/toxcore:os_memory",
80+
"//c-toxcore/toxcore:os_network",
81+
"//c-toxcore/toxcore:os_random",
7882
"//c-toxcore/toxcore:tox",
7983
"//c-toxcore/toxcore:tox_dispatch",
8084
"//c-toxcore/toxcore:tox_events",
8185
"//c-toxcore/toxcore:tox_unpack",
86+
"//c-toxcore/toxcore:tox_time",
8287
"//c-toxcore/toxcore:util",
8388
"//c-toxcore/toxencryptsave",
8489
"@libsodium",

auto_tests/TCP_test.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#include "../toxcore/TCP_server.h"
99
#include "../toxcore/crypto_core.h"
1010
#include "../toxcore/mono_time.h"
11-
#include "../toxcore/network.h"
11+
#include "../toxcore/os_random.h"
12+
#include "../toxcore/os_network.h"
13+
#include "../toxcore/os_memory.h"
1214
#include "auto_test_support.h"
1315

1416
#define NUM_PORTS 3
@@ -52,7 +54,7 @@ static void test_basic(void)
5254
const Memory *mem = os_memory();
5355
ck_assert(mem != nullptr);
5456

55-
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
57+
Mono_Time *mono_time = mono_time_new(mem, nullptr);
5658
Logger *logger = logger_new(mem);
5759
logger_callback_log(logger, print_debug_logger, nullptr, nullptr);
5860

@@ -319,7 +321,7 @@ static void test_some(void)
319321
const Memory *mem = os_memory();
320322
ck_assert(mem != nullptr);
321323

322-
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
324+
Mono_Time *mono_time = mono_time_new(mem, nullptr);
323325
Logger *logger = logger_new(mem);
324326

325327
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
@@ -518,7 +520,7 @@ static void test_client(void)
518520
ck_assert(mem != nullptr);
519521

520522
Logger *logger = logger_new(mem);
521-
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
523+
Mono_Time *mono_time = mono_time_new(mem, nullptr);
522524

523525
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
524526
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
@@ -655,7 +657,7 @@ static void test_client_invalid(void)
655657
const Memory *mem = os_memory();
656658
ck_assert(mem != nullptr);
657659

658-
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
660+
Mono_Time *mono_time = mono_time_new(mem, nullptr);
659661
Logger *logger = logger_new(mem);
660662

661663
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
@@ -734,7 +736,7 @@ static void test_tcp_connection(void)
734736
const Memory *mem = os_memory();
735737
ck_assert(mem != nullptr);
736738

737-
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
739+
Mono_Time *mono_time = mono_time_new(mem, nullptr);
738740
Logger *logger = logger_new(mem);
739741

740742
tcp_data_callback_called = 0;
@@ -849,7 +851,7 @@ static void test_tcp_connection2(void)
849851
const Memory *mem = os_memory();
850852
ck_assert(mem != nullptr);
851853

852-
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
854+
Mono_Time *mono_time = mono_time_new(mem, nullptr);
853855
Logger *logger = logger_new(mem);
854856

855857
tcp_oobdata_callback_called = 0;

auto_tests/announce_test.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "../toxcore/mono_time.h"
88
#include "../toxcore/forwarding.h"
99
#include "../toxcore/net_crypto.h"
10+
#include "../toxcore/os_memory.h"
11+
#include "../toxcore/os_network.h"
12+
#include "../toxcore/os_random.h"
1013
#include "../toxcore/util.h"
1114
#include "auto_test_support.h"
1215
#include "check_compat.h"
@@ -60,7 +63,7 @@ static void test_store_data(void)
6063
Logger *log = logger_new(mem);
6164
ck_assert(log != nullptr);
6265
logger_callback_log(log, print_debug_logger, nullptr, nullptr);
63-
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
66+
Mono_Time *mono_time = mono_time_new(mem, nullptr);
6467
ck_assert(mono_time != nullptr);
6568
Networking_Core *net = new_networking_no_udp(log, mem, ns);
6669
ck_assert(net != nullptr);

auto_tests/auto_test_support.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include "../toxcore/mono_time.h"
88
#include "../toxcore/tox_dispatch.h"
99
#include "../toxcore/tox_events.h"
10-
#include "../toxcore/tox_struct.h"
10+
#include "../toxcore/tox_impl.h"
11+
#include "../toxcore/tox_time_impl.h"
1112

1213
#include "auto_test_support.h"
1314

@@ -157,17 +158,25 @@ static uint64_t get_state_clock_callback(void *user_data)
157158
return *clock;
158159
}
159160

161+
static const Tox_Time_Funcs autotox_time_funcs = {
162+
get_state_clock_callback,
163+
};
164+
160165
void set_mono_time_callback(AutoTox *autotox)
161166
{
162167
ck_assert(autotox != nullptr);
163168

169+
if (autotox->tm == nullptr) {
170+
autotox->tm = tox_time_new(&autotox_time_funcs, &autotox->clock, autotox->tox->sys.mem);
171+
}
172+
164173
Mono_Time *mono_time = autotox->tox->mono_time;
165174

175+
mono_time_set_current_time_callback(mono_time, nullptr); // set to default first
166176
autotox->clock = current_time_monotonic(mono_time);
167177
ck_assert_msg(autotox->clock >= 1000,
168178
"clock is too low (not initialised?): %lu", (unsigned long)autotox->clock);
169-
mono_time_set_current_time_callback(mono_time, nullptr, nullptr); // set to default first
170-
mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &autotox->clock);
179+
mono_time_set_current_time_callback(mono_time, autotox->tm);
171180
}
172181

173182
void save_autotox(AutoTox *autotox)
@@ -194,6 +203,8 @@ void kill_autotox(AutoTox *autotox)
194203
autotox->alive = false;
195204
tox_dispatch_free(autotox->dispatch);
196205
tox_kill(autotox->tox);
206+
tox_time_free(autotox->tm);
207+
autotox->tm = nullptr;
197208
}
198209

199210
void reload(AutoTox *autotox)
@@ -399,6 +410,7 @@ void run_auto_test(struct Tox_Options *options, uint32_t tox_count, autotox_test
399410
for (uint32_t i = 0; i < tox_count; ++i) {
400411
tox_dispatch_free(autotoxes[i].dispatch);
401412
tox_kill(autotoxes[i].tox);
413+
tox_time_free(autotoxes[i].tm);
402414
free(autotoxes[i].state);
403415
free(autotoxes[i].save_state);
404416
}

auto_tests/auto_test_support.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
typedef struct AutoTox {
1313
Tox *tox;
1414
Tox_Dispatch *dispatch;
15+
Tox_Time *tm;
1516

1617
uint32_t index;
1718
uint64_t clock;

auto_tests/conference_av_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdint.h>
88

99
#include "../toxav/toxav.h"
10+
#include "../toxcore/os_random.h"
1011
#include "check_compat.h"
1112

1213
#define NUM_AV_GROUP_TOX 16

auto_tests/conference_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <time.h>
77
#include <stdint.h>
88

9+
#include "../toxcore/os_random.h"
910
#include "../toxcore/util.h"
1011

1112
#include "check_compat.h"

0 commit comments

Comments
 (0)