aboutsummaryrefslogtreecommitdiffstats
path: root/src/channel.c
blob: dfca5aa310b995e005556136c645594256d2cc4f (plain)
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
48
49
50
51
52
53
54
#include <osmocom/core/talloc.h>
#include <osmocom/core/msgb.h>

#include <osmocom/netif/channel.h>

extern struct osmo_chan_type chan_abis_ipa_srv;
extern struct osmo_chan_type chan_abis_ipa_cli;

static struct osmo_chan_type *chan_type[CHAN_MAX] = {
	[CHAN_ABIS_IPA_SRV]	= &chan_abis_ipa_srv,
	[CHAN_ABIS_IPA_CLI]	= &chan_abis_ipa_cli,
};

struct osmo_chan *osmo_chan_create(void *ctx, int type_id)
{
	struct osmo_chan *c;

	if (type_id >= CHAN_MAX)
		return NULL;

	c = talloc_zero_size(ctx, sizeof(struct osmo_chan) +
			     chan_type[type_id]->datasiz);
	if (c == NULL)
		return NULL;

	c->ops = chan_type[type_id];

	if (c->ops->create(c) < 0) {
		talloc_free(c);
		return NULL;
	}
	return c;
}

void osmo_chan_destroy(struct osmo_chan *c)
{
	c->ops->destroy(c);
	talloc_free(c);
}

int osmo_chan_open(struct osmo_chan *c)
{
	return c->ops->open(c);
}

void osmo_chan_close(struct osmo_chan *c)
{
	c->ops->close(c);
}

int osmo_chan_enqueue(struct osmo_chan *c, struct msgb *msg)
{
	return c->ops->enqueue(c, msg);
}