summaryrefslogtreecommitdiff
path: root/system/bta/test/common/bta_gatt_api_mock.cc
blob: de91e6f94ce32e208218a08dc9f09f4699e0cce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.com.
 * Represented by EHIMA - www.ehima.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "bta_gatt_api_mock.h"

#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

static gatt::MockBtaGattInterface* gatt_interface = nullptr;

void gatt::SetMockBtaGattInterface(
    MockBtaGattInterface* mock_bta_gatt_interface) {
  gatt_interface = mock_bta_gatt_interface;
}

void BTA_GATTC_AppRegister(tBTA_GATTC_CBACK* p_client_cb,
                           BtaAppRegisterCallback cb, bool eatt_support) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  gatt_interface->AppRegister(p_client_cb, cb, eatt_support);
}

void BTA_GATTC_AppDeregister(tGATT_IF client_if) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  gatt_interface->AppDeregister(client_if);
}

void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
                    bool is_direct, tBT_TRANSPORT transport, bool opportunistic,
                    uint8_t initiating_phys) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  gatt_interface->Open(client_if, remote_bda, is_direct, transport,
                       opportunistic, initiating_phys);
}

void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
                    bool is_direct, bool opportunistic) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  gatt_interface->Open(client_if, remote_bda, is_direct, opportunistic);
}

void BTA_GATTC_CancelOpen(tGATT_IF client_if, const RawAddress& remote_bda,
                          bool is_direct) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  gatt_interface->CancelOpen(client_if, remote_bda, is_direct);
}

void BTA_GATTC_Close(uint16_t conn_id) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  gatt_interface->Close(conn_id);
}

void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id,
                                    const bluetooth::Uuid* p_srvc_uuid) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  gatt_interface->ServiceSearchRequest(conn_id, p_srvc_uuid);
}

void BTA_GATTC_SendIndConfirm(uint16_t conn_id, uint16_t cid) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  gatt_interface->SendIndConfirm(conn_id, cid);
}

const std::list<gatt::Service>* BTA_GATTC_GetServices(uint16_t conn_id) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  return gatt_interface->GetServices(conn_id);
}

const gatt::Characteristic* BTA_GATTC_GetCharacteristic(uint16_t conn_id,
                                                        uint16_t handle) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  return gatt_interface->GetCharacteristic(conn_id, handle);
}

const gatt::Service* BTA_GATTC_GetOwningService(uint16_t conn_id,
                                                uint16_t handle) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  return gatt_interface->GetOwningService(conn_id, handle);
}

tGATT_STATUS BTA_GATTC_RegisterForNotifications(tGATT_IF client_if,
                                                const RawAddress& remote_bda,
                                                uint16_t handle) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  return gatt_interface->RegisterForNotifications(client_if, remote_bda,
                                                  handle);
}

tGATT_STATUS BTA_GATTC_DeregisterForNotifications(tGATT_IF client_if,
                                                  const RawAddress& remote_bda,
                                                  uint16_t handle) {
  LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
  return gatt_interface->DeregisterForNotifications(client_if, remote_bda,
                                                    handle);
}