OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef DEVICE_BLUETOOTH_PUBLIC_INTERFACES_PROPERTIES_STRUCT_TRAITS_H_ |
| 6 #define DEVICE_BLUETOOTH_PUBLIC_INTERFACES_PROPERTIES_STRUCT_TRAITS_H_ |
| 7 |
| 8 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 9 #include "device/bluetooth/public/interfaces/device.mojom.h" |
| 10 |
| 11 namespace mojo { |
| 12 |
| 13 template <> |
| 14 struct StructTraits<bluetooth::mojom::PropertiesDataView, |
| 15 device::BluetoothGattCharacteristic::Properties> { |
| 16 using Properties = device::BluetoothGattCharacteristic::Properties; |
| 17 using Property = device::BluetoothGattCharacteristic::Property; |
| 18 |
| 19 static bool broadcast(const Properties properties) { |
| 20 return (properties & Property::PROPERTY_BROADCAST) > 0; |
| 21 } |
| 22 |
| 23 static bool read(const Properties properties) { |
| 24 return (properties & Property::PROPERTY_READ) > 0; |
| 25 } |
| 26 |
| 27 static bool write_without_response(const Properties properties) { |
| 28 return (properties & Property::PROPERTY_WRITE_WITHOUT_RESPONSE) > 0; |
| 29 } |
| 30 |
| 31 static bool write(const Properties properties) { |
| 32 return (properties & Property::PROPERTY_WRITE) > 0; |
| 33 } |
| 34 |
| 35 static bool notify(const Properties properties) { |
| 36 return (properties & Property::PROPERTY_NOTIFY) > 0; |
| 37 } |
| 38 |
| 39 static bool indicate(const Properties properties) { |
| 40 return (properties & Property::PROPERTY_INDICATE) > 0; |
| 41 } |
| 42 |
| 43 static bool authenticated_signed_writes(const Properties properties) { |
| 44 return (properties & Property::PROPERTY_AUTHENTICATED_SIGNED_WRITES) > 0; |
| 45 } |
| 46 |
| 47 static bool extended_properties(const Properties properties) { |
| 48 return (properties & Property::PROPERTY_EXTENDED_PROPERTIES) > 0; |
| 49 } |
| 50 |
| 51 static bool reliable_write(const Properties properties) { |
| 52 return (properties & Property::PROPERTY_RELIABLE_WRITE) > 0; |
| 53 } |
| 54 |
| 55 static bool writable_auxiliaries(const Properties properties) { |
| 56 return (properties & Property::PROPERTY_WRITABLE_AUXILIARIES) > 0; |
| 57 } |
| 58 |
| 59 static bool read_encrypted(const Properties properties) { |
| 60 return (properties & Property::PROPERTY_READ_ENCRYPTED) > 0; |
| 61 } |
| 62 |
| 63 static bool write_encrypted(const Properties properties) { |
| 64 return (properties & Property::PROPERTY_WRITE_ENCRYPTED) > 0; |
| 65 } |
| 66 |
| 67 static bool read_encrypted_authenticated(const Properties properties) { |
| 68 return (properties & Property::PROPERTY_READ_ENCRYPTED_AUTHENTICATED) > 0; |
| 69 } |
| 70 |
| 71 static bool write_encrypted_authenticated(const Properties properties) { |
| 72 return (properties & Property::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED) > 0; |
| 73 } |
| 74 |
| 75 static bool Read(bluetooth::mojom::PropertiesDataView input, |
| 76 Properties* output) { |
| 77 uint32_t result = 0; |
| 78 |
| 79 result |= input.broadcast() ? Property::PROPERTY_BROADCAST : 0; |
| 80 result |= input.read() ? Property::PROPERTY_READ : 0; |
| 81 result |= input.write_without_response() |
| 82 ? Property::PROPERTY_WRITE_WITHOUT_RESPONSE |
| 83 : 0; |
| 84 result |= input.write() ? Property::PROPERTY_WRITE : 0; |
| 85 result |= input.notify() ? Property::PROPERTY_NOTIFY : 0; |
| 86 result |= input.indicate() ? Property::PROPERTY_INDICATE : 0; |
| 87 result |= input.authenticated_signed_writes() |
| 88 ? Property::PROPERTY_AUTHENTICATED_SIGNED_WRITES |
| 89 : 0; |
| 90 result |= input.extended_properties() |
| 91 ? Property::PROPERTY_EXTENDED_PROPERTIES |
| 92 : 0; |
| 93 result |= input.reliable_write() ? Property::PROPERTY_RELIABLE_WRITE : 0; |
| 94 result |= input.writable_auxiliaries() |
| 95 ? Property::PROPERTY_WRITABLE_AUXILIARIES |
| 96 : 0; |
| 97 result |= input.read_encrypted() ? Property::PROPERTY_READ_ENCRYPTED : 0; |
| 98 result |= input.write_encrypted() ? Property::PROPERTY_WRITE_ENCRYPTED : 0; |
| 99 result |= input.read_encrypted_authenticated() |
| 100 ? Property::PROPERTY_READ_ENCRYPTED_AUTHENTICATED |
| 101 : 0; |
| 102 result |= input.write_encrypted_authenticated() |
| 103 ? Property::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED |
| 104 : 0; |
| 105 |
| 106 *output = result; |
| 107 return true; |
| 108 } |
| 109 }; |
| 110 |
| 111 } // namespace mojo |
| 112 |
| 113 #endif // DEVICE_BLUETOOTH_PUBLIC_INTERFACES_PROPERTIES_STRUCT_TRAITS_H_ |
OLD | NEW |