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_
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
{
21 class HostController
: public Thread
{
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
,
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
37 // Gets the current device allocated port. Must be called after Connect().
38 int device_port() const { return device_port_
; }
42 virtual void Run() OVERRIDE
;
45 void StartForwarder(scoped_ptr
<Socket
> host_server_data_socket_ptr
);
47 // Helper method that creates a socket and adds the appropriate event file
49 scoped_ptr
<Socket
> CreateSocket();
51 Socket adb_control_socket_
;
53 const std::string forward_to_host_
;
54 const int forward_to_host_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_
;
65 DISALLOW_COPY_AND_ASSIGN(HostController
);
68 } // namespace forwarder2
70 #endif // TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_