OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "device/bluetooth/dbus/bluetooth_gatt_application_service_provider_impl
.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider_impl
.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "third_party/cros_system_api/dbus/service_constants.h" | 9 #include "third_party/cros_system_api/dbus/service_constants.h" |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 object_path_(object_path), | 55 object_path_(object_path), |
56 weak_ptr_factory_(this) { | 56 weak_ptr_factory_(this) { |
57 VLOG(1) << "Creating Fake Bluetooth GATT application service provider."; | 57 VLOG(1) << "Creating Fake Bluetooth GATT application service provider."; |
58 } | 58 } |
59 | 59 |
60 bool BluetoothGattApplicationServiceProviderImpl::OnOriginThread() { | 60 bool BluetoothGattApplicationServiceProviderImpl::OnOriginThread() { |
61 return base::PlatformThread::CurrentId() == origin_thread_id_; | 61 return base::PlatformThread::CurrentId() == origin_thread_id_; |
62 } | 62 } |
63 | 63 |
64 template <typename AttributeProvider> | 64 template <typename AttributeProvider> |
65 void BluetoothGattApplicationServiceProviderImpl::WriteObjectStruct( | 65 void BluetoothGattApplicationServiceProviderImpl::WriteObjectDict( |
66 dbus::MessageWriter* writer, | 66 dbus::MessageWriter* writer, |
67 const std::string& attribute_interface, | 67 const std::string& attribute_interface, |
68 AttributeProvider* attribute_provider) { | 68 AttributeProvider* attribute_provider) { |
69 // Open a struct entry for { object_path : interface_list }. | 69 // Open a dict entry for { object_path : interface_list }. |
70 dbus::MessageWriter object_struct_writer(NULL); | 70 dbus::MessageWriter object_dict_writer(NULL); |
71 // [ (oa(sa{sv}) ] | 71 // [ {oa{sa{sv}} ] |
72 writer->OpenStruct(&object_struct_writer); | 72 writer->OpenDictEntry(&object_dict_writer); |
73 | 73 |
74 // Key: Object path. [ (o ] | 74 // Key: Object path. [ {o ] |
75 object_struct_writer.AppendObjectPath(attribute_provider->object_path()); | 75 object_dict_writer.AppendObjectPath(attribute_provider->object_path()); |
76 | 76 |
77 // Value: Open array for single entry interface_list. [ a(sa{sv}) ] | 77 // Value: Open array for single entry interface_list. [ a{sa{sv}} ] |
78 dbus::MessageWriter interface_array_writer(NULL); | 78 dbus::MessageWriter interface_array_writer(NULL); |
79 object_struct_writer.OpenArray("(sa{sv})", &interface_array_writer); | 79 object_dict_writer.OpenArray("(sa{sv})", &interface_array_writer); |
80 WriteInterfaceStruct(&interface_array_writer, attribute_interface, | 80 WriteInterfaceDict(&interface_array_writer, attribute_interface, |
81 attribute_provider); | 81 attribute_provider); |
82 object_struct_writer.CloseContainer(&interface_array_writer); | 82 object_dict_writer.CloseContainer(&interface_array_writer); |
83 | 83 |
84 writer->CloseContainer(&object_struct_writer); | 84 writer->CloseContainer(&object_dict_writer); |
85 } | 85 } |
86 | 86 |
87 template <typename AttributeProvider> | 87 template <typename AttributeProvider> |
88 void BluetoothGattApplicationServiceProviderImpl::WriteInterfaceStruct( | 88 void BluetoothGattApplicationServiceProviderImpl::WriteInterfaceDict( |
89 dbus::MessageWriter* writer, | 89 dbus::MessageWriter* writer, |
90 const std::string& attribute_interface, | 90 const std::string& attribute_interface, |
91 AttributeProvider* attribute_provider) { | 91 AttributeProvider* attribute_provider) { |
92 // Open a struct entry for { interface_name : properties_list }. | 92 // Open a dict entry for { interface_name : properties_list }. |
93 dbus::MessageWriter interface_struct_writer(NULL); | 93 dbus::MessageWriter interface_dict_writer(NULL); |
94 // [ (sa{sv}) ] | 94 // [ {sa{sv}} ] |
95 writer->OpenStruct(&interface_struct_writer); | 95 writer->OpenDictEntry(&interface_dict_writer); |
96 | 96 |
97 // Key: Interface name. [ (s ] | 97 // Key: Interface name. [ {s ] |
98 interface_struct_writer.AppendString(attribute_interface); | 98 interface_dict_writer.AppendString(attribute_interface); |
99 // Value: Open a array for properties_list. [ a{sv}) ] | 99 // Value: Open a array for properties_list. [ a{sv}} ] |
100 WriteAttributeProperties(&interface_struct_writer, attribute_provider); | 100 WriteAttributeProperties(&interface_dict_writer, attribute_provider); |
101 writer->CloseContainer(&interface_struct_writer); | 101 writer->CloseContainer(&interface_dict_writer); |
102 } | 102 } |
103 | 103 |
104 void BluetoothGattApplicationServiceProviderImpl::WriteAttributeProperties( | 104 void BluetoothGattApplicationServiceProviderImpl::WriteAttributeProperties( |
105 dbus::MessageWriter* writer, | 105 dbus::MessageWriter* writer, |
106 BluetoothGattServiceServiceProvider* service_provider) { | 106 BluetoothGattServiceServiceProvider* service_provider) { |
107 service_provider->WriteProperties(writer); | 107 service_provider->WriteProperties(writer); |
108 } | 108 } |
109 | 109 |
110 void BluetoothGattApplicationServiceProviderImpl::WriteAttributeProperties( | 110 void BluetoothGattApplicationServiceProviderImpl::WriteAttributeProperties( |
111 dbus::MessageWriter* writer, | 111 dbus::MessageWriter* writer, |
(...skipping 12 matching lines...) Expand all Loading... |
124 dbus::ExportedObject::ResponseSender response_sender) { | 124 dbus::ExportedObject::ResponseSender response_sender) { |
125 VLOG(2) << "BluetoothGattApplicationServiceProvider::GetManagedObjects: " | 125 VLOG(2) << "BluetoothGattApplicationServiceProvider::GetManagedObjects: " |
126 << object_path_.value(); | 126 << object_path_.value(); |
127 DCHECK(OnOriginThread()); | 127 DCHECK(OnOriginThread()); |
128 | 128 |
129 dbus::MessageReader reader(method_call); | 129 dbus::MessageReader reader(method_call); |
130 | 130 |
131 std::unique_ptr<dbus::Response> response = | 131 std::unique_ptr<dbus::Response> response = |
132 dbus::Response::FromMethodCall(method_call); | 132 dbus::Response::FromMethodCall(method_call); |
133 | 133 |
134 // The expected format by GetAll is [ a(oa(sa{sv})) ] | 134 // The expected format by GetAll is [ a{oa{sa{sv}}} ] |
135 dbus::MessageWriter writer(response.get()); | 135 dbus::MessageWriter writer(response.get()); |
136 dbus::MessageWriter array_writer(nullptr); | 136 dbus::MessageWriter array_writer(nullptr); |
137 | 137 |
138 writer.OpenArray("(oa(sa{sv}))", &array_writer); | 138 writer.OpenArray("{oa{sa{sv}}}", &array_writer); |
139 | 139 |
140 for (const auto& service_provider : service_providers_) { | 140 for (const auto& service_provider : service_providers_) { |
141 WriteObjectStruct(&array_writer, | 141 WriteObjectDict(&array_writer, |
142 bluetooth_gatt_service::kBluetoothGattServiceInterface, | 142 bluetooth_gatt_service::kBluetoothGattServiceInterface, |
143 service_provider.get()); | 143 service_provider.get()); |
144 } | 144 } |
145 for (const auto& characteristic_provider : characteristic_providers_) { | 145 for (const auto& characteristic_provider : characteristic_providers_) { |
146 WriteObjectStruct( | 146 WriteObjectDict( |
147 &array_writer, | 147 &array_writer, |
148 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, | 148 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, |
149 characteristic_provider.get()); | 149 characteristic_provider.get()); |
150 } | 150 } |
151 for (const auto& descriptor_provider : descriptor_providers_) { | 151 for (const auto& descriptor_provider : descriptor_providers_) { |
152 WriteObjectStruct( | 152 WriteObjectDict( |
153 &array_writer, | 153 &array_writer, |
154 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, | 154 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, |
155 descriptor_provider.get()); | 155 descriptor_provider.get()); |
156 } | 156 } |
157 | 157 |
158 writer.CloseContainer(&array_writer); | 158 writer.CloseContainer(&array_writer); |
159 | |
160 response_sender.Run(std::move(response)); | 159 response_sender.Run(std::move(response)); |
161 } | 160 } |
162 | 161 |
163 // Called by dbus:: when a method is exported. | 162 // Called by dbus:: when a method is exported. |
164 void BluetoothGattApplicationServiceProviderImpl::OnExported( | 163 void BluetoothGattApplicationServiceProviderImpl::OnExported( |
165 const std::string& interface_name, | 164 const std::string& interface_name, |
166 const std::string& method_name, | 165 const std::string& method_name, |
167 bool success) { | 166 bool success) { |
168 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." | 167 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." |
169 << method_name; | 168 << method_name; |
170 } | 169 } |
171 | 170 |
172 } // namespace bluez | 171 } // namespace bluez |
OLD | NEW |