Index: device/bluetooth/public/interfaces/properties_struct_traits.h |
diff --git a/device/bluetooth/public/interfaces/properties_struct_traits.h b/device/bluetooth/public/interfaces/properties_struct_traits.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..91589a5e6188e74922781ec445e9b3a780921fe0 |
--- /dev/null |
+++ b/device/bluetooth/public/interfaces/properties_struct_traits.h |
@@ -0,0 +1,113 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef DEVICE_BLUETOOTH_PUBLIC_INTERFACES_PROPERTIES_STRUCT_TRAITS_H_ |
+#define DEVICE_BLUETOOTH_PUBLIC_INTERFACES_PROPERTIES_STRUCT_TRAITS_H_ |
+ |
+#include "device/bluetooth/bluetooth_gatt_characteristic.h" |
+#include "device/bluetooth/public/interfaces/device.mojom.h" |
+ |
+namespace mojo { |
+ |
+template <> |
+struct StructTraits<bluetooth::mojom::PropertiesDataView, |
+ device::BluetoothGattCharacteristic::Properties> { |
+ using Properties = device::BluetoothGattCharacteristic::Properties; |
+ using Property = device::BluetoothGattCharacteristic::Property; |
+ |
+ static bool broadcast(const Properties properties) { |
+ return (properties & Property::PROPERTY_BROADCAST) > 0; |
+ } |
+ |
+ static bool read(const Properties properties) { |
+ return (properties & Property::PROPERTY_READ) > 0; |
+ } |
+ |
+ static bool write_without_response(const Properties properties) { |
+ return (properties & Property::PROPERTY_WRITE_WITHOUT_RESPONSE) > 0; |
+ } |
+ |
+ static bool write(const Properties properties) { |
+ return (properties & Property::PROPERTY_WRITE) > 0; |
+ } |
+ |
+ static bool notify(const Properties properties) { |
+ return (properties & Property::PROPERTY_NOTIFY) > 0; |
+ } |
+ |
+ static bool indicate(const Properties properties) { |
+ return (properties & Property::PROPERTY_INDICATE) > 0; |
+ } |
+ |
+ static bool authenticated_signed_writes(const Properties properties) { |
+ return (properties & Property::PROPERTY_AUTHENTICATED_SIGNED_WRITES) > 0; |
+ } |
+ |
+ static bool extended_properties(const Properties properties) { |
+ return (properties & Property::PROPERTY_EXTENDED_PROPERTIES) > 0; |
+ } |
+ |
+ static bool reliable_write(const Properties properties) { |
+ return (properties & Property::PROPERTY_RELIABLE_WRITE) > 0; |
+ } |
+ |
+ static bool writable_auxiliaries(const Properties properties) { |
+ return (properties & Property::PROPERTY_WRITABLE_AUXILIARIES) > 0; |
+ } |
+ |
+ static bool read_encrypted(const Properties properties) { |
+ return (properties & Property::PROPERTY_READ_ENCRYPTED) > 0; |
+ } |
+ |
+ static bool write_encrypted(const Properties properties) { |
+ return (properties & Property::PROPERTY_WRITE_ENCRYPTED) > 0; |
+ } |
+ |
+ static bool read_encrypted_authenticated(const Properties properties) { |
+ return (properties & Property::PROPERTY_READ_ENCRYPTED_AUTHENTICATED) > 0; |
+ } |
+ |
+ static bool write_encrypted_authenticated(const Properties properties) { |
+ return (properties & Property::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED) > 0; |
+ } |
+ |
+ static bool Read(bluetooth::mojom::PropertiesDataView input, |
+ Properties* output) { |
dcheng
2017/01/18 00:17:08
Nit: please out-of-line
mbrunson
2017/01/18 22:04:24
Removed this completely. Using bitfield and enum f
|
+ uint32_t result = 0; |
+ |
+ result |= input.broadcast() ? Property::PROPERTY_BROADCAST : 0; |
+ result |= input.read() ? Property::PROPERTY_READ : 0; |
+ result |= input.write_without_response() |
+ ? Property::PROPERTY_WRITE_WITHOUT_RESPONSE |
+ : 0; |
+ result |= input.write() ? Property::PROPERTY_WRITE : 0; |
+ result |= input.notify() ? Property::PROPERTY_NOTIFY : 0; |
+ result |= input.indicate() ? Property::PROPERTY_INDICATE : 0; |
+ result |= input.authenticated_signed_writes() |
+ ? Property::PROPERTY_AUTHENTICATED_SIGNED_WRITES |
+ : 0; |
+ result |= input.extended_properties() |
+ ? Property::PROPERTY_EXTENDED_PROPERTIES |
+ : 0; |
+ result |= input.reliable_write() ? Property::PROPERTY_RELIABLE_WRITE : 0; |
+ result |= input.writable_auxiliaries() |
+ ? Property::PROPERTY_WRITABLE_AUXILIARIES |
+ : 0; |
+ result |= input.read_encrypted() ? Property::PROPERTY_READ_ENCRYPTED : 0; |
+ result |= input.write_encrypted() ? Property::PROPERTY_WRITE_ENCRYPTED : 0; |
+ result |= input.read_encrypted_authenticated() |
+ ? Property::PROPERTY_READ_ENCRYPTED_AUTHENTICATED |
+ : 0; |
+ result |= input.write_encrypted_authenticated() |
+ ? Property::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED |
+ : 0; |
+ |
+ *output = result; |
+ return true; |
+ } |
+}; |
+ |
+} // namespace mojo |
+ |
+#endif // DEVICE_BLUETOOTH_PUBLIC_INTERFACES_PROPERTIES_STRUCT_TRAITS_H_ |