OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
6 * @fileoverview A class for managing all enumerated gnubby devices. | 6 * @fileoverview A class for managing all enumerated gnubby devices. |
7 */ | 7 */ |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 * @private | 182 * @private |
183 */ | 183 */ |
184 Gnubbies.prototype.inactivityTimeout_ = function() { | 184 Gnubbies.prototype.inactivityTimeout_ = function() { |
185 this.inactivityTimer = undefined; | 185 this.inactivityTimer = undefined; |
186 for (var namespace in this.openDevs_) { | 186 for (var namespace in this.openDevs_) { |
187 for (var dev in this.openDevs_[namespace]) { | 187 for (var dev in this.openDevs_[namespace]) { |
188 var deviceId = Number(dev); | 188 var deviceId = Number(dev); |
189 console.warn(namespace + ' device ' + deviceId + | 189 console.warn(namespace + ' device ' + deviceId + |
190 ' still open after inactivity, closing'); | 190 ' still open after inactivity, closing'); |
191 this.openDevs_[namespace][deviceId].destroy(); | 191 this.openDevs_[namespace][deviceId].destroy(); |
192 this.removeOpenDevice({namespace: namespace, device: deviceId}); | |
193 } | 192 } |
194 } | 193 } |
195 }; | 194 }; |
196 | 195 |
197 /** | 196 /** |
198 * Opens and adds a new client of the specified device. | 197 * Opens and adds a new client of the specified device. |
199 * @param {llGnubbyDeviceId} which Which device to open. | 198 * @param {llGnubbyDeviceId} which Which device to open. |
200 * @param {*} who Client of the device. | 199 * @param {*} who Client of the device. |
201 * @param {function(number, llGnubby=)} cb Called back with the result of | 200 * @param {function(number, llGnubby=)} cb Called back with the result of |
202 * opening the device. | 201 * opening the device. |
203 */ | 202 */ |
204 Gnubbies.prototype.addClient = function(which, who, cb) { | 203 Gnubbies.prototype.addClient = function(which, who, cb) { |
205 this.resetInactivityTimer(); | 204 this.resetInactivityTimer(); |
206 | 205 |
207 var self = this; | 206 var self = this; |
208 | 207 |
209 function opened(gnubby, who, cb) { | 208 function opened(gnubby, who, cb) { |
210 if (gnubby.closing) { | 209 if (gnubby.closing) { |
211 // Device is closing or already closed. | 210 // Device is closing or already closed. |
212 self.removeClient(gnubby, who); | 211 self.removeClient(gnubby, who); |
213 if (cb) { cb(-llGnubby.GONE); } | 212 if (cb) { cb(-llGnubby.NODEVICE); } |
214 } else { | 213 } else { |
215 gnubby.registerClient(who); | 214 gnubby.registerClient(who); |
216 if (cb) { cb(-llGnubby.OK, gnubby); } | 215 if (cb) { cb(-llGnubby.OK, gnubby); } |
217 } | 216 } |
218 } | 217 } |
219 | 218 |
220 function notifyOpenResult(rc) { | 219 function notifyOpenResult(rc) { |
221 if (self.pendingOpens_[which.namespace]) { | 220 if (self.pendingOpens_[which.namespace]) { |
222 while (self.pendingOpens_[which.namespace][which.device].length != 0) { | 221 while (self.pendingOpens_[which.namespace][which.device].length != 0) { |
223 var client = self.pendingOpens_[which.namespace][which.device].shift(); | 222 var client = self.pendingOpens_[which.namespace][which.device].shift(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 267 |
269 if (this.openDevs_[which.namespace] && | 268 if (this.openDevs_[which.namespace] && |
270 this.openDevs_[which.namespace].hasOwnProperty(which.device)) { | 269 this.openDevs_[which.namespace].hasOwnProperty(which.device)) { |
271 var gnubby = this.openDevs_[which.namespace][which.device]; | 270 var gnubby = this.openDevs_[which.namespace][which.device]; |
272 opened(gnubby, who, cb); | 271 opened(gnubby, who, cb); |
273 } else { | 272 } else { |
274 var opener = {who: who, cb: cb}; | 273 var opener = {who: who, cb: cb}; |
275 if (!this.pendingOpens_.hasOwnProperty(which.namespace)) { | 274 if (!this.pendingOpens_.hasOwnProperty(which.namespace)) { |
276 this.pendingOpens_[which.namespace] = {}; | 275 this.pendingOpens_[which.namespace] = {}; |
277 } | 276 } |
278 if (this.pendingOpens_[which.namespace].hasOwnProperty(which)) { | 277 if (this.pendingOpens_[which.namespace].hasOwnProperty(which.device)) { |
279 this.pendingOpens_[which.namespace][which.device].push(opener); | 278 this.pendingOpens_[which.namespace][which.device].push(opener); |
280 } else { | 279 } else { |
281 this.pendingOpens_[which.namespace][which.device] = [opener]; | 280 this.pendingOpens_[which.namespace][which.device] = [opener]; |
282 var openImpl = this.impl_[which.namespace].open; | 281 var openImpl = this.impl_[which.namespace].open; |
283 openImpl(this, which.device, dev, openCb); | 282 openImpl(this, which.device, dev, openCb); |
284 } | 283 } |
285 } | 284 } |
286 }; | 285 }; |
287 | 286 |
288 /** | 287 /** |
(...skipping 15 matching lines...) Expand all Loading... |
304 if (whichDev && dev != whichDev) { | 303 if (whichDev && dev != whichDev) { |
305 console.warn('usbGnubby attached to more than one device!?'); | 304 console.warn('usbGnubby attached to more than one device!?'); |
306 } | 305 } |
307 if (!dev.deregisterClient(who)) { | 306 if (!dev.deregisterClient(who)) { |
308 dev.destroy(); | 307 dev.destroy(); |
309 } | 308 } |
310 } | 309 } |
311 } | 310 } |
312 } | 311 } |
313 }; | 312 }; |
OLD | NEW |