mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
log: dynamically load the logger API
This commit is contained in:
parent
b4fdcbd322
commit
0af8377d10
14 changed files with 134 additions and 200 deletions
|
|
@ -55,10 +55,6 @@ static inline void spa_log_impl_log(struct spa_log *log,
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
static inline void spa_log_impl_set_loop(struct spa_log *log, struct spa_loop *loop)
|
||||
{
|
||||
}
|
||||
|
||||
#define SPA_LOG_IMPL_DEFINE(name) \
|
||||
struct { \
|
||||
struct spa_log log; \
|
||||
|
|
@ -69,8 +65,7 @@ struct { \
|
|||
NULL, \
|
||||
SPA_LOG_LEVEL_INFO, \
|
||||
spa_log_impl_log, \
|
||||
spa_log_impl_logv, \
|
||||
spa_log_impl_set_loop,} }
|
||||
spa_log_impl_logv,} }
|
||||
|
||||
#define SPA_LOG_IMPL(name) \
|
||||
SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT
|
||||
|
|
|
|||
|
|
@ -103,21 +103,8 @@ struct spa_log {
|
|||
const char *func,
|
||||
const char *fmt,
|
||||
va_list args) SPA_PRINTF_FUNC(6, 0);
|
||||
/**
|
||||
* Set the loop for trace logging
|
||||
* \param log the logger
|
||||
* \param loop the loop for trace logging
|
||||
*
|
||||
* Trace logging will be done to a ringbuffer and written to
|
||||
* the console/device from \a loop to ensure no blocking operations
|
||||
* are done from the realtime thread.
|
||||
*/
|
||||
void (*set_loop) (struct spa_log *log,
|
||||
struct spa_loop *loop);
|
||||
};
|
||||
|
||||
#define spa_log_set_loop(l,...) (l)->set_loop((l),__VA_ARGS__)
|
||||
|
||||
#define spa_log_level_enabled(l,lev) ((l) && (l)->level >= (lev))
|
||||
|
||||
#if __STDC_VERSION__ >= 199901L
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
#define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_INFO
|
||||
|
||||
#define TRACE_BUFFER 4096
|
||||
#define TRACE_BUFFER (16*1024)
|
||||
|
||||
struct type {
|
||||
uint32_t log;
|
||||
|
|
@ -142,33 +142,12 @@ static void on_trace_event(struct spa_source *source)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
impl_log_set_loop(struct spa_log *log, struct spa_loop *loop)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(log, struct impl, log);
|
||||
if (impl->have_source) {
|
||||
spa_loop_remove_source(impl->source.loop, &impl->source);
|
||||
close(impl->source.fd);
|
||||
impl->have_source = false;
|
||||
}
|
||||
if (loop) {
|
||||
impl->source.func = on_trace_event;
|
||||
impl->source.data = impl;
|
||||
impl->source.fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
||||
impl->source.mask = SPA_IO_IN;
|
||||
impl->source.rmask = 0;
|
||||
spa_loop_add_source(loop, &impl->source);
|
||||
impl->have_source = true;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct spa_log impl_log = {
|
||||
sizeof(struct spa_log),
|
||||
NULL,
|
||||
DEFAULT_LOG_LEVEL,
|
||||
impl_log_log,
|
||||
impl_log_logv,
|
||||
impl_log_set_loop,
|
||||
impl_log_log,
|
||||
impl_log_logv,
|
||||
};
|
||||
|
||||
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
|
||||
|
|
@ -196,8 +175,11 @@ static int impl_clear(struct spa_handle *handle)
|
|||
|
||||
this = (struct impl *) handle;
|
||||
|
||||
impl_log_set_loop(&this->log, NULL);
|
||||
|
||||
if (this->have_source) {
|
||||
spa_loop_remove_source(this->source.loop, &this->source);
|
||||
close(this->source.fd);
|
||||
this->have_source = false;
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -210,6 +192,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
{
|
||||
struct impl *this;
|
||||
uint32_t i;
|
||||
struct spa_loop *loop = NULL;
|
||||
|
||||
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
||||
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
||||
|
|
@ -224,6 +207,8 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error(&this->log, "a type-map is needed");
|
||||
|
|
@ -231,6 +216,16 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
init_type(&this->type, this->map);
|
||||
|
||||
if (loop) {
|
||||
this->source.func = on_trace_event;
|
||||
this->source.data = this;
|
||||
this->source.fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
||||
this->source.mask = SPA_IO_IN;
|
||||
this->source.rmask = 0;
|
||||
spa_loop_add_source(loop, &this->source);
|
||||
this->have_source = true;
|
||||
}
|
||||
|
||||
spa_ringbuffer_init(&this->trace_rb, TRACE_BUFFER);
|
||||
|
||||
spa_log_info(&this->log, NAME " %p: initialized", this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue