summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/tox_test.c88
-rw-r--r--auto_tests/toxav_basic_test.c6
-rw-r--r--auto_tests/toxav_many_test.c18
-rw-r--r--other/apidsl/README.md20
-rw-r--r--other/apidsl/tox.in.h19
-rw-r--r--testing/Messenger_test.c2
-rw-r--r--testing/irc_syncbot.c2
-rw-r--r--testing/nTox.c4
-rw-r--r--testing/tox_shell.c2
-rw-r--r--testing/tox_sync.c2
-rw-r--r--toxcore/Messenger.c11
-rw-r--r--toxcore/Messenger.h5
-rw-r--r--toxcore/tox.c8
-rw-r--r--toxcore/tox.h17
14 files changed, 114 insertions, 90 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 397c8acd..f578a5c9 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -443,7 +443,7 @@ START_TEST(test_few_clients)
443 443
444 uint32_t to_compare = 974536; 444 uint32_t to_compare = 974536;
445 connected_t1 = 0; 445 connected_t1 = 0;
446 tox_callback_self_connection_status(tox1, tox_connection_status, &to_compare); 446 tox_callback_self_connection_status(tox1, tox_connection_status);
447 tox_callback_friend_request(tox2, accept_friend_request, &to_compare); 447 tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
448 uint8_t address[TOX_ADDRESS_SIZE]; 448 uint8_t address[TOX_ADDRESS_SIZE];
449 tox_self_get_address(tox2, address); 449 tox_self_get_address(tox2, address);
@@ -453,9 +453,9 @@ START_TEST(test_few_clients)
453 uint8_t off = 1; 453 uint8_t off = 1;
454 454
455 while (1) { 455 while (1) {
456 tox_iterate(tox1); 456 tox_iterate(tox1, &to_compare);
457 tox_iterate(tox2); 457 tox_iterate(tox2, &to_compare);
458 tox_iterate(tox3); 458 tox_iterate(tox3, &to_compare);
459 459
460 if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2) 460 if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2)
461 && tox_self_get_connection_status(tox3)) { 461 && tox_self_get_connection_status(tox3)) {
@@ -487,9 +487,9 @@ START_TEST(test_few_clients)
487 487
488 while (1) { 488 while (1) {
489 messages_received = 0; 489 messages_received = 0;
490 tox_iterate(tox1); 490 tox_iterate(tox1, &to_compare);
491 tox_iterate(tox2); 491 tox_iterate(tox2, &to_compare);
492 tox_iterate(tox3); 492 tox_iterate(tox3, &to_compare);
493 493
494 if (messages_received) 494 if (messages_received)
495 break; 495 break;
@@ -516,9 +516,9 @@ START_TEST(test_few_clients)
516 off = 1; 516 off = 1;
517 517
518 while (1) { 518 while (1) {
519 tox_iterate(tox1); 519 tox_iterate(tox1, &to_compare);
520 tox_iterate(tox2); 520 tox_iterate(tox2, &to_compare);
521 tox_iterate(tox3); 521 tox_iterate(tox3, &to_compare);
522 522
523 if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2) 523 if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2)
524 && tox_self_get_connection_status(tox3)) { 524 && tox_self_get_connection_status(tox3)) {
@@ -544,9 +544,9 @@ START_TEST(test_few_clients)
544 544
545 while (1) { 545 while (1) {
546 name_changes = 0; 546 name_changes = 0;
547 tox_iterate(tox1); 547 tox_iterate(tox1, &to_compare);
548 tox_iterate(tox2); 548 tox_iterate(tox2, &to_compare);
549 tox_iterate(tox3); 549 tox_iterate(tox3, &to_compare);
550 550
551 if (name_changes) 551 if (name_changes)
552 break; 552 break;
@@ -565,9 +565,9 @@ START_TEST(test_few_clients)
565 565
566 while (1) { 566 while (1) {
567 status_m_changes = 0; 567 status_m_changes = 0;
568 tox_iterate(tox1); 568 tox_iterate(tox1, &to_compare);
569 tox_iterate(tox2); 569 tox_iterate(tox2, &to_compare);
570 tox_iterate(tox3); 570 tox_iterate(tox3, &to_compare);
571 571
572 if (status_m_changes) 572 if (status_m_changes)
573 break; 573 break;
@@ -587,9 +587,9 @@ START_TEST(test_few_clients)
587 587
588 while (1) { 588 while (1) {
589 typing_changes = 0; 589 typing_changes = 0;
590 tox_iterate(tox1); 590 tox_iterate(tox1, &to_compare);
591 tox_iterate(tox2); 591 tox_iterate(tox2, &to_compare);
592 tox_iterate(tox3); 592 tox_iterate(tox3, &to_compare);
593 593
594 594
595 if (typing_changes == 2) 595 if (typing_changes == 2)
@@ -605,9 +605,9 @@ START_TEST(test_few_clients)
605 605
606 while (1) { 606 while (1) {
607 typing_changes = 0; 607 typing_changes = 0;
608 tox_iterate(tox1); 608 tox_iterate(tox1, &to_compare);
609 tox_iterate(tox2); 609 tox_iterate(tox2, &to_compare);
610 tox_iterate(tox3); 610 tox_iterate(tox3, &to_compare);
611 611
612 if (typing_changes == 1) 612 if (typing_changes == 1)
613 break; 613 break;
@@ -632,9 +632,9 @@ START_TEST(test_few_clients)
632 632
633 while (1) { 633 while (1) {
634 custom_packet = 0; 634 custom_packet = 0;
635 tox_iterate(tox1); 635 tox_iterate(tox1, &to_compare);
636 tox_iterate(tox2); 636 tox_iterate(tox2, &to_compare);
637 tox_iterate(tox3); 637 tox_iterate(tox3, &to_compare);
638 638
639 if (custom_packet == 1) 639 if (custom_packet == 1)
640 break; 640 break;
@@ -654,9 +654,9 @@ START_TEST(test_few_clients)
654 654
655 while (1) { 655 while (1) {
656 custom_packet = 0; 656 custom_packet = 0;
657 tox_iterate(tox1); 657 tox_iterate(tox1, &to_compare);
658 tox_iterate(tox2); 658 tox_iterate(tox2, &to_compare);
659 tox_iterate(tox3); 659 tox_iterate(tox3, &to_compare);
660 660
661 if (custom_packet == 1) 661 if (custom_packet == 1)
662 break; 662 break;
@@ -690,9 +690,9 @@ START_TEST(test_few_clients)
690 ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error"); 690 ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error");
691 691
692 while (1) { 692 while (1) {
693 tox_iterate(tox1); 693 tox_iterate(tox1, &to_compare);
694 tox_iterate(tox2); 694 tox_iterate(tox2, &to_compare);
695 tox_iterate(tox3); 695 tox_iterate(tox3, &to_compare);
696 696
697 if (file_sending_done) { 697 if (file_sending_done) {
698 if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv 698 if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
@@ -742,9 +742,9 @@ START_TEST(test_few_clients)
742 m_send_reached = 0; 742 m_send_reached = 0;
743 743
744 while (1) { 744 while (1) {
745 tox_iterate(tox1); 745 tox_iterate(tox1, &to_compare);
746 tox_iterate(tox2); 746 tox_iterate(tox2, &to_compare);
747 tox_iterate(tox3); 747 tox_iterate(tox3, &to_compare);
748 748
749 if (file_sending_done) { 749 if (file_sending_done) {
750 if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending 750 if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
@@ -791,9 +791,9 @@ START_TEST(test_few_clients)
791 791
792 792
793 while (1) { 793 while (1) {
794 tox_iterate(tox1); 794 tox_iterate(tox1, &to_compare);
795 tox_iterate(tox2); 795 tox_iterate(tox2, &to_compare);
796 tox_iterate(tox3); 796 tox_iterate(tox3, &to_compare);
797 797
798 if (file_sending_done) { 798 if (file_sending_done) {
799 if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv 799 if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
@@ -904,7 +904,7 @@ loop_top:
904 } 904 }
905 905
906 for (i = 0; i < NUM_TOXES; ++i) { 906 for (i = 0; i < NUM_TOXES; ++i) {
907 tox_iterate(toxes[i]); 907 tox_iterate(toxes[i], NULL);
908 } 908 }
909 909
910 c_sleep(50); 910 c_sleep(50);
@@ -1002,7 +1002,7 @@ loop_top:
1002 } 1002 }
1003 1003
1004 for (i = 0; i < NUM_TOXES_TCP; ++i) { 1004 for (i = 0; i < NUM_TOXES_TCP; ++i) {
1005 tox_iterate(toxes[i]); 1005 tox_iterate(toxes[i], NULL);
1006 } 1006 }
1007 1007
1008 c_sleep(50); 1008 c_sleep(50);
@@ -1098,7 +1098,7 @@ loop_top:
1098 } 1098 }
1099 1099
1100 for (i = 0; i < NUM_TOXES_TCP; ++i) { 1100 for (i = 0; i < NUM_TOXES_TCP; ++i) {
1101 tox_iterate(toxes[i]); 1101 tox_iterate(toxes[i], NULL);
1102 } 1102 }
1103 1103
1104 c_sleep(30); 1104 c_sleep(30);
@@ -1206,7 +1206,7 @@ group_test_restart:
1206 break; 1206 break;
1207 1207
1208 for (i = 0; i < NUM_GROUP_TOX; ++i) { 1208 for (i = 0; i < NUM_GROUP_TOX; ++i) {
1209 tox_iterate(toxes[i]); 1209 tox_iterate(toxes[i], NULL);
1210 } 1210 }
1211 1211
1212 c_sleep(25); 1212 c_sleep(25);
@@ -1224,7 +1224,7 @@ group_test_restart:
1224 1224
1225 while (1) { 1225 while (1) {
1226 for (i = 0; i < NUM_GROUP_TOX; ++i) { 1226 for (i = 0; i < NUM_GROUP_TOX; ++i) {
1227 tox_iterate(toxes[i]); 1227 tox_iterate(toxes[i], NULL);
1228 } 1228 }
1229 1229
1230 if (!invite_counter) { 1230 if (!invite_counter) {
@@ -1287,7 +1287,7 @@ group_test_restart:
1287 1287
1288 for (j = 0; j < 20; ++j) { 1288 for (j = 0; j < 20; ++j) {
1289 for (i = 0; i < NUM_GROUP_TOX; ++i) { 1289 for (i = 0; i < NUM_GROUP_TOX; ++i) {
1290 tox_iterate(toxes[i]); 1290 tox_iterate(toxes[i], NULL);
1291 } 1291 }
1292 1292
1293 c_sleep(25); 1293 c_sleep(25);
@@ -1301,7 +1301,7 @@ group_test_restart:
1301 1301
1302 for (j = 0; j < 10; ++j) { 1302 for (j = 0; j < 10; ++j) {
1303 for (i = 0; i < NUM_GROUP_TOX; ++i) { 1303 for (i = 0; i < NUM_GROUP_TOX; ++i) {
1304 tox_iterate(toxes[i]); 1304 tox_iterate(toxes[i], NULL);
1305 } 1305 }
1306 1306
1307 c_sleep(50); 1307 c_sleep(50);
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c
index 20432dca..f66846c5 100644
--- a/auto_tests/toxav_basic_test.c
+++ b/auto_tests/toxav_basic_test.c
@@ -124,9 +124,9 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t
124 */ 124 */
125int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) 125int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob)
126{ 126{
127 tox_iterate(bootstrap); 127 tox_iterate(bootstrap, NULL);
128 tox_iterate(Alice); 128 tox_iterate(Alice, NULL);
129 tox_iterate(Bob); 129 tox_iterate(Bob, NULL);
130 130
131 return MIN(tox_iteration_interval(Alice), tox_iteration_interval(Bob)); 131 return MIN(tox_iteration_interval(Alice), tox_iteration_interval(Bob));
132} 132}
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index ab496024..d626067c 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -248,11 +248,11 @@ START_TEST(test_AV_three_calls)
248 uint8_t off = 1; 248 uint8_t off = 1;
249 249
250 while (1) { 250 while (1) {
251 tox_iterate(bootstrap); 251 tox_iterate(bootstrap, NULL);
252 tox_iterate(Alice); 252 tox_iterate(Alice, NULL);
253 tox_iterate(Bobs[0]); 253 tox_iterate(Bobs[0], NULL);
254 tox_iterate(Bobs[1]); 254 tox_iterate(Bobs[1], NULL);
255 tox_iterate(Bobs[2]); 255 tox_iterate(Bobs[2], NULL);
256 256
257 if (tox_self_get_connection_status(bootstrap) && 257 if (tox_self_get_connection_status(bootstrap) &&
258 tox_self_get_connection_status(Alice) && 258 tox_self_get_connection_status(Alice) &&
@@ -313,10 +313,10 @@ START_TEST(test_AV_three_calls)
313 time_t start_time = time(NULL); 313 time_t start_time = time(NULL);
314 314
315 while (time(NULL) - start_time < 5) { 315 while (time(NULL) - start_time < 5) {
316 tox_iterate(Alice); 316 tox_iterate(Alice, NULL);
317 tox_iterate(Bobs[0]); 317 tox_iterate(Bobs[0], NULL);
318 tox_iterate(Bobs[1]); 318 tox_iterate(Bobs[1], NULL);
319 tox_iterate(Bobs[2]); 319 tox_iterate(Bobs[2], NULL);
320 c_sleep(20); 320 c_sleep(20);
321 } 321 }
322 322
diff --git a/other/apidsl/README.md b/other/apidsl/README.md
index 3ba44678..99694dca 100644
--- a/other/apidsl/README.md
+++ b/other/apidsl/README.md
@@ -18,14 +18,16 @@ If you want to do it quickly and you don't have time for anything other than cop
18 18
19Command to run from ``toxcore`` directory (quick way, involves using curl): 19Command to run from ``toxcore`` directory (quick way, involves using curl):
20```bash 20```bash
21rm toxcore/tox.h && \ 21# For tox.h:
22( curl -X POST --data-binary @- https://apidsl.herokuapp.com/apidsl < ./other/apidsl/tox.in.h > ./toxcore/tox.h ) && \ 22curl -X POST --data-binary @- https://apidsl.herokuapp.com/apidsl \
23astyle --options=./other/astyle/astylerc ./toxcore/tox.h 23 < other/apidsl/tox.in.h \
24``` 24 | astyle --options=other/astyle/astylerc \
25 25 > toxcore/tox.h
26When formatting will be complete, you should see output like: 26# For toxav.h:
27``` 27curl -X POST --data-binary @- https://apidsl.herokuapp.com/apidsl \
28Formatted ./toxcore/tox.h 28 < other/apidsl/toxav.in.h \
29 | astyle --options=other/astyle/astylerc \
30 > toxav/toxav.h
29``` 31```
30 32
31You may want to make sure with ``git diff`` that changes made in ``tox.h`` reflect changes in ``tox.in.h``. 33You may want to make sure with ``git diff`` that changes made in ``tox.h`` reflect changes in ``tox.in.h``.
@@ -43,7 +45,7 @@ If you prefer to have more control over what is happening, there are steps below
434. Use ``apidsl`` ``??`` 454. Use ``apidsl`` ``??``
445. Parse generated ``tox.h`` with astyle, minimal command for it would be: 465. Parse generated ``tox.h`` with astyle, minimal command for it would be:
45```bash 47```bash
46astyle --options=./other/astyle/astylerc ./toxcore/tox.h 48astyle --options=other/astyle/astylerc toxcore/tox.h
47``` 49```
48 50
49**Always pass output from ``apidsl`` through astyle.** 51**Always pass output from ``apidsl`` through astyle.**
diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h
index 577515b1..6e65ed1f 100644
--- a/other/apidsl/tox.in.h
+++ b/other/apidsl/tox.in.h
@@ -86,6 +86,19 @@ extern "C" {
86 * callback will result in no callback being registered for that event. Only 86 * callback will result in no callback being registered for that event. Only
87 * one callback per event can be registered, so if a client needs multiple 87 * one callback per event can be registered, so if a client needs multiple
88 * event listeners, it needs to implement the dispatch functionality itself. 88 * event listeners, it needs to implement the dispatch functionality itself.
89 *
90 * The last argument to a callback is the user data pointer. It is passed from
91 * ${tox.iterate} to each callback in sequence.
92 *
93 * The user data pointer is never stored or dereferenced by any library code, so
94 * can be any pointer, including NULL. Callbacks must all operate on the same
95 * object type. In the apidsl code (tox.in.h), this is denoted with `any`. The
96 * `any` in ${tox.iterate} must be the same `any` as in all callbacks. In C,
97 * lacking parametric polymorphism, this is a pointer to void.
98 *
99 * Old style callbacks that are registered together with a user data pointer
100 * receive that pointer as argument when they are called. They can each have
101 * their own user data pointer of their own type.
89 */ 102 */
90 103
91/** \subsection threading Threading implications 104/** \subsection threading Threading implications
@@ -713,7 +726,7 @@ inline namespace self {
713 * 726 *
714 * TODO: how long should a client wait before bootstrapping again? 727 * TODO: how long should a client wait before bootstrapping again?
715 */ 728 */
716 event connection_status { 729 event connection_status const {
717 /** 730 /**
718 * @param connection_status Whether we are connected to the DHT. 731 * @param connection_status Whether we are connected to the DHT.
719 */ 732 */
@@ -734,7 +747,7 @@ const uint32_t iteration_interval();
734 * The main loop that needs to be run in intervals of $iteration_interval() 747 * The main loop that needs to be run in intervals of $iteration_interval()
735 * milliseconds. 748 * milliseconds.
736 */ 749 */
737void iterate(); 750void iterate(any user_data);
738 751
739 752
740/******************************************************************************* 753/*******************************************************************************
@@ -858,7 +871,6 @@ inline namespace self {
858 * If this parameter is NULL, the function has no effect. 871 * If this parameter is NULL, the function has no effect.
859 */ 872 */
860 get(); 873 get();
861
862 } 874 }
863 875
864 876
@@ -1058,7 +1070,6 @@ namespace friend {
1058 */ 1070 */
1059 const bool exists(uint32_t friend_number); 1071 const bool exists(uint32_t friend_number);
1060 1072
1061
1062} 1073}
1063 1074
1064inline namespace self { 1075inline namespace self {
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 22e16c38..0c439a05 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -186,7 +186,7 @@ int main(int argc, char *argv[])
186 printf("%s\n", name); 186 printf("%s\n", name);
187 187
188 m_send_message_generic(m, num, MESSAGE_NORMAL, (uint8_t *)"Test", 5, 0); 188 m_send_message_generic(m, num, MESSAGE_NORMAL, (uint8_t *)"Test", 5, 0);
189 do_messenger(m); 189 do_messenger(m, NULL);
190 c_sleep(30); 190 c_sleep(30);
191 FILE *file = fopen("Save.bak", "wb"); 191 FILE *file = fopen("Save.bak", "wb");
192 192
diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c
index a4e2254a..f8d29bfc 100644
--- a/testing/irc_syncbot.c
+++ b/testing/irc_syncbot.c
@@ -349,7 +349,7 @@ int main(int argc, char *argv[])
349 } 349 }
350 } 350 }
351 351
352 tox_iterate(tox); 352 tox_iterate(tox, NULL);
353 usleep(1000 * 50); 353 usleep(1000 * 50);
354 } 354 }
355 355
diff --git a/testing/nTox.c b/testing/nTox.c
index 03f17da5..bbc48831 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -389,7 +389,7 @@ void line_eval(Tox *m, char *line)
389 389
390 new_lines(numstring); 390 new_lines(numstring);
391 } else if (inpt_command == 'd') { 391 } else if (inpt_command == 'd') {
392 tox_iterate(m); 392 tox_iterate(m, NULL);
393 } else if (inpt_command == 'm') { //message command: /m friendnumber messsage 393 } else if (inpt_command == 'm') { //message command: /m friendnumber messsage
394 char *posi[1]; 394 char *posi[1];
395 int num = strtoul(line + prompt_offset, posi, 0); 395 int num = strtoul(line + prompt_offset, posi, 0);
@@ -1354,7 +1354,7 @@ int main(int argc, char *argv[])
1354 } 1354 }
1355 } 1355 }
1356 1356
1357 tox_iterate(m); 1357 tox_iterate(m, NULL);
1358 do_refresh(); 1358 do_refresh();
1359 1359
1360 int c = timeout_getch(m); 1360 int c = timeout_getch(m);
diff --git a/testing/tox_shell.c b/testing/tox_shell.c
index 0292222b..bda147b3 100644
--- a/testing/tox_shell.c
+++ b/testing/tox_shell.c
@@ -152,7 +152,7 @@ int main(int argc, char *argv[])
152 tox_friend_send_message(tox, num, TOX_MESSAGE_TYPE_NORMAL, buf, ret, 0); 152 tox_friend_send_message(tox, num, TOX_MESSAGE_TYPE_NORMAL, buf, ret, 0);
153 } 153 }
154 154
155 tox_iterate(tox); 155 tox_iterate(tox, NULL);
156 c_sleep(1); 156 c_sleep(1);
157 } 157 }
158 158
diff --git a/testing/tox_sync.c b/testing/tox_sync.c
index 738c2f2d..a90e343e 100644
--- a/testing/tox_sync.c
+++ b/testing/tox_sync.c
@@ -320,7 +320,7 @@ int main(int argc, char *argv[])
320 } 320 }
321 } 321 }
322 322
323 tox_iterate(tox); 323 tox_iterate(tox, NULL);
324 c_sleep(1); 324 c_sleep(1);
325 } 325 }
326 326
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 34296c24..3c60a818 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -816,10 +816,9 @@ void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, ui
816 m->friend_connectionstatuschange_userdata = userdata; 816 m->friend_connectionstatuschange_userdata = userdata;
817} 817}
818 818
819void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *), void *userdata) 819void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *))
820{ 820{
821 m->core_connection_change = function; 821 m->core_connection_change = function;
822 m->core_connection_change_userdata = userdata;
823} 822}
824 823
825void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, void *), 824void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, void *),
@@ -2232,13 +2231,13 @@ void do_friends(Messenger *m)
2232 } 2231 }
2233} 2232}
2234 2233
2235static void connection_status_cb(Messenger *m) 2234static void connection_status_cb(Messenger *m, void *userdata)
2236{ 2235{
2237 unsigned int conn_status = onion_connection_status(m->onion_c); 2236 unsigned int conn_status = onion_connection_status(m->onion_c);
2238 2237
2239 if (conn_status != m->last_connection_status) { 2238 if (conn_status != m->last_connection_status) {
2240 if (m->core_connection_change) 2239 if (m->core_connection_change)
2241 (*m->core_connection_change)(m, conn_status, m->core_connection_change_userdata); 2240 (*m->core_connection_change)(m, conn_status, userdata);
2242 2241
2243 m->last_connection_status = conn_status; 2242 m->last_connection_status = conn_status;
2244 } 2243 }
@@ -2282,7 +2281,7 @@ uint32_t messenger_run_interval(const Messenger *m)
2282} 2281}
2283 2282
2284/* The main loop that needs to be run at least 20 times per second. */ 2283/* The main loop that needs to be run at least 20 times per second. */
2285void do_messenger(Messenger *m) 2284void do_messenger(Messenger *m, void *userdata)
2286{ 2285{
2287 // Add the TCP relays, but only if this is the first time calling do_messenger 2286 // Add the TCP relays, but only if this is the first time calling do_messenger
2288 if (m->has_added_relays == 0) { 2287 if (m->has_added_relays == 0) {
@@ -2319,7 +2318,7 @@ void do_messenger(Messenger *m)
2319 do_onion_client(m->onion_c); 2318 do_onion_client(m->onion_c);
2320 do_friend_connections(m->fr_c); 2319 do_friend_connections(m->fr_c);
2321 do_friends(m); 2320 do_friends(m);
2322 connection_status_cb(m); 2321 connection_status_cb(m, userdata);
2323 2322
2324#ifdef TOX_LOGGER 2323#ifdef TOX_LOGGER
2325 2324
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 26704dd1..dab792c8 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -277,7 +277,6 @@ struct Messenger {
277 void *lossless_packethandler_userdata; 277 void *lossless_packethandler_userdata;
278 278
279 void (*core_connection_change)(struct Messenger *m, unsigned int, void *); 279 void (*core_connection_change)(struct Messenger *m, unsigned int, void *);
280 void *core_connection_change_userdata;
281 unsigned int last_connection_status; 280 unsigned int last_connection_status;
282 281
283 Messenger_Options options; 282 Messenger_Options options;
@@ -540,7 +539,7 @@ void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Mess
540/* Set the callback for typing changes. 539/* Set the callback for typing changes.
541 * Function(unsigned int connection_status (0 = not connected, 1 = TCP only, 2 = UDP + TCP)) 540 * Function(unsigned int connection_status (0 = not connected, 1 = TCP only, 2 = UDP + TCP))
542 */ 541 */
543void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *), void *userdata); 542void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *));
544 543
545/**********GROUP CHATS************/ 544/**********GROUP CHATS************/
546 545
@@ -747,7 +746,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error);
747void kill_messenger(Messenger *m); 746void kill_messenger(Messenger *m);
748 747
749/* The main loop that needs to be run at least 20 times per second. */ 748/* The main loop that needs to be run at least 20 times per second. */
750void do_messenger(Messenger *m); 749void do_messenger(Messenger *m, void *userdata);
751 750
752/* Return the time in milliseconds before do_messenger() should be called again 751/* Return the time in milliseconds before do_messenger() should be called again
753 * for optimal performance. 752 * for optimal performance.
diff --git a/toxcore/tox.c b/toxcore/tox.c
index b642db75..4708bc97 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -390,10 +390,10 @@ TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
390} 390}
391 391
392 392
393void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *function, void *user_data) 393void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *function)
394{ 394{
395 Messenger *m = tox; 395 Messenger *m = tox;
396 m_callback_core_connection(m, function, user_data); 396 m_callback_core_connection(m, function);
397} 397}
398 398
399uint32_t tox_iteration_interval(const Tox *tox) 399uint32_t tox_iteration_interval(const Tox *tox)
@@ -402,10 +402,10 @@ uint32_t tox_iteration_interval(const Tox *tox)
402 return messenger_run_interval(m); 402 return messenger_run_interval(m);
403} 403}
404 404
405void tox_iterate(Tox *tox) 405void tox_iterate(Tox *tox, void *userdata)
406{ 406{
407 Messenger *m = tox; 407 Messenger *m = tox;
408 do_messenger(m); 408 do_messenger(m, userdata);
409 do_groupchats(m->group_chat_object); 409 do_groupchats(m->group_chat_object);
410} 410}
411 411
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 1655d9c1..ca6869e4 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -84,6 +84,19 @@ extern "C" {
84 * callback will result in no callback being registered for that event. Only 84 * callback will result in no callback being registered for that event. Only
85 * one callback per event can be registered, so if a client needs multiple 85 * one callback per event can be registered, so if a client needs multiple
86 * event listeners, it needs to implement the dispatch functionality itself. 86 * event listeners, it needs to implement the dispatch functionality itself.
87 *
88 * The last argument to a callback is the user data pointer. It is passed from
89 * tox_iterate to each callback in sequence.
90 *
91 * The user data pointer is never stored or dereferenced by any library code, so
92 * can be any pointer, including NULL. Callbacks must all operate on the same
93 * object type. In the apidsl code (tox.in.h), this is denoted with `any`. The
94 * `any` in tox_iterate must be the same `any` as in all callbacks. In C,
95 * lacking parametric polymorphism, this is a pointer to void.
96 *
97 * Old style callbacks that are registered together with a user data pointer
98 * receive that pointer as argument when they are called. They can each have
99 * their own user data pointer of their own type.
87 */ 100 */
88/** \subsection threading Threading implications 101/** \subsection threading Threading implications
89 * 102 *
@@ -776,7 +789,7 @@ typedef void tox_self_connection_status_cb(Tox *tox, TOX_CONNECTION connection_s
776 * 789 *
777 * TODO: how long should a client wait before bootstrapping again? 790 * TODO: how long should a client wait before bootstrapping again?
778 */ 791 */
779void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback, void *user_data); 792void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback);
780 793
781/** 794/**
782 * Return the time in milliseconds before tox_iterate() should be called again 795 * Return the time in milliseconds before tox_iterate() should be called again
@@ -788,7 +801,7 @@ uint32_t tox_iteration_interval(const Tox *tox);
788 * The main loop that needs to be run in intervals of tox_iteration_interval() 801 * The main loop that needs to be run in intervals of tox_iteration_interval()
789 * milliseconds. 802 * milliseconds.
790 */ 803 */
791void tox_iterate(Tox *tox); 804void tox_iterate(Tox *tox, void *user_data);
792 805
793 806
794/******************************************************************************* 807/*******************************************************************************