mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-01-07 11:10:14 +01:00
brei: abstract the message type away
Once we start passing fds within messages, we need something more abstract. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
dabd48c028
commit
d4fedc1a4b
4 changed files with 20 additions and 15 deletions
|
|
@ -76,9 +76,7 @@ brei_next_message(const char *data, size_t *msglen, size_t *consumed)
|
|||
|
||||
int
|
||||
brei_dispatch(int fd,
|
||||
int (*callback)(const char *msgdata,
|
||||
size_t len,
|
||||
void *user_data),
|
||||
int (*callback)(struct brei_message *m, void *user_data),
|
||||
void *user_data)
|
||||
{
|
||||
_cleanup_iobuf_ struct iobuf *buf = iobuf_new(64);
|
||||
|
|
@ -107,8 +105,13 @@ brei_dispatch(int fd,
|
|||
|
||||
assert(len >= msglen);
|
||||
|
||||
struct brei_message msg = {
|
||||
.data = msgdata,
|
||||
.len = msglen,
|
||||
};
|
||||
|
||||
/* Actual message parsing is done by the caller */
|
||||
consumed = callback(msgdata, msglen, user_data);
|
||||
consumed = callback(&msg, user_data);
|
||||
assert(consumed != 0);
|
||||
if (consumed < 0) {
|
||||
rc = consumed;
|
||||
|
|
@ -164,15 +167,14 @@ MUNIT_TEST(test_proto_next_message)
|
|||
}
|
||||
|
||||
static int
|
||||
brei_dispatch_cb(const char *msgdata,
|
||||
size_t len,
|
||||
brei_dispatch_cb(struct brei_message *msg,
|
||||
void *user_data)
|
||||
{
|
||||
char *buf = user_data;
|
||||
|
||||
memcpy(buf, msgdata, len);
|
||||
memcpy(buf, msg->data, msg->len);
|
||||
|
||||
return len;
|
||||
return msg->len;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
struct brei_message {
|
||||
const char *data;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispatch messages for the data on fd.
|
||||
* The callback is called for each protocol message, parsing must be done by
|
||||
|
|
@ -37,7 +42,5 @@
|
|||
*/
|
||||
int
|
||||
brei_dispatch(int fd,
|
||||
int (*callback)(const char *msgdata,
|
||||
size_t len,
|
||||
void *userdata),
|
||||
int (*callback)(struct brei_message *msg, void *userdata),
|
||||
void *user_data);
|
||||
|
|
|
|||
|
|
@ -539,13 +539,13 @@ connection_connected_handle_msg(struct ei *ei, struct message *msg)
|
|||
}
|
||||
|
||||
static int
|
||||
connection_message_callback(const char *msgdata, size_t len, void *userdata)
|
||||
connection_message_callback(struct brei_message *bmsg, void *userdata)
|
||||
{
|
||||
struct ei *ei = userdata;
|
||||
size_t consumed;
|
||||
|
||||
_cleanup_message_ struct message *msg =
|
||||
ei_proto_parse_message(msgdata, len, &consumed);
|
||||
ei_proto_parse_message(bmsg->data, bmsg->len, &consumed);
|
||||
if (!msg)
|
||||
return -EBADMSG;
|
||||
|
||||
|
|
|
|||
|
|
@ -386,13 +386,13 @@ client_connected_handle_msg(struct eis_client *client,
|
|||
}
|
||||
|
||||
static int
|
||||
client_message_callback(const char *msgdata, size_t len, void *userdata)
|
||||
client_message_callback(struct brei_message *bmsg, void *userdata)
|
||||
{
|
||||
struct eis_client *client = userdata;
|
||||
size_t consumed;
|
||||
|
||||
_cleanup_message_ struct message *msg =
|
||||
eis_proto_parse_message(msgdata, len, &consumed);
|
||||
eis_proto_parse_message(bmsg->data, bmsg->len, &consumed);
|
||||
if (!msg)
|
||||
return -EBADMSG;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue