aboutsummaryrefslogtreecommitdiff
path: root/libs/libgui/msg.c
blob: 16f72d4940082be2c68cf39aefc652482b00c77a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// MIT License, Copyright (c) 2021 Marvin Borner

#include <assert.h>
#include <errno.h>
#include <libgui/msg.h>
#include <print.h>
#include <sys.h>

// TODO: Remove debug assertions?

res msg_connect_bus(const char *bus, u32 *conn)
{
	res ret = dev_control(DEV_BUS, DEVCTL_BUS_CONNECT_BUS, bus, conn);
	/* assert(ret == EOK && *conn); */
	return ret;
}

res msg_connect_conn(u32 conn)
{
	res ret = dev_control(DEV_BUS, DEVCTL_BUS_CONNECT_CONN, conn);
	/* assert(ret == EOK); */
	return ret;
}

res msg_send(enum message_type type, void *data, u32 size)
{
	assert(size >= sizeof(struct message_header));
	struct message_header *header = data;
	header->magic = MSG_MAGIC;
	header->type = type;
	res ret = dev_write(DEV_BUS, (u8 *)data + sizeof(struct bus_header), 0, size);
	/* assert(ret >= EOK); */
	return ret;
}

res msg_receive(void *buf, u32 size)
{
	assert(size >= sizeof(struct message_header));
	struct message_header *header = buf;
	memset(header, 0, sizeof(*header));

	res ret = dev_read(DEV_BUS, buf, 0, size);
	if (header->magic == MSG_MAGIC)
		return ret;
	else
		return -EINVAL;
}