mirror of https://gerrit.osmocom.org/libosmocore
i460: pass more context to call-back functions
When calling a user-provided call-back function for the i460 mux or demux, always pass a pointer to the osmo_i460_subchan the callback relates to. This way, the user can walk the i460 data structures to obtain information about which mux/demux instances is calling. Change-Id: Id842c72ce371a67fe5df6694e195c281aaf607ab
This commit is contained in:
parent
eb8240d564
commit
b3b474d8ad
|
@ -36,8 +36,12 @@ enum osmo_i460_rate {
|
|||
OSMO_I460_RATE_8k,
|
||||
};
|
||||
|
||||
typedef void (*out_cb_bits_t)(void *user_data, const ubit_t *bits, unsigned int num_bits);
|
||||
typedef void (*out_cb_bytes_t)(void *user_data, const uint8_t *bytes, unsigned int num_bytes);
|
||||
struct osmo_i460_subchan;
|
||||
|
||||
typedef void (*out_cb_bits_t)(struct osmo_i460_subchan *schan, void *user_data,
|
||||
const ubit_t *bits, unsigned int num_bits);
|
||||
typedef void (*out_cb_bytes_t)(struct osmo_i460_subchan *schan, void *user_data,
|
||||
const uint8_t *bytes, unsigned int num_bytes);
|
||||
|
||||
struct osmo_i460_subchan_demux {
|
||||
/*! bit-buffer for output bits */
|
||||
|
@ -52,7 +56,7 @@ struct osmo_i460_subchan_demux {
|
|||
void *user_data;
|
||||
};
|
||||
|
||||
typedef void (*in_cb_queue_empty_t)(void *user_data);
|
||||
typedef void (*in_cb_queue_empty_t)(struct osmo_i460_subchan *schan, void *user_data);
|
||||
|
||||
struct osmo_i460_subchan_mux {
|
||||
/*! list of to-be-transmitted message buffers */
|
||||
|
|
|
@ -69,14 +69,14 @@ static void demux_subchan_append_bit(struct osmo_i460_subchan *schan, uint8_t bi
|
|||
|
||||
if (demux->out_idx >= demux->out_bitbuf_size) {
|
||||
if (demux->out_cb_bits)
|
||||
demux->out_cb_bits(demux->user_data, demux->out_bitbuf, demux->out_idx);
|
||||
demux->out_cb_bits(schan, demux->user_data, demux->out_bitbuf, demux->out_idx);
|
||||
else {
|
||||
/* pack bits into bytes */
|
||||
OSMO_ASSERT((demux->out_idx % 8) == 0);
|
||||
unsigned int num_bytes = demux->out_idx / 8;
|
||||
uint8_t bytes[num_bytes];
|
||||
osmo_ubit2pbit(bytes, demux->out_bitbuf, demux->out_idx);
|
||||
demux->out_cb_bytes(demux->user_data, bytes, num_bytes);
|
||||
demux->out_cb_bytes(schan, demux->user_data, bytes, num_bytes);
|
||||
}
|
||||
demux->out_idx = 0;
|
||||
}
|
||||
|
@ -137,11 +137,11 @@ void osmo_i460_demux_in(struct osmo_i460_timeslot *ts, const uint8_t *data, size
|
|||
schan = &ts->schan[0];
|
||||
demux = &schan->demux;
|
||||
if (demux->out_cb_bytes)
|
||||
demux->out_cb_bytes(demux->user_data, data, data_len);
|
||||
demux->out_cb_bytes(schan, demux->user_data, data, data_len);
|
||||
else {
|
||||
ubit_t bits[data_len*8];
|
||||
osmo_pbit2ubit(bits, data, data_len*8);
|
||||
demux->out_cb_bits(demux->user_data, bits, data_len*8);
|
||||
demux->out_cb_bits(schan, demux->user_data, bits, data_len*8);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ static ubit_t mux_schan_provide_bit(struct osmo_i460_subchan *schan)
|
|||
if (llist_empty(&mux->tx_queue)) {
|
||||
/* User code now has a last chance to put something into the queue. */
|
||||
if (mux->in_cb_queue_empty)
|
||||
mux->in_cb_queue_empty(mux->user_data);
|
||||
mux->in_cb_queue_empty(schan, mux->user_data);
|
||||
|
||||
/* If the queue is still empty, return idle bits */
|
||||
if (llist_empty(&mux->tx_queue))
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
#include <osmocom/gsm/i460_mux.h>
|
||||
|
||||
static void bits_cb(void *user_data, const ubit_t *bits, unsigned int num_bits)
|
||||
static void bits_cb(struct osmo_i460_subchan *schan, void *user_data,
|
||||
const ubit_t *bits, unsigned int num_bits)
|
||||
{
|
||||
char *str = user_data;
|
||||
printf("demux_bits_cb '%s': %s\n", str, osmo_ubit_dump(bits, num_bits));
|
||||
|
|
Loading…
Reference in New Issue