• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_IO_HANDLER_WIN_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_IO_HANDLER_WIN_H_
7 
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/extensions/api/serial/serial_io_handler.h"
11 
12 namespace extensions {
13 
14 class SerialIoHandlerWin : public SerialIoHandler,
15                            public base::MessageLoopForIO::IOHandler {
16  protected:
17   // SerialIoHandler implementation.
18   virtual void InitializeImpl() OVERRIDE;
19   virtual void ReadImpl() OVERRIDE;
20   virtual void WriteImpl() OVERRIDE;
21   virtual void CancelReadImpl() OVERRIDE;
22   virtual void CancelWriteImpl() OVERRIDE;
23 
24  private:
25   friend class SerialIoHandler;
26 
27   SerialIoHandlerWin();
28   virtual ~SerialIoHandlerWin();
29 
30   // base::MessageLoopForIO::IOHandler implementation.
31   virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context,
32                              DWORD bytes_transfered,
33                              DWORD error) OVERRIDE;
34 
35   // Context used for asynchronous WaitCommEvent calls.
36   scoped_ptr<base::MessageLoopForIO::IOContext> comm_context_;
37 
38   // Context used for overlapped reads.
39   scoped_ptr<base::MessageLoopForIO::IOContext> read_context_;
40 
41   // Context used for overlapped writes.
42   scoped_ptr<base::MessageLoopForIO::IOContext> write_context_;
43 
44   // Asynchronous event mask state
45   DWORD event_mask_;
46 
47   // Indicates if a pending read is waiting on initial data arrival via
48   // WaitCommEvent, as opposed to waiting on actual ReadFile completion
49   // after a corresponding WaitCommEvent has completed.
50   bool is_comm_pending_;
51 
52   DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerWin);
53 };
54 
55 }  // namespace extensions
56 
57 #endif  // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_IO_HANDLER_WIN_H_
58 
59