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

Side by Side Diff: content/renderer/bluetooth/bluetooth_dispatcher.cc

Issue 1723723002: bluetooth: Implement Service.getCharacteristics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Merge with ToT Created 4 years, 10 months 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
OLDNEW
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 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" 5 #include "content/renderer/bluetooth/bluetooth_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 : service_instance_id(service_instance_id), 58 : service_instance_id(service_instance_id),
59 characteristic_uuid(characteristic_uuid), 59 characteristic_uuid(characteristic_uuid),
60 callbacks(callbacks) {} 60 callbacks(callbacks) {}
61 ~BluetoothCharacteristicRequest() {} 61 ~BluetoothCharacteristicRequest() {}
62 62
63 blink::WebString service_instance_id; 63 blink::WebString service_instance_id;
64 blink::WebString characteristic_uuid; 64 blink::WebString characteristic_uuid;
65 scoped_ptr<blink::WebBluetoothGetCharacteristicCallbacks> callbacks; 65 scoped_ptr<blink::WebBluetoothGetCharacteristicCallbacks> callbacks;
66 }; 66 };
67 67
68 struct BluetoothCharacteristicsRequest {
69 BluetoothCharacteristicsRequest(
70 blink::WebString service_instance_id,
71 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks)
72 : service_instance_id(service_instance_id), callbacks(callbacks) {}
73 ~BluetoothCharacteristicsRequest() {}
74
75 blink::WebString service_instance_id;
76 scoped_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks;
77 };
78
68 // Struct that holds a pending WriteValue request. 79 // Struct that holds a pending WriteValue request.
69 struct BluetoothWriteValueRequest { 80 struct BluetoothWriteValueRequest {
70 BluetoothWriteValueRequest(const blink::WebVector<uint8_t>& value, 81 BluetoothWriteValueRequest(const blink::WebVector<uint8_t>& value,
71 blink::WebBluetoothWriteValueCallbacks* callbacks) 82 blink::WebBluetoothWriteValueCallbacks* callbacks)
72 : value(value), callbacks(callbacks) {} 83 : value(value), callbacks(callbacks) {}
73 ~BluetoothWriteValueRequest() {} 84 ~BluetoothWriteValueRequest() {}
74 85
75 const blink::WebVector<uint8_t> value; 86 const blink::WebVector<uint8_t> value;
76 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks; 87 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks;
77 }; 88 };
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 IPC_MESSAGE_HANDLER(BluetoothMsg_GATTServerConnectError, 183 IPC_MESSAGE_HANDLER(BluetoothMsg_GATTServerConnectError,
173 OnGATTServerConnectError); 184 OnGATTServerConnectError);
174 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess, 185 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess,
175 OnGetPrimaryServiceSuccess); 186 OnGetPrimaryServiceSuccess);
176 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, 187 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError,
177 OnGetPrimaryServiceError); 188 OnGetPrimaryServiceError);
178 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess, 189 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess,
179 OnGetCharacteristicSuccess); 190 OnGetCharacteristicSuccess);
180 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, 191 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError,
181 OnGetCharacteristicError); 192 OnGetCharacteristicError);
193 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsSuccess,
194 OnGetCharacteristicsSuccess);
195 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicsError,
196 OnGetCharacteristicsError);
182 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, 197 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess,
183 OnReadValueSuccess); 198 OnReadValueSuccess);
184 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, 199 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError,
185 OnReadValueError); 200 OnReadValueError);
186 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess, 201 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess,
187 OnWriteValueSuccess); 202 OnWriteValueSuccess);
188 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError, 203 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError,
189 OnWriteValueError); 204 OnWriteValueError);
190 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsSuccess, 205 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsSuccess,
191 OnStartNotificationsSuccess) 206 OnStartNotificationsSuccess)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 const blink::WebString& characteristic_uuid, 277 const blink::WebString& characteristic_uuid,
263 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) { 278 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) {
264 int request_id = 279 int request_id =
265 pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest( 280 pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest(
266 service_instance_id, characteristic_uuid, callbacks)); 281 service_instance_id, characteristic_uuid, callbacks));
267 Send(new BluetoothHostMsg_GetCharacteristic( 282 Send(new BluetoothHostMsg_GetCharacteristic(
268 CurrentWorkerId(), request_id, frame_routing_id, 283 CurrentWorkerId(), request_id, frame_routing_id,
269 service_instance_id.utf8(), characteristic_uuid.utf8())); 284 service_instance_id.utf8(), characteristic_uuid.utf8()));
270 } 285 }
271 286
287 void BluetoothDispatcher::getCharacteristics(
288 int frame_routing_id,
289 const blink::WebString& service_instance_id,
290 const blink::WebString& characteristics_uuid,
291 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) {
292 int request_id = pending_characteristics_requests_.Add(
293 new BluetoothCharacteristicsRequest(service_instance_id, callbacks));
294 Send(new BluetoothHostMsg_GetCharacteristics(
295 CurrentWorkerId(), request_id, frame_routing_id,
296 service_instance_id.utf8(), characteristics_uuid.utf8()));
297 }
298
272 void BluetoothDispatcher::readValue( 299 void BluetoothDispatcher::readValue(
273 int frame_routing_id, 300 int frame_routing_id,
274 const blink::WebString& characteristic_instance_id, 301 const blink::WebString& characteristic_instance_id,
275 blink::WebBluetoothReadValueCallbacks* callbacks) { 302 blink::WebBluetoothReadValueCallbacks* callbacks) {
276 int request_id = pending_read_value_requests_.Add(callbacks); 303 int request_id = pending_read_value_requests_.Add(callbacks);
277 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, 304 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id,
278 frame_routing_id, 305 frame_routing_id,
279 characteristic_instance_id.utf8())); 306 characteristic_instance_id.utf8()));
280 } 307 }
281 308
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 int thread_id, 679 int thread_id,
653 int request_id, 680 int request_id,
654 const std::string& characteristic_instance_id, 681 const std::string& characteristic_instance_id,
655 uint32_t characteristic_properties) { 682 uint32_t characteristic_properties) {
656 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; 683 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id;
657 684
658 BluetoothCharacteristicRequest* request = 685 BluetoothCharacteristicRequest* request =
659 pending_characteristic_requests_.Lookup(request_id); 686 pending_characteristic_requests_.Lookup(request_id);
660 request->callbacks->onSuccess( 687 request->callbacks->onSuccess(
661 blink::adoptWebPtr(new WebBluetoothRemoteGATTCharacteristicInit( 688 blink::adoptWebPtr(new WebBluetoothRemoteGATTCharacteristicInit(
689 request->service_instance_id,
662 WebString::fromUTF8(characteristic_instance_id), 690 WebString::fromUTF8(characteristic_instance_id),
663 request->service_instance_id, request->characteristic_uuid, 691 request->characteristic_uuid, characteristic_properties)));
664 characteristic_properties)));
665 692
666 pending_characteristic_requests_.Remove(request_id); 693 pending_characteristic_requests_.Remove(request_id);
667 } 694 }
668 695
669 void BluetoothDispatcher::OnGetCharacteristicError(int thread_id, 696 void BluetoothDispatcher::OnGetCharacteristicError(int thread_id,
670 int request_id, 697 int request_id,
671 WebBluetoothError error) { 698 WebBluetoothError error) {
672 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; 699 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id;
673 700
674 pending_characteristic_requests_.Lookup(request_id) 701 pending_characteristic_requests_.Lookup(request_id)
675 ->callbacks->onError(WebBluetoothError(error)); 702 ->callbacks->onError(WebBluetoothError(error));
676 703
677 pending_characteristic_requests_.Remove(request_id); 704 pending_characteristic_requests_.Remove(request_id);
678 } 705 }
679 706
707 void BluetoothDispatcher::OnGetCharacteristicsSuccess(
708 int thread_id,
709 int request_id,
710 const std::vector<std::string>& characteristics_instance_ids,
711 const std::vector<std::string>& characteristics_uuids,
712 const std::vector<uint32_t>& characteristics_properties) {
713 DCHECK(pending_characteristics_requests_.Lookup(request_id)) << request_id;
714
715 BluetoothCharacteristicsRequest* request =
716 pending_characteristics_requests_.Lookup(request_id);
717
718 WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*>* characteristics =
719 new WebVector<WebBluetoothRemoteGATTCharacteristicInit*>(
720 characteristics_instance_ids.size());
721
722 for (size_t i = 0; i < characteristics_instance_ids.size(); i++) {
723 (*characteristics)[i] = new WebBluetoothRemoteGATTCharacteristicInit(
724 request->service_instance_id,
725 WebString::fromUTF8(characteristics_instance_ids[i]),
726 WebString::fromUTF8(characteristics_uuids[i]),
727 characteristics_properties[i]);
728 }
729
730 request->callbacks->onSuccess(blink::adoptWebPtr(characteristics));
731
732 pending_characteristics_requests_.Lookup(request_id);
733 }
734
735 void BluetoothDispatcher::OnGetCharacteristicsError(int thread_id,
736 int request_id,
737 WebBluetoothError error) {
738 DCHECK(pending_characteristics_requests_.Lookup(request_id)) << request_id;
739
740 pending_characteristics_requests_.Lookup(request_id)
741 ->callbacks->onError(WebBluetoothError(error));
742
743 pending_characteristics_requests_.Remove(request_id);
744 }
745
680 void BluetoothDispatcher::OnReadValueSuccess( 746 void BluetoothDispatcher::OnReadValueSuccess(
681 int thread_id, 747 int thread_id,
682 int request_id, 748 int request_id,
683 const std::vector<uint8_t>& value) { 749 const std::vector<uint8_t>& value) {
684 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; 750 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
685 751
686 // WebArrayBuffer is not accessible from Source/modules so we pass a 752 // WebArrayBuffer is not accessible from Source/modules so we pass a
687 // WebVector instead. 753 // WebVector instead.
688 pending_read_value_requests_.Lookup(request_id)->onSuccess(value); 754 pending_read_value_requests_.Lookup(request_id)->onSuccess(value);
689 755
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 int thread_id, 870 int thread_id,
805 const std::string& characteristic_instance_id, 871 const std::string& characteristic_instance_id,
806 const std::vector<uint8_t> new_value) { 872 const std::vector<uint8_t> new_value) {
807 auto active_iter = active_characteristics_.find(characteristic_instance_id); 873 auto active_iter = active_characteristics_.find(characteristic_instance_id);
808 if (active_iter != active_characteristics_.end()) { 874 if (active_iter != active_characteristics_.end()) {
809 active_iter->second->dispatchCharacteristicValueChanged(new_value); 875 active_iter->second->dispatchCharacteristicValueChanged(new_value);
810 } 876 }
811 } 877 }
812 878
813 } // namespace content 879 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/bluetooth/bluetooth_dispatcher.h ('k') | content/renderer/bluetooth/web_bluetooth_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698