itm / testbed-runtime

WISEBED Wireless Sensor Network Testbed Infrastructure Software
https://github.com/itm/testbed-runtime/wiki
15 stars 11 forks source link

Simplify message handling and creation #366

Closed danbim closed 9 years ago

danbim commented 10 years ago

Currently message handling on both gateway and portal is quite tedious. There's a lot of switch/case code that looks at at the type of message/event and decides in which direction to forward. This is typically either posting to a local EventBus (e.g., in PortalChannelHandler) or forwarding it to another host (e.g., the gateways).

By modifying iwsn-messages.proto we can introduce a distinction between upstream messages (from device/gateway to portal to client) and downstream messages (from client/portal towards devices/gateways. This would greatly simplify message/event handling code and result in cleaner implementations.

Apart from simplifying the handling code we can also simplify the way events are created (and e.g., wrapped by message objects). Ideally, it should e.g. only be allowed to post and retrieve high-level requests and events (such as FlashImageRequest and NodeOutputEvent) onto the EventBus instances and forbid to post / subscribe to wrapper types (e.g., Message, Event). The EventBus implementations could then be used to wrap/unwrap the high-level messages themselves so we can also remove noisy code from classes interacting with the EventBus interface. Consequently, the class MessagesHelper should afterwards probably only contain method to generate high-level events.