• 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_POSIX_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
7 
8 #include "base/message_loop/message_loop.h"
9 #include "chrome/browser/extensions/api/serial/serial_io_handler.h"
10 
11 namespace extensions {
12 
13 class SerialIoHandlerPosix : public SerialIoHandler,
14                              public base::MessageLoopForIO::Watcher {
15  protected:
16   // SerialIoHandler impl.
17   virtual void ReadImpl() OVERRIDE;
18   virtual void WriteImpl() OVERRIDE;
19   virtual void CancelReadImpl() OVERRIDE;
20   virtual void CancelWriteImpl() OVERRIDE;
21 
22  private:
23   friend class SerialIoHandler;
24 
25   SerialIoHandlerPosix();
26   virtual ~SerialIoHandlerPosix();
27 
28   // base::MessageLoopForIO::Watcher implementation.
29   virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
30   virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
31 
32   void EnsureWatchingReads();
33   void EnsureWatchingWrites();
34 
35   base::MessageLoopForIO::FileDescriptorWatcher file_read_watcher_;
36   base::MessageLoopForIO::FileDescriptorWatcher file_write_watcher_;
37 
38   // Flags indicating if the message loop is watching the device for IO events.
39   bool is_watching_reads_;
40   bool is_watching_writes_;
41 
42   DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerPosix);
43 };
44 
45 }  // namespace extensions
46 
47 #endif  // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
48 
49