[M73 Dev][Tizen] Fix linker errors
[platform/framework/web/chromium-efl.git] / services / device / serial / serial_io_handler_win.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 SERVICES_DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_
6 #define SERVICES_DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/macros.h"
12 #include "base/message_loop/message_pump_for_io.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h"
15 #include "services/device/serial/serial_io_handler.h"
16
17 namespace device {
18
19 class SerialIoHandlerWin : public SerialIoHandler,
20                            public base::MessagePumpForIO::IOHandler {
21  protected:
22   // SerialIoHandler implementation.
23   void ReadImpl() override;
24   void WriteImpl() override;
25   void CancelReadImpl() override;
26   void CancelWriteImpl() override;
27   bool ConfigurePortImpl() override;
28   bool Flush() const override;
29   mojom::SerialPortControlSignalsPtr GetControlSignals() const override;
30   bool SetControlSignals(
31       const mojom::SerialHostControlSignals& control_signals) override;
32   mojom::SerialConnectionInfoPtr GetPortInfo() const override;
33   bool SetBreak() override;
34   bool ClearBreak() override;
35   bool PostOpen() override;
36
37  private:
38   class UiThreadHelper;
39   friend class SerialIoHandler;
40
41   explicit SerialIoHandlerWin(
42       const base::FilePath& port,
43       scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
44   ~SerialIoHandlerWin() override;
45
46   // base::MessagePumpForIO::IOHandler implementation.
47   void OnIOCompleted(base::MessagePumpForIO::IOContext* context,
48                      DWORD bytes_transfered,
49                      DWORD error) override;
50
51   void OnDeviceRemoved(const std::string& device_path);
52
53   // Context used for asynchronous WaitCommEvent calls.
54   std::unique_ptr<base::MessagePumpForIO::IOContext> comm_context_;
55
56   // Context used for overlapped reads.
57   std::unique_ptr<base::MessagePumpForIO::IOContext> read_context_;
58
59   // Context used for overlapped writes.
60   std::unique_ptr<base::MessagePumpForIO::IOContext> write_context_;
61
62   // Asynchronous event mask state
63   DWORD event_mask_;
64
65   // Indicates if a pending read is waiting on initial data arrival via
66   // WaitCommEvent, as opposed to waiting on actual ReadFile completion
67   // after a corresponding WaitCommEvent has completed.
68   bool is_comm_pending_;
69
70   // The helper lives on the UI thread and holds a weak reference back to the
71   // handler that owns it.
72   UiThreadHelper* helper_;
73   base::WeakPtrFactory<SerialIoHandlerWin> weak_factory_;
74
75   DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerWin);
76 };
77
78 }  // namespace device
79
80 #endif  // SERVICES_DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_