]> sigrok.org Git - libsigrokdecode.git/commitdiff
log: add a public srd_log_callback_get() API routine
authorGerhard Sittig <redacted>
Wed, 15 Aug 2018 21:09:11 +0000 (23:09 +0200)
committerUwe Hermann <redacted>
Thu, 30 Aug 2018 20:14:27 +0000 (22:14 +0200)
Allow applications to query the currently registered log callback. So
they can either restore the previously registered routine, or register
another routine _and_ log to the previously registered routine as well.

libsigrokdecode.h
log.c

index deba470149306de3b30289affa6b7e38c53ee843..55620a7f52551df6e01ea1521711ce34fdf12496 100644 (file)
@@ -367,6 +367,7 @@ typedef int (*srd_log_callback)(void *cb_data, int loglevel,
                                  const char *format, va_list args);
 SRD_API int srd_log_loglevel_set(int loglevel);
 SRD_API int srd_log_loglevel_get(void);
+SRD_API int srd_log_callback_get(srd_log_callback *cb, void **cb_data);
 SRD_API int srd_log_callback_set(srd_log_callback cb, void *cb_data);
 SRD_API int srd_log_callback_set_default(void);
 
diff --git a/log.c b/log.c
index 459a5c10be9023ad2422a4c35a015abfd79f95ee..b5402f8bb8e21b81961be9f16b5ef9ebb3623827 100644 (file)
--- a/log.c
+++ b/log.c
@@ -129,6 +129,28 @@ SRD_API int srd_log_callback_set(srd_log_callback cb, void *cb_data)
        return SRD_OK;
 }
 
+/**
+ * Get the libsigrokdecode log callback routine and callback data.
+ *
+ * @param[out] cb Pointer to a function pointer to receive the log callback
+ *     function. Optional, can be NULL.
+ * @param[out] cb_data Pointer to a void pointer to receive the log callback's
+ *     additional arguments. Optional, can be NULL.
+ *
+ * @return SRD_OK upon success.
+ *
+ * @since 0.6.0
+ */
+SRD_API int srd_log_callback_get(srd_log_callback *cb, void **cb_data)
+{
+       if (cb)
+               *cb = srd_log_cb;
+       if (cb_data)
+               *cb_data = srd_log_cb_data;
+
+       return SRD_OK;
+}
+
 /**
  * Set the libsigrokdecode log callback to the default built-in one.
  *