| OLD | NEW |
| 1 'use strict'; | 1 'use strict'; |
| 2 | 2 |
| 3 // Wraps callback and calls reject_func if callback throws an error. | 3 // Wraps callback and calls reject_func if callback throws an error. |
| 4 class CallbackWrapper { | 4 class CallbackWrapper { |
| 5 constructor(callback, reject_func) { | 5 constructor(callback, reject_func) { |
| 6 this.wrapper_func_ = (args) => { | 6 this.wrapper_func_ = (args) => { |
| 7 try { | 7 try { |
| 8 callback(args); | 8 callback(args); |
| 9 } catch(e) { | 9 } catch(e) { |
| 10 reject_func(); | 10 reject_func(); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 assert_equals(rv.result, core.RESULT_OK, "Failed to create buffer"); | 237 assert_equals(rv.result, core.RESULT_OK, "Failed to create buffer"); |
| 238 this.shared_buffer_handle_ = rv.handle; | 238 this.shared_buffer_handle_ = rv.handle; |
| 239 this.active_sensor_ = null; | 239 this.active_sensor_ = null; |
| 240 this.get_sensor_should_fail_ = false; | 240 this.get_sensor_should_fail_ = false; |
| 241 this.resolve_func_ = null; | 241 this.resolve_func_ = null; |
| 242 this.is_continuous_ = false; | 242 this.is_continuous_ = false; |
| 243 this.max_frequency_ = 60; | 243 this.max_frequency_ = 60; |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Returns initialized Sensor proxy to the client. | 246 // Returns initialized Sensor proxy to the client. |
| 247 getSensor(type, stub) { | 247 getSensor(type, request) { |
| 248 if (this.get_sensor_should_fail_) { | 248 if (this.get_sensor_should_fail_) { |
| 249 return getSensorResponse(null, | 249 var ignored = new sensor.SensorClientPtr(); |
| 250 connection.bindProxy(null, sensor.SensorClient)); | 250 return getSensorResponse(null, bindings.makeRequest(ignored)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 let offset = | 253 let offset = |
| 254 (sensor.SensorType.LAST - type) * this.reading_size_in_bytes_; | 254 (sensor.SensorType.LAST - type) * this.reading_size_in_bytes_; |
| 255 let reporting_mode = sensor.ReportingMode.ON_CHANGE; | 255 let reporting_mode = sensor.ReportingMode.ON_CHANGE; |
| 256 if (this.is_continuous_) { | 256 if (this.is_continuous_) { |
| 257 reporting_mode = sensor.ReportingMode.CONTINUOUS; | 257 reporting_mode = sensor.ReportingMode.CONTINUOUS; |
| 258 } | 258 } |
| 259 | 259 |
| 260 if (this.active_sensor_ == null) { | 260 if (this.active_sensor_ == null) { |
| 261 var stub = connection.bindHandleToStub(request.handle, sensor.Sensor); |
| 261 let mockSensor = new MockSensor(stub, this.shared_buffer_handle_, | 262 let mockSensor = new MockSensor(stub, this.shared_buffer_handle_, |
| 262 offset, this.reading_size_in_bytes_, reporting_mode); | 263 offset, this.reading_size_in_bytes_, reporting_mode); |
| 263 this.active_sensor_ = mockSensor; | 264 this.active_sensor_ = mockSensor; |
| 264 } | 265 } |
| 265 | 266 |
| 266 let rv = | 267 let rv = |
| 267 core.duplicateBufferHandle( | 268 core.duplicateBufferHandle( |
| 268 this.shared_buffer_handle_, | 269 this.shared_buffer_handle_, |
| 269 core.DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE); | 270 core.DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE); |
| 270 | 271 |
| 271 assert_equals(rv.result, core.RESULT_OK); | 272 assert_equals(rv.result, core.RESULT_OK); |
| 272 | 273 |
| 273 let default_config = {frequency: 5}; | 274 let default_config = {frequency: 5}; |
| 274 | 275 |
| 275 let init_params = | 276 let init_params = |
| 276 new sensor_provider.SensorInitParams( | 277 new sensor_provider.SensorInitParams( |
| 277 { memory: rv.handle, | 278 { memory: rv.handle, |
| 278 buffer_offset: offset, | 279 buffer_offset: offset, |
| 279 mode: reporting_mode, | 280 mode: reporting_mode, |
| 280 default_configuration: default_config, | 281 default_configuration: default_config, |
| 281 maximum_frequency: this.max_frequency_}); | 282 maximum_frequency: this.max_frequency_}); |
| 282 | 283 |
| 283 if (this.resolve_func_ !== null) { | 284 if (this.resolve_func_ !== null) { |
| 284 this.resolve_func_(this.active_sensor_); | 285 this.resolve_func_(this.active_sensor_); |
| 285 } | 286 } |
| 286 | 287 |
| 287 var client_handle = connection.bindProxy(proxy => { | 288 var client_request = new bindings.InterfaceRequest( |
| 288 this.active_sensor_.client_ = proxy; | 289 connection.bindProxy(proxy => { |
| 289 }, sensor.SensorClient); | 290 this.active_sensor_.client_ = proxy; |
| 290 return getSensorResponse(init_params, client_handle); | 291 }, sensor.SensorClient)); |
| 292 return getSensorResponse(init_params, client_request); |
| 291 } | 293 } |
| 292 | 294 |
| 293 // Binds object to mojo message pipe | 295 // Binds object to mojo message pipe |
| 294 bindToPipe(pipe) { | 296 bindToPipe(pipe) { |
| 295 this.stub_ = connection.bindHandleToStub( | 297 this.stub_ = connection.bindHandleToStub( |
| 296 pipe, sensor_provider.SensorProvider); | 298 pipe, sensor_provider.SensorProvider); |
| 297 bindings.StubBindings(this.stub_).delegate = this; | 299 bindings.StubBindings(this.stub_).delegate = this; |
| 298 bindings.StubBindings(this.stub_).connectionErrorHandler = () => { | 300 bindings.StubBindings(this.stub_).connectionErrorHandler = () => { |
| 299 this.reset(); | 301 this.reset(); |
| 300 }; | 302 }; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 }; | 371 }; |
| 370 | 372 |
| 371 let onFailure = () => { | 373 let onFailure = () => { |
| 372 sensor.mockSensorProvider.reset(); | 374 sensor.mockSensorProvider.reset(); |
| 373 return new Promise((resolve, reject) => { setTimeout(reject, 0); }); | 375 return new Promise((resolve, reject) => { setTimeout(reject, 0); }); |
| 374 }; | 376 }; |
| 375 | 377 |
| 376 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); | 378 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); |
| 377 }), name, properties); | 379 }), name, properties); |
| 378 } | 380 } |
| OLD | NEW |