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):
return { def setup(self):
"foo": "bar", return {
} "foo": "bar",
}
def teardown(self):
print("teardown")
def teardown(context):
print("teardown")
def process(self, msg_type, payload):
def process(context, 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):
return { def setup(self):
"foo": "bar", return {
} "foo": "bar",
}
def teardown(self):
print("teardown")
def teardown(context):
print("teardown")
def process(self, msg_type, payload):
print(msg_type, payload)
def process(context, msg_type, payload): return msg_type, payload
print(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,32 +7,32 @@ import zmq ...@@ -7,32 +7,32 @@ import zmq
import sn import sn
def setup(): class MyBox(sn.SNGeneratorBox):
return { def setup(self):
"foo": "bar", return {
} "foo": "bar",
}
def teardown(context): def teardown(self):
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()),
} }
serial += 1 serial += 1
yield "sentinel/dev/sn", data yield "sentinel/dev/sn", data
print("PUB", data) print("PUB", data)
time.sleep(1) time.sleep(1)
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