Commit 481d11ab authored by Jean-Paul Saman's avatar Jean-Paul Saman

chain.c: simplify dvbpsi_chain_del()

parent 1173b527
......@@ -52,6 +52,20 @@
#define TEST_PASSED(msg) fprintf(stderr, "test %s -- PASSED\n", (msg));
#define TEST_FAILED(msg) fprintf(stderr, "test %s -- FAILED\n", (msg));
/* debug */
//#define _TEST_CHAIN_DEBUG
#ifdef _TEST_CHAIN_DEBUG /* debug */
static void dvbpsi_decoder_chain_dump(dvbpsi_t *p_dvbpsi)
{
dvbpsi_decoder_t *p = (dvbpsi_decoder_t *)p_dvbpsi->p_decoder;
while (p) {
dvbpsi_debug(p_dvbpsi, "dump chain", "found decoder %d:%d",
p->i_table_id, p->i_extension);
p = p->p_next;
}
}
#endif
static void message(dvbpsi_t *handle, const dvbpsi_msg_level_t level, const char* msg)
{
switch(level)
......@@ -208,6 +222,10 @@ int main(int i_argc, char* pa_argv[])
}
TEST_PASSED("dvbpsi_decoder_chain_add with extensions");
#ifdef _TEST_CHAIN_DEBUG
dvbpsi_decoder_chain_dump(p_dvbpsi);
#endif
/* Test dvbpsi_decoder_chain_del() */
if (!chain_release(p_dvbpsi, CHAIN_DECODERS)) {
TEST_FAILED("dvbpsi_decoder_chain_del");
......@@ -224,8 +242,6 @@ int main(int i_argc, char* pa_argv[])
}
TEST_PASSED("dvbpsi_decoder_chain_del with extensions");
//dvbpsi_decoder_chain_dump(p_dvbpsi);
assert(!p_dvbpsi->p_decoder);
p_dvbpsi->p_decoder = NULL;
dvbpsi_delete(p_dvbpsi);
fprintf(stderr, "ALL CHAIN TESTS PASSED\n");
......
......@@ -95,23 +95,19 @@ bool dvbpsi_decoder_chain_del(dvbpsi_t *p_dvbpsi, const dvbpsi_decoder_t *p_deco
{
if (!p_decoder) return false;
dvbpsi_decoder_t *p = (dvbpsi_decoder_t *)p_dvbpsi->p_decoder;
dvbpsi_decoder_t *last = NULL;
while (p) {
if ((p_decoder->i_table_id == p->i_table_id) &&
(p_decoder->i_extension == p->i_extension)) {
assert(p == p_decoder);
if (last == NULL)
p_dvbpsi->p_decoder = p->p_next;
else
last->p_next = p->p_next;
dvbpsi_decoder_t **pp_prev = &p_dvbpsi->p_decoder;
while (pp_prev) {
if ((p_decoder->i_table_id == (*pp_prev)->i_table_id) &&
(p_decoder->i_extension == (*pp_prev)->i_extension)) {
*pp_prev = p_decoder->p_next;
/* NOTE: caller must call dvbpsi_decoder_delete(p_decoder) */
return true;
}
last = p;
p = p->p_next;
pp_prev = &(*pp_prev)->p_next;
}
dvbpsi_warning(p_dvbpsi, "chain", "decoder not found");
dvbpsi_warning(p_dvbpsi, "chain", "decoder (table id: %u, extension: %u) not found",
p_decoder->i_table_id, p_decoder->i_extension);
return false;
}
......@@ -134,14 +130,3 @@ dvbpsi_decoder_t *dvbpsi_decoder_chain_get(dvbpsi_t *p_dvbpsi, const uint16_t ta
return NULL;
}
#if 0 /* debug */
void dvbpsi_decoder_chain_dump(dvbpsi_t *p_dvbpsi)
{
dvbpsi_decoder_t *p = (dvbpsi_decoder_t *)p_dvbpsi->p_decoder;
while (p) {
dvbpsi_debug(p_dvbpsi, "dump chain", "found decoder %d:%d",
p->i_table_id, p->i_extension);
p = p->p_next;
}
}
#endif
......@@ -81,10 +81,6 @@ bool dvbpsi_decoder_chain_del(dvbpsi_t *p_dvbpsi, const dvbpsi_decoder_t *p_deco
*/
dvbpsi_decoder_t *dvbpsi_decoder_chain_get(dvbpsi_t *p_dvbpsi, const uint16_t table_id, const uint16_t extension);
#if 0 /* debug code */
void dvbpsi_decoder_chain_dump(dvbpsi_t *p_dvbpsi);
#endif
#ifdef __cplusplus
};
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment