1#!/usr/bin/env python3
2#
3#   Copyright 2022 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16import asyncio
17import grpc
18
19from blueberry.facade.topshim import facade_pb2
20from blueberry.facade.topshim import facade_pb2_grpc
21from blueberry.tests.topshim.lib.async_closable import AsyncClosable
22
23
24class HfClientClient(AsyncClosable):
25    """
26    Wrapper gRPC interface to the HF Client Service
27    """
28    __channel = None
29    __hf_client_stub = None
30
31    def __init__(self, port=8999):
32        self.__channel = grpc.aio.insecure_channel("localhost:%d" % port)
33        self.__hf_client_stub = facade_pb2_grpc.HfClientServiceStub(self.__channel)
34
35    async def close(self):
36        await self.__channel.close()
37
38    async def start_slc(self, address):
39        """
40        """
41        await self.__hf_client_stub.StartSlc(
42            facade_pb2.StartSlcRequest(connection=facade_pb2.Connection(cookie=address.encode())))
43
44    async def stop_slc(self, address):
45        """
46        """
47        await self.__hf_client_stub.StopSlc(
48            facade_pb2.StopSlcRequest(connection=facade_pb2.Connection(cookie=address.encode())))
49
50    async def connect_audio(self, address):
51        """
52        """
53        await self.__hf_client_stub.ConnectAudio(
54            facade_pb2.ConnectAudioRequest(connection=facade_pb2.Connection(cookie=address.encode())))
55
56    async def disconnect_audio(self, address):
57        """
58        """
59        await self.__hf_client_stub.DisconnectAudio(
60            facade_pb2.DisconnectAudioRequest(connection=facade_pb2.Connection(cookie=address.encode())))
61