OLD | NEW |
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 // Custom binding for the Bluetooth API. | 5 // Custom binding for the Bluetooth API. |
6 | 6 |
7 var binding = require('binding').Binding.create('bluetooth'); | 7 var binding = require('binding').Binding.create('bluetooth'); |
8 | 8 |
9 var chrome = requireNative('chrome').GetChrome(); | 9 var chrome = requireNative('chrome').GetChrome(); |
10 var Event = require('event_bindings').Event; | 10 var Event = require('event_bindings').Event; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 removeDeviceSearchListeners(); | 114 removeDeviceSearchListeners(); |
115 bluetooth.getDevicesState = null; | 115 bluetooth.getDevicesState = null; |
116 | 116 |
117 if (finalCallback) { | 117 if (finalCallback) { |
118 finalCallback(); | 118 finalCallback(); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 apiFunctions.setUpdateArgumentsPostValidate('getDevices', | 122 apiFunctions.setUpdateArgumentsPostValidate('getDevices', |
123 function() { | 123 function() { |
124 var args = Array.prototype.slice.call(arguments); | 124 var args = $Array.slice(arguments); |
125 | 125 |
126 if (bluetooth.getDevicesState != null) { | 126 if (bluetooth.getDevicesState != null) { |
127 throw new Error('Concurrent calls to getDevices are not allowed.'); | 127 throw new Error('Concurrent calls to getDevices are not allowed.'); |
128 } | 128 } |
129 | 129 |
130 var state = { actualEvents: 0 }; | 130 var state = { actualEvents: 0 }; |
131 | 131 |
132 if (typeof(args[args.length - 1]) == 'function') { | 132 if (typeof(args[args.length - 1]) == 'function') { |
133 state.finalCallback = args.pop(); | 133 state.finalCallback = args.pop(); |
134 args.push( | 134 $Array.push(args, |
135 function() { | 135 function() { |
136 if (chrome.runtime.lastError) { | 136 if (chrome.runtime.lastError) { |
137 finishDeviceSearch(); | 137 finishDeviceSearch(); |
138 } | 138 } |
139 }); | 139 }); |
140 } else { | 140 } else { |
141 throw new Error('getDevices must have a final callback parameter.'); | 141 throw new Error('getDevices must have a final callback parameter.'); |
142 } | 142 } |
143 | 143 |
144 if (typeof(args[0].deviceCallback) == 'function') { | 144 if (typeof(args[0].deviceCallback) == 'function') { |
145 state.deviceCallback = args[0].deviceCallback; | 145 state.deviceCallback = args[0].deviceCallback; |
146 } else { | 146 } else { |
147 throw new Error('getDevices must be passed options with a ' + | 147 throw new Error('getDevices must be passed options with a ' + |
148 'deviceCallback.'); | 148 'deviceCallback.'); |
149 } | 149 } |
150 | 150 |
151 bluetooth.getDevicesState = state; | 151 bluetooth.getDevicesState = state; |
152 addDeviceSearchListeners(); | 152 addDeviceSearchListeners(); |
153 | 153 |
154 return args; | 154 return args; |
155 }); | 155 }); |
156 }); | 156 }); |
157 | 157 |
158 exports.binding = binding.generate(); | 158 exports.binding = binding.generate(); |
OLD | NEW |