channel: osmo_chan_init takes one pointer to set the talloc context

Also remove this parameter from osmo_chan_create
This commit is contained in:
Pablo Neira Ayuso 2012-08-19 00:39:21 +02:00 committed by Pablo Neira Ayuso
parent d73c757e6d
commit b71627b1f7
4 changed files with 13 additions and 9 deletions

View File

@ -55,10 +55,10 @@ int main(void)
log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
/* initialize channel infrastructure. */
osmo_chan_init();
osmo_chan_init(tall_example);
/* create channel. */
chan = osmo_chan_create(tall_example, OSMO_CHAN_ABIS_IPA_CLI);
chan = osmo_chan_create(OSMO_CHAN_ABIS_IPA_CLI);
if (chan == NULL) {
LOGP(DEXAMPLE, LOGL_ERROR, "Cannot create A-bis IPA client\n");
exit(EXIT_FAILURE);

View File

@ -52,10 +52,10 @@ int main(void)
log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
/* initialize channel infrastructure. */
osmo_chan_init();
osmo_chan_init(tall_example);
/* create channel. */
chan = osmo_chan_create(tall_example, OSMO_CHAN_ABIS_IPA_SRV);
chan = osmo_chan_create(OSMO_CHAN_ABIS_IPA_SRV);
if (chan == NULL) {
LOGP(DEXAMPLE, LOGL_ERROR, "Cannot create A-bis IPA server\n");
exit(EXIT_FAILURE);

View File

@ -34,9 +34,9 @@ struct osmo_chan {
char data[0];
};
void osmo_chan_init(void);
void osmo_chan_init(void *ctx);
struct osmo_chan *osmo_chan_create(void *ctx, int type);
struct osmo_chan *osmo_chan_create(int type);
void osmo_chan_destroy(struct osmo_chan *c);
int osmo_chan_open(struct osmo_chan *c);

View File

@ -10,14 +10,17 @@ static LLIST_HEAD(channel_list);
extern struct osmo_chan_type chan_abis_ipa_srv;
extern struct osmo_chan_type chan_abis_ipa_cli;
void osmo_chan_init(void)
static void *osmo_chan_ctx;
void osmo_chan_init(void *ctx)
{
osmo_chan_ctx = ctx;
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 *osmo_chan_create(int type_id)
{
struct osmo_chan_type *cur = NULL;
int found = 0;
@ -42,7 +45,8 @@ struct osmo_chan *osmo_chan_create(void *ctx, int type_id)
return NULL;
}
c = talloc_zero_size(ctx, sizeof(struct osmo_chan) + cur->datasiz);
c = talloc_zero_size(osmo_chan_ctx,
sizeof(struct osmo_chan) + cur->datasiz);
if (c == NULL) {
LOGP(DLINP, LOGL_ERROR, "cannot allocate channel data\n");
return NULL;