1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 11:28:14 +00:00

dispatch on wire_type instead of message_type

This commit is contained in:
Jan Pochyla 2016-05-31 13:55:23 +02:00 committed by Pavol Rusnak
parent 852a950d66
commit 7195e1d12f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 27 additions and 17 deletions

View File

@ -1,11 +1,17 @@
from trezor.dispatcher import register
from trezor.messages.Initialize import Initialize
from trezor.utils import unimport_func
def dispatch(message):
@unimport_func
def dispatch_Initialize(mtype, mbuf):
from trezor.messages.Initialize import Initialize
message = Initialize.loads(mbuf)
from .layout_homescreen import layout_homescreen
return layout_homescreen(message)
def boot():
register(Initialize, dispatch)
Initialize = 0
register(Initialize, dispatch_Initialize)

View File

@ -1,12 +1,17 @@
from trezor.dispatcher import register
from trezor.messages.GetPublicKey import GetPublicKey
from trezor.utils import unimport_func
def dispatch(message):
if message.message_type is GetPublicKey:
from .layout_get_public_key import layout_get_public_key
return layout_get_public_key(message)
@unimport_func
def dispatch_GetPublicKey(mtype, mbuf):
from trezor.messages.GetPublicKey import GetPublicKey
message = GetPublicKey.loads(mbuf)
from .layout_get_public_key import layout_get_public_key
return layout_get_public_key(message)
def boot():
register(GetPublicKey, dispatch)
GetPublicKey = 11
register(GetPublicKey, dispatch_GetPublicKey)

View File

@ -5,16 +5,15 @@ from . import layout
message_handlers = {}
def register(message_type, handler):
message_handlers[message_type] = handler
def register(mtype, handler):
message_handlers[mtype] = handler
def unregister(message_type):
del message_handlers[message_type]
def unregister(mtype):
del message_handlers[mtype]
def dispatch():
mtypes = message_handlers.keys()
message = yield from wire.read_msg(*mtypes)
handler = message_handlers[message.message_type]
layout.change(handler(message))
mtype, mbuf = yield from wire.read_wire_msg()
handler = message_handlers[mtype]
layout.change(handler(mtype, mbuf))