aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2012-08-19 00:23:21 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2012-08-19 00:49:20 +0200
commitc05485c90c17e4fafbf71867e223a6e148c2ca43 (patch)
tree7f0c41537777a4ac6d20a4559069a7948587b989 /src
parent557e5c127a5b6cd33deb85d047dba36e2c43a862 (diff)
channel: use linked list instead of array of existing channels
This also adds osmo_chan_init() that needs to initialize the channel infrastructure.
Diffstat (limited to 'src')
-rw-r--r--src/channel.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/channel.c b/src/channel.c
index 0fe9e17..16e9dfc 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -1,35 +1,54 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/logging.h>
+#include <osmocom/core/linuxlist.h>
#include <osmocom/netif/channel.h>
+static LLIST_HEAD(channel_list);
+
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,
-};
+void osmo_chan_init(void)
+{
+ llist_add(&chan_abis_ipa_srv.head, &channel_list);
+ llist_add(&chan_abis_ipa_cli.head, &channel_list);
+ /* add your new channel type here */
+}
struct osmo_chan *osmo_chan_create(void *ctx, int type_id)
{
+ struct osmo_chan_type *cur = NULL;
+ int found = 0;
struct osmo_chan *c;
- if (type_id >= CHAN_MAX) {
- LOGP(DLINP, LOGL_ERROR, "unsupported channel type `%u'\n",
- type_id);
+ if (type_id > CHAN_MAX) {
+ LOGP(DLINP, LOGL_ERROR, "unsupported channel type "
+ "number `%u'\n", type_id);
+ return NULL;
+ }
+
+ llist_for_each_entry(cur, &channel_list, head) {
+ if (type_id == cur->type) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found) {
+ LOGP(DLINP, LOGL_ERROR, "unsupported channel type `%s'\n",
+ cur->name);
return NULL;
}
- c = talloc_zero_size(ctx, sizeof(struct osmo_chan) +
- chan_type[type_id]->datasiz);
+ c = talloc_zero_size(ctx, sizeof(struct osmo_chan) + cur->datasiz);
if (c == NULL) {
LOGP(DLINP, LOGL_ERROR, "cannot allocate channel data\n");
return NULL;
}
- c->ops = chan_type[type_id];
+ c->ops = cur;
if (c->ops->create(c) < 0) {
LOGP(DLINP, LOGL_ERROR, "cannot create channel\n");