Chromium Code Reviews| 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 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ | 5 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ |
| 6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ | 6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "device/serial/serial_io_handler.h" | 11 #include "device/serial/serial_io_handler.h" |
| 12 | 12 |
| 13 namespace device { | 13 namespace device { |
| 14 | 14 |
| 15 enum ByteRead { | |
|
Reilly Grant (use Gerrit)
2015/07/28 22:06:03
These names still aren't very clear to me. Maybe s
juncai
2015/07/29 04:22:42
Done.
| |
| 16 BYTEREAD_REGULAR, | |
| 17 BYTEREAD_ALL_ONE, | |
| 18 BYTEREAD_ALL_ZERO, | |
| 19 }; | |
| 20 | |
| 15 class SerialIoHandlerPosix : public SerialIoHandler, | 21 class SerialIoHandlerPosix : public SerialIoHandler, |
| 16 public base::MessageLoopForIO::Watcher { | 22 public base::MessageLoopForIO::Watcher { |
| 17 protected: | 23 protected: |
| 18 // SerialIoHandler impl. | 24 // SerialIoHandler impl. |
| 19 void ReadImpl() override; | 25 void ReadImpl() override; |
| 20 void WriteImpl() override; | 26 void WriteImpl() override; |
| 21 void CancelReadImpl() override; | 27 void CancelReadImpl() override; |
| 22 void CancelWriteImpl() override; | 28 void CancelWriteImpl() override; |
| 23 bool ConfigurePortImpl() override; | 29 bool ConfigurePortImpl() override; |
| 24 bool Flush() const override; | 30 bool Flush() const override; |
| 25 serial::DeviceControlSignalsPtr GetControlSignals() const override; | 31 serial::DeviceControlSignalsPtr GetControlSignals() const override; |
| 26 bool SetControlSignals( | 32 bool SetControlSignals( |
| 27 const serial::HostControlSignals& control_signals) override; | 33 const serial::HostControlSignals& control_signals) override; |
| 28 serial::ConnectionInfoPtr GetPortInfo() const override; | 34 serial::ConnectionInfoPtr GetPortInfo() const override; |
| 29 bool SetBreak() override; | 35 bool SetBreak() override; |
| 30 bool ClearBreak() override; | 36 bool ClearBreak() override; |
| 37 int CheckReceiveError(char* buffer, | |
| 38 int buffer_len, | |
| 39 int bytes_read, | |
| 40 bool& break_detected, | |
| 41 bool& parity_error_detected); | |
| 31 | 42 |
| 32 private: | 43 private: |
| 33 friend class SerialIoHandler; | 44 friend class SerialIoHandler; |
| 45 friend class SerialIoHandlerPosixTest; | |
| 46 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, NoErrorReadOnce); | |
|
Reilly Grant (use Gerrit)
2015/07/28 22:06:03
You can avoid adding all of these friend declarati
juncai
2015/07/29 04:22:41
Done.
| |
| 47 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 48 NoErrorReadTwiceBytesReadTwoAndOne); | |
| 49 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 50 NoErrorReadTwiceBytesReadOneAndTwo); | |
| 51 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, NoErrorReadThreeTimes); | |
| 52 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, BreakReadOnce); | |
| 53 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 54 BreakReadTwiceBytesReadTwoAndOne); | |
| 55 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 56 BreakReadTwiceBytesReadOneAndTwo); | |
| 57 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, BreakReadThreeTimes); | |
| 58 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, ParityErrorReadOnce); | |
| 59 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 60 ParityErrorReadTwiceBytesReadTwoAndOne); | |
| 61 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 62 ParityErrorReadTwiceBytesReadOneAndTwo); | |
| 63 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, ParityErrorReadThreeTimes); | |
| 64 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, TwoEOFsReadOnce); | |
| 65 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, TwoEOFsReadTwice); | |
| 66 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 67 ParityCheckDisabledReadOnce); | |
| 68 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 69 ParityCheckDisabledReadTwiceBytesReadTwoAndOne); | |
| 70 FRIEND_TEST_ALL_PREFIXES( | |
| 71 SerialIoHandlerPosixTest, | |
| 72 ParityCheckDisabledReadTwiceBytesReadTwoAndOneLargerBufferLen); | |
| 73 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 74 ParityCheckDisabledReadTwiceBytesReadOneAndTwo); | |
| 75 FRIEND_TEST_ALL_PREFIXES( | |
| 76 SerialIoHandlerPosixTest, | |
| 77 ParityCheckDisabledReadTwiceBytesReadOneAndTwoLargerBufferLen); | |
| 78 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 79 ParityCheckDisabledReadThreeTimesBufferLenOne); | |
| 80 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 81 ParityCheckDisabledReadThreeTimesBufferLenTwo); | |
| 82 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 83 ParityCheckDisabledReadThreeTimesLargerBufferLen); | |
| 84 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, BytesReadZero); | |
| 85 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, InvalidSequenceReadOnce); | |
| 86 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 87 InvalidSequenceReadTwiceBytesReadTwoAndOne); | |
| 88 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 89 InvalidSequenceReadTwiceBytesReadOneAndTwo); | |
| 90 FRIEND_TEST_ALL_PREFIXES( | |
| 91 SerialIoHandlerPosixTest, | |
| 92 InvalidSequenceReadTwiceBytesReadOneAndTwoLargerBufferLen); | |
| 93 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 94 InvalidSequenceReadThreeTimes); | |
| 95 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, | |
| 96 InvalidSequenceReadThreeTimesLargerBufferLen); | |
| 97 FRIEND_TEST_ALL_PREFIXES(SerialIoHandlerPosixTest, CharsIgnoredPreset); | |
| 34 | 98 |
| 35 SerialIoHandlerPosix( | 99 SerialIoHandlerPosix( |
| 36 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 100 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 37 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); | 101 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); |
| 38 ~SerialIoHandlerPosix() override; | 102 ~SerialIoHandlerPosix() override; |
| 39 | 103 |
| 40 // base::MessageLoopForIO::Watcher implementation. | 104 // base::MessageLoopForIO::Watcher implementation. |
| 41 void OnFileCanWriteWithoutBlocking(int fd) override; | 105 void OnFileCanWriteWithoutBlocking(int fd) override; |
| 42 void OnFileCanReadWithoutBlocking(int fd) override; | 106 void OnFileCanReadWithoutBlocking(int fd) override; |
| 43 | 107 |
| 44 void EnsureWatchingReads(); | 108 void EnsureWatchingReads(); |
| 45 void EnsureWatchingWrites(); | 109 void EnsureWatchingWrites(); |
| 46 | 110 |
| 47 base::MessageLoopForIO::FileDescriptorWatcher file_read_watcher_; | 111 base::MessageLoopForIO::FileDescriptorWatcher file_read_watcher_; |
| 48 base::MessageLoopForIO::FileDescriptorWatcher file_write_watcher_; | 112 base::MessageLoopForIO::FileDescriptorWatcher file_write_watcher_; |
| 49 | 113 |
| 50 // Flags indicating if the message loop is watching the device for IO events. | 114 // Flags indicating if the message loop is watching the device for IO events. |
| 51 bool is_watching_reads_; | 115 bool is_watching_reads_; |
| 52 bool is_watching_writes_; | 116 bool is_watching_writes_; |
| 53 | 117 |
| 118 ByteRead byte_read_state_; | |
| 119 bool parity_check_enabled_; | |
| 120 char chars_ignored_[2]; | |
| 121 int num_chars_ignored_; | |
| 122 | |
| 54 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix); | 123 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix); |
| 55 }; | 124 }; |
| 56 | 125 |
| 57 } // namespace device | 126 } // namespace device |
| 58 | 127 |
| 59 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ | 128 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ |
| OLD | NEW |