| 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/serial/serial_io_handler.h" | 5 #include "device/serial/serial_io_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 | 14 |
| 15 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
| 16 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
| 17 #include "chromeos/dbus/permission_broker_client.h" | 17 #include "chromeos/dbus/permission_broker_client.h" |
| 18 #include "dbus/file_descriptor.h" // nogncheck | 18 #include "dbus/file_descriptor.h" // nogncheck |
| 19 #endif // defined(OS_CHROMEOS) | 19 #endif // defined(OS_CHROMEOS) |
| 20 | 20 |
| 21 namespace device { | 21 namespace device { |
| 22 | 22 |
| 23 SerialIoHandler::SerialIoHandler( | 23 SerialIoHandler::SerialIoHandler( |
| 24 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 24 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 25 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) | 25 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) |
| 26 : file_thread_task_runner_(file_thread_task_runner), | 26 : file_thread_task_runner_(file_thread_task_runner), |
| 27 ui_thread_task_runner_(ui_thread_task_runner) { | 27 ui_thread_task_runner_(ui_thread_task_runner) { |
| 28 options_.bitrate = 9600; | 28 options_.bitrate = 9600; |
| 29 options_.data_bits = serial::DATA_BITS_EIGHT; | 29 options_.data_bits = serial::DataBits::EIGHT; |
| 30 options_.parity_bit = serial::PARITY_BIT_NO; | 30 options_.parity_bit = serial::ParityBit::NO; |
| 31 options_.stop_bits = serial::STOP_BITS_ONE; | 31 options_.stop_bits = serial::StopBits::ONE; |
| 32 options_.cts_flow_control = false; | 32 options_.cts_flow_control = false; |
| 33 options_.has_cts_flow_control = true; | 33 options_.has_cts_flow_control = true; |
| 34 } | 34 } |
| 35 | 35 |
| 36 SerialIoHandler::~SerialIoHandler() { | 36 SerialIoHandler::~SerialIoHandler() { |
| 37 DCHECK(CalledOnValidThread()); | 37 DCHECK(CalledOnValidThread()); |
| 38 Close(); | 38 Close(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SerialIoHandler::Open(const std::string& port, | 41 void SerialIoHandler::Open(const std::string& port, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 base::Bind(&SerialIoHandler::FinishOpen, this, base::Passed(&file))); | 93 base::Bind(&SerialIoHandler::FinishOpen, this, base::Passed(&file))); |
| 94 } | 94 } |
| 95 | 95 |
| 96 #endif | 96 #endif |
| 97 | 97 |
| 98 void SerialIoHandler::MergeConnectionOptions( | 98 void SerialIoHandler::MergeConnectionOptions( |
| 99 const serial::ConnectionOptions& options) { | 99 const serial::ConnectionOptions& options) { |
| 100 if (options.bitrate) { | 100 if (options.bitrate) { |
| 101 options_.bitrate = options.bitrate; | 101 options_.bitrate = options.bitrate; |
| 102 } | 102 } |
| 103 if (options.data_bits != serial::DATA_BITS_NONE) { | 103 if (options.data_bits != serial::DataBits::NONE) { |
| 104 options_.data_bits = options.data_bits; | 104 options_.data_bits = options.data_bits; |
| 105 } | 105 } |
| 106 if (options.parity_bit != serial::PARITY_BIT_NONE) { | 106 if (options.parity_bit != serial::ParityBit::NONE) { |
| 107 options_.parity_bit = options.parity_bit; | 107 options_.parity_bit = options.parity_bit; |
| 108 } | 108 } |
| 109 if (options.stop_bits != serial::STOP_BITS_NONE) { | 109 if (options.stop_bits != serial::StopBits::NONE) { |
| 110 options_.stop_bits = options.stop_bits; | 110 options_.stop_bits = options.stop_bits; |
| 111 } | 111 } |
| 112 if (options.has_cts_flow_control) { | 112 if (options.has_cts_flow_control) { |
| 113 DCHECK(options_.has_cts_flow_control); | 113 DCHECK(options_.has_cts_flow_control); |
| 114 options_.cts_flow_control = options.cts_flow_control; | 114 options_.cts_flow_control = options.cts_flow_control; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 void SerialIoHandler::StartOpen( | 118 void SerialIoHandler::StartOpen( |
| 119 const std::string& port, | 119 const std::string& port, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 AddRef(); | 193 AddRef(); |
| 194 WriteImpl(); | 194 WriteImpl(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void SerialIoHandler::ReadCompleted(int bytes_read, | 197 void SerialIoHandler::ReadCompleted(int bytes_read, |
| 198 serial::ReceiveError error) { | 198 serial::ReceiveError error) { |
| 199 DCHECK(CalledOnValidThread()); | 199 DCHECK(CalledOnValidThread()); |
| 200 DCHECK(IsReadPending()); | 200 DCHECK(IsReadPending()); |
| 201 scoped_ptr<WritableBuffer> pending_read_buffer = | 201 scoped_ptr<WritableBuffer> pending_read_buffer = |
| 202 std::move(pending_read_buffer_); | 202 std::move(pending_read_buffer_); |
| 203 if (error == serial::RECEIVE_ERROR_NONE) { | 203 if (error == serial::ReceiveError::NONE) { |
| 204 pending_read_buffer->Done(bytes_read); | 204 pending_read_buffer->Done(bytes_read); |
| 205 } else { | 205 } else { |
| 206 pending_read_buffer->DoneWithError(bytes_read, error); | 206 pending_read_buffer->DoneWithError(bytes_read, static_cast<int32_t>(error)); |
| 207 } | 207 } |
| 208 Release(); | 208 Release(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void SerialIoHandler::WriteCompleted(int bytes_written, | 211 void SerialIoHandler::WriteCompleted(int bytes_written, |
| 212 serial::SendError error) { | 212 serial::SendError error) { |
| 213 DCHECK(CalledOnValidThread()); | 213 DCHECK(CalledOnValidThread()); |
| 214 DCHECK(IsWritePending()); | 214 DCHECK(IsWritePending()); |
| 215 scoped_ptr<ReadOnlyBuffer> pending_write_buffer = | 215 scoped_ptr<ReadOnlyBuffer> pending_write_buffer = |
| 216 std::move(pending_write_buffer_); | 216 std::move(pending_write_buffer_); |
| 217 if (error == serial::SEND_ERROR_NONE) { | 217 if (error == serial::SendError::NONE) { |
| 218 pending_write_buffer->Done(bytes_written); | 218 pending_write_buffer->Done(bytes_written); |
| 219 } else { | 219 } else { |
| 220 pending_write_buffer->DoneWithError(bytes_written, error); | 220 pending_write_buffer->DoneWithError(bytes_written, |
| 221 static_cast<int32_t>(error)); |
| 221 } | 222 } |
| 222 Release(); | 223 Release(); |
| 223 } | 224 } |
| 224 | 225 |
| 225 bool SerialIoHandler::IsReadPending() const { | 226 bool SerialIoHandler::IsReadPending() const { |
| 226 DCHECK(CalledOnValidThread()); | 227 DCHECK(CalledOnValidThread()); |
| 227 return pending_read_buffer_ != NULL; | 228 return pending_read_buffer_ != NULL; |
| 228 } | 229 } |
| 229 | 230 |
| 230 bool SerialIoHandler::IsWritePending() const { | 231 bool SerialIoHandler::IsWritePending() const { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 264 } |
| 264 | 265 |
| 265 void SerialIoHandler::QueueWriteCompleted(int bytes_written, | 266 void SerialIoHandler::QueueWriteCompleted(int bytes_written, |
| 266 serial::SendError error) { | 267 serial::SendError error) { |
| 267 base::MessageLoop::current()->PostTask( | 268 base::MessageLoop::current()->PostTask( |
| 268 FROM_HERE, | 269 FROM_HERE, |
| 269 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); | 270 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); |
| 270 } | 271 } |
| 271 | 272 |
| 272 } // namespace device | 273 } // namespace device |
| OLD | NEW |