9f14ea7988f313154b2d91dbfa7332708d6d3b64
[platform/upstream/connectedhomeip.git] / src / controller / python / ChipDeviceController-BlePlatformDelegate.h
1 /*
2  *
3  *
4  *    Copyright (c) 2020 Project CHIP Authors
5  *    Copyright (c) 2014-2017 Nest Labs, Inc.
6  *    All rights reserved.
7  *
8  *    Licensed under the Apache License, Version 2.0 (the "License");
9  *    you may not use this file except in compliance with the License.
10  *    You may obtain a copy of the License at
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing, software
15  *    distributed under the License is distributed on an "AS IS" BASIS,
16  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *    See the License for the specific language governing permissions and
18  *    limitations under the License.
19  */
20 #pragma once
21
22 #include <ble/BleLayer.h>
23 #include <ble/BlePlatformDelegate.h>
24
25 typedef bool (*WriteBleCharacteristicCBFunct)(void * connObj, const void * svcId, const void * charId, const void * buffer,
26                                               uint16_t length);
27 typedef bool (*SubscribeBleCharacteristicCBFunct)(void * connObj, const void * svcId, const void * charId, bool subscribe);
28 typedef bool (*CloseBleCBFunct)(void * connObj);
29
30 class DeviceController_BlePlatformDelegate : public chip::Ble::BlePlatformDelegate
31 {
32 public:
33     DeviceController_BlePlatformDelegate(chip::Ble::BleLayer * ble);
34
35     // Set callback used to send GATT write request
36     inline void SetWriteCharCB(WriteBleCharacteristicCBFunct cb) { writeCB = cb; };
37     inline void SetSubscribeCharCB(SubscribeBleCharacteristicCBFunct cb) { subscribeCB = cb; };
38     inline void SetCloseCB(CloseBleCBFunct cb) { closeCB = cb; };
39
40     // Virtuals from BlePlatformDelegate:
41     bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
42                                  const chip::Ble::ChipBleUUID * charId);
43     bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
44                                    const chip::Ble::ChipBleUUID * charId);
45     bool CloseConnection(BLE_CONNECTION_OBJECT connObj);
46     uint16_t GetMTU(BLE_CONNECTION_OBJECT connObj) const;
47     bool SendIndication(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId, const chip::Ble::ChipBleUUID * charId,
48                         chip::System::PacketBufferHandle pBuf);
49     bool SendWriteRequest(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
50                           const chip::Ble::ChipBleUUID * charId, chip::System::PacketBufferHandle pBuf);
51     bool SendReadRequest(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId, const chip::Ble::ChipBleUUID * charId,
52                          chip::System::PacketBufferHandle pBuf);
53     bool SendReadResponse(BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext,
54                           const chip::Ble::ChipBleUUID * svcId, const chip::Ble::ChipBleUUID * charId);
55
56 private:
57     chip::Ble::BleLayer * Ble;
58     WriteBleCharacteristicCBFunct writeCB;
59     SubscribeBleCharacteristicCBFunct subscribeCB;
60     CloseBleCBFunct closeCB;
61 };