| 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::Close() { NOTIMPLEMENTED(); } | |
| 127 | |
| 128 void BluetoothSocketMac::Disconnect(const base::Closure& callback) { | |
| 129 NOTIMPLEMENTED(); | |
| 130 } | |
| 131 | |
| 132 void BluetoothSocketMac::Receive( | |
| 133 int count, | |
| 134 const ReceiveCompletionCallback& success_callback, | |
| 135 const ReceiveErrorCompletionCallback& error_callback) { | |
| 136 NOTIMPLEMENTED(); | |
| 137 } | |
| 138 | |
| 139 void BluetoothSocketMac::Send(scoped_refptr<net::IOBuffer> buffer, | |
| 140 int buffer_size, | |
| 141 const SendCompletionCallback& success_callback, | |
| 142 const ErrorCompletionCallback& error_callback) { | |
| 143 NOTIMPLEMENTED(); | |
| 144 } | |
| 145 | |
| 146 #if 0 | |
| 147 bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) { | 126 bool BluetoothSocketMac::Receive(net::GrowableIOBuffer* buffer) { |
| 148 CHECK(buffer->offset() == 0); | 127 CHECK(buffer->offset() == 0); |
| 149 int length = incoming_data_buffer_->offset(); | 128 int length = incoming_data_buffer_->offset(); |
| 150 if (length > 0) { | 129 if (length > 0) { |
| 151 buffer->SetCapacity(length); | 130 buffer->SetCapacity(length); |
| 152 memcpy(buffer->data(), incoming_data_buffer_->StartOfBuffer(), length); | 131 memcpy(buffer->data(), incoming_data_buffer_->StartOfBuffer(), length); |
| 153 buffer->set_offset(length); | 132 buffer->set_offset(length); |
| 154 | 133 |
| 155 ResetIncomingDataBuffer(); | 134 ResetIncomingDataBuffer(); |
| 156 } | 135 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 168 return false; | 147 return false; |
| 169 } | 148 } |
| 170 | 149 |
| 171 buffer->DidConsume(bytes_written); | 150 buffer->DidConsume(bytes_written); |
| 172 return true; | 151 return true; |
| 173 } | 152 } |
| 174 | 153 |
| 175 std::string BluetoothSocketMac::GetLastErrorMessage() const { | 154 std::string BluetoothSocketMac::GetLastErrorMessage() const { |
| 176 return error_message_; | 155 return error_message_; |
| 177 } | 156 } |
| 178 #endif | 157 |
| 179 void BluetoothSocketMac::OnDataReceived( | 158 void BluetoothSocketMac::OnDataReceived( |
| 180 IOBluetoothRFCOMMChannel* rfcomm_channel, void* data, size_t length) { | 159 IOBluetoothRFCOMMChannel* rfcomm_channel, void* data, size_t length) { |
| 181 DCHECK(rfcomm_channel_ == rfcomm_channel); | 160 DCHECK(rfcomm_channel_ == rfcomm_channel); |
| 182 CHECK_LT(length, static_cast<size_t>(std::numeric_limits<int>::max())); | 161 CHECK_LT(length, static_cast<size_t>(std::numeric_limits<int>::max())); |
| 183 int data_size = static_cast<int>(length); | 162 int data_size = static_cast<int>(length); |
| 184 if (incoming_data_buffer_->RemainingCapacity() < data_size) { | 163 if (incoming_data_buffer_->RemainingCapacity() < data_size) { |
| 185 int additional_capacity = | 164 int additional_capacity = |
| 186 std::max(data_size, incoming_data_buffer_->capacity()); | 165 std::max(data_size, incoming_data_buffer_->capacity()); |
| 187 CHECK_LT( | 166 CHECK_LT( |
| 188 additional_capacity, | 167 additional_capacity, |
| 189 std::numeric_limits<int>::max() - incoming_data_buffer_->capacity()); | 168 std::numeric_limits<int>::max() - incoming_data_buffer_->capacity()); |
| 190 incoming_data_buffer_->SetCapacity( | 169 incoming_data_buffer_->SetCapacity( |
| 191 incoming_data_buffer_->capacity() + additional_capacity); | 170 incoming_data_buffer_->capacity() + additional_capacity); |
| 192 } | 171 } |
| 193 memcpy(incoming_data_buffer_->data(), data, data_size); | 172 memcpy(incoming_data_buffer_->data(), data, data_size); |
| 194 incoming_data_buffer_->set_offset( | 173 incoming_data_buffer_->set_offset( |
| 195 incoming_data_buffer_->offset() + data_size); | 174 incoming_data_buffer_->offset() + data_size); |
| 196 } | 175 } |
| 197 | 176 |
| 198 void BluetoothSocketMac::ResetIncomingDataBuffer() { | 177 void BluetoothSocketMac::ResetIncomingDataBuffer() { |
| 199 incoming_data_buffer_ = new net::GrowableIOBuffer(); | 178 incoming_data_buffer_ = new net::GrowableIOBuffer(); |
| 200 incoming_data_buffer_->SetCapacity(1024); | 179 incoming_data_buffer_->SetCapacity(1024); |
| 201 } | 180 } |
| 202 | 181 |
| 203 } // namespace device | 182 } // namespace device |
| OLD | NEW |