Commit eb837beb authored by Robin Obůrka's avatar Robin Obůrka Committed by Robin Obůrka

dev: Rewrite boxes to object oriented approach

parent 3a9205cc
...@@ -5,19 +5,19 @@ import zmq ...@@ -5,19 +5,19 @@ import zmq
import sn import sn
def setup(): class MyBox(sn.SNTerminationBox):
def setup(self):
return { return {
"foo": "bar", "foo": "bar",
} }
def teardown(self):
def teardown(context):
print("teardown") print("teardown")
def process(context, msg_type, payload): def process(self, msg_type, payload):
print(msg_type, payload) print(msg_type, payload)
if __name__ == "__main__": if __name__ == "__main__":
sn.sn_main("in_only", process, setup=setup, teardown=teardown) MyBox("in_only").run()
...@@ -5,21 +5,21 @@ import zmq ...@@ -5,21 +5,21 @@ import zmq
import sn import sn
def setup(): class MyBox(sn.SNPipelineBox):
def setup(self):
return { return {
"foo": "bar", "foo": "bar",
} }
def teardown(self):
def teardown(context):
print("teardown") print("teardown")
def process(context, msg_type, payload): def process(self, msg_type, payload):
print(msg_type, payload) print(msg_type, payload)
return msg_type, payload return msg_type, payload
if __name__ == "__main__": if __name__ == "__main__":
sn.sn_main("in_out", process, setup=setup, teardown=teardown) MyBox("in_out").run()
...@@ -7,21 +7,21 @@ import zmq ...@@ -7,21 +7,21 @@ import zmq
import sn import sn
def setup(): class MyBox(sn.SNGeneratorBox):
def setup(self):
return { return {
"foo": "bar", "foo": "bar",
} }
def teardown(self):
def teardown(context):
print("teardown") print("teardown")
def process(context): def process(self):
serial = 0 serial = 0
while True: while True:
data = { data = {
"foo": context.foo, "foo": self.context.foo,
"serial": serial, "serial": serial,
"ts": int(time.time()), "ts": int(time.time()),
} }
...@@ -35,4 +35,4 @@ def process(context): ...@@ -35,4 +35,4 @@ def process(context):
if __name__ == "__main__": if __name__ == "__main__":
sn.sn_main("out_only", process, setup=setup, teardown=teardown) MyBox("out_only").run()
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