Add chan_copy

This commit is contained in:
Rodrigo Arias 2022-10-03 10:51:58 +02:00
parent 3f3c3c8f34
commit 68a3daffe2
2 changed files with 28 additions and 4 deletions

View File

@ -132,7 +132,7 @@ chan_disable(struct ovni_chan *chan)
} }
int int
chan_is_enabled(struct ovni_chan *chan) chan_is_enabled(const struct ovni_chan *chan)
{ {
return chan->enabled; return chan->enabled;
} }
@ -287,7 +287,7 @@ chan_ev(struct ovni_chan *chan, int ev)
} }
int int
chan_get_st(struct ovni_chan *chan) chan_get_st(const struct ovni_chan *chan)
{ {
if (chan->enabled == 0) if (chan->enabled == 0)
return chan->badst; return chan->badst;
@ -301,6 +301,27 @@ chan_get_st(struct ovni_chan *chan)
return chan->stack[chan->n - 1]; return chan->stack[chan->n - 1];
} }
void
chan_copy(struct ovni_chan *dst, const struct ovni_chan *src)
{
if (!chan_is_enabled(src)) {
chan_disable(dst);
return;
}
if (!chan_is_enabled(dst))
chan_enable(dst, 1);
if (src->ev != -1) {
chan_ev(dst, src->ev);
} else {
int src_st = chan_get_st(src);
int dst_st = chan_get_st(dst);
if (src_st != dst_st)
chan_set(dst, src_st);
}
}
static void static void
emit(struct ovni_chan *chan, int64_t t, int state) emit(struct ovni_chan *chan, int64_t t, int state)
{ {

View File

@ -37,7 +37,7 @@ void
chan_disable(struct ovni_chan *chan); chan_disable(struct ovni_chan *chan);
int int
chan_is_enabled(struct ovni_chan *chan); chan_is_enabled(const struct ovni_chan *chan);
void void
chan_set(struct ovni_chan *chan, int st); chan_set(struct ovni_chan *chan, int st);
@ -52,9 +52,12 @@ void
chan_ev(struct ovni_chan *chan, int ev); chan_ev(struct ovni_chan *chan, int ev);
int int
chan_get_st(struct ovni_chan *chan); chan_get_st(const struct ovni_chan *chan);
void void
chan_emit(struct ovni_chan *chan); chan_emit(struct ovni_chan *chan);
void
chan_copy(struct ovni_chan *dst, const struct ovni_chan *src);
#endif /* OVNI_CHAN_H */ #endif /* OVNI_CHAN_H */