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 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "chrome/browser/extensions/api/api_resource.h" | 13 #include "chrome/browser/extensions/api/api_resource.h" |
14 #include "chrome/browser/extensions/api/api_resource_manager.h" | 14 #include "chrome/browser/extensions/api/api_resource_manager.h" |
| 15 #include "chrome/common/extensions/api/serial.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
17 | 18 |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 | 20 |
| 21 namespace serial = extensions::api::serial; |
| 22 |
20 namespace extensions { | 23 namespace extensions { |
21 | 24 |
22 extern const char kSerialConnectionNotFoundError[]; | 25 extern const char kSerialConnectionNotFoundError[]; |
23 | 26 |
24 // Encapsulates an open serial port. Platform-specific implementations are in | 27 // Encapsulates an open serial port. Platform-specific implementations are in |
25 // _win and _posix versions of the the .cc file. | 28 // _win and _posix versions of the the .cc file. |
26 class SerialConnection : public ApiResource { | 29 class SerialConnection : public ApiResource { |
27 public: | 30 public: |
28 SerialConnection(const std::string& port, | 31 SerialConnection(const std::string& port, int bitrate, |
29 int bitrate, | 32 serial::DataBit databit, serial::ParityBit parity, |
| 33 serial::StopBit stopbit, |
30 const std::string& owner_extension_id); | 34 const std::string& owner_extension_id); |
31 virtual ~SerialConnection(); | 35 virtual ~SerialConnection(); |
32 | 36 |
33 virtual bool Open(); | 37 virtual bool Open(); |
34 virtual void Close(); | 38 virtual void Close(); |
35 virtual void Flush(); | 39 virtual void Flush(); |
36 | 40 |
37 virtual int Read(scoped_refptr<net::IOBufferWithSize> io_buffer); | 41 virtual int Read(scoped_refptr<net::IOBufferWithSize> io_buffer); |
38 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, int byte_count); | 42 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, int byte_count); |
39 | 43 |
(...skipping 24 matching lines...) Expand all Loading... |
64 // Platform-specific port name adapter | 68 // Platform-specific port name adapter |
65 static std::string MaybeFixUpPortName(const std::string &port_name); | 69 static std::string MaybeFixUpPortName(const std::string &port_name); |
66 | 70 |
67 private: | 71 private: |
68 friend class ApiResourceManager<SerialConnection>; | 72 friend class ApiResourceManager<SerialConnection>; |
69 static const char* service_name() { | 73 static const char* service_name() { |
70 return "SerialConnectionManager"; | 74 return "SerialConnectionManager"; |
71 } | 75 } |
72 std::string port_; | 76 std::string port_; |
73 int bitrate_; | 77 int bitrate_; |
| 78 serial::DataBit databit_; |
| 79 serial::ParityBit parity_; |
| 80 serial::StopBit stopbit_; |
74 base::PlatformFile file_; | 81 base::PlatformFile file_; |
75 }; | 82 }; |
76 | 83 |
77 } // namespace extensions | 84 } // namespace extensions |
78 | 85 |
79 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ | 86 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ |
OLD | NEW |