1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

loop: rename Future to Signal

Future semantics were changed to allow multiple deliveries to avoid allocating more future objects than neccessary, and Signal describes this behaviour more accurately.
This commit is contained in:
Jan Pochyla 2016-11-25 15:42:33 +01:00
parent 1b27bb480d
commit 0b7874ad43
4 changed files with 14 additions and 15 deletions

View File

@ -3,7 +3,7 @@ from trezor.utils import unimport
# used to confirm/cancel the dialogs from outside of this module (i.e.
# through debug link)
future = loop.Future()
signal = loop.Signal()
@unimport
@ -20,7 +20,7 @@ async def confirm(session_id, content=None, code=None, *args, **kwargs):
if code is None:
code = Other
await wire.reply_message(session_id, ButtonRequest(code=code), ButtonAck)
return await loop.Wait((future, dialog)) == CONFIRMED
return await loop.Wait((signal, dialog)) == CONFIRMED
@unimport
@ -40,7 +40,7 @@ async def hold_to_confirm(session_id, content=None, code=None, *args, **kwargs):
if code is None:
code = Other
await wire.reply_message(session_id, ButtonRequest(code=code), ButtonAck)
return await loop.Wait((future, dialog)) == CONFIRMED
return await loop.Wait((signal, dialog)) == CONFIRMED
@unimport

View File

@ -6,8 +6,8 @@ from trezor.messages.wire_types import \
async def dispatch_DebugLinkDecision(msg, session_id):
from trezor.ui.confirm import CONFIRMED, CANCELLED
from ..common.confirm import future
future.resolve(CONFIRMED if msg.yes_no else CANCELLED)
from ..common.confirm import signal
signal.send(CONFIRMED if msg.yes_no else CANCELLED)
async def dispatch_DebugLinkGetState(msg, session_id):

View File

@ -1,7 +1,6 @@
import utime
from micropython import const
from uheapq import heappop, heappush, heapify
from .utils import type_gen
from . import msg, log, ui
if __debug__:
@ -136,7 +135,7 @@ class Select(Syscall):
NO_VALUE = ()
class Future(Syscall):
class Signal(Syscall):
def __init__(self):
self.value = NO_VALUE
@ -146,7 +145,7 @@ class Future(Syscall):
self.task = task
self._deliver()
def resolve(self, value):
def send(self, value):
self.value = value
self._deliver()

View File

@ -77,16 +77,16 @@ def setup():
async def read_message(session_id, *exp_types):
log.info(__name__, 'session %d: read types %s', session_id, exp_types)
future = Future()
signal = Signal()
if session_id == SESSION_V1:
wire_decoder = decode_wire_v1_stream(
_dispatch_and_build_protobuf, session_id, exp_types, future)
_dispatch_and_build_protobuf, session_id, exp_types, signal)
else:
wire_decoder = decode_wire_stream(
_dispatch_and_build_protobuf, session_id, exp_types, future)
_dispatch_and_build_protobuf, session_id, exp_types, signal)
wire_decoder.send(None)
register_session(session_id, wire_decoder)
return await future
return await signal
async def write_message(session_id, pbuf_message):
@ -178,15 +178,15 @@ def _handle_unknown_session(session_id, report_data):
pass # TODO
def _dispatch_and_build_protobuf(msg_type, data_len, session_id, exp_types, future):
def _dispatch_and_build_protobuf(msg_type, data_len, session_id, exp_types, signal):
if msg_type in exp_types:
pbuf_type = get_protobuf_type(msg_type)
builder = build_protobuf_message(pbuf_type, future.resolve)
builder = build_protobuf_message(pbuf_type, signal.send)
builder.send(None)
return pbuf_type.load(target=builder)
else:
from trezor.messages.FailureType import UnexpectedMessage
future.resolve(FailureError(UnexpectedMessage, 'Unexpected message'))
signal.send(FailureError(UnexpectedMessage, 'Unexpected message'))
return _handle_registered_type(msg_type, data_len, session_id)