diff options
Diffstat (limited to 'mmi2grpc/__init__.py')
-rw-r--r-- | mmi2grpc/__init__.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/mmi2grpc/__init__.py b/mmi2grpc/__init__.py index 194676a..953d814 100644 --- a/mmi2grpc/__init__.py +++ b/mmi2grpc/__init__.py @@ -1,21 +1,19 @@ -# Copyright 2022 Google LLC - from typing import List import grpc import time import sys -import textwrap - -from .a2dp import A2DPProxy from blueberry.host_grpc import Host +from .a2dp import A2DPProxy +from ._description import format_proxy + GRPC_PORT = 8999 class IUT: - def __init__(self, test: str, args: List[str], - port: int = GRPC_PORT, **kwargs): + def __init__( + self, test: str, args: List[str], port: int = GRPC_PORT, **kwargs): self.a2dp_ = None self.address_ = None self.port = port @@ -32,11 +30,13 @@ class IUT: def address(self) -> bytes: with grpc.insecure_channel(f'localhost:{self.port}') as channel: try: - return Host(channel).ReadLocalAddress(wait_for_ready=True).address + return Host(channel).ReadLocalAddress( + wait_for_ready=True).address except grpc.RpcError: print('Retry') time.sleep(5) - return Host(channel).ReadLocalAddress(wait_for_ready=True).address + return Host(channel).ReadLocalAddress( + wait_for_ready=True).address def interact(self, pts_address: bytes, @@ -49,5 +49,17 @@ class IUT: print(f'{profile} mmi: {interaction}', file=sys.stderr) if profile in ('A2DP', 'AVDTP'): if not self.a2dp_: - self.a2dp_ = A2DPProxy(grpc.insecure_channel(f'localhost:{self.port}')) - return self.a2dp_.interact(interaction, test, description, pts_address) + self.a2dp_ = A2DPProxy( + grpc.insecure_channel(f'localhost:{self.port}')) + return self.a2dp_.interact( + interaction, test, description, pts_address) + + code = format_proxy(profile, interaction, description) + error_msg = ( + f'Missing {profile} proxy and mmi: {interaction}\n' + f'Create a {profile.lower()}.py in mmi2grpc/:\n\n{code}\n' + f'Then, instantiate the corresponding proxy in __init__.py\n' + f'Finally, create a {profile.lower()}.proto in proto/blueberry/' + f'and generate the corresponding interface.' + ) + assert False, error_msg |