--- l2_channel.c 2001/11/04 13:55:06 1.23
+++ l2_channel.c 2001/11/06 15:02:49 1.24
@@ -105,55 +105,62 @@
}
/* link channels */
-l2_result_t l2_channel_link(l2_channel_t *chR, l2_link_t id, l2_channel_t *chC, ...)
+l2_result_t l2_channel_link(l2_channel_t *ch0, l2_link_t id, l2_channel_t *ch, ...)
{
l2_channel_t *chT;
l2_channel_t *chN;
va_list ap;
/* argument sanity check */
- if (chR == NULL || chC == NULL)
+ if (ch0 == NULL || ch == NULL)
return L2_ERR_ARG;
- /* make sure root channel is in state "created" */
- if (chR->state != L2_CHSTATE_CREATED)
- return L2_ERR_USE;
-
- /* make sure root channel is a filter channel */
- if (chR->handler.type != L2_CHANNEL_FILTER)
- return L2_ERR_USE;
-
- /* check childs */
- va_start(ap, chC);
- chT = chC;
- do {
- chN = (l2_channel_t *)va_arg(ap, l2_channel_t *);
- if (id == L2_LINK_CHILDS && chN != NULL)
- if (chT->handler.type != L2_CHANNEL_FILTER)
+ /* perform either child or sibling linking operation(s) */
+ if (id == L2_LINK_CHILD) {
+ /* make sure child parents are filters only */
+ if (ch0->handler.type != L2_CHANNEL_FILTER)
+ return L2_ERR_USE;
+ va_start(ap, ch);
+ chT = ch;
+ do {
+ chN = (l2_channel_t *)va_arg(ap, l2_channel_t *);
+ if (chN != NULL && chT->handler.type != L2_CHANNEL_FILTER)
return L2_ERR_USE;
- } while ((chT = chN) != NULL);
- va_end(ap);
+ } while ((chT = chN) != NULL);
+ va_end(ap);
- /* perform link operation(s) */
- va_start(ap, chC);
- do {
- chC->parent = chR;
- chC->sibling = NULL;
- chC->child = NULL;
- if (chR->child == NULL)
- chR->child = chC;
- else {
- chT = chR->child;
- while (chT->sibling != NULL)
- chT = chT->sibling;
- chT->sibling = chC;
- }
- if (id == L2_LINK_CHILDS)
- chR = chC;
- chC = (l2_channel_t *)va_arg(ap, l2_channel_t *);
+ /* perform link operation(s) */
+ va_start(ap, ch);
+ do {
+ ch->parent = ch0;
+ ch->sibling = NULL;
+ ch->child = NULL;
+ if (ch0->child == NULL)
+ ch0->child = ch;
+ else {
+ chT = ch0->child;
+ while (chT->sibling != NULL)
+ chT = chT->sibling;
+ chT->sibling = ch;
+ }
+ ch0 = ch;
+ ch = (l2_channel_t *)va_arg(ap, l2_channel_t *);
+ } while (ch != NULL);
+ va_end(ap);
+ }
+ else if (id == L2_LINK_SIBLING) {
+ /* perform link operation(s) */
+ va_start(ap, ch);
+ do {
+ ch0->sibling = ch;
+ ch->parent = ch0->parent;
+ ch->sibling = NULL;
+ ch->child = NULL;
+ ch0 = ch;
+ ch = (l2_channel_t *)va_arg(ap, l2_channel_t *);
+ } while (ch != NULL);
+ va_end(ap);
}
- while (chC != NULL);
- va_end(ap);
return L2_OK;
}
|