OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/bluetooth/bluetooth_l2cap_channel_mac.h" | 5 #include "device/bluetooth/bluetooth_l2cap_channel_mac.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
9 #include "device/bluetooth/bluetooth_classic_device_mac.h" | 9 #include "device/bluetooth/bluetooth_classic_device_mac.h" |
10 #include "device/bluetooth/bluetooth_socket_mac.h" | 10 #include "device/bluetooth/bluetooth_socket_mac.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 // Now that the socket is set, it's safe to associate a delegate, which can | 110 // Now that the socket is set, it's safe to associate a delegate, which can |
111 // call back to the socket. | 111 // call back to the socket. |
112 DCHECK(!delegate_); | 112 DCHECK(!delegate_); |
113 delegate_.reset( | 113 delegate_.reset( |
114 [[BluetoothL2capChannelDelegate alloc] initWithChannel:this]); | 114 [[BluetoothL2capChannelDelegate alloc] initWithChannel:this]); |
115 [channel_ setDelegate:delegate_]; | 115 [channel_ setDelegate:delegate_]; |
116 } | 116 } |
117 | 117 |
118 IOBluetoothDevice* BluetoothL2capChannelMac::GetDevice() { | 118 IOBluetoothDevice* BluetoothL2capChannelMac::GetDevice() { |
119 return [channel_ getDevice]; | 119 return [channel_ device]; |
120 } | 120 } |
121 | 121 |
122 uint16_t BluetoothL2capChannelMac::GetOutgoingMTU() { | 122 uint16_t BluetoothL2capChannelMac::GetOutgoingMTU() { |
123 return [channel_ outgoingMTU]; | 123 return [channel_ outgoingMTU]; |
124 } | 124 } |
125 | 125 |
126 IOReturn BluetoothL2capChannelMac::WriteAsync(void* data, | 126 IOReturn BluetoothL2capChannelMac::WriteAsync(void* data, |
127 uint16_t length, | 127 uint16_t length, |
128 void* refcon) { | 128 void* refcon) { |
129 DCHECK_LE(length, GetOutgoingMTU()); | 129 DCHECK_LE(length, GetOutgoingMTU()); |
130 return [channel_ writeAsync:data length:length refcon:refcon]; | 130 return [channel_ writeAsync:data length:length refcon:refcon]; |
131 } | 131 } |
132 | 132 |
133 void BluetoothL2capChannelMac::OnChannelOpenComplete( | 133 void BluetoothL2capChannelMac::OnChannelOpenComplete( |
134 IOBluetoothL2CAPChannel* channel, | 134 IOBluetoothL2CAPChannel* channel, |
135 IOReturn status) { | 135 IOReturn status) { |
136 if (channel_) { | 136 if (channel_) { |
137 DCHECK_EQ(channel_, channel); | 137 DCHECK_EQ(channel_, channel); |
138 } else { | 138 } else { |
139 // The (potentially) asynchronous connection occurred synchronously. | 139 // The (potentially) asynchronous connection occurred synchronously. |
140 // Should only be reachable from OpenAsync(). | 140 // Should only be reachable from OpenAsync(). |
141 DCHECK_EQ(status, kIOReturnSuccess); | 141 DCHECK_EQ(status, kIOReturnSuccess); |
142 } | 142 } |
143 | 143 |
144 socket()->OnChannelOpenComplete( | 144 socket()->OnChannelOpenComplete( |
145 BluetoothClassicDeviceMac::GetDeviceAddress([channel getDevice]), status); | 145 BluetoothClassicDeviceMac::GetDeviceAddress([channel device]), status); |
146 } | 146 } |
147 | 147 |
148 void BluetoothL2capChannelMac::OnChannelClosed( | 148 void BluetoothL2capChannelMac::OnChannelClosed( |
149 IOBluetoothL2CAPChannel* channel) { | 149 IOBluetoothL2CAPChannel* channel) { |
150 DCHECK_EQ(channel_, channel); | 150 DCHECK_EQ(channel_, channel); |
151 socket()->OnChannelClosed(); | 151 socket()->OnChannelClosed(); |
152 } | 152 } |
153 | 153 |
154 void BluetoothL2capChannelMac::OnChannelDataReceived( | 154 void BluetoothL2capChannelMac::OnChannelDataReceived( |
155 IOBluetoothL2CAPChannel* channel, | 155 IOBluetoothL2CAPChannel* channel, |
156 void* data, | 156 void* data, |
157 size_t length) { | 157 size_t length) { |
158 DCHECK_EQ(channel_, channel); | 158 DCHECK_EQ(channel_, channel); |
159 socket()->OnChannelDataReceived(data, length); | 159 socket()->OnChannelDataReceived(data, length); |
160 } | 160 } |
161 | 161 |
162 void BluetoothL2capChannelMac::OnChannelWriteComplete( | 162 void BluetoothL2capChannelMac::OnChannelWriteComplete( |
163 IOBluetoothL2CAPChannel* channel, | 163 IOBluetoothL2CAPChannel* channel, |
164 void* refcon, | 164 void* refcon, |
165 IOReturn status) { | 165 IOReturn status) { |
166 // Note: We use "CHECK" below to ensure we never run into unforeseen | 166 // Note: We use "CHECK" below to ensure we never run into unforeseen |
167 // occurrences of asynchronous callbacks, which could lead to data | 167 // occurrences of asynchronous callbacks, which could lead to data |
168 // corruption. | 168 // corruption. |
169 CHECK_EQ(channel_, channel); | 169 CHECK_EQ(channel_, channel); |
170 socket()->OnChannelWriteComplete(refcon, status); | 170 socket()->OnChannelWriteComplete(refcon, status); |
171 } | 171 } |
172 | 172 |
173 } // namespace device | 173 } // namespace device |
OLD | NEW |