Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / controller / java / AndroidBlePlatformDelegate.cpp
1 /*
2  *   Copyright (c) 2020 Project CHIP Authors
3  *   All rights reserved.
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  *
17  */
18
19 #include <ble/BleConfig.h>
20
21 #if CONFIG_NETWORK_LAYER_BLE
22
23 #include "AndroidBlePlatformDelegate.h"
24
25 #include <stddef.h>
26
27 using namespace chip::Ble;
28
29 AndroidBlePlatformDelegate::AndroidBlePlatformDelegate() :
30     SendWriteRequestCb(NULL), SubscribeCharacteristicCb(NULL), UnsubscribeCharacteristicCb(NULL), CloseConnectionCb(NULL),
31     GetMTUCb(NULL)
32 {}
33
34 bool AndroidBlePlatformDelegate::SubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId,
35                                                          const ChipBleUUID * charId)
36 {
37     bool rc = true;
38     if (SubscribeCharacteristicCb)
39     {
40         rc = SubscribeCharacteristicCb(connObj, static_cast<const uint8_t *>(svcId->bytes),
41                                        static_cast<const uint8_t *>(charId->bytes));
42     }
43     return rc;
44 }
45
46 bool AndroidBlePlatformDelegate::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId,
47                                                            const ChipBleUUID * charId)
48 {
49     bool rc = true;
50     if (UnsubscribeCharacteristicCb)
51     {
52         rc = UnsubscribeCharacteristicCb(connObj, static_cast<const uint8_t *>(svcId->bytes),
53                                          static_cast<const uint8_t *>(charId->bytes));
54     }
55     return rc;
56 }
57
58 uint16_t AndroidBlePlatformDelegate::GetMTU(BLE_CONNECTION_OBJECT connObj) const
59 {
60     uint16_t mtu = 0;
61     if (GetMTUCb)
62     {
63         mtu = GetMTUCb(connObj);
64     }
65     return mtu;
66 }
67
68 bool AndroidBlePlatformDelegate::CloseConnection(BLE_CONNECTION_OBJECT connObj)
69 {
70     bool rc = true;
71     if (CloseConnectionCb)
72     {
73         rc = CloseConnectionCb(connObj);
74     }
75     return rc;
76 }
77
78 bool AndroidBlePlatformDelegate::SendIndication(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId,
79                                                 const ChipBleUUID * charId, PacketBufferHandle pBuf)
80 {
81     // Going out of scope releases delegate's reference to pBuf. pBuf will be freed when both
82     // platform delegate and Chip stack free their references to it.
83     return false;
84 }
85
86 bool AndroidBlePlatformDelegate::SendWriteRequest(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId,
87                                                   const ChipBleUUID * charId, PacketBufferHandle pBuf)
88 {
89     bool rc = true;
90     if (SendWriteRequestCb)
91     {
92         rc = SendWriteRequestCb(connObj, static_cast<const uint8_t *>(svcId->bytes), static_cast<const uint8_t *>(charId->bytes),
93                                 pBuf->Start(), pBuf->DataLength());
94     }
95
96     // Going out of scope releases delegate's reference to pBuf. pBuf will be freed when both
97     // platform delegate and Chip stack free their references to it.
98     // We release pBuf's reference here since its payload bytes were copied
99     // onto the Java heap by SendWriteRequestCb.
100     return rc;
101 }
102
103 bool AndroidBlePlatformDelegate::SendReadRequest(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId,
104                                                  const ChipBleUUID * charId, PacketBufferHandle pBuf)
105 {
106     return true;
107 }
108
109 bool AndroidBlePlatformDelegate::SendReadResponse(BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext,
110                                                   const ChipBleUUID * svcId, const ChipBleUUID * charId)
111 {
112     return true;
113 }
114
115 void AndroidBlePlatformDelegate::SetSendWriteRequestCallback(SendWriteRequestCallback cb)
116 {
117     SendWriteRequestCb = cb;
118 }
119
120 void AndroidBlePlatformDelegate::SetSubscribeCharacteristicCallback(SubscribeCharacteristicCallback cb)
121 {
122     SubscribeCharacteristicCb = cb;
123 }
124
125 void AndroidBlePlatformDelegate::SetUnsubscribeCharacteristicCallback(UnsubscribeCharacteristicCallback cb)
126 {
127     UnsubscribeCharacteristicCb = cb;
128 }
129
130 void AndroidBlePlatformDelegate::SetCloseConnectionCallback(CloseConnectionCallback cb)
131 {
132     CloseConnectionCb = cb;
133 }
134
135 void AndroidBlePlatformDelegate::SetGetMTUCallback(GetMTUCallback cb)
136 {
137     GetMTUCb = cb;
138 }
139 #endif /* CONFIG_NETWORK_LAYER_BLE */