When Retrier succeeds, record errors it encountered.
[chromium-blink-merge.git] / tools / android / forwarder2 / host_controller.h
blobaa7c0e2237a0166bd0823123dc3ffb02d6fd2a17
1 // Copyright (c) 2012 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 TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_
6 #define TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "tools/android/forwarder2/pipe_notifier.h"
14 #include "tools/android/forwarder2/socket.h"
15 #include "tools/android/forwarder2/thread.h"
17 namespace forwarder2 {
19 class HostProxy;
21 class HostController : public Thread {
22 public:
23 // If |device_port| is zero, it dynamically allocates a port.
24 HostController(int device_port,
25 const std::string& forward_to_host,
26 int forward_to_host_port,
27 int adb_port,
28 int exit_notifier_fd);
29 virtual ~HostController();
31 // Connects to the device forwarder app and sets the |device_port_| to the
32 // dynamically allocated port (when the provided |device_port| is zero).
33 // Returns true on success. Clients must call Connect() before calling
34 // Start().
35 bool Connect();
37 // Gets the current device allocated port. Must be called after Connect().
38 int device_port() const { return device_port_; }
40 protected:
41 // Thread:
42 virtual void Run() OVERRIDE;
44 private:
45 void StartForwarder(scoped_ptr<Socket> host_server_data_socket_ptr);
47 // Helper method that creates a socket and adds the appropriate event file
48 // descriptors.
49 scoped_ptr<Socket> CreateSocket();
51 Socket adb_control_socket_;
52 int device_port_;
53 const std::string forward_to_host_;
54 const int forward_to_host_port_;
55 const int adb_port_;
57 // Used to notify the controller when the process is killed.
58 const int global_exit_notifier_fd_;
59 // Used to cancel the pending blocking IO operations when the host controller
60 // instance is deleted.
61 PipeNotifier delete_controller_notifier_;
63 bool ready_;
65 DISALLOW_COPY_AND_ASSIGN(HostController);
68 } // namespace forwarder2
70 #endif // TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_