Skip to content

Commit

Permalink
Using event decorator instead of manually registering events in setup()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Azim Khan committed Feb 23, 2016
1 parent a7a3a01 commit d2d78c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions test/host_tests/tcpecho_client_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from threading import Thread
from sys import stdout
from SocketServer import BaseRequestHandler, TCPServer
from mbed_host_tests import BaseHostTest
from mbed_host_tests import BaseHostTest, event_callback


class TCPEchoClientHandler(BaseRequestHandler):
Expand Down Expand Up @@ -162,6 +162,7 @@ def server_thread_func(this):
"""
this.server.serve_forever()

@event_callback("target_ip")
def _callback_target_ip(self, key, value, timestamp):
"""
Callback to handle reception of target's IP address.
Expand All @@ -175,24 +176,21 @@ def _callback_target_ip(self, key, value, timestamp):
self.SERVER_IP = self.find_interface_to_target_addr(self.target_ip)
self.setup_tcp_server()

@event_callback("host_ip")
def _callback_host_ip(self, key, value, timestamp):
"""
Callback for request for host IP Addr
"""
self.send_kv("host_ip", self.SERVER_IP)

@event_callback("host_port")
def _callback_host_port(self, key, value, timestamp):
"""
Callback for request for host port
"""
self.send_kv("host_port", self.SERVER_PORT)

def setup(self):
self.register_callback("target_ip", self._callback_target_ip)
self.register_callback("host_ip", self._callback_host_ip)
self.register_callback("host_port", self._callback_host_port)

def teardown(self):
if self.server:
self.server.shutdown()
Expand Down
10 changes: 4 additions & 6 deletions test/host_tests/udpecho_client_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from sys import stdout
from threading import Thread
from SocketServer import BaseRequestHandler, UDPServer
from mbed_host_tests import BaseHostTest
from mbed_host_tests import BaseHostTest, event_callback


class UDPEchoClientHandler(BaseRequestHandler):
Expand Down Expand Up @@ -90,6 +90,7 @@ def server_thread_func(this):
"""
this.server.serve_forever()

@event_callback("target_ip")
def _callback_target_ip(self, key, value, timestamp):
"""
Callback to handle reception of target's IP address.
Expand All @@ -103,24 +104,21 @@ def _callback_target_ip(self, key, value, timestamp):
self.SERVER_IP = self.find_interface_to_target_addr(self.target_ip)
self.setup_udp_server()

@event_callback("host_ip")
def _callback_host_ip(self, key, value, timestamp):
"""
Callback for request for host IP Addr
"""
self.send_kv("host_ip", self.SERVER_IP)

@event_callback("host_port")
def _callback_host_port(self, key, value, timestamp):
"""
Callback for request for host port
"""
self.send_kv("host_port", self.SERVER_PORT)

def setup(self):
self.register_callback("target_ip", self._callback_target_ip)
self.register_callback("host_ip", self._callback_host_ip)
self.register_callback("host_port", self._callback_host_port)

def teardown(self):
if self.server:
self.server.shutdown()
Expand Down

0 comments on commit d2d78c4

Please sign in to comment.