[M71 Dev][Tizen] Fix compiler errors
[platform/framework/web/chromium-efl.git] / device / serial / serial_io_handler_posix.h
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
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
7
8 #include <memory>
9
10 #include "base/files/file_descriptor_watcher_posix.h"
11 #include "base/macros.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "device/serial/serial_io_handler.h"
15
16 namespace device {
17
18 // Linux reports breaks and parity errors by inserting the sequence '\377\0x'
19 // into the byte stream where 'x' is '\0' for a break and the corrupted byte for
20 // a parity error.
21 enum class ErrorDetectState { NO_ERROR, MARK_377_SEEN, MARK_0_SEEN };
22
23 class SerialIoHandlerPosix : public SerialIoHandler {
24  protected:
25   // SerialIoHandler impl.
26   void ReadImpl() override;
27   void WriteImpl() override;
28   void CancelReadImpl() override;
29   void CancelWriteImpl() override;
30   bool ConfigurePortImpl() override;
31   bool PostOpen() override;
32   bool Flush() const override;
33   mojom::SerialDeviceControlSignalsPtr GetControlSignals() const override;
34   bool SetControlSignals(
35       const mojom::SerialHostControlSignals& control_signals) override;
36   mojom::SerialConnectionInfoPtr GetPortInfo() const override;
37   bool SetBreak() override;
38   bool ClearBreak() override;
39   int CheckReceiveError(char* buffer,
40                         int buffer_len,
41                         int bytes_read,
42                         bool& break_detected,
43                         bool& parity_error_detected);
44
45  private:
46   friend class SerialIoHandler;
47   friend class SerialIoHandlerPosixTest;
48
49   SerialIoHandlerPosix(
50       scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
51   ~SerialIoHandlerPosix() override;
52
53   void AttemptRead(bool within_read);
54   void RunReadCompleted(bool within_read,
55                         int bytes_read,
56                         mojom::SerialReceiveError error);
57
58   // Called when file() is writable without blocking.
59   void OnFileCanWriteWithoutBlocking();
60
61   void EnsureWatchingReads();
62   void EnsureWatchingWrites();
63
64   std::unique_ptr<base::FileDescriptorWatcher::Controller> file_read_watcher_;
65   std::unique_ptr<base::FileDescriptorWatcher::Controller> file_write_watcher_;
66
67   ErrorDetectState error_detect_state_;
68   bool parity_check_enabled_;
69   char chars_stashed_[2];
70   int num_chars_stashed_;
71
72   DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix);
73 };
74
75 }  // namespace device
76
77 #endif  // DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_