_Endpoint: allow direct access of payload elements

This commit is contained in:
Florent Kermarrec 2014-10-20 08:47:48 +02:00 committed by Sebastien Bourdeauducq
parent dbaeaf7833
commit ff688fb2f9
1 changed files with 15 additions and 0 deletions

View File

@ -12,8 +12,17 @@ def _make_m2s(layout):
r.append((f[0], _make_m2s(f[1])))
return r
def _check_layout(layout, packetized):
reserveds = ["stb", "ack", "payload"]
if packetized:
reserveds += ["sop", "eop"]
for f in layout:
if f[0] in reserveds:
raise ValueError(f[0] + " cannot be used in Sink/Source layout")
class _Endpoint(Record):
def __init__(self, layout, packetized=False):
_check_layout(layout, packetized)
endpoint_layout = [
("payload", _make_m2s(layout)),
("stb", 1, DIR_M_TO_S),
@ -26,6 +35,12 @@ class _Endpoint(Record):
]
Record.__init__(self, endpoint_layout)
def __del__(self):
pass
def __getattr__(self, name):
return getattr(self.payload, name)
class Source(_Endpoint):
def connect(self, sink):
return Record.connect(self, sink)