|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2017-2017 ARM Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef BLE_TYPES_H_ |
| 18 | +#define BLE_TYPES_H_ |
| 19 | + |
| 20 | +#include <stddef.h> |
| 21 | +#include <stdint.h> |
| 22 | + |
| 23 | +namespace ble { |
| 24 | + |
| 25 | +/** |
| 26 | + * A connection handle is an unsigned integer capable of holding a pointer. |
| 27 | + * The real type (either a pointer to an object or an integer) is opaque and |
| 28 | + * platform dependent. |
| 29 | + */ |
| 30 | +typedef uintptr_t connection_handle_t; |
| 31 | + |
| 32 | +/** |
| 33 | + * Model an attribute handle in a GATT database. |
| 34 | + */ |
| 35 | +typedef uint16_t attribute_handle_t; |
| 36 | + |
| 37 | + |
| 38 | + /** |
| 39 | + * Model an inclusive range of GATT attributes handles. |
| 40 | + */ |
| 41 | +struct attribute_handle_range_t { |
| 42 | + attribute_handle_t begin; |
| 43 | + attribute_handle_t end; |
| 44 | + |
| 45 | + friend bool operator==( |
| 46 | + const attribute_handle_range_t& lhs, const attribute_handle_range_t& rhs |
| 47 | + ) { |
| 48 | + return (lhs.begin == rhs.begin) && (lhs.end == rhs.end); |
| 49 | + } |
| 50 | + |
| 51 | + friend bool operator!=( |
| 52 | + const attribute_handle_range_t& lhs, const attribute_handle_range_t& rhs |
| 53 | + ) { |
| 54 | + return !(lhs == rhs); |
| 55 | + } |
| 56 | +}; |
| 57 | + |
| 58 | + |
| 59 | +/** |
| 60 | + * Construct an attribute_handle_range_t from its start and end handle. |
| 61 | + * @note This function is defined instead of a constructor to keep "POD-ness" |
| 62 | + * of attribute_handle_range_t. |
| 63 | + */ |
| 64 | +static inline attribute_handle_range_t attribute_handle_range( |
| 65 | + attribute_handle_t begin, |
| 66 | + attribute_handle_t end |
| 67 | +) { |
| 68 | + attribute_handle_range_t result = { |
| 69 | + begin, |
| 70 | + end |
| 71 | + }; |
| 72 | + return result; |
| 73 | +} |
| 74 | + |
| 75 | +} // namespace ble |
| 76 | + |
| 77 | +#endif /* BLE_TYPES_H_ */ |
0 commit comments