OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 define("device/devices_app/usb/public/interfaces/device_manager.mojom", [ |
| 6 "mojo/public/js/bindings", |
| 7 "mojo/public/js/codec", |
| 8 "mojo/public/js/connection", |
| 9 "mojo/public/js/core", |
| 10 "mojo/public/js/validator", |
| 11 "device/devices_app/usb/public/interfaces/device.mojom", |
| 12 ], function(bindings, codec, connection, core, validator, device$) { |
| 13 |
| 14 function DeviceFilter(values) { |
| 15 this.initDefaults_(); |
| 16 this.initFields_(values); |
| 17 } |
| 18 |
| 19 |
| 20 DeviceFilter.prototype.initDefaults_ = function() { |
| 21 this.has_vendor_id = false; |
| 22 this.has_product_id = false; |
| 23 this.has_class_code = false; |
| 24 this.has_subclass_code = false; |
| 25 this.has_protocol_code = false; |
| 26 this.class_code = 0; |
| 27 this.vendor_id = 0; |
| 28 this.product_id = 0; |
| 29 this.subclass_code = 0; |
| 30 this.protocol_code = 0; |
| 31 }; |
| 32 DeviceFilter.prototype.initFields_ = function(fields) { |
| 33 for(var field in fields) { |
| 34 if (this.hasOwnProperty(field)) |
| 35 this[field] = fields[field]; |
| 36 } |
| 37 }; |
| 38 |
| 39 DeviceFilter.validate = function(messageValidator, offset) { |
| 40 var err; |
| 41 err = messageValidator.validateStructHeader(offset, DeviceFilter.encodedSize
, 0); |
| 42 if (err !== validator.validationError.NONE) |
| 43 return err; |
| 44 |
| 45 |
| 46 |
| 47 |
| 48 |
| 49 |
| 50 |
| 51 |
| 52 |
| 53 |
| 54 |
| 55 return validator.validationError.NONE; |
| 56 }; |
| 57 |
| 58 DeviceFilter.encodedSize = codec.kStructHeaderSize + 8; |
| 59 |
| 60 DeviceFilter.decode = function(decoder) { |
| 61 var packed; |
| 62 var val = new DeviceFilter(); |
| 63 var numberOfBytes = decoder.readUint32(); |
| 64 var version = decoder.readUint32(); |
| 65 packed = decoder.readUint8(); |
| 66 val.has_vendor_id = (packed >> 0) & 1 ? true : false; |
| 67 val.has_product_id = (packed >> 1) & 1 ? true : false; |
| 68 val.has_class_code = (packed >> 2) & 1 ? true : false; |
| 69 val.has_subclass_code = (packed >> 3) & 1 ? true : false; |
| 70 val.has_protocol_code = (packed >> 4) & 1 ? true : false; |
| 71 val.class_code = decoder.decodeStruct(codec.Uint8); |
| 72 val.vendor_id = decoder.decodeStruct(codec.Uint16); |
| 73 val.product_id = decoder.decodeStruct(codec.Uint16); |
| 74 val.subclass_code = decoder.decodeStruct(codec.Uint8); |
| 75 val.protocol_code = decoder.decodeStruct(codec.Uint8); |
| 76 return val; |
| 77 }; |
| 78 |
| 79 DeviceFilter.encode = function(encoder, val) { |
| 80 var packed; |
| 81 encoder.writeUint32(DeviceFilter.encodedSize); |
| 82 encoder.writeUint32(0); |
| 83 packed = 0; |
| 84 packed |= (val.has_vendor_id & 1) << 0 |
| 85 packed |= (val.has_product_id & 1) << 1 |
| 86 packed |= (val.has_class_code & 1) << 2 |
| 87 packed |= (val.has_subclass_code & 1) << 3 |
| 88 packed |= (val.has_protocol_code & 1) << 4 |
| 89 encoder.writeUint8(packed); |
| 90 encoder.encodeStruct(codec.Uint8, val.class_code); |
| 91 encoder.encodeStruct(codec.Uint16, val.vendor_id); |
| 92 encoder.encodeStruct(codec.Uint16, val.product_id); |
| 93 encoder.encodeStruct(codec.Uint8, val.subclass_code); |
| 94 encoder.encodeStruct(codec.Uint8, val.protocol_code); |
| 95 }; |
| 96 |
| 97 function EnumerationOptions(values) { |
| 98 this.initDefaults_(); |
| 99 this.initFields_(values); |
| 100 } |
| 101 |
| 102 |
| 103 EnumerationOptions.prototype.initDefaults_ = function() { |
| 104 this.filters = null; |
| 105 }; |
| 106 EnumerationOptions.prototype.initFields_ = function(fields) { |
| 107 for(var field in fields) { |
| 108 if (this.hasOwnProperty(field)) |
| 109 this[field] = fields[field]; |
| 110 } |
| 111 }; |
| 112 |
| 113 EnumerationOptions.validate = function(messageValidator, offset) { |
| 114 var err; |
| 115 err = messageValidator.validateStructHeader(offset, EnumerationOptions.encod
edSize, 0); |
| 116 if (err !== validator.validationError.NONE) |
| 117 return err; |
| 118 |
| 119 |
| 120 // validate EnumerationOptions.filters |
| 121 err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize
+ 0, 8, new codec.PointerTo(DeviceFilter), true, [0], 0); |
| 122 if (err !== validator.validationError.NONE) |
| 123 return err; |
| 124 |
| 125 return validator.validationError.NONE; |
| 126 }; |
| 127 |
| 128 EnumerationOptions.encodedSize = codec.kStructHeaderSize + 8; |
| 129 |
| 130 EnumerationOptions.decode = function(decoder) { |
| 131 var packed; |
| 132 var val = new EnumerationOptions(); |
| 133 var numberOfBytes = decoder.readUint32(); |
| 134 var version = decoder.readUint32(); |
| 135 val.filters = decoder.decodeArrayPointer(new codec.PointerTo(DeviceFilter)); |
| 136 return val; |
| 137 }; |
| 138 |
| 139 EnumerationOptions.encode = function(encoder, val) { |
| 140 var packed; |
| 141 encoder.writeUint32(EnumerationOptions.encodedSize); |
| 142 encoder.writeUint32(0); |
| 143 encoder.encodeArrayPointer(new codec.PointerTo(DeviceFilter), val.filters); |
| 144 }; |
| 145 |
| 146 function DeviceChangeNotification(values) { |
| 147 this.initDefaults_(); |
| 148 this.initFields_(values); |
| 149 } |
| 150 |
| 151 |
| 152 DeviceChangeNotification.prototype.initDefaults_ = function() { |
| 153 this.devices_added = null; |
| 154 this.devices_removed = null; |
| 155 }; |
| 156 DeviceChangeNotification.prototype.initFields_ = function(fields) { |
| 157 for(var field in fields) { |
| 158 if (this.hasOwnProperty(field)) |
| 159 this[field] = fields[field]; |
| 160 } |
| 161 }; |
| 162 |
| 163 DeviceChangeNotification.validate = function(messageValidator, offset) { |
| 164 var err; |
| 165 err = messageValidator.validateStructHeader(offset, DeviceChangeNotification
.encodedSize, 0); |
| 166 if (err !== validator.validationError.NONE) |
| 167 return err; |
| 168 |
| 169 |
| 170 // validate DeviceChangeNotification.devices_added |
| 171 err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize
+ 0, 8, new codec.PointerTo(device$.DeviceInfo), false, [0], 0); |
| 172 if (err !== validator.validationError.NONE) |
| 173 return err; |
| 174 |
| 175 |
| 176 // validate DeviceChangeNotification.devices_removed |
| 177 err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize
+ 8, 8, new codec.PointerTo(device$.DeviceInfo), false, [0], 0); |
| 178 if (err !== validator.validationError.NONE) |
| 179 return err; |
| 180 |
| 181 return validator.validationError.NONE; |
| 182 }; |
| 183 |
| 184 DeviceChangeNotification.encodedSize = codec.kStructHeaderSize + 16; |
| 185 |
| 186 DeviceChangeNotification.decode = function(decoder) { |
| 187 var packed; |
| 188 var val = new DeviceChangeNotification(); |
| 189 var numberOfBytes = decoder.readUint32(); |
| 190 var version = decoder.readUint32(); |
| 191 val.devices_added = decoder.decodeArrayPointer(new codec.PointerTo(device$.D
eviceInfo)); |
| 192 val.devices_removed = decoder.decodeArrayPointer(new codec.PointerTo(device$
.DeviceInfo)); |
| 193 return val; |
| 194 }; |
| 195 |
| 196 DeviceChangeNotification.encode = function(encoder, val) { |
| 197 var packed; |
| 198 encoder.writeUint32(DeviceChangeNotification.encodedSize); |
| 199 encoder.writeUint32(0); |
| 200 encoder.encodeArrayPointer(new codec.PointerTo(device$.DeviceInfo), val.devi
ces_added); |
| 201 encoder.encodeArrayPointer(new codec.PointerTo(device$.DeviceInfo), val.devi
ces_removed); |
| 202 }; |
| 203 |
| 204 function DeviceManager_GetDevices_Params(values) { |
| 205 this.initDefaults_(); |
| 206 this.initFields_(values); |
| 207 } |
| 208 |
| 209 |
| 210 DeviceManager_GetDevices_Params.prototype.initDefaults_ = function() { |
| 211 this.options = null; |
| 212 }; |
| 213 DeviceManager_GetDevices_Params.prototype.initFields_ = function(fields) { |
| 214 for(var field in fields) { |
| 215 if (this.hasOwnProperty(field)) |
| 216 this[field] = fields[field]; |
| 217 } |
| 218 }; |
| 219 |
| 220 DeviceManager_GetDevices_Params.validate = function(messageValidator, offset)
{ |
| 221 var err; |
| 222 err = messageValidator.validateStructHeader(offset, DeviceManager_GetDevices
_Params.encodedSize, 0); |
| 223 if (err !== validator.validationError.NONE) |
| 224 return err; |
| 225 |
| 226 |
| 227 // validate DeviceManager_GetDevices_Params.options |
| 228 err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSiz
e + 0, EnumerationOptions, true); |
| 229 if (err !== validator.validationError.NONE) |
| 230 return err; |
| 231 |
| 232 return validator.validationError.NONE; |
| 233 }; |
| 234 |
| 235 DeviceManager_GetDevices_Params.encodedSize = codec.kStructHeaderSize + 8; |
| 236 |
| 237 DeviceManager_GetDevices_Params.decode = function(decoder) { |
| 238 var packed; |
| 239 var val = new DeviceManager_GetDevices_Params(); |
| 240 var numberOfBytes = decoder.readUint32(); |
| 241 var version = decoder.readUint32(); |
| 242 val.options = decoder.decodeStructPointer(EnumerationOptions); |
| 243 return val; |
| 244 }; |
| 245 |
| 246 DeviceManager_GetDevices_Params.encode = function(encoder, val) { |
| 247 var packed; |
| 248 encoder.writeUint32(DeviceManager_GetDevices_Params.encodedSize); |
| 249 encoder.writeUint32(0); |
| 250 encoder.encodeStructPointer(EnumerationOptions, val.options); |
| 251 }; |
| 252 |
| 253 function DeviceManager_GetDevices_ResponseParams(values) { |
| 254 this.initDefaults_(); |
| 255 this.initFields_(values); |
| 256 } |
| 257 |
| 258 |
| 259 DeviceManager_GetDevices_ResponseParams.prototype.initDefaults_ = function() { |
| 260 this.results = null; |
| 261 }; |
| 262 DeviceManager_GetDevices_ResponseParams.prototype.initFields_ = function(field
s) { |
| 263 for(var field in fields) { |
| 264 if (this.hasOwnProperty(field)) |
| 265 this[field] = fields[field]; |
| 266 } |
| 267 }; |
| 268 |
| 269 DeviceManager_GetDevices_ResponseParams.validate = function(messageValidator,
offset) { |
| 270 var err; |
| 271 err = messageValidator.validateStructHeader(offset, DeviceManager_GetDevices
_ResponseParams.encodedSize, 0); |
| 272 if (err !== validator.validationError.NONE) |
| 273 return err; |
| 274 |
| 275 |
| 276 // validate DeviceManager_GetDevices_ResponseParams.results |
| 277 err = messageValidator.validateArrayPointer(offset + codec.kStructHeaderSize
+ 0, 8, new codec.PointerTo(device$.DeviceInfo), false, [0], 0); |
| 278 if (err !== validator.validationError.NONE) |
| 279 return err; |
| 280 |
| 281 return validator.validationError.NONE; |
| 282 }; |
| 283 |
| 284 DeviceManager_GetDevices_ResponseParams.encodedSize = codec.kStructHeaderSize
+ 8; |
| 285 |
| 286 DeviceManager_GetDevices_ResponseParams.decode = function(decoder) { |
| 287 var packed; |
| 288 var val = new DeviceManager_GetDevices_ResponseParams(); |
| 289 var numberOfBytes = decoder.readUint32(); |
| 290 var version = decoder.readUint32(); |
| 291 val.results = decoder.decodeArrayPointer(new codec.PointerTo(device$.DeviceI
nfo)); |
| 292 return val; |
| 293 }; |
| 294 |
| 295 DeviceManager_GetDevices_ResponseParams.encode = function(encoder, val) { |
| 296 var packed; |
| 297 encoder.writeUint32(DeviceManager_GetDevices_ResponseParams.encodedSize); |
| 298 encoder.writeUint32(0); |
| 299 encoder.encodeArrayPointer(new codec.PointerTo(device$.DeviceInfo), val.resu
lts); |
| 300 }; |
| 301 |
| 302 function DeviceManager_GetDeviceChanges_Params(values) { |
| 303 this.initDefaults_(); |
| 304 this.initFields_(values); |
| 305 } |
| 306 |
| 307 |
| 308 DeviceManager_GetDeviceChanges_Params.prototype.initDefaults_ = function() { |
| 309 }; |
| 310 DeviceManager_GetDeviceChanges_Params.prototype.initFields_ = function(fields)
{ |
| 311 for(var field in fields) { |
| 312 if (this.hasOwnProperty(field)) |
| 313 this[field] = fields[field]; |
| 314 } |
| 315 }; |
| 316 |
| 317 DeviceManager_GetDeviceChanges_Params.validate = function(messageValidator, of
fset) { |
| 318 var err; |
| 319 err = messageValidator.validateStructHeader(offset, DeviceManager_GetDeviceC
hanges_Params.encodedSize, 0); |
| 320 if (err !== validator.validationError.NONE) |
| 321 return err; |
| 322 |
| 323 return validator.validationError.NONE; |
| 324 }; |
| 325 |
| 326 DeviceManager_GetDeviceChanges_Params.encodedSize = codec.kStructHeaderSize +
0; |
| 327 |
| 328 DeviceManager_GetDeviceChanges_Params.decode = function(decoder) { |
| 329 var packed; |
| 330 var val = new DeviceManager_GetDeviceChanges_Params(); |
| 331 var numberOfBytes = decoder.readUint32(); |
| 332 var version = decoder.readUint32(); |
| 333 return val; |
| 334 }; |
| 335 |
| 336 DeviceManager_GetDeviceChanges_Params.encode = function(encoder, val) { |
| 337 var packed; |
| 338 encoder.writeUint32(DeviceManager_GetDeviceChanges_Params.encodedSize); |
| 339 encoder.writeUint32(0); |
| 340 }; |
| 341 |
| 342 function DeviceManager_GetDeviceChanges_ResponseParams(values) { |
| 343 this.initDefaults_(); |
| 344 this.initFields_(values); |
| 345 } |
| 346 |
| 347 |
| 348 DeviceManager_GetDeviceChanges_ResponseParams.prototype.initDefaults_ = functi
on() { |
| 349 this.changes = null; |
| 350 }; |
| 351 DeviceManager_GetDeviceChanges_ResponseParams.prototype.initFields_ = function
(fields) { |
| 352 for(var field in fields) { |
| 353 if (this.hasOwnProperty(field)) |
| 354 this[field] = fields[field]; |
| 355 } |
| 356 }; |
| 357 |
| 358 DeviceManager_GetDeviceChanges_ResponseParams.validate = function(messageValid
ator, offset) { |
| 359 var err; |
| 360 err = messageValidator.validateStructHeader(offset, DeviceManager_GetDeviceC
hanges_ResponseParams.encodedSize, 0); |
| 361 if (err !== validator.validationError.NONE) |
| 362 return err; |
| 363 |
| 364 |
| 365 // validate DeviceManager_GetDeviceChanges_ResponseParams.changes |
| 366 err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSiz
e + 0, DeviceChangeNotification, false); |
| 367 if (err !== validator.validationError.NONE) |
| 368 return err; |
| 369 |
| 370 return validator.validationError.NONE; |
| 371 }; |
| 372 |
| 373 DeviceManager_GetDeviceChanges_ResponseParams.encodedSize = codec.kStructHeade
rSize + 8; |
| 374 |
| 375 DeviceManager_GetDeviceChanges_ResponseParams.decode = function(decoder) { |
| 376 var packed; |
| 377 var val = new DeviceManager_GetDeviceChanges_ResponseParams(); |
| 378 var numberOfBytes = decoder.readUint32(); |
| 379 var version = decoder.readUint32(); |
| 380 val.changes = decoder.decodeStructPointer(DeviceChangeNotification); |
| 381 return val; |
| 382 }; |
| 383 |
| 384 DeviceManager_GetDeviceChanges_ResponseParams.encode = function(encoder, val)
{ |
| 385 var packed; |
| 386 encoder.writeUint32(DeviceManager_GetDeviceChanges_ResponseParams.encodedSiz
e); |
| 387 encoder.writeUint32(0); |
| 388 encoder.encodeStructPointer(DeviceChangeNotification, val.changes); |
| 389 }; |
| 390 |
| 391 function DeviceManager_GetDevice_Params(values) { |
| 392 this.initDefaults_(); |
| 393 this.initFields_(values); |
| 394 } |
| 395 |
| 396 |
| 397 DeviceManager_GetDevice_Params.prototype.initDefaults_ = function() { |
| 398 this.guid = null; |
| 399 this.device_request = null; |
| 400 }; |
| 401 DeviceManager_GetDevice_Params.prototype.initFields_ = function(fields) { |
| 402 for(var field in fields) { |
| 403 if (this.hasOwnProperty(field)) |
| 404 this[field] = fields[field]; |
| 405 } |
| 406 }; |
| 407 |
| 408 DeviceManager_GetDevice_Params.validate = function(messageValidator, offset) { |
| 409 var err; |
| 410 err = messageValidator.validateStructHeader(offset, DeviceManager_GetDevice_
Params.encodedSize, 0); |
| 411 if (err !== validator.validationError.NONE) |
| 412 return err; |
| 413 |
| 414 |
| 415 // validate DeviceManager_GetDevice_Params.guid |
| 416 err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSiz
e + 0, false) |
| 417 if (err !== validator.validationError.NONE) |
| 418 return err; |
| 419 |
| 420 |
| 421 // validate DeviceManager_GetDevice_Params.device_request |
| 422 err = messageValidator.validateHandle(offset + codec.kStructHeaderSize + 8,
false) |
| 423 if (err !== validator.validationError.NONE) |
| 424 return err; |
| 425 |
| 426 return validator.validationError.NONE; |
| 427 }; |
| 428 |
| 429 DeviceManager_GetDevice_Params.encodedSize = codec.kStructHeaderSize + 16; |
| 430 |
| 431 DeviceManager_GetDevice_Params.decode = function(decoder) { |
| 432 var packed; |
| 433 var val = new DeviceManager_GetDevice_Params(); |
| 434 var numberOfBytes = decoder.readUint32(); |
| 435 var version = decoder.readUint32(); |
| 436 val.guid = decoder.decodeStruct(codec.String); |
| 437 val.device_request = decoder.decodeStruct(codec.Handle); |
| 438 decoder.skip(1); |
| 439 decoder.skip(1); |
| 440 decoder.skip(1); |
| 441 decoder.skip(1); |
| 442 return val; |
| 443 }; |
| 444 |
| 445 DeviceManager_GetDevice_Params.encode = function(encoder, val) { |
| 446 var packed; |
| 447 encoder.writeUint32(DeviceManager_GetDevice_Params.encodedSize); |
| 448 encoder.writeUint32(0); |
| 449 encoder.encodeStruct(codec.String, val.guid); |
| 450 encoder.encodeStruct(codec.Handle, val.device_request); |
| 451 encoder.skip(1); |
| 452 encoder.skip(1); |
| 453 encoder.skip(1); |
| 454 encoder.skip(1); |
| 455 }; |
| 456 |
| 457 var kDeviceManager_GetDevices_Name = 0; |
| 458 var kDeviceManager_GetDeviceChanges_Name = 1; |
| 459 var kDeviceManager_GetDevice_Name = 2; |
| 460 |
| 461 function DeviceManagerProxy(receiver) { |
| 462 bindings.ProxyBase.call(this, receiver); |
| 463 } |
| 464 DeviceManagerProxy.prototype = Object.create(bindings.ProxyBase.prototype); |
| 465 DeviceManagerProxy.prototype.getDevices = function(options) { |
| 466 var params = new DeviceManager_GetDevices_Params(); |
| 467 params.options = options; |
| 468 return new Promise(function(resolve, reject) { |
| 469 var builder = new codec.MessageWithRequestIDBuilder( |
| 470 kDeviceManager_GetDevices_Name, |
| 471 codec.align(DeviceManager_GetDevices_Params.encodedSize), |
| 472 codec.kMessageExpectsResponse, 0); |
| 473 builder.encodeStruct(DeviceManager_GetDevices_Params, params); |
| 474 var message = builder.finish(); |
| 475 this.receiver_.acceptAndExpectResponse(message).then(function(message) { |
| 476 var reader = new codec.MessageReader(message); |
| 477 var responseParams = |
| 478 reader.decodeStruct(DeviceManager_GetDevices_ResponseParams); |
| 479 resolve(responseParams); |
| 480 }).catch(function(result) { |
| 481 reject(Error("Connection error: " + result)); |
| 482 }); |
| 483 }.bind(this)); |
| 484 }; |
| 485 DeviceManagerProxy.prototype.getDeviceChanges = function() { |
| 486 var params = new DeviceManager_GetDeviceChanges_Params(); |
| 487 return new Promise(function(resolve, reject) { |
| 488 var builder = new codec.MessageWithRequestIDBuilder( |
| 489 kDeviceManager_GetDeviceChanges_Name, |
| 490 codec.align(DeviceManager_GetDeviceChanges_Params.encodedSize), |
| 491 codec.kMessageExpectsResponse, 0); |
| 492 builder.encodeStruct(DeviceManager_GetDeviceChanges_Params, params); |
| 493 var message = builder.finish(); |
| 494 this.receiver_.acceptAndExpectResponse(message).then(function(message) { |
| 495 var reader = new codec.MessageReader(message); |
| 496 var responseParams = |
| 497 reader.decodeStruct(DeviceManager_GetDeviceChanges_ResponseParams); |
| 498 resolve(responseParams); |
| 499 }).catch(function(result) { |
| 500 reject(Error("Connection error: " + result)); |
| 501 }); |
| 502 }.bind(this)); |
| 503 }; |
| 504 DeviceManagerProxy.prototype.getDevice = function(guid, device_request) { |
| 505 var params = new DeviceManager_GetDevice_Params(); |
| 506 params.guid = guid; |
| 507 params.device_request = core.isHandle(device_request) ? device_request : con
nection.bindProxy(device_request, device$.Device); |
| 508 var builder = new codec.MessageBuilder( |
| 509 kDeviceManager_GetDevice_Name, |
| 510 codec.align(DeviceManager_GetDevice_Params.encodedSize)); |
| 511 builder.encodeStruct(DeviceManager_GetDevice_Params, params); |
| 512 var message = builder.finish(); |
| 513 this.receiver_.accept(message); |
| 514 }; |
| 515 |
| 516 function DeviceManagerStub(delegate) { |
| 517 bindings.StubBase.call(this, delegate); |
| 518 } |
| 519 DeviceManagerStub.prototype = Object.create(bindings.StubBase.prototype); |
| 520 DeviceManagerStub.prototype.getDevices = function(options) { |
| 521 return bindings.StubBindings(this).delegate && bindings.StubBindings(this).d
elegate.getDevices && bindings.StubBindings(this).delegate.getDevices(options); |
| 522 } |
| 523 DeviceManagerStub.prototype.getDeviceChanges = function() { |
| 524 return bindings.StubBindings(this).delegate && bindings.StubBindings(this).d
elegate.getDeviceChanges && bindings.StubBindings(this).delegate.getDeviceChange
s(); |
| 525 } |
| 526 DeviceManagerStub.prototype.getDevice = function(guid, device_request) { |
| 527 return bindings.StubBindings(this).delegate && bindings.StubBindings(this).d
elegate.getDevice && bindings.StubBindings(this).delegate.getDevice(guid, connec
tion.bindHandleToStub(device_request, device$.Device)); |
| 528 } |
| 529 |
| 530 DeviceManagerStub.prototype.accept = function(message) { |
| 531 var reader = new codec.MessageReader(message); |
| 532 switch (reader.messageName) { |
| 533 case kDeviceManager_GetDevice_Name: |
| 534 var params = reader.decodeStruct(DeviceManager_GetDevice_Params); |
| 535 this.getDevice(params.guid, params.device_request); |
| 536 return true; |
| 537 default: |
| 538 return false; |
| 539 } |
| 540 }; |
| 541 |
| 542 DeviceManagerStub.prototype.acceptWithResponder = |
| 543 function(message, responder) { |
| 544 var reader = new codec.MessageReader(message); |
| 545 switch (reader.messageName) { |
| 546 case kDeviceManager_GetDevices_Name: |
| 547 var params = reader.decodeStruct(DeviceManager_GetDevices_Params); |
| 548 return this.getDevices(params.options).then(function(response) { |
| 549 var responseParams = |
| 550 new DeviceManager_GetDevices_ResponseParams(); |
| 551 responseParams.results = response.results; |
| 552 var builder = new codec.MessageWithRequestIDBuilder( |
| 553 kDeviceManager_GetDevices_Name, |
| 554 codec.align(DeviceManager_GetDevices_ResponseParams.encodedSize), |
| 555 codec.kMessageIsResponse, reader.requestID); |
| 556 builder.encodeStruct(DeviceManager_GetDevices_ResponseParams, |
| 557 responseParams); |
| 558 var message = builder.finish(); |
| 559 responder.accept(message); |
| 560 }); |
| 561 case kDeviceManager_GetDeviceChanges_Name: |
| 562 var params = reader.decodeStruct(DeviceManager_GetDeviceChanges_Params); |
| 563 return this.getDeviceChanges().then(function(response) { |
| 564 var responseParams = |
| 565 new DeviceManager_GetDeviceChanges_ResponseParams(); |
| 566 responseParams.changes = response.changes; |
| 567 var builder = new codec.MessageWithRequestIDBuilder( |
| 568 kDeviceManager_GetDeviceChanges_Name, |
| 569 codec.align(DeviceManager_GetDeviceChanges_ResponseParams.encodedSiz
e), |
| 570 codec.kMessageIsResponse, reader.requestID); |
| 571 builder.encodeStruct(DeviceManager_GetDeviceChanges_ResponseParams, |
| 572 responseParams); |
| 573 var message = builder.finish(); |
| 574 responder.accept(message); |
| 575 }); |
| 576 default: |
| 577 return Promise.reject(Error("Unhandled message: " + reader.messageName)); |
| 578 } |
| 579 }; |
| 580 |
| 581 function validateDeviceManagerRequest(messageValidator) { |
| 582 var message = messageValidator.message; |
| 583 var paramsClass = null; |
| 584 switch (message.getName()) { |
| 585 case kDeviceManager_GetDevices_Name: |
| 586 if (message.expectsResponse()) |
| 587 paramsClass = DeviceManager_GetDevices_Params; |
| 588 break; |
| 589 case kDeviceManager_GetDeviceChanges_Name: |
| 590 if (message.expectsResponse()) |
| 591 paramsClass = DeviceManager_GetDeviceChanges_Params; |
| 592 break; |
| 593 case kDeviceManager_GetDevice_Name: |
| 594 if (!message.expectsResponse() && !message.isResponse()) |
| 595 paramsClass = DeviceManager_GetDevice_Params; |
| 596 break; |
| 597 } |
| 598 if (paramsClass === null) |
| 599 return validator.validationError.NONE; |
| 600 return paramsClass.validate(messageValidator, messageValidator.message.getHe
aderNumBytes()); |
| 601 } |
| 602 |
| 603 function validateDeviceManagerResponse(messageValidator) { |
| 604 var message = messageValidator.message; |
| 605 var paramsClass = null; |
| 606 switch (message.getName()) { |
| 607 case kDeviceManager_GetDevices_Name: |
| 608 if (message.isResponse()) |
| 609 paramsClass = DeviceManager_GetDevices_ResponseParams; |
| 610 break; |
| 611 case kDeviceManager_GetDeviceChanges_Name: |
| 612 if (message.isResponse()) |
| 613 paramsClass = DeviceManager_GetDeviceChanges_ResponseParams; |
| 614 break; |
| 615 } |
| 616 if (paramsClass === null) |
| 617 return validator.validationError.NONE; |
| 618 return paramsClass.validate(messageValidator, messageValidator.message.getHe
aderNumBytes()); |
| 619 } |
| 620 |
| 621 var DeviceManager = { |
| 622 name: 'device::usb::DeviceManager', |
| 623 proxyClass: DeviceManagerProxy, |
| 624 stubClass: DeviceManagerStub, |
| 625 validateRequest: validateDeviceManagerRequest, |
| 626 validateResponse: validateDeviceManagerResponse, |
| 627 }; |
| 628 DeviceManagerStub.prototype.validator = validateDeviceManagerRequest; |
| 629 DeviceManagerProxy.prototype.validator = validateDeviceManagerResponse; |
| 630 |
| 631 |
| 632 var exports = {}; |
| 633 exports.DeviceFilter = DeviceFilter; |
| 634 exports.EnumerationOptions = EnumerationOptions; |
| 635 exports.DeviceChangeNotification = DeviceChangeNotification; |
| 636 exports.DeviceManager = DeviceManager; |
| 637 |
| 638 |
| 639 return exports; |
| 640 }); |
OLD | NEW |