OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_socket_mac.h" | 5 #include "device/bluetooth/bluetooth_socket_mac.h" |
6 | 6 |
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> | 7 #import <IOBluetooth/objc/IOBluetoothDevice.h> |
8 #import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h> | 8 #import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h> |
9 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> | 9 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> |
10 | 10 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 << base::SysNSStringToUTF8([device addressString]) << "): (" << status | 116 << base::SysNSStringToUTF8([device addressString]) << "): (" << status |
117 << ")"; | 117 << ")"; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 // TODO(youngki): Add support for L2CAP sockets as well. | 121 // TODO(youngki): Add support for L2CAP sockets as well. |
122 | 122 |
123 return scoped_refptr<BluetoothSocketMac>(bluetooth_socket); | 123 return scoped_refptr<BluetoothSocketMac>(bluetooth_socket); |
124 } | 124 } |
125 | 125 |
| 126 void BluetoothSocketMac::Release() { |
| 127 NOTIMPLEMENTED(); |
| 128 } |
| 129 |
| 130 void BluetoothSocketMac::Disconnect(const base::Closure& callback) { |
| 131 NOTIMPLEMENTED(); |
| 132 } |
| 133 |
| 134 void BluetoothSocketMac::Receive( |
| 135 int count, |
| 136 const ReceiveCompletionCallback& success_callback, |
| 137 const ReceiveErrorCompletionCallback& error_callback) { |
| 138 NOTIMPLEMENTED(); |
| 139 } |
| 140 |
| 141 void BluetoothSocketMac::Send(scoped_refptr<net::IOBuffer> buffer, |
| 142 int buffer_size, |
| 143 const SendCompletionCallback& success_callback, |
| 144 const ErrorCompletionCallback& error_callback) { |
| 145 NOTIMPLEMENTED(); |
| 146 } |
| 147 |
| 148 #if 0 |
126 bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) { | 149 bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) { |
127 CHECK(buffer->offset() == 0); | 150 CHECK(buffer->offset() == 0); |
128 int length = incoming_data_buffer_->offset(); | 151 int length = incoming_data_buffer_->offset(); |
129 if (length > 0) { | 152 if (length > 0) { |
130 buffer->SetCapacity(length); | 153 buffer->SetCapacity(length); |
131 memcpy(buffer->data(), incoming_data_buffer_->StartOfBuffer(), length); | 154 memcpy(buffer->data(), incoming_data_buffer_->StartOfBuffer(), length); |
132 buffer->set_offset(length); | 155 buffer->set_offset(length); |
133 | 156 |
134 ResetIncomingDataBuffer(); | 157 ResetIncomingDataBuffer(); |
135 } | 158 } |
(...skipping 11 matching lines...) Expand all Loading... |
147 return false; | 170 return false; |
148 } | 171 } |
149 | 172 |
150 buffer->DidConsume(bytes_written); | 173 buffer->DidConsume(bytes_written); |
151 return true; | 174 return true; |
152 } | 175 } |
153 | 176 |
154 std::string BluetoothSocketMac::GetLastErrorMessage() const { | 177 std::string BluetoothSocketMac::GetLastErrorMessage() const { |
155 return error_message_; | 178 return error_message_; |
156 } | 179 } |
157 | 180 #endif |
158 void BluetoothSocketMac::OnDataReceived( | 181 void BluetoothSocketMac::OnDataReceived( |
159 IOBluetoothRFCOMMChannel* rfcomm_channel, void* data, size_t length) { | 182 IOBluetoothRFCOMMChannel* rfcomm_channel, void* data, size_t length) { |
160 DCHECK(rfcomm_channel_ == rfcomm_channel); | 183 DCHECK(rfcomm_channel_ == rfcomm_channel); |
161 CHECK_LT(length, static_cast<size_t>(std::numeric_limits<int>::max())); | 184 CHECK_LT(length, static_cast<size_t>(std::numeric_limits<int>::max())); |
162 int data_size = static_cast<int>(length); | 185 int data_size = static_cast<int>(length); |
163 if (incoming_data_buffer_->RemainingCapacity() < data_size) { | 186 if (incoming_data_buffer_->RemainingCapacity() < data_size) { |
164 int additional_capacity = | 187 int additional_capacity = |
165 std::max(data_size, incoming_data_buffer_->capacity()); | 188 std::max(data_size, incoming_data_buffer_->capacity()); |
166 CHECK_LT( | 189 CHECK_LT( |
167 additional_capacity, | 190 additional_capacity, |
168 std::numeric_limits<int>::max() - incoming_data_buffer_->capacity()); | 191 std::numeric_limits<int>::max() - incoming_data_buffer_->capacity()); |
169 incoming_data_buffer_->SetCapacity( | 192 incoming_data_buffer_->SetCapacity( |
170 incoming_data_buffer_->capacity() + additional_capacity); | 193 incoming_data_buffer_->capacity() + additional_capacity); |
171 } | 194 } |
172 memcpy(incoming_data_buffer_->data(), data, data_size); | 195 memcpy(incoming_data_buffer_->data(), data, data_size); |
173 incoming_data_buffer_->set_offset( | 196 incoming_data_buffer_->set_offset( |
174 incoming_data_buffer_->offset() + data_size); | 197 incoming_data_buffer_->offset() + data_size); |
175 } | 198 } |
176 | 199 |
177 void BluetoothSocketMac::ResetIncomingDataBuffer() { | 200 void BluetoothSocketMac::ResetIncomingDataBuffer() { |
178 incoming_data_buffer_ = new net::GrowableIOBuffer(); | 201 incoming_data_buffer_ = new net::GrowableIOBuffer(); |
179 incoming_data_buffer_->SetCapacity(1024); | 202 incoming_data_buffer_->SetCapacity(1024); |
180 } | 203 } |
181 | 204 |
182 } // namespace device | 205 } // namespace device |
OLD | NEW |