mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 15:14:38 +01:00
add log buffer functionality
Useful to debug the incoming and outgoing data. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#define LIBRATBAG_PRIVATE_H
|
||||
|
||||
#include <linux/input.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libratbag.h"
|
||||
#include "libratbag-util.h"
|
||||
@@ -244,6 +245,11 @@ log_msg_va(struct ratbag *ratbag,
|
||||
void log_msg(struct ratbag *ratbag,
|
||||
enum ratbag_log_priority priority,
|
||||
const char *format, ...);
|
||||
void
|
||||
log_buffer(struct ratbag *ratbag,
|
||||
enum ratbag_log_priority priority,
|
||||
const char *header,
|
||||
uint8_t *buf, size_t len);
|
||||
|
||||
#define log_debug(li_, ...) log_msg((li_), RATBAG_LOG_PRIORITY_DEBUG, __VA_ARGS__)
|
||||
#define log_info(li_, ...) log_msg((li_), RATBAG_LOG_PRIORITY_INFO, __VA_ARGS__)
|
||||
@@ -251,6 +257,9 @@ void log_msg(struct ratbag *ratbag,
|
||||
#define log_bug_kernel(li_, ...) log_msg((li_), RATBAG_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
|
||||
#define log_bug_libratbag(li_, ...) log_msg((li_), RATBAG_LOG_PRIORITY_ERROR, "libratbag bug: " __VA_ARGS__)
|
||||
#define log_bug_client(li_, ...) log_msg((li_), LIBRATBAG_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
|
||||
#define log_buf_debug(li_, h_, buf_, len_) log_buffer(li_, RATBAG_LOG_PRIORITY_DEBUG, h_, buf_, len_)
|
||||
#define log_buf_info(li_, h_, buf_, len_) log_buffer(li_, RATBAG_LOG_PRIORITY_INFO, h_, buf_, len_)
|
||||
#define log_buf_error(li_, h_, buf_, len_) log_buffer(li_, RATBAG_LOG_PRIORITY_ERROR, h_, buf_, len_)
|
||||
|
||||
/* list of all supported drivers */
|
||||
struct ratbag_driver etekcity_driver;
|
||||
|
||||
@@ -78,6 +78,48 @@ log_msg(struct ratbag *ratbag,
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
log_buffer(struct ratbag *ratbag,
|
||||
enum ratbag_log_priority priority,
|
||||
const char *header,
|
||||
uint8_t *buf, size_t len)
|
||||
{
|
||||
char *output_buf;
|
||||
char *sep = "";
|
||||
unsigned int i, n;
|
||||
unsigned int buf_len;
|
||||
|
||||
if (ratbag->log_handler &&
|
||||
ratbag->log_priority > priority)
|
||||
return;
|
||||
|
||||
buf_len = header ? strlen(header) : 0;
|
||||
buf_len += len * 3;
|
||||
buf_len += 1; /* terminating '\0' */
|
||||
|
||||
output_buf = zalloc(buf_len);
|
||||
if (!output_buf) {
|
||||
if (header)
|
||||
log_msg(ratbag, priority, "%s ......", header);
|
||||
else
|
||||
log_msg(ratbag, priority, " ......");
|
||||
return;
|
||||
}
|
||||
|
||||
n = 0;
|
||||
if (header)
|
||||
n += sprintf(output_buf, "%s", header);
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
n += sprintf(&output_buf[n], "%s%02x", sep, buf[i] & 0xFF);
|
||||
sep = " ";
|
||||
}
|
||||
|
||||
log_msg(ratbag, priority, "%s\n", output_buf);
|
||||
|
||||
free(output_buf);
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT void
|
||||
ratbag_log_set_priority(struct ratbag *ratbag,
|
||||
enum ratbag_log_priority priority)
|
||||
|
||||
Reference in New Issue
Block a user