modules: switch protocol-native to the new logging system

This is more complicated than a normal module because we have two
logging topics: mod.protocol-native and conn.protocol-native for wire
messages. Because the latter use spa_debug (through spa_debug_pod) we
need to #define our way around so those too use the right topics.

Note that this removes the previous "connection" category, it is now
"conn.protocol-native" instead.
This commit is contained in:
Peter Hutterer 2021-09-17 10:12:28 +10:00 committed by Wim Taymans
parent 14112fd168
commit 96f8a7597e
6 changed files with 58 additions and 32 deletions

View file

@ -58,8 +58,14 @@
#include "modules/module-protocol-native/connection.h" #include "modules/module-protocol-native/connection.h"
#include "modules/module-protocol-native/defs.h" #include "modules/module-protocol-native/defs.h"
#define NAME "protocol-native"
PW_LOG_TOPIC(mod_topic, "mod." NAME);
#define PW_LOG_TOPIC_DEFAULT mod_topic
PW_LOG_TOPIC(mod_topic_connection, "conn." NAME);
#undef spa_debug #undef spa_debug
#define spa_debug pw_log_debug #define spa_debug(...) pw_logt_debug(mod_topic_connection, __VA_ARGS__)
#include <spa/debug/pod.h> #include <spa/debug/pod.h>
#include <spa/debug/types.h> #include <spa/debug/types.h>
@ -67,8 +73,6 @@
/** \page page_module_protocol_native PipeWire Module: Protocol Native /** \page page_module_protocol_native PipeWire Module: Protocol Native
*/ */
#define NAME "protocol-native"
#ifndef UNIX_PATH_MAX #ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108 #define UNIX_PATH_MAX 108
#endif #endif
@ -156,7 +160,8 @@ struct client_data {
static void debug_msg(const char *prefix, const struct pw_protocol_native_message *msg, bool hex) static void debug_msg(const char *prefix, const struct pw_protocol_native_message *msg, bool hex)
{ {
struct spa_pod *pod; struct spa_pod *pod;
pw_log_debug("%s: id:%d op:%d size:%d seq:%d", prefix, pw_logt_debug(mod_topic_connection,
"%s: id:%d op:%d size:%d seq:%d", prefix,
msg->id, msg->opcode, msg->size, msg->seq); msg->id, msg->opcode, msg->size, msg->seq);
if ((pod = spa_pod_from_data(msg->data, msg->size, 0, msg->size)) != NULL) if ((pod = spa_pod_from_data(msg->data, msg->size, 0, msg->size)) != NULL)
@ -202,7 +207,7 @@ process_messages(struct client_data *data)
client->recv_seq = msg->seq; client->recv_seq = msg->seq;
pw_log_trace(NAME" %p: got message %d from %u", client->protocol, pw_log_trace("%p: got message %d from %u", client->protocol,
msg->opcode, msg->id); msg->opcode, msg->id);
if (debug_messages) if (debug_messages)
@ -276,7 +281,7 @@ client_busy_changed(void *data, bool busy)
SPA_FLAG_UPDATE(mask, SPA_IO_IN, !busy); SPA_FLAG_UPDATE(mask, SPA_IO_IN, !busy);
pw_log_debug(NAME" %p: busy changed %d", client->protocol, busy); pw_log_debug("%p: busy changed %d", client->protocol, busy);
pw_loop_update_io(client->context->main_loop, c->source, mask); pw_loop_update_io(client->context->main_loop, c->source, mask);
if (!busy) if (!busy)
@ -286,9 +291,9 @@ client_busy_changed(void *data, bool busy)
static void handle_client_error(struct pw_impl_client *client, int res) static void handle_client_error(struct pw_impl_client *client, int res)
{ {
if (res == -EPIPE) if (res == -EPIPE)
pw_log_info(NAME" %p: client %p disconnected", client->protocol, client); pw_log_info("%p: client %p disconnected", client->protocol, client);
else else
pw_log_error(NAME" %p: client %p error %d (%s)", client->protocol, pw_log_error("%p: client %p error %d (%s)", client->protocol,
client, res, spa_strerror(res)); client, res, spa_strerror(res));
pw_impl_client_destroy(client); pw_impl_client_destroy(client);
} }
@ -331,7 +336,7 @@ static void client_free(void *data)
struct client_data *this = data; struct client_data *this = data;
struct pw_impl_client *client = this->client; struct pw_impl_client *client = this->client;
pw_log_debug(NAME" %p: free", this); pw_log_debug("%p: free", this);
spa_list_remove(&this->protocol_link); spa_list_remove(&this->protocol_link);
spa_hook_remove(&this->client_listener); spa_hook_remove(&this->client_listener);
@ -751,7 +756,7 @@ process_remote(struct client *impl)
if (res == 0) if (res == 0)
break; break;
pw_log_trace(NAME" %p: got message %d from %u seq:%d", pw_log_trace("%p: got message %d from %u seq:%d",
this, msg->opcode, msg->id, msg->seq); this, msg->opcode, msg->id, msg->seq);
this->recv_seq = msg->seq; this->recv_seq = msg->seq;
@ -762,9 +767,9 @@ process_remote(struct client *impl)
proxy = pw_core_find_proxy(this, msg->id); proxy = pw_core_find_proxy(this, msg->id);
if (proxy == NULL || proxy->zombie) { if (proxy == NULL || proxy->zombie) {
if (proxy == NULL) if (proxy == NULL)
pw_log_error(NAME" %p: could not find proxy %u", this, msg->id); pw_log_error("%p: could not find proxy %u", this, msg->id);
else else
pw_log_debug(NAME" %p: zombie proxy %u", this, msg->id); pw_log_debug("%p: zombie proxy %u", this, msg->id);
/* FIXME close fds */ /* FIXME close fds */
continue; continue;
@ -772,7 +777,7 @@ process_remote(struct client *impl)
marshal = pw_proxy_get_marshal(proxy); marshal = pw_proxy_get_marshal(proxy);
if (marshal == NULL || msg->opcode >= marshal->n_server_methods) { if (marshal == NULL || msg->opcode >= marshal->n_server_methods) {
pw_log_error(NAME" %p: invalid method %u for %u (%d)", pw_log_error("%p: invalid method %u for %u (%d)",
this, msg->opcode, msg->id, this, msg->opcode, msg->id,
marshal ? marshal->n_server_methods : (uint32_t)-1); marshal ? marshal->n_server_methods : (uint32_t)-1);
continue; continue;
@ -780,7 +785,7 @@ process_remote(struct client *impl)
demarshal = marshal->client_demarshal; demarshal = marshal->client_demarshal;
if (!demarshal[msg->opcode].func) { if (!demarshal[msg->opcode].func) {
pw_log_error(NAME" %p: function %d not implemented on %u", pw_log_error("%p: function %d not implemented on %u",
this, msg->opcode, msg->id); this, msg->opcode, msg->id);
continue; continue;
} }
@ -791,7 +796,7 @@ process_remote(struct client *impl)
pw_proxy_unref(proxy); pw_proxy_unref(proxy);
if (res < 0) { if (res < 0) {
pw_log_error(NAME" %p: invalid message received %u for %u: %s", pw_log_error("%p: invalid message received %u for %u: %s",
this, msg->opcode, msg->id, spa_strerror(res)); this, msg->opcode, msg->id, spa_strerror(res));
debug_msg("*invalid*", msg, true); debug_msg("*invalid*", msg, true);
} }
@ -829,7 +834,7 @@ on_remote_data(void *data, int fd, uint32_t mask)
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &res, &len) < 0) { if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &res, &len) < 0) {
res = -errno; res = -errno;
pw_log_error(NAME" getsockopt: %m"); pw_log_error("getsockopt: %m");
goto error; goto error;
} }
if (res != 0) { if (res != 0) {
@ -837,7 +842,7 @@ on_remote_data(void *data, int fd, uint32_t mask)
goto error; goto error;
} }
impl->connected = true; impl->connected = true;
pw_log_debug(NAME" %p: connected, fd %d", impl, fd); pw_log_debug("%p: connected, fd %d", impl, fd);
} }
impl->need_flush = false; impl->need_flush = false;
res = pw_protocol_native_connection_flush(conn); res = pw_protocol_native_connection_flush(conn);
@ -853,7 +858,7 @@ done:
pw_proxy_unref(core_proxy); pw_proxy_unref(core_proxy);
return; return;
error: error:
pw_log_debug(NAME" %p: got connection error %d (%s)", impl, res, spa_strerror(res)); pw_log_debug("%p: got connection error %d (%s)", impl, res, spa_strerror(res));
if (impl->source) { if (impl->source) {
pw_loop_destroy_source(loop, impl->source); pw_loop_destroy_source(loop, impl->source);
impl->source = NULL; impl->source = NULL;
@ -960,7 +965,7 @@ static int impl_set_paused(struct pw_protocol_client *client, bool paused)
SPA_FLAG_UPDATE(mask, SPA_IO_IN, !paused); SPA_FLAG_UPDATE(mask, SPA_IO_IN, !paused);
pw_log_debug(NAME" %p: paused %d", client->protocol, paused); pw_log_debug("%p: paused %d", client->protocol, paused);
pw_loop_update_io(impl->context->main_loop, impl->source, mask); pw_loop_update_io(impl->context->main_loop, impl->source, mask);
return paused ? 0 : process_remote(impl); return paused ? 0 : process_remote(impl);
@ -1021,7 +1026,7 @@ impl_new_client(struct pw_protocol *protocol,
if ((impl = calloc(1, sizeof(struct client))) == NULL) if ((impl = calloc(1, sizeof(struct client))) == NULL)
return NULL; return NULL;
pw_log_debug(NAME" %p: new client %p", protocol, impl); pw_log_debug("%p: new client %p", protocol, impl);
this = &impl->this; this = &impl->this;
this->protocol = protocol; this->protocol = protocol;
@ -1045,7 +1050,7 @@ impl_new_client(struct pw_protocol *protocol,
if (str == NULL) if (str == NULL)
str = "generic"; str = "generic";
pw_log_debug(NAME" %p: connect %s", protocol, str); pw_log_debug("%p: connect %s", protocol, str);
if (spa_streq(str, "screencast")) if (spa_streq(str, "screencast"))
this->connect = pw_protocol_native_connect_portal_screencast; this->connect = pw_protocol_native_connect_portal_screencast;
@ -1075,7 +1080,7 @@ static void destroy_server(struct pw_protocol_server *server)
struct server *s = SPA_CONTAINER_OF(server, struct server, this); struct server *s = SPA_CONTAINER_OF(server, struct server, this);
struct client_data *data, *tmp; struct client_data *data, *tmp;
pw_log_debug(NAME" %p: server %p", s->this.protocol, s); pw_log_debug("%p: server %p", s->this.protocol, s);
spa_list_remove(&server->link); spa_list_remove(&server->link);
@ -1148,7 +1153,7 @@ create_server(struct pw_protocol *protocol,
spa_list_append(&protocol->server_list, &this->link); spa_list_append(&protocol->server_list, &this->link);
pw_log_debug(NAME" %p: created server %p", protocol, this); pw_log_debug("%p: created server %p", protocol, this);
return s; return s;
} }
@ -1182,7 +1187,7 @@ impl_add_server(struct pw_protocol *protocol,
if ((s->resume = pw_loop_add_event(s->loop, do_resume, s)) == NULL) if ((s->resume = pw_loop_add_event(s->loop, do_resume, s)) == NULL)
goto error; goto error;
pw_log_info(NAME" %p: Listening on '%s'", protocol, name); pw_log_info("%p: Listening on '%s'", protocol, name);
return this; return this;
@ -1299,6 +1304,9 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
const struct pw_properties *props; const struct pw_properties *props;
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic);
PW_LOG_TOPIC_INIT(mod_topic_connection);
if (pw_context_find_protocol(context, PW_TYPE_INFO_PROTOCOL_Native) != NULL) if (pw_context_find_protocol(context, PW_TYPE_INFO_PROTOCOL_Native) != NULL)
return 0; return 0;
@ -1306,7 +1314,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
if (this == NULL) if (this == NULL)
return -errno; return -errno;
debug_messages = pw_debug_is_category_enabled("connection"); debug_messages = mod_topic_connection->level >= SPA_LOG_LEVEL_DEBUG;
this->implementation = &protocol_impl; this->implementation = &protocol_impl;
this->extension = &protocol_ext_impl; this->extension = &protocol_ext_impl;
@ -1314,7 +1322,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
pw_protocol_native_init(this); pw_protocol_native_init(this);
pw_protocol_native0_init(this); pw_protocol_native0_init(this);
pw_log_debug(NAME" %p: new debug:%d", this, debug_messages); pw_log_debug("%p: new debug:%d", this, debug_messages);
d = pw_protocol_get_user_data(this); d = pw_protocol_get_user_data(this);
d->protocol = this; d->protocol = this;

View file

@ -36,7 +36,12 @@
#include <pipewire/pipewire.h> #include <pipewire/pipewire.h>
#define spa_debug pw_log_debug PW_LOG_TOPIC_EXTERN(mod_topic);
#define PW_LOG_TOPIC_DEFAULT mod_topic
PW_LOG_TOPIC_EXTERN(mod_topic_connection);
#undef spa_debug
#define spa_debug(...) pw_logt_debug(mod_topic_connection, __VA_ARGS__)
#include <spa/debug/pod.h> #include <spa/debug/pod.h>
#include "connection.h" #include "connection.h"
@ -48,8 +53,6 @@
#define HDR_SIZE_V0 8 #define HDR_SIZE_V0 8
#define HDR_SIZE 16 #define HDR_SIZE 16
static bool debug_messages = 0;
struct buffer { struct buffer {
uint8_t *buffer_data; uint8_t *buffer_data;
size_t buffer_size; size_t buffer_size;
@ -367,7 +370,6 @@ struct pw_protocol_native_connection *pw_protocol_native_connection_new(struct p
if (impl == NULL) if (impl == NULL)
return NULL; return NULL;
debug_messages = pw_debug_is_category_enabled("connection");
impl->context = context; impl->context = context;
this = &impl->this; this = &impl->this;
@ -633,7 +635,7 @@ pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
else else
buf->n_fds = buf->msg.n_fds; buf->n_fds = buf->msg.n_fds;
if (debug_messages) { if (mod_topic_connection->level >= SPA_LOG_LEVEL_DEBUG) {
pw_log_debug(">>>>>>>>> out: id:%d op:%d size:%d seq:%d", pw_log_debug(">>>>>>>>> out: id:%d op:%d size:%d seq:%d",
buf->msg.id, buf->msg.opcode, size, buf->msg.seq); buf->msg.id, buf->msg.opcode, size, buf->msg.seq);
spa_debug_pod(0, NULL, SPA_PTROFF(p, impl->hdr_size, struct spa_pod)); spa_debug_pod(0, NULL, SPA_PTROFF(p, impl->hdr_size, struct spa_pod));

View file

@ -43,6 +43,9 @@
#define DEFAULT_SYSTEM_RUNTIME_DIR "/run/pipewire" #define DEFAULT_SYSTEM_RUNTIME_DIR "/run/pipewire"
PW_LOG_TOPIC_EXTERN(mod_topic);
#define PW_LOG_TOPIC_DEFAULT mod_topic
static const char * static const char *
get_remote(const struct spa_dict *props) get_remote(const struct spa_dict *props)
{ {

View file

@ -34,6 +34,9 @@
#include "connection.h" #include "connection.h"
PW_LOG_TOPIC_EXTERN(mod_topic);
#define PW_LOG_TOPIC_DEFAULT mod_topic
static int core_method_marshal_add_listener(void *object, static int core_method_marshal_add_listener(void *object,
struct spa_hook *listener, struct spa_hook *listener,
const struct pw_core_events *events, const struct pw_core_events *events,

View file

@ -32,6 +32,10 @@
#include "connection.h" #include "connection.h"
#define NAME "protocol-native"
PW_LOG_TOPIC(mod_topic, "mod." NAME);
PW_LOG_TOPIC(mod_topic_connection, "conn." NAME);
static void test_create(struct pw_protocol_native_connection *conn) static void test_create(struct pw_protocol_native_connection *conn)
{ {
const struct pw_protocol_native_message *msg; const struct pw_protocol_native_message *msg;
@ -190,6 +194,9 @@ int main(int argc, char *argv[])
pw_init(&argc, &argv); pw_init(&argc, &argv);
PW_LOG_TOPIC_INIT(mod_topic);
PW_LOG_TOPIC_INIT(mod_topic_connection);
loop = pw_main_loop_new(NULL); loop = pw_main_loop_new(NULL);
spa_assert_se(loop != NULL); spa_assert_se(loop != NULL);
context = pw_context_new(pw_main_loop_get_loop(loop), NULL, 0); context = pw_context_new(pw_main_loop_get_loop(loop), NULL, 0);

View file

@ -44,6 +44,9 @@
#include "../connection.h" #include "../connection.h"
PW_LOG_TOPIC_EXTERN(mod_topic);
#define PW_LOG_TOPIC_DEFAULT mod_topic
#define PW_PROTOCOL_NATIVE_FLAG_REMAP (1<<0) #define PW_PROTOCOL_NATIVE_FLAG_REMAP (1<<0)
SPA_EXPORT SPA_EXPORT