diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-11-05 16:52:41 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-11-06 20:35:09 +0000 |
commit | 82515f92eecde2dffc0659519317d00459a09239 (patch) | |
tree | f17b9afe68fdd475be368623d58c7f51e8cc0ba2 /toxcore/tox.api.h | |
parent | fcc8ad943e93308b7048c4e0071ae00b54804934 (diff) |
Move log callback to options.
Previously, all log messages generated by tox_new (which is quite a lot)
were dropped, because client code had no chance to register a logging
callback, yet. This change allows setting the log callback from the
beginning and removes the ability to unset it.
Since the log callback is forever special, since it can't be stateless,
we don't necessarily need to treat it uniformly (with `event`).
Diffstat (limited to 'toxcore/tox.api.h')
-rw-r--r-- | toxcore/tox.api.h | 109 |
1 files changed, 58 insertions, 51 deletions
diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 0a651c11..fd908a49 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h | |||
@@ -376,6 +376,52 @@ enum class SAVEDATA_TYPE { | |||
376 | } | 376 | } |
377 | 377 | ||
378 | 378 | ||
379 | /** | ||
380 | * Severity level of log messages. | ||
381 | */ | ||
382 | enum class LOG_LEVEL { | ||
383 | /** | ||
384 | * Very detailed traces including all network activity. | ||
385 | */ | ||
386 | TRACE, | ||
387 | /** | ||
388 | * Debug messages such as which port we bind to. | ||
389 | */ | ||
390 | DEBUG, | ||
391 | /** | ||
392 | * Informational log messages such as video call status changes. | ||
393 | */ | ||
394 | INFO, | ||
395 | /** | ||
396 | * Warnings about internal inconsistency or logic errors. | ||
397 | */ | ||
398 | WARNING, | ||
399 | /** | ||
400 | * Severe unexpected errors caused by external or internal inconsistency. | ||
401 | */ | ||
402 | ERROR, | ||
403 | } | ||
404 | |||
405 | /** | ||
406 | * This event is triggered when the toxcore library logs an internal message. | ||
407 | * This is mostly useful for debugging. This callback can be called from any | ||
408 | * function, not just $iterate. This means the user data lifetime must at | ||
409 | * least extend between registering and unregistering it or $kill. | ||
410 | * | ||
411 | * Other toxcore modules such as toxav may concurrently call this callback at | ||
412 | * any time. Thus, user code must make sure it is equipped to handle concurrent | ||
413 | * execution, e.g. by employing appropriate mutex locking. | ||
414 | * | ||
415 | * @param level The severity of the log message. | ||
416 | * @param file The source file from which the message originated. | ||
417 | * @param line The source line from which the message originated. | ||
418 | * @param func The function from which the message originated. | ||
419 | * @param message The log message. | ||
420 | * @param user_data The user data pointer passed to $new in options. | ||
421 | */ | ||
422 | typedef void log_cb(LOG_LEVEL level, string file, uint32_t line, string func, string message, any user_data); | ||
423 | |||
424 | |||
379 | static class options { | 425 | static class options { |
380 | /** | 426 | /** |
381 | * This struct contains all the startup options for Tox. You can either | 427 | * This struct contains all the startup options for Tox. You can either |
@@ -491,6 +537,18 @@ static class options { | |||
491 | */ | 537 | */ |
492 | size_t length; | 538 | size_t length; |
493 | } | 539 | } |
540 | |||
541 | namespace log { | ||
542 | /** | ||
543 | * Logging callback for the new tox instance. | ||
544 | */ | ||
545 | log_cb *callback; | ||
546 | |||
547 | /** | ||
548 | * User data pointer passed to the logging callback. | ||
549 | */ | ||
550 | any user_data; | ||
551 | } | ||
494 | } | 552 | } |
495 | 553 | ||
496 | 554 | ||
@@ -620,57 +678,6 @@ static this new(const options_t *options) { | |||
620 | void kill(); | 678 | void kill(); |
621 | 679 | ||
622 | 680 | ||
623 | /** | ||
624 | * Severity level of log messages. | ||
625 | */ | ||
626 | enum class LOG_LEVEL { | ||
627 | /** | ||
628 | * Very detailed traces including all network activity. | ||
629 | */ | ||
630 | TRACE, | ||
631 | /** | ||
632 | * Debug messages such as which port we bind to. | ||
633 | */ | ||
634 | DEBUG, | ||
635 | /** | ||
636 | * Informational log messages such as video call status changes. | ||
637 | */ | ||
638 | INFO, | ||
639 | /** | ||
640 | * Warnings about internal inconsistency or logic errors. | ||
641 | */ | ||
642 | WARNING, | ||
643 | /** | ||
644 | * Severe unexpected errors caused by external or internal inconsistency. | ||
645 | */ | ||
646 | ERROR, | ||
647 | } | ||
648 | |||
649 | /** | ||
650 | * This event is triggered when the toxcore library logs an internal message. | ||
651 | * This is mostly useful for debugging. This callback can be called from any | ||
652 | * function, not just $iterate. This means the user data lifetime must at | ||
653 | * least extend between registering and unregistering it or $kill. | ||
654 | * | ||
655 | * Other toxcore modules such as toxav may concurrently call this callback at | ||
656 | * any time. Thus, user code must make sure it is equipped to handle concurrent | ||
657 | * execution, e.g. by employing appropriate mutex locking. The callback | ||
658 | * registration function must not be called during execution of any other Tox | ||
659 | * library function (toxcore or toxav). | ||
660 | */ | ||
661 | event log { | ||
662 | /** | ||
663 | * @param level The severity of the log message. | ||
664 | * @param file The source file from which the message originated. | ||
665 | * @param line The source line from which the message originated. | ||
666 | * @param func The function from which the message originated. | ||
667 | * @param message The log message. | ||
668 | */ | ||
669 | typedef void(LOG_LEVEL level, string file, uint32_t line, string func, | ||
670 | string message); | ||
671 | } | ||
672 | |||
673 | |||
674 | uint8_t[size] savedata { | 681 | uint8_t[size] savedata { |
675 | /** | 682 | /** |
676 | * Calculates the number of bytes required to store the tox instance with | 683 | * Calculates the number of bytes required to store the tox instance with |