X-Git-Url: http://code.vuplus.com/gitweb/?a=blobdiff_plain;f=lib%2Fpython%2FComponents%2FElement.py;h=54a1cc251cce6239537eec090249279db409d0d8;hb=7c1b7fe307737d330493694f0735b380b718576c;hp=6f812b207a6f9a4d7b5e0849c0068dd214ea18f3;hpb=ee0903f520403c5e03caef287f813e7b062d05ab;p=vuplus_dvbapp diff --git a/lib/python/Components/Element.py b/lib/python/Components/Element.py index 6f812b2..54a1cc2 100644 --- a/lib/python/Components/Element.py +++ b/lib/python/Components/Element.py @@ -7,7 +7,6 @@ from Tools.CList import CList class Element: def __init__(self): self.downstream_elements = CList() - self.upstream_elements = CList() self.master = None self.source = None @@ -17,14 +16,34 @@ class Element: self.master = downstream def connectUpstream(self, upstream): - self.upstream_elements.append(upstream) - self.source = upstream # for single-source elements (i.e., most of them.) + assert self.source is None + self.source = upstream self.changed() def connect(self, upstream): self.connectUpstream(upstream) upstream.connectDownstream(self) + # we disconnect from down to up + def disconnectAll(self): + # we should not disconnect from upstream if + # there are still elements depending on us. + assert len(self.downstream_elements) == 0, "there are still downstream elements left" + if self.source: + self.source.disconnectDownstream(self) + + def disconnectDownstream(self, downstream): + self.downstream_elements.remove(downstream) + if self.master == downstream: + self.master = None + + if len(self.downstream_elements) == 0: + self.disconnectAll() + # default action: push downstream - def changed(self): - self.downstream_elements.changed() + def changed(self, *args, **kwargs): + self.downstream_elements.changed(*args, **kwargs) + + def reconnectUpstream(self, new_upstream): + assert self.source is not None + self.source = new_upstream