Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / api / serial / serial_api.h
blob03604f67d17e67f2eb68a30c68dc79f12e5f8f5d
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_SERIAL_SERIAL_API_H_
6 #define EXTENSIONS_BROWSER_API_SERIAL_SERIAL_API_H_
8 #include <string>
10 #include "device/serial/serial.mojom.h"
11 #include "extensions/browser/api/api_resource_manager.h"
12 #include "extensions/browser/api/async_api_function.h"
13 #include "extensions/common/api/serial.h"
15 namespace extensions {
17 class SerialConnection;
19 namespace api {
21 class SerialEventDispatcher;
23 class SerialAsyncApiFunction : public AsyncApiFunction {
24 public:
25 SerialAsyncApiFunction();
27 protected:
28 ~SerialAsyncApiFunction() override;
30 // AsyncApiFunction:
31 bool PrePrepare() override;
32 bool Respond() override;
34 SerialConnection* GetSerialConnection(int api_resource_id);
35 void RemoveSerialConnection(int api_resource_id);
37 ApiResourceManager<SerialConnection>* manager_;
40 class SerialGetDevicesFunction : public SerialAsyncApiFunction {
41 public:
42 DECLARE_EXTENSION_FUNCTION("serial.getDevices", SERIAL_GETDEVICES)
44 SerialGetDevicesFunction();
46 protected:
47 ~SerialGetDevicesFunction() override {}
49 // AsyncApiFunction:
50 bool Prepare() override;
51 void Work() override;
54 class SerialConnectFunction : public SerialAsyncApiFunction {
55 public:
56 DECLARE_EXTENSION_FUNCTION("serial.connect", SERIAL_CONNECT)
58 SerialConnectFunction();
60 protected:
61 ~SerialConnectFunction() override;
63 // AsyncApiFunction:
64 bool Prepare() override;
65 void AsyncWorkStart() override;
67 virtual SerialConnection* CreateSerialConnection(
68 const std::string& port,
69 const std::string& extension_id) const;
71 private:
72 void OnConnected(bool success);
73 void FinishConnect();
75 scoped_ptr<serial::Connect::Params> params_;
77 // SerialEventDispatcher is owned by a BrowserContext.
78 SerialEventDispatcher* serial_event_dispatcher_;
80 // This connection is created within SerialConnectFunction.
81 // From there it is either destroyed in OnConnected (upon failure)
82 // or its ownership is transferred to the
83 // ApiResourceManager<SerialConnection>.
84 SerialConnection* connection_;
87 class SerialUpdateFunction : public SerialAsyncApiFunction {
88 public:
89 DECLARE_EXTENSION_FUNCTION("serial.update", SERIAL_UPDATE);
91 SerialUpdateFunction();
93 protected:
94 ~SerialUpdateFunction() override;
96 // AsyncApiFunction:
97 bool Prepare() override;
98 void Work() override;
100 private:
101 scoped_ptr<serial::Update::Params> params_;
104 class SerialDisconnectFunction : public SerialAsyncApiFunction {
105 public:
106 DECLARE_EXTENSION_FUNCTION("serial.disconnect", SERIAL_DISCONNECT)
108 SerialDisconnectFunction();
110 protected:
111 ~SerialDisconnectFunction() override;
113 // AsyncApiFunction:
114 bool Prepare() override;
115 void Work() override;
117 private:
118 scoped_ptr<serial::Disconnect::Params> params_;
121 class SerialSetPausedFunction : public SerialAsyncApiFunction {
122 public:
123 DECLARE_EXTENSION_FUNCTION("serial.setPaused", SERIAL_SETPAUSED)
125 SerialSetPausedFunction();
127 protected:
128 ~SerialSetPausedFunction() override;
130 // AsyncApiFunction:
131 bool Prepare() override;
132 void Work() override;
134 private:
135 scoped_ptr<serial::SetPaused::Params> params_;
136 SerialEventDispatcher* serial_event_dispatcher_;
139 class SerialGetInfoFunction : public SerialAsyncApiFunction {
140 public:
141 DECLARE_EXTENSION_FUNCTION("serial.getInfo", SERIAL_GETINFO)
143 SerialGetInfoFunction();
145 protected:
146 ~SerialGetInfoFunction() override;
148 // AsyncApiFunction:
149 bool Prepare() override;
150 void Work() override;
152 private:
153 scoped_ptr<serial::GetInfo::Params> params_;
156 class SerialGetConnectionsFunction : public SerialAsyncApiFunction {
157 public:
158 DECLARE_EXTENSION_FUNCTION("serial.getConnections", SERIAL_GETCONNECTIONS);
160 SerialGetConnectionsFunction();
162 protected:
163 ~SerialGetConnectionsFunction() override;
165 // AsyncApiFunction:
166 bool Prepare() override;
167 void Work() override;
170 class SerialSendFunction : public SerialAsyncApiFunction {
171 public:
172 DECLARE_EXTENSION_FUNCTION("serial.send", SERIAL_SEND)
174 SerialSendFunction();
176 protected:
177 ~SerialSendFunction() override;
179 // AsyncApiFunction:
180 bool Prepare() override;
181 void AsyncWorkStart() override;
183 private:
184 void OnSendComplete(int bytes_sent, serial::SendError error);
186 scoped_ptr<serial::Send::Params> params_;
189 class SerialFlushFunction : public SerialAsyncApiFunction {
190 public:
191 DECLARE_EXTENSION_FUNCTION("serial.flush", SERIAL_FLUSH)
193 SerialFlushFunction();
195 protected:
196 ~SerialFlushFunction() override;
198 // AsyncApiFunction:
199 bool Prepare() override;
200 void Work() override;
202 private:
203 scoped_ptr<serial::Flush::Params> params_;
206 class SerialGetControlSignalsFunction : public SerialAsyncApiFunction {
207 public:
208 DECLARE_EXTENSION_FUNCTION("serial.getControlSignals",
209 SERIAL_GETCONTROLSIGNALS)
211 SerialGetControlSignalsFunction();
213 protected:
214 ~SerialGetControlSignalsFunction() override;
216 // AsyncApiFunction:
217 bool Prepare() override;
218 void Work() override;
220 private:
221 scoped_ptr<serial::GetControlSignals::Params> params_;
224 class SerialSetControlSignalsFunction : public SerialAsyncApiFunction {
225 public:
226 DECLARE_EXTENSION_FUNCTION("serial.setControlSignals",
227 SERIAL_SETCONTROLSIGNALS)
229 SerialSetControlSignalsFunction();
231 protected:
232 ~SerialSetControlSignalsFunction() override;
234 // AsyncApiFunction:
235 bool Prepare() override;
236 void Work() override;
238 private:
239 scoped_ptr<serial::SetControlSignals::Params> params_;
242 class SerialSetBreakFunction : public SerialAsyncApiFunction {
243 public:
244 DECLARE_EXTENSION_FUNCTION("serial.setBreak", SERIAL_SETBREAK)
245 SerialSetBreakFunction();
247 protected:
248 ~SerialSetBreakFunction() override;
250 // AsyncApiFunction:
251 bool Prepare() override;
252 void Work() override;
254 private:
255 scoped_ptr<serial::SetBreak::Params> params_;
258 class SerialClearBreakFunction : public SerialAsyncApiFunction {
259 public:
260 DECLARE_EXTENSION_FUNCTION("serial.clearBreak", SERIAL_CLEARBREAK)
261 SerialClearBreakFunction();
263 protected:
264 ~SerialClearBreakFunction() override;
266 // AsyncApiFunction:
267 bool Prepare() override;
268 void Work() override;
270 private:
271 scoped_ptr<serial::ClearBreak::Params> params_;
274 } // namespace api
276 } // namespace extensions
278 namespace mojo {
280 template <>
281 struct TypeConverter<linked_ptr<extensions::api::serial::DeviceInfo>,
282 device::serial::DeviceInfoPtr> {
283 static linked_ptr<extensions::api::serial::DeviceInfo> Convert(
284 const device::serial::DeviceInfoPtr& input);
287 } // namespace mojo
289 #endif // EXTENSIONS_BROWSER_API_SERIAL_SERIAL_API_H_