1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +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. # used to confirm/cancel the dialogs from outside of this module (i.e.
# through debug link) # through debug link)
future = loop.Future() signal = loop.Signal()
@unimport @unimport
@ -20,7 +20,7 @@ async def confirm(session_id, content=None, code=None, *args, **kwargs):
if code is None: if code is None:
code = Other code = Other
await wire.reply_message(session_id, ButtonRequest(code=code), ButtonAck) 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 @unimport
@ -40,7 +40,7 @@ async def hold_to_confirm(session_id, content=None, code=None, *args, **kwargs):
if code is None: if code is None:
code = Other code = Other
await wire.reply_message(session_id, ButtonRequest(code=code), ButtonAck) 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 @unimport

View File

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

View File

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

View File

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