1#!/usr/bin/env python3
2#
3#   Copyright 2019 - 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.
16
17from acts.controllers.fuchsia_lib.base_lib import BaseLib
18
19
20class FuchsiaGattsLib(BaseLib):
21    def __init__(self, addr, tc, client_id):
22        self.address = addr
23        self.test_counter = tc
24        self.client_id = client_id
25
26    def publishServer(self, database):
27        """Publishes services specified by input args
28
29        Args:
30            database: A database that follows the conventions of
31                acts.test_utils.bt.gatt_test_database.
32
33        Returns:
34            Dictionary, None if success, error if error.
35        """
36        test_cmd = "gatt_server_facade.GattServerPublishServer"
37        test_args = {
38            "database": database,
39        }
40        test_id = self.build_id(self.test_counter)
41        self.test_counter += 1
42
43        return self.send_command(test_id, test_cmd, test_args)
44
45    def closeServer(self):
46        """Closes an active GATT server.
47
48        Returns:
49            Dictionary, None if success, error if error.
50        """
51        test_cmd = "gatt_server_facade.GattServerCloseServer"
52        test_args = {}
53        test_id = self.build_id(self.test_counter)
54        self.test_counter += 1
55
56        return self.send_command(test_id, test_cmd, test_args)
57