Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: tools/android/forwarder2/device_controller.cc

Issue 15008004: Add device port unmapping support to forwarder2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address David's comments Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/android/forwarder2/daemon.cc ('k') | tools/android/forwarder2/device_forwarder_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/android/forwarder2/device_controller.h" 5 #include "tools/android/forwarder2/device_controller.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/safe_strerror_posix.h" 12 #include "base/safe_strerror_posix.h"
13 #include "tools/android/forwarder2/command.h" 13 #include "tools/android/forwarder2/command.h"
14 #include "tools/android/forwarder2/device_listener.h" 14 #include "tools/android/forwarder2/device_listener.h"
15 #include "tools/android/forwarder2/socket.h" 15 #include "tools/android/forwarder2/socket.h"
16 16
17 namespace forwarder2 { 17 namespace forwarder2 {
18 18
19 DeviceController::DeviceController(int exit_notifier_fd) 19 DeviceController::DeviceController(int exit_notifier_fd)
20 : exit_notifier_fd_(exit_notifier_fd) { 20 : exit_notifier_fd_(exit_notifier_fd) {
21 kickstart_adb_socket_.set_exit_notifier_fd(exit_notifier_fd); 21 kickstart_adb_socket_.AddEventFd(exit_notifier_fd);
22 } 22 }
23 23
24 DeviceController::~DeviceController() { 24 DeviceController::~DeviceController() {
25 KillAllListeners(); 25 KillAllListeners();
26 CleanUpDeadListeners(); 26 CleanUpDeadListeners();
27 CHECK_EQ(0, listeners_.size()); 27 CHECK_EQ(0, listeners_.size());
28 } 28 }
29 29
30 void DeviceController::CleanUpDeadListeners() { 30 void DeviceController::CleanUpDeadListeners() {
31 // Clean up dead listeners. 31 // Clean up dead listeners.
(...skipping 21 matching lines...) Expand all
53 } 53 }
54 LOG(INFO) << "Listening on Unix Domain Socket " << adb_unix_socket; 54 LOG(INFO) << "Listening on Unix Domain Socket " << adb_unix_socket;
55 return true; 55 return true;
56 } 56 }
57 57
58 void DeviceController::Start() { 58 void DeviceController::Start() {
59 while (true) { 59 while (true) {
60 CleanUpDeadListeners(); 60 CleanUpDeadListeners();
61 scoped_ptr<Socket> socket(new Socket); 61 scoped_ptr<Socket> socket(new Socket);
62 if (!kickstart_adb_socket_.Accept(socket.get())) { 62 if (!kickstart_adb_socket_.Accept(socket.get())) {
63 if (!kickstart_adb_socket_.exited()) { 63 if (!kickstart_adb_socket_.DidReceiveEvent()) {
64 LOG(ERROR) << "Could not Accept DeviceController socket: " 64 LOG(ERROR) << "Could not Accept DeviceController socket: "
65 << safe_strerror(errno); 65 << safe_strerror(errno);
66 } else { 66 } else {
67 LOG(INFO) << "Received exit notification"; 67 LOG(INFO) << "Received exit notification";
68 } 68 }
69 break; 69 break;
70 } 70 }
71 // So that |socket| doesn't block on read if it has notifications. 71 // So that |socket| doesn't block on read if it has notifications.
72 socket->set_exit_notifier_fd(exit_notifier_fd_); 72 socket->AddEventFd(exit_notifier_fd_);
73 int port; 73 int port;
74 command::Type command; 74 command::Type command;
75 if (!ReadCommand(socket.get(), &port, &command)) { 75 if (!ReadCommand(socket.get(), &port, &command)) {
76 LOG(ERROR) << "Invalid command received."; 76 LOG(ERROR) << "Invalid command received.";
77 continue; 77 continue;
78 } 78 }
79 DeviceListener* listener = listeners_.Lookup(port); 79 DeviceListener* listener = listeners_.Lookup(port);
80 switch (command) { 80 switch (command) {
81 case command::LISTEN: { 81 case command::LISTEN: {
82 if (listener != NULL) { 82 if (listener != NULL) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // TODO(felipeg): add a KillAllListeners command. 122 // TODO(felipeg): add a KillAllListeners command.
123 LOG(ERROR) << "Invalid command received. Port: " << port 123 LOG(ERROR) << "Invalid command received. Port: " << port
124 << " Command: " << command; 124 << " Command: " << command;
125 } 125 }
126 } 126 }
127 KillAllListeners(); 127 KillAllListeners();
128 CleanUpDeadListeners(); 128 CleanUpDeadListeners();
129 } 129 }
130 130
131 } // namespace forwarder 131 } // namespace forwarder
OLDNEW
« no previous file with comments | « tools/android/forwarder2/daemon.cc ('k') | tools/android/forwarder2/device_forwarder_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698