OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ |
6 #define EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ | 6 #define EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "device/serial/serial_io_handler.h" | 15 #include "device/serial/serial_io_handler.h" |
15 #include "extensions/browser/api/api_resource.h" | 16 #include "extensions/browser/api/api_resource.h" |
16 #include "extensions/browser/api/api_resource_manager.h" | 17 #include "extensions/browser/api/api_resource_manager.h" |
17 #include "extensions/common/api/serial.h" | 18 #include "extensions/common/api/serial.h" |
18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
19 | 20 |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 // Encapsulates an open serial port. | 25 // Encapsulates an open serial port. |
25 // NOTE: Instances of this object should only be constructed on the IO thread, | 26 // NOTE: Instances of this object should only be constructed on the IO thread, |
26 // and all methods should only be called on the IO thread unless otherwise | 27 // and all methods should only be called on the IO thread unless otherwise |
27 // noted. | 28 // noted. |
28 class SerialConnection : public ApiResource, | 29 class SerialConnection : public ApiResource, |
29 public base::SupportsWeakPtr<SerialConnection> { | 30 public base::SupportsWeakPtr<SerialConnection> { |
30 public: | 31 public: |
31 typedef device::SerialIoHandler::OpenCompleteCallback OpenCompleteCallback; | 32 typedef device::SerialIoHandler::OpenCompleteCallback OpenCompleteCallback; |
32 | 33 |
33 // This is the callback type expected by Receive. Note that an error result | 34 // This is the callback type expected by Receive. Note that an error result |
34 // does not necessarily imply an empty |data| string, since a receive may | 35 // does not necessarily imply an empty |data| string, since a receive may |
35 // complete partially before being interrupted by an error condition. | 36 // complete partially before being interrupted by an error condition. |
36 typedef base::Callback< | 37 typedef base::Callback<void(const std::vector<char>& data, |
37 void(const std::string& data, core_api::serial::ReceiveError error)> | 38 core_api::serial::ReceiveError error)> |
38 ReceiveCompleteCallback; | 39 ReceiveCompleteCallback; |
39 | 40 |
40 // This is the callback type expected by Send. Note that an error result | 41 // This is the callback type expected by Send. Note that an error result |
41 // does not necessarily imply 0 bytes sent, since a send may complete | 42 // does not necessarily imply 0 bytes sent, since a send may complete |
42 // partially before being interrupted by an error condition. | 43 // partially before being interrupted by an error condition. |
43 typedef base::Callback< | 44 typedef base::Callback< |
44 void(int bytes_sent, core_api::serial::SendError error)> | 45 void(int bytes_sent, core_api::serial::SendError error)> |
45 SendCompleteCallback; | 46 SendCompleteCallback; |
46 | 47 |
47 SerialConnection(const std::string& port, | 48 SerialConnection(const std::string& port, |
(...skipping 27 matching lines...) Expand all Loading... |
75 void Open(const OpenCompleteCallback& callback); | 76 void Open(const OpenCompleteCallback& callback); |
76 | 77 |
77 // Begins an asynchronous receive operation. Calling this while a Receive | 78 // Begins an asynchronous receive operation. Calling this while a Receive |
78 // is already pending is a no-op and returns |false| without calling | 79 // is already pending is a no-op and returns |false| without calling |
79 // |callback|. | 80 // |callback|. |
80 bool Receive(const ReceiveCompleteCallback& callback); | 81 bool Receive(const ReceiveCompleteCallback& callback); |
81 | 82 |
82 // Begins an asynchronous send operation. Calling this while a Send | 83 // Begins an asynchronous send operation. Calling this while a Send |
83 // is already pending is a no-op and returns |false| without calling | 84 // is already pending is a no-op and returns |false| without calling |
84 // |callback|. | 85 // |callback|. |
85 bool Send(const std::string& data, const SendCompleteCallback& callback); | 86 bool Send(const std::vector<char>& data, |
| 87 const SendCompleteCallback& callback); |
86 | 88 |
87 // Flushes input and output buffers. | 89 // Flushes input and output buffers. |
88 bool Flush() const; | 90 bool Flush() const; |
89 | 91 |
90 // Configures some subset of port options for this connection. | 92 // Configures some subset of port options for this connection. |
91 // Omitted options are unchanged. Returns |true| iff the configuration | 93 // Omitted options are unchanged. Returns |true| iff the configuration |
92 // changes were successful. | 94 // changes were successful. |
93 bool Configure(const core_api::serial::ConnectionOptions& options); | 95 bool Configure(const core_api::serial::ConnectionOptions& options); |
94 | 96 |
95 // Connection configuration query. Fills values in an existing | 97 // Connection configuration query. Fills values in an existing |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 template <> | 207 template <> |
206 struct TypeConverter<device::serial::ConnectionOptionsPtr, | 208 struct TypeConverter<device::serial::ConnectionOptionsPtr, |
207 extensions::core_api::serial::ConnectionOptions> { | 209 extensions::core_api::serial::ConnectionOptions> { |
208 static device::serial::ConnectionOptionsPtr Convert( | 210 static device::serial::ConnectionOptionsPtr Convert( |
209 const extensions::core_api::serial::ConnectionOptions& input); | 211 const extensions::core_api::serial::ConnectionOptions& input); |
210 }; | 212 }; |
211 | 213 |
212 } // namespace mojo | 214 } // namespace mojo |
213 | 215 |
214 #endif // EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ | 216 #endif // EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ |
OLD | NEW |