Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: device/serial/serial_io_handler_posix.h

Issue 1249933004: Add code to detect new added ReceiveError on Linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated comments, changed variable name. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/device_tests.gyp ('k') | device/serial/serial_io_handler_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Linux reports breaks and parity errors by inserting the sequence '\377\0x'
16 // into the byte stream where 'x' is '\0' for a break and the corrupted byte for
17 // a parity error.
18 enum class ErrorDetectState { NO_ERROR, MARK_377_SEEN, MARK_0_SEEN };
19
15 class SerialIoHandlerPosix : public SerialIoHandler, 20 class SerialIoHandlerPosix : public SerialIoHandler,
16 public base::MessageLoopForIO::Watcher { 21 public base::MessageLoopForIO::Watcher {
17 protected: 22 protected:
18 // SerialIoHandler impl. 23 // SerialIoHandler impl.
19 void ReadImpl() override; 24 void ReadImpl() override;
20 void WriteImpl() override; 25 void WriteImpl() override;
21 void CancelReadImpl() override; 26 void CancelReadImpl() override;
22 void CancelWriteImpl() override; 27 void CancelWriteImpl() override;
23 bool ConfigurePortImpl() override; 28 bool ConfigurePortImpl() override;
24 bool Flush() const override; 29 bool Flush() const override;
25 serial::DeviceControlSignalsPtr GetControlSignals() const override; 30 serial::DeviceControlSignalsPtr GetControlSignals() const override;
26 bool SetControlSignals( 31 bool SetControlSignals(
27 const serial::HostControlSignals& control_signals) override; 32 const serial::HostControlSignals& control_signals) override;
28 serial::ConnectionInfoPtr GetPortInfo() const override; 33 serial::ConnectionInfoPtr GetPortInfo() const override;
29 bool SetBreak() override; 34 bool SetBreak() override;
30 bool ClearBreak() override; 35 bool ClearBreak() override;
36 int CheckReceiveError(char* buffer,
37 int buffer_len,
38 int bytes_read,
39 bool& break_detected,
40 bool& parity_error_detected);
31 41
32 private: 42 private:
33 friend class SerialIoHandler; 43 friend class SerialIoHandler;
44 friend class SerialIoHandlerPosixTest;
34 45
35 SerialIoHandlerPosix( 46 SerialIoHandlerPosix(
36 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, 47 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
37 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); 48 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
38 ~SerialIoHandlerPosix() override; 49 ~SerialIoHandlerPosix() override;
39 50
40 // base::MessageLoopForIO::Watcher implementation. 51 // base::MessageLoopForIO::Watcher implementation.
41 void OnFileCanWriteWithoutBlocking(int fd) override; 52 void OnFileCanWriteWithoutBlocking(int fd) override;
42 void OnFileCanReadWithoutBlocking(int fd) override; 53 void OnFileCanReadWithoutBlocking(int fd) override;
43 54
44 void EnsureWatchingReads(); 55 void EnsureWatchingReads();
45 void EnsureWatchingWrites(); 56 void EnsureWatchingWrites();
46 57
47 base::MessageLoopForIO::FileDescriptorWatcher file_read_watcher_; 58 base::MessageLoopForIO::FileDescriptorWatcher file_read_watcher_;
48 base::MessageLoopForIO::FileDescriptorWatcher file_write_watcher_; 59 base::MessageLoopForIO::FileDescriptorWatcher file_write_watcher_;
49 60
50 // Flags indicating if the message loop is watching the device for IO events. 61 // Flags indicating if the message loop is watching the device for IO events.
51 bool is_watching_reads_; 62 bool is_watching_reads_;
52 bool is_watching_writes_; 63 bool is_watching_writes_;
53 64
65 ErrorDetectState error_detect_state_;
66 bool parity_check_enabled_;
67 char chars_stashed_[2];
68 int num_chars_stashed_;
69
54 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix); 70 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix);
55 }; 71 };
56 72
57 } // namespace device 73 } // namespace device
58 74
59 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ 75 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
OLDNEW
« no previous file with comments | « device/device_tests.gyp ('k') | device/serial/serial_io_handler_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698