libei: unify the wire message logging in one place

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-13 13:20:10 +10:00
parent 81cb24124d
commit f149a93743

View file

@ -217,9 +217,41 @@ ei_queue_removed_event(struct ei_device *device)
ei_queue_event(ei, e);
}
static inline void
log_wire_message(struct ei *ei, const ClientMessage *msg)
{
const char *message = NULL;
#define MSG_STRING_CASE(_name) \
case CLIENT_MESSAGE__MSG_##_name: message = #_name; break;
switch (msg->msg_case) {
case CLIENT_MESSAGE__MSG__NOT_SET:
abort();
MSG_STRING_CASE(CONNECT);
MSG_STRING_CASE(DISCONNECT);
MSG_STRING_CASE(ADD_DEVICE);
MSG_STRING_CASE(REMOVE_DEVICE);
MSG_STRING_CASE(REL);
MSG_STRING_CASE(BUTTON);
MSG_STRING_CASE(KEY);
MSG_STRING_CASE(CONFIGURE_NAME);
MSG_STRING_CASE(CONFIGURE_CAPS);
default:
assert(!"Unimplemented message type");
break;
}
log_debug(ei, "sending wire message %s\n", message);
#undef MSG_STRING_CASE
}
static int
connection_send_msg(struct ei *ei, const ClientMessage *msg)
{
log_wire_message(ei, msg);
size_t msglen = client_message__get_packed_size(msg);
Frame frame = FRAME__INIT;
frame.length = msglen;
@ -238,8 +270,6 @@ connection_send_connect(struct ei *ei)
ei->state == EI_STATE_DISCONNECTED)
return 0;
log_debug(ei, "sending connect\n");
ClientMessage msg = CLIENT_MESSAGE__INIT;
Connect connect = CONNECT__INIT;
connect.name = ei->name;
@ -257,8 +287,6 @@ connection_send_disconnect(struct ei *ei)
ei->state == EI_STATE_DISCONNECTED)
return 0;
log_debug(ei, "sending disconnect\n");
ClientMessage msg = CLIENT_MESSAGE__INIT;
Disconnect disconnect = DISCONNECT__INIT;
@ -275,8 +303,6 @@ connection_send_add(struct ei *ei, struct ei_device *device)
ei->state == EI_STATE_DISCONNECTED)
return 0;
log_debug(ei, "sending add\n");
ClientMessage msg = CLIENT_MESSAGE__INIT;
AddDevice add = ADD_DEVICE__INIT;
@ -296,8 +322,6 @@ connection_send_remove(struct ei *ei, struct ei_device *device)
ei->state == EI_STATE_DISCONNECTED)
return 0;
log_debug(ei, "sending remove\n");
ClientMessage msg = CLIENT_MESSAGE__INIT;
RemoveDevice remove = REMOVE_DEVICE__INIT;