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_posix.h" | 5 #include "device/serial/serial_io_handler_posix.h" |
6 | 6 |
7 #include <sys/ioctl.h> | 7 #include <sys/ioctl.h> |
8 #include <termios.h> | 8 #include <termios.h> |
9 | 9 |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
11 | 11 |
12 #if defined(OS_LINUX) | 12 #if defined(OS_LINUX) |
13 #include <linux/serial.h> | 13 #include <linux/serial.h> |
14 #endif | 14 #if defined(OS_CHROMEOS) |
15 #include "base/bind.h" | |
16 #include "base/sys_info.h" | |
17 #include "chromeos/dbus/dbus_thread_manager.h" | |
18 #include "chromeos/dbus/permission_broker_client.h" | |
19 #endif // defined(OS_CHROMEOS) | |
20 #endif // defined(OS_LINUX) | |
15 | 21 |
16 namespace { | 22 namespace { |
17 | 23 |
18 // Convert an integral bit rate to a nominal one. Returns |true| | 24 // Convert an integral bit rate to a nominal one. Returns |true| |
19 // if the conversion was successful and |false| otherwise. | 25 // if the conversion was successful and |false| otherwise. |
20 bool BitrateToSpeedConstant(int bitrate, speed_t* speed) { | 26 bool BitrateToSpeedConstant(int bitrate, speed_t* speed) { |
21 #define BITRATE_TO_SPEED_CASE(x) \ | 27 #define BITRATE_TO_SPEED_CASE(x) \ |
22 case x: \ | 28 case x: \ |
23 *speed = B##x; \ | 29 *speed = B##x; \ |
24 return true; | 30 return true; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } // namespace | 126 } // namespace |
121 | 127 |
122 namespace device { | 128 namespace device { |
123 | 129 |
124 // static | 130 // static |
125 scoped_refptr<SerialIoHandler> SerialIoHandler::Create( | 131 scoped_refptr<SerialIoHandler> SerialIoHandler::Create( |
126 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop) { | 132 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop) { |
127 return new SerialIoHandlerPosix(file_thread_message_loop); | 133 return new SerialIoHandlerPosix(file_thread_message_loop); |
128 } | 134 } |
129 | 135 |
136 void SerialIoHandlerPosix::RequestAccess( | |
137 const std::string& port, | |
138 scoped_refptr<base::MessageLoopProxy> io_message_loop) { | |
139 #if defined(OS_LINUX) && defined(OS_CHROMEOS) | |
140 if (base::SysInfo::IsRunningOnChromeOS()) { | |
141 chromeos::PermissionBrokerClient* client = | |
142 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); | |
143 if (!client) { | |
144 DVLOG(1) << "Could not get permission_broker client."; | |
145 OnRequestAccessComplete(port, false /* failure */); | |
146 return; | |
147 } | |
148 io_message_loop->PostTask( | |
Reilly Grant (use Gerrit)
2014/10/10 21:31:53
chromeos::PermissionBrokerClient must as I underst
Jorge Lucangeli Obes
2014/10/13 20:56:43
Done.
| |
149 FROM_HERE, | |
150 base::Bind( | |
151 &chromeos::PermissionBrokerClient::RequestPathAccess, | |
152 base::Unretained(client), | |
153 port, | |
154 -1, | |
155 base::Bind(&SerialIoHandler::OnRequestAccessComplete, this, port))); | |
156 } else { | |
157 OnRequestAccessComplete(port, true /* success */); | |
158 return; | |
159 } | |
160 #else | |
161 OnRequestAccessComplete(port, true /* success */); | |
162 #endif // defined(OS_LINUX) && defined(OS_CHROMEOS) | |
163 } | |
164 | |
130 void SerialIoHandlerPosix::ReadImpl() { | 165 void SerialIoHandlerPosix::ReadImpl() { |
131 DCHECK(CalledOnValidThread()); | 166 DCHECK(CalledOnValidThread()); |
132 DCHECK(pending_read_buffer()); | 167 DCHECK(pending_read_buffer()); |
133 DCHECK(file().IsValid()); | 168 DCHECK(file().IsValid()); |
134 | 169 |
135 EnsureWatchingReads(); | 170 EnsureWatchingReads(); |
136 } | 171 } |
137 | 172 |
138 void SerialIoHandlerPosix::WriteImpl() { | 173 void SerialIoHandlerPosix::WriteImpl() { |
139 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 (config.c_cflag & CSTOPB) ? serial::STOP_BITS_TWO : serial::STOP_BITS_ONE; | 438 (config.c_cflag & CSTOPB) ? serial::STOP_BITS_TWO : serial::STOP_BITS_ONE; |
404 info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0; | 439 info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0; |
405 return info.Pass(); | 440 return info.Pass(); |
406 } | 441 } |
407 | 442 |
408 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 443 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
409 return port_name; | 444 return port_name; |
410 } | 445 } |
411 | 446 |
412 } // namespace device | 447 } // namespace device |
OLD | NEW |