diff options
author | Harald Welte <laforge@osmocom.org> | 2020-08-02 11:54:56 +0200 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2020-08-02 11:57:55 +0200 |
commit | b3b474d8ade2c28ab8b0e3021dea87fae19b333c (patch) | |
tree | 455e341bfd152ff031633639f21da7b277c37c34 | |
parent | eb8240d56422b23a6aa2ba62ad57c9dee19047d1 (diff) |
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
-rw-r--r-- | include/osmocom/gsm/i460_mux.h | 10 | ||||
-rw-r--r-- | src/gsm/i460_mux.c | 10 | ||||
-rw-r--r-- | tests/i460_mux/i460_mux_test.c | 3 |
3 files changed, 14 insertions, 9 deletions
diff --git a/include/osmocom/gsm/i460_mux.h b/include/osmocom/gsm/i460_mux.h index e7ea9bd5..8e392434 100644 --- a/include/osmocom/gsm/i460_mux.h +++ b/include/osmocom/gsm/i460_mux.h @@ -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 */ diff --git a/src/gsm/i460_mux.c b/src/gsm/i460_mux.c index 3b2a589f..320e781b 100644 --- a/src/gsm/i460_mux.c +++ b/src/gsm/i460_mux.c @@ -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)) diff --git a/tests/i460_mux/i460_mux_test.c b/tests/i460_mux/i460_mux_test.c index 53144fde..d63b2ae6 100644 --- a/tests/i460_mux/i460_mux_test.c +++ b/tests/i460_mux/i460_mux_test.c @@ -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)); |