From 45eab17e0c35b9527dd8f68364fa577c61f33551 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 4 Jan 2014 14:42:32 +1300 Subject: Decouple message type from message class name. --- libmproxy/controller.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'libmproxy/controller.py') diff --git a/libmproxy/controller.py b/libmproxy/controller.py index 62d1dbbc..b662b6d5 100644 --- a/libmproxy/controller.py +++ b/libmproxy/controller.py @@ -39,13 +39,13 @@ class Channel: def __init__(self, q): self.q = q - def ask(self, m): + def ask(self, mtype, m): """ Decorate a message with a reply attribute, and send it to the master. then wait for a response. """ m.reply = Reply(m) - self.q.put(m) + self.q.put((mtype, m)) while not should_exit: try: # The timeout is here so we can handle a should_exit event. @@ -54,13 +54,13 @@ class Channel: continue return g - def tell(self, m): + def tell(self, mtype, m): """ Decorate a message with a dummy reply attribute, send it to the master, then return immediately. """ m.reply = DummyReply() - self.q.put(m) + self.q.put((mtype, m)) class Slave(threading.Thread): @@ -98,7 +98,7 @@ class Master: while True: # Small timeout to prevent pegging the CPU msg = q.get(timeout=0.01) - self.handle(msg) + self.handle(*msg) changed = True except Queue.Empty: pass @@ -112,13 +112,13 @@ class Master: self.tick(self.masterq) self.shutdown() - def handle(self, msg): - c = "handle_" + msg.__class__.__name__.lower() + def handle(self, mtype, obj): + c = "handle_" + mtype m = getattr(self, c, None) if m: - m(msg) + m(obj) else: - msg.reply() + obj.reply() def shutdown(self): global should_exit -- cgit v1.2.3