| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/platform_file.h" |
| 13 #include "chrome/browser/extensions/api/api_resource.h" | 14 #include "chrome/browser/extensions/api/api_resource.h" |
| 14 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 15 | 16 |
| 16 namespace extensions { | 17 namespace extensions { |
| 17 | 18 |
| 18 extern const char kSerialConnectionNotFoundError[]; | 19 extern const char kSerialConnectionNotFoundError[]; |
| 19 | 20 |
| 20 class APIResourceEventNotifier; | 21 class APIResourceEventNotifier; |
| 21 | 22 |
| 22 // Encapsulates an open serial port. Platform-specific implementations are in | 23 // Encapsulates an open serial port. Platform-specific implementations are in |
| 23 // _win and _posix versions of the the .cc file. | 24 // _win and _posix versions of the the .cc file. |
| 24 class SerialConnection : public APIResource { | 25 class SerialConnection : public APIResource { |
| 25 public: | 26 public: |
| 26 SerialConnection(const std::string& port, | 27 SerialConnection(const std::string& port, |
| 27 APIResourceEventNotifier* event_notifier); | 28 APIResourceEventNotifier* event_notifier); |
| 28 virtual ~SerialConnection(); | 29 virtual ~SerialConnection(); |
| 29 | 30 |
| 30 bool Open(); | 31 bool Open(); |
| 31 void Close(); | 32 void Close(); |
| 32 | 33 |
| 33 int Read(uint8* byte); | 34 int Read(uint8* byte); |
| 34 int Write(scoped_refptr<net::IOBuffer> io_buffer, int byte_count); | 35 int Write(scoped_refptr<net::IOBuffer> io_buffer, int byte_count); |
| 35 | 36 |
| 37 protected: |
| 38 // Do platform-specific work after a successful Open(). |
| 39 bool PostOpen(); |
| 40 |
| 36 private: | 41 private: |
| 37 std::string port_; | 42 std::string port_; |
| 38 int fd_; | 43 base::PlatformFile file_; |
| 39 }; | 44 }; |
| 40 | 45 |
| 41 } // namespace extensions | 46 } // namespace extensions |
| 42 | 47 |
| 43 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ | 48 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ |
| OLD | NEW |