Chromium Code Reviews| Index: tools/battor_agent/battor_agent.h |
| diff --git a/tools/battor_agent/battor_agent.h b/tools/battor_agent/battor_agent.h |
| index 413890e4ec2294e531167d79c086b00a65c87f6b..0ff6ec599446b1f4a1064b4649d4d9fa5ecb92c5 100644 |
| --- a/tools/battor_agent/battor_agent.h |
| +++ b/tools/battor_agent/battor_agent.h |
| @@ -5,17 +5,13 @@ |
| #ifndef TOOLS_BATTOR_AGENT_BATTOR_AGENT_H_ |
| #define TOOLS_BATTOR_AGENT_BATTOR_AGENT_H_ |
| -#include "base/callback_forward.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/threading/thread_checker.h" |
| +#include "tools/battor_agent/battor_connection.h" |
| #include "tools/battor_agent/battor_error.h" |
| -namespace device { |
| -class SerialIoHandler; |
| -} |
| - |
| namespace battor { |
| // A BattOrAgent is a class used to asynchronously communicate with a BattOr for |
| @@ -32,7 +28,8 @@ namespace battor { |
| // |
| // This class is NOT thread safe, and must be interacted with only from the IO |
| // thread. The IO thread must also have a running MessageLoop. |
| -class BattOrAgent : public base::SupportsWeakPtr<BattOrAgent> { |
| +class BattOrAgent : public BattOrConnection::Listener, |
| + public base::SupportsWeakPtr<BattOrAgent> { |
| public: |
| // The listener interface that must be implemented in order to interact with |
| // the BattOrAgent. |
| @@ -43,7 +40,7 @@ class BattOrAgent : public base::SupportsWeakPtr<BattOrAgent> { |
| BattOrAgent( |
| scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| - scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_rnuner, |
| + scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner, |
| const std::string& path, |
| Listener* listener); |
| virtual ~BattOrAgent(); |
| @@ -55,34 +52,30 @@ class BattOrAgent : public base::SupportsWeakPtr<BattOrAgent> { |
| // trace log. |
| static bool SupportsExplicitClockSync() { return true; } |
| - private: |
| - // Initializes the serial connection (if not done already) and calls one of |
| - // the two callbacks depending its success. The callback will be invoked on |
| - // the same thread that this method is called on. |
| - void ConnectIfNeeded(const base::Closure& success_callback, |
| - const base::Closure& failure_callback); |
| - void OnConnectComplete(const base::Closure& success_callback, |
| - const base::Closure& failure_callback, |
| - bool success); |
| + // Callback for when the connection is opened. |
|
Primiano Tucci (use gerrit)
2015/12/16 16:47:43
I'd probably just say
// BattOrConnection::Listen
charliea (OOO until 10-5)
2015/12/16 18:27:55
Hah, true :) Changed.
|
| + void OnConnectionOpened(bool success) override; |
| - // StartTracing continuation called once the connection is initialized. |
| - void DoStartTracing(); |
| + // Callback for when bytes are sent over the connection. |
| + void OnBytesSent(bool success) override; |
| - // Resets the connection to its unopened state. |
| - void ResetConnection(); |
| + // Callback for when bytes are read from the connection. |
| + void OnBytesRead(bool success, |
| + BattOrMessageType type, |
| + scoped_ptr<std::vector<char>> bytes) override; |
| - // Threads needed for serial communication. |
| - scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; |
| - scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; |
| + private: |
| + // Initializes the serial connection (if not done already). |
| + // OnConnectionOpened() will be called once the connection is made. |
| + void ConnectIfNeeded(); |
| - // The path of the BattOr (e.g. "/dev/tty.battor_serial"). |
| - std::string path_; |
| + // StartTracing continuation called once the connection is initialized. |
| + void DoStartTracing(); |
| // The listener that handles the commands' results. It must outlive the agent. |
| Listener* listener_; |
| - // IO handler capable of reading and writing from the serial connection. |
| - scoped_refptr<device::SerialIoHandler> io_handler_; |
| + // The serial connection to the BattOr. |
| + scoped_ptr<BattOrConnection> connection_; |
| // Checker to make sure that this is only ever called on the IO thread. |
| base::ThreadChecker thread_checker_; |