summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-30 11:39:37 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-30 11:39:37 +0100
commit949ef785a4e7aa7868c9605b6bbed15c3f4beab9 (patch)
tree24e3ab7b32724f8d17a225463dfefc840b736b5c
parent48ddb115995f2bb55a736ae4cc54c70f3d34eeb4 (diff)
Add the 'Tox' context object to the logger.
We don't currently support callbacks without context object.
-rw-r--r--toxcore/Messenger.c4
-rw-r--r--toxcore/Messenger.h2
-rw-r--r--toxcore/logger.c8
-rw-r--r--toxcore/logger.h9
-rw-r--r--toxcore/tox.c2
5 files changed, 14 insertions, 11 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 2355eb89..26c963db 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -831,9 +831,9 @@ static void set_friend_typing(const Messenger *m, int32_t friendnumber, uint8_t
831 m->friendlist[friendnumber].is_typing = is_typing; 831 m->friendlist[friendnumber].is_typing = is_typing;
832} 832}
833 833
834void m_callback_log(Messenger *m, logger_cb *function, void *userdata) 834void m_callback_log(Messenger *m, logger_cb *function, void *context, void *userdata)
835{ 835{
836 logger_callback_log(m->log, function, userdata); 836 logger_callback_log(m->log, function, context, userdata);
837} 837}
838 838
839/* Set the function that will be executed when a friend request is received. */ 839/* Set the function that will be executed when a friend request is received. */
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index ac7d7245..0744ae58 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -460,7 +460,7 @@ int m_get_istyping(const Messenger *m, int32_t friendnumber);
460 460
461/* Set the logger callback. 461/* Set the logger callback.
462 */ 462 */
463void m_callback_log(Messenger *m, logger_cb *function, void *userdata); 463void m_callback_log(Messenger *m, logger_cb *function, void *context, void *userdata);
464 464
465/* Set the function that will be executed when a friend request is received. 465/* Set the function that will be executed when a friend request is received.
466 * Function format is function(uint8_t * public_key, uint8_t * data, size_t length) 466 * Function format is function(uint8_t * public_key, uint8_t * data, size_t length)
diff --git a/toxcore/logger.c b/toxcore/logger.c
index bbb31aa2..fae5d205 100644
--- a/toxcore/logger.c
+++ b/toxcore/logger.c
@@ -28,6 +28,7 @@
28 28
29struct Logger { 29struct Logger {
30 logger_cb *callback; 30 logger_cb *callback;
31 void *context;
31 void *userdata; 32 void *userdata;
32}; 33};
33 34
@@ -35,7 +36,7 @@ struct Logger {
35/** 36/**
36 * Public Functions 37 * Public Functions
37 */ 38 */
38Logger *logger_new(void) 39Logger *logger_new()
39{ 40{
40 return (Logger *)calloc(1, sizeof(Logger)); 41 return (Logger *)calloc(1, sizeof(Logger));
41} 42}
@@ -45,9 +46,10 @@ void logger_kill(Logger *log)
45 free(log); 46 free(log);
46} 47}
47 48
48void logger_callback_log(Logger *log, logger_cb *function, void *userdata) 49void logger_callback_log(Logger *log, logger_cb *function, void *context, void *userdata)
49{ 50{
50 log->callback = function; 51 log->callback = function;
52 log->context = context;
51 log->userdata = userdata; 53 log->userdata = userdata;
52} 54}
53 55
@@ -65,5 +67,5 @@ void logger_write(Logger *log, LOGGER_LEVEL level, const char *file, int line, c
65 vsnprintf(msg, sizeof msg, format, args); 67 vsnprintf(msg, sizeof msg, format, args);
66 va_end(args); 68 va_end(args);
67 69
68 log->callback(level, file, line, func, msg, log->userdata); 70 log->callback(log->context, level, file, line, func, msg, log->userdata);
69} 71}
diff --git a/toxcore/logger.h b/toxcore/logger.h
index 947b9411..96dc7c9c 100644
--- a/toxcore/logger.h
+++ b/toxcore/logger.h
@@ -39,20 +39,21 @@ typedef enum {
39 39
40typedef struct Logger Logger; 40typedef struct Logger Logger;
41 41
42typedef void logger_cb(LOGGER_LEVEL level, const char *file, int line, const char *func, 42typedef void logger_cb(void *context, LOGGER_LEVEL level, const char *file, int line,
43 const char *message, void *userdata); 43 const char *func, const char *message, void *userdata);
44 44
45/** 45/**
46 * Creates a new logger with logging disabled (callback is NULL) by default. 46 * Creates a new logger with logging disabled (callback is NULL) by default.
47 */ 47 */
48Logger *logger_new(void); 48Logger *logger_new();
49 49
50void logger_kill(Logger *log); 50void logger_kill(Logger *log);
51 51
52/** 52/**
53 * Sets the logger callback. Disables logging if set to NULL. 53 * Sets the logger callback. Disables logging if set to NULL.
54 * The context parameter is passed to the callback as first argument.
54 */ 55 */
55void logger_callback_log(Logger *log, logger_cb *function, void *userdata); 56void logger_callback_log(Logger *log, logger_cb *function, void *context, void *userdata);
56 57
57/** 58/**
58 * Main write function. If logging disabled does nothing. 59 * Main write function. If logging disabled does nothing.
diff --git a/toxcore/tox.c b/toxcore/tox.c
index df2fde53..fccf3480 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -311,7 +311,7 @@ void tox_kill(Tox *tox)
311void tox_callback_log(Tox *tox, tox_log_cb *callback, void *user_data) 311void tox_callback_log(Tox *tox, tox_log_cb *callback, void *user_data)
312{ 312{
313 Messenger *m = tox; 313 Messenger *m = tox;
314 m_callback_log(m, (logger_cb *)callback, user_data); 314 m_callback_log(m, (logger_cb *)callback, tox, user_data);
315} 315}
316 316
317size_t tox_get_savedata_size(const Tox *tox) 317size_t tox_get_savedata_size(const Tox *tox)