OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "tools/battor_agent/battor_agent.h" | 5 #include "tools/battor_agent/battor_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "device/serial/serial.mojom.h" | 9 #include "device/serial/serial.mojom.h" |
10 #include "device/serial/serial_io_handler.h" | |
11 | |
12 namespace { | |
13 | |
14 // Serial configuration parameters for the BattOr. | |
15 const uint32 kBattOrBitrate = 2000000; | |
16 const device::serial::DataBits kBattOrDataBits = | |
17 device::serial::DATA_BITS_EIGHT; | |
18 const device::serial::ParityBit kBattOrParityBit = | |
19 device::serial::PARITY_BIT_NONE; | |
20 const device::serial::StopBits kBattOrStopBit = device::serial::STOP_BITS_ONE; | |
21 const bool kBattOrCtsFlowControl = true; | |
22 const bool kBattOrHasCtsFlowControl = true; | |
23 | |
24 } // namespace | |
25 | 10 |
26 namespace battor { | 11 namespace battor { |
27 | 12 |
28 BattOrAgent::BattOrAgent( | 13 BattOrAgent::BattOrAgent( |
29 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 14 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
30 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner, | 15 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner, |
31 const std::string& path, | 16 const std::string& path, |
32 Listener* listener) | 17 Listener* listener) |
33 : file_thread_task_runner_(file_thread_task_runner), | 18 : file_thread_task_runner_(file_thread_task_runner), |
34 ui_thread_task_runner_(ui_thread_task_runner), | 19 ui_thread_task_runner_(ui_thread_task_runner), |
(...skipping 19 matching lines...) Expand all Loading... | |
54 DCHECK(thread_checker_.CalledOnValidThread()); | 39 DCHECK(thread_checker_.CalledOnValidThread()); |
55 | 40 |
56 // TODO(charliea): Tell the BattOr to start tracing. | 41 // TODO(charliea): Tell the BattOr to start tracing. |
57 listener_->OnStartTracingComplete(BATTOR_ERROR_NONE); | 42 listener_->OnStartTracingComplete(BATTOR_ERROR_NONE); |
58 } | 43 } |
59 | 44 |
60 void BattOrAgent::ConnectIfNeeded(const base::Closure& success_callback, | 45 void BattOrAgent::ConnectIfNeeded(const base::Closure& success_callback, |
61 const base::Closure& failure_callback) { | 46 const base::Closure& failure_callback) { |
62 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
63 | 48 |
64 if (io_handler_) { | 49 if (connection_) { |
65 success_callback.Run(); | 50 success_callback.Run(); |
66 return; | 51 return; |
67 } | 52 } |
68 | 53 |
69 io_handler_ = device::SerialIoHandler::Create(file_thread_task_runner_, | 54 connection_.reset( |
70 ui_thread_task_runner_); | 55 new BattOrConnection(file_thread_task_runner_, ui_thread_task_runner_)); |
71 | 56 connection_->Connect(path_, |
72 device::serial::ConnectionOptions options; | 57 base::Bind(&BattOrAgent::OnConnectComplete, AsWeakPtr(), |
73 options.bitrate = kBattOrBitrate; | 58 success_callback, failure_callback)); |
74 options.data_bits = kBattOrDataBits; | |
75 options.parity_bit = kBattOrParityBit; | |
76 options.stop_bits = kBattOrStopBit; | |
77 options.cts_flow_control = kBattOrCtsFlowControl; | |
78 options.has_cts_flow_control = kBattOrHasCtsFlowControl; | |
79 | |
80 io_handler_->Open(path_, options, | |
81 base::Bind(&BattOrAgent::OnConnectComplete, AsWeakPtr(), | |
82 success_callback, failure_callback)); | |
83 } | 59 } |
84 | 60 |
85 void BattOrAgent::OnConnectComplete(const base::Closure& success_callback, | 61 void BattOrAgent::OnConnectComplete(const base::Closure& success_callback, |
86 const base::Closure& failure_callback, | 62 const base::Closure& failure_callback, |
87 bool success) { | 63 bool success) { |
88 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
89 | 65 |
90 if (success) { | 66 if (success) { |
91 success_callback.Run(); | 67 success_callback.Run(); |
92 } else { | 68 } else { |
93 io_handler_ = nullptr; | 69 connection_ = nullptr; |
Primiano Tucci (use gerrit)
2015/12/15 11:07:19
typically I see this as connection_.reset() (doesn
charliea (OOO until 10-5)
2015/12/15 23:50:03
Done.
| |
94 failure_callback.Run(); | 70 failure_callback.Run(); |
95 } | 71 } |
96 } | 72 } |
97 | 73 |
98 } // namespace battor | 74 } // namespace battor |
OLD | NEW |