OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "chrome/browser/extensions/api/serial/serial_api.h" | 5 #include "extensions/browser/api/serial/serial_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> |
8 | 9 |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/browser/extensions/api/serial/serial_connection.h" | |
11 #include "chrome/browser/extensions/api/serial/serial_event_dispatcher.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/common/extensions/api/serial.h" | |
14 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
15 #include "device/serial/serial_device_enumerator.h" | 12 #include "device/serial/serial_device_enumerator.h" |
16 #include "extensions/browser/extension_system.h" | 13 #include "extensions/browser/api/serial/serial_connection.h" |
| 14 #include "extensions/browser/api/serial/serial_event_dispatcher.h" |
| 15 #include "extensions/common/api/serial.h" |
17 | 16 |
18 using content::BrowserThread; | 17 using content::BrowserThread; |
19 | 18 |
20 namespace extensions { | 19 namespace extensions { |
21 | 20 |
22 namespace api { | 21 namespace core_api { |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 // It's a fool's errand to come up with a default bitrate, because we don't get | 25 // It's a fool's errand to come up with a default bitrate, because we don't get |
27 // to control both sides of the communication. Unless the other side has | 26 // to control both sides of the communication. Unless the other side has |
28 // implemented auto-bitrate detection (rare), if we pick the wrong rate, then | 27 // implemented auto-bitrate detection (rare), if we pick the wrong rate, then |
29 // you're gonna have a bad time. Close doesn't count. | 28 // you're gonna have a bad time. Close doesn't count. |
30 // | 29 // |
31 // But we'd like to pick something that has a chance of working, and 9600 is a | 30 // But we'd like to pick something that has a chance of working, and 9600 is a |
32 // good balance between popularity and speed. So 9600 it is. | 31 // good balance between popularity and speed. So 9600 it is. |
(...skipping 10 matching lines...) Expand all Loading... |
43 const char kErrorGetControlSignalsFailed[] = "Failed to get control signals."; | 42 const char kErrorGetControlSignalsFailed[] = "Failed to get control signals."; |
44 | 43 |
45 template <class T> | 44 template <class T> |
46 void SetDefaultScopedPtrValue(scoped_ptr<T>& ptr, const T& value) { | 45 void SetDefaultScopedPtrValue(scoped_ptr<T>& ptr, const T& value) { |
47 if (!ptr.get()) | 46 if (!ptr.get()) |
48 ptr.reset(new T(value)); | 47 ptr.reset(new T(value)); |
49 } | 48 } |
50 | 49 |
51 } // namespace | 50 } // namespace |
52 | 51 |
53 SerialAsyncApiFunction::SerialAsyncApiFunction() | 52 SerialAsyncApiFunction::SerialAsyncApiFunction() : manager_(NULL) { |
54 : manager_(NULL) { | |
55 } | 53 } |
56 | 54 |
57 SerialAsyncApiFunction::~SerialAsyncApiFunction() {} | 55 SerialAsyncApiFunction::~SerialAsyncApiFunction() { |
| 56 } |
58 | 57 |
59 bool SerialAsyncApiFunction::PrePrepare() { | 58 bool SerialAsyncApiFunction::PrePrepare() { |
60 manager_ = ApiResourceManager<SerialConnection>::Get(browser_context()); | 59 manager_ = ApiResourceManager<SerialConnection>::Get(browser_context()); |
61 DCHECK(manager_); | 60 DCHECK(manager_); |
62 return true; | 61 return true; |
63 } | 62 } |
64 | 63 |
65 bool SerialAsyncApiFunction::Respond() { | 64 bool SerialAsyncApiFunction::Respond() { |
66 return error_.empty(); | 65 return error_.empty(); |
67 } | 66 } |
68 | 67 |
69 SerialConnection* SerialAsyncApiFunction::GetSerialConnection( | 68 SerialConnection* SerialAsyncApiFunction::GetSerialConnection( |
70 int api_resource_id) { | 69 int api_resource_id) { |
71 return manager_->Get(extension_->id(), api_resource_id); | 70 return manager_->Get(extension_->id(), api_resource_id); |
72 } | 71 } |
73 | 72 |
74 void SerialAsyncApiFunction::RemoveSerialConnection(int api_resource_id) { | 73 void SerialAsyncApiFunction::RemoveSerialConnection(int api_resource_id) { |
75 manager_->Remove(extension_->id(), api_resource_id); | 74 manager_->Remove(extension_->id(), api_resource_id); |
76 } | 75 } |
77 | 76 |
78 SerialGetDevicesFunction::SerialGetDevicesFunction() {} | 77 SerialGetDevicesFunction::SerialGetDevicesFunction() { |
| 78 } |
79 | 79 |
80 bool SerialGetDevicesFunction::Prepare() { | 80 bool SerialGetDevicesFunction::Prepare() { |
81 set_work_thread_id(BrowserThread::FILE); | 81 set_work_thread_id(BrowserThread::FILE); |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 void SerialGetDevicesFunction::Work() { | 85 void SerialGetDevicesFunction::Work() { |
86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
87 | 87 |
88 scoped_ptr<device::SerialDeviceEnumerator> enumerator = | 88 scoped_ptr<device::SerialDeviceEnumerator> enumerator = |
89 device::SerialDeviceEnumerator::Create(); | 89 device::SerialDeviceEnumerator::Create(); |
90 mojo::Array<device::serial::DeviceInfoPtr> devices = enumerator->GetDevices(); | 90 mojo::Array<device::serial::DeviceInfoPtr> devices = enumerator->GetDevices(); |
91 results_ = serial::GetDevices::Results::Create( | 91 results_ = serial::GetDevices::Results::Create( |
92 devices.To<std::vector<linked_ptr<serial::DeviceInfo> > >()); | 92 devices.To<std::vector<linked_ptr<serial::DeviceInfo> > >()); |
93 } | 93 } |
94 | 94 |
95 SerialConnectFunction::SerialConnectFunction() {} | 95 SerialConnectFunction::SerialConnectFunction() { |
| 96 } |
96 | 97 |
97 SerialConnectFunction::~SerialConnectFunction() {} | 98 SerialConnectFunction::~SerialConnectFunction() { |
| 99 } |
98 | 100 |
99 bool SerialConnectFunction::Prepare() { | 101 bool SerialConnectFunction::Prepare() { |
100 params_ = serial::Connect::Params::Create(*args_); | 102 params_ = serial::Connect::Params::Create(*args_); |
101 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 103 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
102 | 104 |
103 // Fill in any omitted options to ensure a known initial configuration. | 105 // Fill in any omitted options to ensure a known initial configuration. |
104 if (!params_->options.get()) | 106 if (!params_->options.get()) |
105 params_->options.reset(new serial::ConnectionOptions()); | 107 params_->options.reset(new serial::ConnectionOptions()); |
106 serial::ConnectionOptions* options = params_->options.get(); | 108 serial::ConnectionOptions* options = params_->options.get(); |
107 | 109 |
(...skipping 29 matching lines...) Expand all Loading... |
137 if (success) { | 139 if (success) { |
138 if (!connection_->Configure(*params_->options.get())) { | 140 if (!connection_->Configure(*params_->options.get())) { |
139 delete connection_; | 141 delete connection_; |
140 connection_ = NULL; | 142 connection_ = NULL; |
141 } | 143 } |
142 } else { | 144 } else { |
143 delete connection_; | 145 delete connection_; |
144 connection_ = NULL; | 146 connection_ = NULL; |
145 } | 147 } |
146 | 148 |
147 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 149 BrowserThread::PostTask( |
148 base::Bind(&SerialConnectFunction::FinishConnect, | 150 BrowserThread::IO, |
149 this)); | 151 FROM_HERE, |
| 152 base::Bind(&SerialConnectFunction::FinishConnect, this)); |
150 } | 153 } |
151 | 154 |
152 void SerialConnectFunction::FinishConnect() { | 155 void SerialConnectFunction::FinishConnect() { |
153 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
154 if (!connection_) { | 157 if (!connection_) { |
155 error_ = kErrorConnectFailed; | 158 error_ = kErrorConnectFailed; |
156 } else { | 159 } else { |
157 int id = manager_->Add(connection_); | 160 int id = manager_->Add(connection_); |
158 serial::ConnectionInfo info; | 161 serial::ConnectionInfo info; |
159 info.connection_id = id; | 162 info.connection_id = id; |
160 if (connection_->GetInfo(&info)) { | 163 if (connection_->GetInfo(&info)) { |
161 serial_event_dispatcher_->PollConnection(extension_->id(), id); | 164 serial_event_dispatcher_->PollConnection(extension_->id(), id); |
162 results_ = serial::Connect::Results::Create(info); | 165 results_ = serial::Connect::Results::Create(info); |
163 } else { | 166 } else { |
164 RemoveSerialConnection(id); | 167 RemoveSerialConnection(id); |
165 error_ = kErrorConnectFailed; | 168 error_ = kErrorConnectFailed; |
166 } | 169 } |
167 } | 170 } |
168 AsyncWorkCompleted(); | 171 AsyncWorkCompleted(); |
169 } | 172 } |
170 | 173 |
171 SerialConnection* SerialConnectFunction::CreateSerialConnection( | 174 SerialConnection* SerialConnectFunction::CreateSerialConnection( |
172 const std::string& port, const std::string& extension_id) const { | 175 const std::string& port, |
| 176 const std::string& extension_id) const { |
173 return new SerialConnection(port, extension_id); | 177 return new SerialConnection(port, extension_id); |
174 } | 178 } |
175 | 179 |
176 SerialUpdateFunction::SerialUpdateFunction() {} | 180 SerialUpdateFunction::SerialUpdateFunction() { |
| 181 } |
177 | 182 |
178 SerialUpdateFunction::~SerialUpdateFunction() {} | 183 SerialUpdateFunction::~SerialUpdateFunction() { |
| 184 } |
179 | 185 |
180 bool SerialUpdateFunction::Prepare() { | 186 bool SerialUpdateFunction::Prepare() { |
181 params_ = serial::Update::Params::Create(*args_); | 187 params_ = serial::Update::Params::Create(*args_); |
182 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 188 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
183 | 189 |
184 return true; | 190 return true; |
185 } | 191 } |
186 | 192 |
187 void SerialUpdateFunction::Work() { | 193 void SerialUpdateFunction::Work() { |
188 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 194 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
189 if (!connection) { | 195 if (!connection) { |
190 error_ = kErrorSerialConnectionNotFound; | 196 error_ = kErrorSerialConnectionNotFound; |
191 return; | 197 return; |
192 } | 198 } |
193 bool success = connection->Configure(params_->options); | 199 bool success = connection->Configure(params_->options); |
194 results_ = serial::Update::Results::Create(success); | 200 results_ = serial::Update::Results::Create(success); |
195 } | 201 } |
196 | 202 |
197 SerialDisconnectFunction::SerialDisconnectFunction() {} | 203 SerialDisconnectFunction::SerialDisconnectFunction() { |
| 204 } |
198 | 205 |
199 SerialDisconnectFunction::~SerialDisconnectFunction() {} | 206 SerialDisconnectFunction::~SerialDisconnectFunction() { |
| 207 } |
200 | 208 |
201 bool SerialDisconnectFunction::Prepare() { | 209 bool SerialDisconnectFunction::Prepare() { |
202 params_ = serial::Disconnect::Params::Create(*args_); | 210 params_ = serial::Disconnect::Params::Create(*args_); |
203 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 211 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
204 | 212 |
205 return true; | 213 return true; |
206 } | 214 } |
207 | 215 |
208 void SerialDisconnectFunction::Work() { | 216 void SerialDisconnectFunction::Work() { |
209 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 217 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
210 if (!connection) { | 218 if (!connection) { |
211 error_ = kErrorSerialConnectionNotFound; | 219 error_ = kErrorSerialConnectionNotFound; |
212 return; | 220 return; |
213 } | 221 } |
214 RemoveSerialConnection(params_->connection_id); | 222 RemoveSerialConnection(params_->connection_id); |
215 results_ = serial::Disconnect::Results::Create(true); | 223 results_ = serial::Disconnect::Results::Create(true); |
216 } | 224 } |
217 | 225 |
218 SerialSendFunction::SerialSendFunction() {} | 226 SerialSendFunction::SerialSendFunction() { |
| 227 } |
219 | 228 |
220 SerialSendFunction::~SerialSendFunction() {} | 229 SerialSendFunction::~SerialSendFunction() { |
| 230 } |
221 | 231 |
222 bool SerialSendFunction::Prepare() { | 232 bool SerialSendFunction::Prepare() { |
223 params_ = serial::Send::Params::Create(*args_); | 233 params_ = serial::Send::Params::Create(*args_); |
224 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 234 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
225 | 235 |
226 return true; | 236 return true; |
227 } | 237 } |
228 | 238 |
229 void SerialSendFunction::AsyncWorkStart() { | 239 void SerialSendFunction::AsyncWorkStart() { |
230 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 240 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
231 if (!connection) { | 241 if (!connection) { |
232 error_ = kErrorSerialConnectionNotFound; | 242 error_ = kErrorSerialConnectionNotFound; |
233 AsyncWorkCompleted(); | 243 AsyncWorkCompleted(); |
234 return; | 244 return; |
235 } | 245 } |
236 | 246 |
237 if (!connection->Send(params_->data, | 247 if (!connection->Send( |
238 base::Bind(&SerialSendFunction::OnSendComplete, | 248 params_->data, |
239 this))) { | 249 base::Bind(&SerialSendFunction::OnSendComplete, this))) { |
240 OnSendComplete(0, serial::SEND_ERROR_PENDING); | 250 OnSendComplete(0, serial::SEND_ERROR_PENDING); |
241 } | 251 } |
242 } | 252 } |
243 | 253 |
244 void SerialSendFunction::OnSendComplete(int bytes_sent, | 254 void SerialSendFunction::OnSendComplete(int bytes_sent, |
245 serial::SendError error) { | 255 serial::SendError error) { |
246 serial::SendInfo send_info; | 256 serial::SendInfo send_info; |
247 send_info.bytes_sent = bytes_sent; | 257 send_info.bytes_sent = bytes_sent; |
248 send_info.error = error; | 258 send_info.error = error; |
249 results_ = serial::Send::Results::Create(send_info); | 259 results_ = serial::Send::Results::Create(send_info); |
250 AsyncWorkCompleted(); | 260 AsyncWorkCompleted(); |
251 } | 261 } |
252 | 262 |
253 SerialFlushFunction::SerialFlushFunction() {} | 263 SerialFlushFunction::SerialFlushFunction() { |
| 264 } |
254 | 265 |
255 SerialFlushFunction::~SerialFlushFunction() {} | 266 SerialFlushFunction::~SerialFlushFunction() { |
| 267 } |
256 | 268 |
257 bool SerialFlushFunction::Prepare() { | 269 bool SerialFlushFunction::Prepare() { |
258 params_ = serial::Flush::Params::Create(*args_); | 270 params_ = serial::Flush::Params::Create(*args_); |
259 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 271 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
260 return true; | 272 return true; |
261 } | 273 } |
262 | 274 |
263 void SerialFlushFunction::Work() { | 275 void SerialFlushFunction::Work() { |
264 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 276 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
265 if (!connection) { | 277 if (!connection) { |
266 error_ = kErrorSerialConnectionNotFound; | 278 error_ = kErrorSerialConnectionNotFound; |
267 return; | 279 return; |
268 } | 280 } |
269 | 281 |
270 bool success = connection->Flush(); | 282 bool success = connection->Flush(); |
271 results_ = serial::Flush::Results::Create(success); | 283 results_ = serial::Flush::Results::Create(success); |
272 } | 284 } |
273 | 285 |
274 SerialSetPausedFunction::SerialSetPausedFunction() {} | 286 SerialSetPausedFunction::SerialSetPausedFunction() { |
| 287 } |
275 | 288 |
276 SerialSetPausedFunction::~SerialSetPausedFunction() {} | 289 SerialSetPausedFunction::~SerialSetPausedFunction() { |
| 290 } |
277 | 291 |
278 bool SerialSetPausedFunction::Prepare() { | 292 bool SerialSetPausedFunction::Prepare() { |
279 params_ = serial::SetPaused::Params::Create(*args_); | 293 params_ = serial::SetPaused::Params::Create(*args_); |
280 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 294 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
281 | 295 |
282 serial_event_dispatcher_ = SerialEventDispatcher::Get(browser_context()); | 296 serial_event_dispatcher_ = SerialEventDispatcher::Get(browser_context()); |
283 DCHECK(serial_event_dispatcher_); | 297 DCHECK(serial_event_dispatcher_); |
284 return true; | 298 return true; |
285 } | 299 } |
286 | 300 |
287 void SerialSetPausedFunction::Work() { | 301 void SerialSetPausedFunction::Work() { |
288 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 302 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
289 if (!connection) { | 303 if (!connection) { |
290 error_ = kErrorSerialConnectionNotFound; | 304 error_ = kErrorSerialConnectionNotFound; |
291 return; | 305 return; |
292 } | 306 } |
293 | 307 |
294 if (params_->paused != connection->paused()) { | 308 if (params_->paused != connection->paused()) { |
295 connection->set_paused(params_->paused); | 309 connection->set_paused(params_->paused); |
296 if (!params_->paused) { | 310 if (!params_->paused) { |
297 serial_event_dispatcher_->PollConnection(extension_->id(), | 311 serial_event_dispatcher_->PollConnection(extension_->id(), |
298 params_->connection_id); | 312 params_->connection_id); |
299 } | 313 } |
300 } | 314 } |
301 | 315 |
302 results_ = serial::SetPaused::Results::Create(); | 316 results_ = serial::SetPaused::Results::Create(); |
303 } | 317 } |
304 | 318 |
305 SerialGetInfoFunction::SerialGetInfoFunction() {} | 319 SerialGetInfoFunction::SerialGetInfoFunction() { |
| 320 } |
306 | 321 |
307 SerialGetInfoFunction::~SerialGetInfoFunction() {} | 322 SerialGetInfoFunction::~SerialGetInfoFunction() { |
| 323 } |
308 | 324 |
309 bool SerialGetInfoFunction::Prepare() { | 325 bool SerialGetInfoFunction::Prepare() { |
310 params_ = serial::GetInfo::Params::Create(*args_); | 326 params_ = serial::GetInfo::Params::Create(*args_); |
311 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 327 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
312 | 328 |
313 return true; | 329 return true; |
314 } | 330 } |
315 | 331 |
316 void SerialGetInfoFunction::Work() { | 332 void SerialGetInfoFunction::Work() { |
317 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 333 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
318 if (!connection) { | 334 if (!connection) { |
319 error_ = kErrorSerialConnectionNotFound; | 335 error_ = kErrorSerialConnectionNotFound; |
320 return; | 336 return; |
321 } | 337 } |
322 | 338 |
323 serial::ConnectionInfo info; | 339 serial::ConnectionInfo info; |
324 info.connection_id = params_->connection_id; | 340 info.connection_id = params_->connection_id; |
325 connection->GetInfo(&info); | 341 connection->GetInfo(&info); |
326 results_ = serial::GetInfo::Results::Create(info); | 342 results_ = serial::GetInfo::Results::Create(info); |
327 } | 343 } |
328 | 344 |
329 SerialGetConnectionsFunction::SerialGetConnectionsFunction() {} | 345 SerialGetConnectionsFunction::SerialGetConnectionsFunction() { |
| 346 } |
330 | 347 |
331 SerialGetConnectionsFunction::~SerialGetConnectionsFunction() {} | 348 SerialGetConnectionsFunction::~SerialGetConnectionsFunction() { |
| 349 } |
332 | 350 |
333 bool SerialGetConnectionsFunction::Prepare() { | 351 bool SerialGetConnectionsFunction::Prepare() { |
334 return true; | 352 return true; |
335 } | 353 } |
336 | 354 |
337 void SerialGetConnectionsFunction::Work() { | 355 void SerialGetConnectionsFunction::Work() { |
338 std::vector<linked_ptr<serial::ConnectionInfo> > infos; | 356 std::vector<linked_ptr<serial::ConnectionInfo> > infos; |
339 const base::hash_set<int>* connection_ids = manager_->GetResourceIds( | 357 const base::hash_set<int>* connection_ids = |
340 extension_->id()); | 358 manager_->GetResourceIds(extension_->id()); |
341 if (connection_ids) { | 359 if (connection_ids) { |
342 for (base::hash_set<int>::const_iterator it = connection_ids->begin(); | 360 for (base::hash_set<int>::const_iterator it = connection_ids->begin(); |
343 it != connection_ids->end(); ++it) { | 361 it != connection_ids->end(); |
| 362 ++it) { |
344 int connection_id = *it; | 363 int connection_id = *it; |
345 SerialConnection *connection = GetSerialConnection(connection_id); | 364 SerialConnection* connection = GetSerialConnection(connection_id); |
346 if (connection) { | 365 if (connection) { |
347 linked_ptr<serial::ConnectionInfo> info(new serial::ConnectionInfo()); | 366 linked_ptr<serial::ConnectionInfo> info(new serial::ConnectionInfo()); |
348 info->connection_id = connection_id; | 367 info->connection_id = connection_id; |
349 connection->GetInfo(info.get()); | 368 connection->GetInfo(info.get()); |
350 infos.push_back(info); | 369 infos.push_back(info); |
351 } | 370 } |
352 } | 371 } |
353 } | 372 } |
354 results_ = serial::GetConnections::Results::Create(infos); | 373 results_ = serial::GetConnections::Results::Create(infos); |
355 } | 374 } |
356 | 375 |
357 SerialGetControlSignalsFunction::SerialGetControlSignalsFunction() {} | 376 SerialGetControlSignalsFunction::SerialGetControlSignalsFunction() { |
| 377 } |
358 | 378 |
359 SerialGetControlSignalsFunction::~SerialGetControlSignalsFunction() {} | 379 SerialGetControlSignalsFunction::~SerialGetControlSignalsFunction() { |
| 380 } |
360 | 381 |
361 bool SerialGetControlSignalsFunction::Prepare() { | 382 bool SerialGetControlSignalsFunction::Prepare() { |
362 params_ = serial::GetControlSignals::Params::Create(*args_); | 383 params_ = serial::GetControlSignals::Params::Create(*args_); |
363 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 384 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
364 | 385 |
365 return true; | 386 return true; |
366 } | 387 } |
367 | 388 |
368 void SerialGetControlSignalsFunction::Work() { | 389 void SerialGetControlSignalsFunction::Work() { |
369 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 390 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
370 if (!connection) { | 391 if (!connection) { |
371 error_ = kErrorSerialConnectionNotFound; | 392 error_ = kErrorSerialConnectionNotFound; |
372 return; | 393 return; |
373 } | 394 } |
374 | 395 |
375 serial::DeviceControlSignals signals; | 396 serial::DeviceControlSignals signals; |
376 if (!connection->GetControlSignals(&signals)) { | 397 if (!connection->GetControlSignals(&signals)) { |
377 error_ = kErrorGetControlSignalsFailed; | 398 error_ = kErrorGetControlSignalsFailed; |
378 return; | 399 return; |
379 } | 400 } |
380 | 401 |
381 results_ = serial::GetControlSignals::Results::Create(signals); | 402 results_ = serial::GetControlSignals::Results::Create(signals); |
382 } | 403 } |
383 | 404 |
384 SerialSetControlSignalsFunction::SerialSetControlSignalsFunction() {} | 405 SerialSetControlSignalsFunction::SerialSetControlSignalsFunction() { |
| 406 } |
385 | 407 |
386 SerialSetControlSignalsFunction::~SerialSetControlSignalsFunction() {} | 408 SerialSetControlSignalsFunction::~SerialSetControlSignalsFunction() { |
| 409 } |
387 | 410 |
388 bool SerialSetControlSignalsFunction::Prepare() { | 411 bool SerialSetControlSignalsFunction::Prepare() { |
389 params_ = serial::SetControlSignals::Params::Create(*args_); | 412 params_ = serial::SetControlSignals::Params::Create(*args_); |
390 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 413 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
391 | 414 |
392 return true; | 415 return true; |
393 } | 416 } |
394 | 417 |
395 void SerialSetControlSignalsFunction::Work() { | 418 void SerialSetControlSignalsFunction::Work() { |
396 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 419 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
397 if (!connection) { | 420 if (!connection) { |
398 error_ = kErrorSerialConnectionNotFound; | 421 error_ = kErrorSerialConnectionNotFound; |
399 return; | 422 return; |
400 } | 423 } |
401 | 424 |
402 bool success = connection->SetControlSignals(params_->signals); | 425 bool success = connection->SetControlSignals(params_->signals); |
403 results_ = serial::SetControlSignals::Results::Create(success); | 426 results_ = serial::SetControlSignals::Results::Create(success); |
404 } | 427 } |
405 | 428 |
406 } // namespace api | 429 } // namespace core_api |
407 | 430 |
408 } // namespace extensions | 431 } // namespace extensions |
409 | 432 |
410 namespace mojo { | 433 namespace mojo { |
411 | 434 |
412 // static | 435 // static |
413 linked_ptr<extensions::api::serial::DeviceInfo> | 436 linked_ptr<extensions::core_api::serial::DeviceInfo> |
414 TypeConverter<device::serial::DeviceInfoPtr, | 437 TypeConverter<device::serial::DeviceInfoPtr, |
415 linked_ptr<extensions::api::serial::DeviceInfo> >:: | 438 linked_ptr<extensions::core_api::serial::DeviceInfo> >:: |
416 ConvertTo(const device::serial::DeviceInfoPtr& device) { | 439 ConvertTo(const device::serial::DeviceInfoPtr& device) { |
417 linked_ptr<extensions::api::serial::DeviceInfo> info( | 440 linked_ptr<extensions::core_api::serial::DeviceInfo> info( |
418 new extensions::api::serial::DeviceInfo); | 441 new extensions::core_api::serial::DeviceInfo); |
419 info->path = device->path; | 442 info->path = device->path; |
420 if (device->has_vendor_id) | 443 if (device->has_vendor_id) |
421 info->vendor_id.reset(new int(static_cast<int>(device->vendor_id))); | 444 info->vendor_id.reset(new int(static_cast<int>(device->vendor_id))); |
422 if (device->has_product_id) | 445 if (device->has_product_id) |
423 info->product_id.reset(new int(static_cast<int>(device->product_id))); | 446 info->product_id.reset(new int(static_cast<int>(device->product_id))); |
424 if (device->display_name) | 447 if (device->display_name) |
425 info->display_name.reset(new std::string(device->display_name)); | 448 info->display_name.reset(new std::string(device->display_name)); |
426 return info; | 449 return info; |
427 } | 450 } |
428 | 451 |
429 } // namespace mojo | 452 } // namespace mojo |
OLD | NEW |