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

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

Issue 11360248: Use the new forwarder2's Daemon implementation in device_forwarder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address David's comments Created 8 years 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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 57 }
58 58
59 void DeviceController::Start() { 59 void DeviceController::Start() {
60 while (true) { 60 while (true) {
61 CleanUpDeadListeners(); 61 CleanUpDeadListeners();
62 scoped_ptr<Socket> socket(new Socket); 62 scoped_ptr<Socket> socket(new Socket);
63 if (!kickstart_adb_socket_.Accept(socket.get())) { 63 if (!kickstart_adb_socket_.Accept(socket.get())) {
64 if (!kickstart_adb_socket_.exited()) { 64 if (!kickstart_adb_socket_.exited()) {
65 LOG(ERROR) << "Could not Accept DeviceController socket: " 65 LOG(ERROR) << "Could not Accept DeviceController socket: "
66 << safe_strerror(errno); 66 << safe_strerror(errno);
67 } else {
68 LOG(INFO) << "Received exit notification";
67 } 69 }
68 break; 70 break;
69 } 71 }
70 // So that |socket| doesn't block on read if it has notifications. 72 // So that |socket| doesn't block on read if it has notifications.
71 socket->set_exit_notifier_fd(exit_notifier_fd_); 73 socket->set_exit_notifier_fd(exit_notifier_fd_);
72 int port; 74 int port;
73 command::Type command; 75 command::Type command;
74 if (!ReadCommand(socket.get(), &port, &command)) { 76 if (!ReadCommand(socket.get(), &port, &command)) {
75 LOG(ERROR) << "Invalid command received."; 77 LOG(ERROR) << "Invalid command received.";
76 socket->Close();
77 continue; 78 continue;
78 } 79 }
79 DeviceListener* listener = listeners_.Lookup(port); 80 DeviceListener* listener = listeners_.Lookup(port);
80 switch (command) { 81 switch (command) {
81 case command::LISTEN: { 82 case command::LISTEN: {
82 if (listener != NULL) { 83 if (listener != NULL) {
83 LOG(WARNING) << "Already forwarding port " << port 84 LOG(WARNING) << "Already forwarding port " << port
84 << ". Attempting to restart the listener.\n"; 85 << ". Attempting to restart the listener.\n";
85 listener->ForceExit(); 86 listener->ForceExit();
86 listener->Join(); 87 listener->Join();
(...skipping 16 matching lines...) Expand all
103 LOG(INFO) << "Forwarding device port " << listener_port << " to host."; 104 LOG(INFO) << "Forwarding device port " << listener_port << " to host.";
104 break; 105 break;
105 } 106 }
106 case command::DATA_CONNECTION: 107 case command::DATA_CONNECTION:
107 if (listener == NULL) { 108 if (listener == NULL) {
108 LOG(ERROR) << "Data Connection command received, but " 109 LOG(ERROR) << "Data Connection command received, but "
109 << "listener has not been set up yet for port " << port; 110 << "listener has not been set up yet for port " << port;
110 // After this point it is assumed that, once we close our Adb Data 111 // After this point it is assumed that, once we close our Adb Data
111 // socket, the Adb forwarder command will propagate the closing of 112 // socket, the Adb forwarder command will propagate the closing of
112 // sockets all the way to the host side. 113 // sockets all the way to the host side.
113 socket->Close();
114 continue; 114 continue;
115 } else if (!listener->SetAdbDataSocket(socket.Pass())) { 115 } else if (!listener->SetAdbDataSocket(socket.Pass())) {
116 LOG(ERROR) << "Could not set Adb Data Socket for port: " << port; 116 LOG(ERROR) << "Could not set Adb Data Socket for port: " << port;
117 // Same assumption as above, but in this case the socket is closed 117 // Same assumption as above, but in this case the socket is closed
118 // inside SetAdbDataSocket. 118 // inside SetAdbDataSocket.
119 continue; 119 continue;
120 } 120 }
121 break; 121 break;
122 default: 122 default:
123 // TODO(felipeg): add a KillAllListeners command. 123 // TODO(felipeg): add a KillAllListeners command.
124 LOG(ERROR) << "Invalid command received. Port: " << port 124 LOG(ERROR) << "Invalid command received. Port: " << port
125 << " Command: " << command; 125 << " Command: " << command;
126 socket->Close();
127 } 126 }
128 } 127 }
129 KillAllListeners(); 128 KillAllListeners();
130 CleanUpDeadListeners(); 129 CleanUpDeadListeners();
131 kickstart_adb_socket_.Close();
132 } 130 }
133 131
134 } // namespace forwarder 132 } // 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