1#ifndef BLUETOE_FIND_NOTIFICATION_DATA_HPP
2#define BLUETOE_FIND_NOTIFICATION_DATA_HPP
10 template <
typename Characteristics,
typename Pair >
11 struct filter_characteristics_with_cccd
14 Pair::characteristic_t::number_of_client_configs,
15 typename add_type< Characteristics, Pair >::type,
20 template <
typename Characteristic, std::
size_t Offset,
int Prio >
21 struct characteristic_with_service_attribute_offset
23 using characteristic_t = Characteristic;
24 static constexpr std::size_t service_offset = Offset;
25 static constexpr int priority = Prio;
28 struct preudo_first_char
30 static constexpr std::size_t number_of_attributes = 0;
33 template <
typename Characteristic, std::
size_t FirstAttributesIndex,
int Prio >
34 struct characteristic_index_pair
36 using characteristic_t = Characteristic;
37 static constexpr std::size_t first_attribute_index = FirstAttributesIndex;
38 static constexpr int priority = Prio;
41 template <
typename Characteristics,
typename Characteristic >
42 struct add_index_to_characteristic
44 using last =
typename last_type< Characteristics, impl::characteristic_index_pair< impl::preudo_first_char, 0, 0 > >::type;
46 static constexpr std::size_t attribute_handle = last::first_attribute_index + last::characteristic_t::number_of_attributes + Characteristic::service_offset;
48 using type =
typename add_type<
50 impl::characteristic_index_pair< typename Characteristic::characteristic_t, attribute_handle, Characteristic::priority >
56 constexpr attribute_at( std::size_t& r, std::size_t i )
61 template<
typename O >
66 result = O::first_attribute_index;
76 template <
typename A,
typename B >
79 using type = std::integral_constant< bool, A::priority < B::priority >;
82 template <
typename Characteristics,
typename Characteristic >
83 struct add_cccd_position
85 template < std::
size_t CCCD,
typename HandlePair >
86 struct with_cccd_position : HandlePair
88 static constexpr std::size_t cccd_position = CCCD;
91 static constexpr std::size_t cccd_position = std::tuple_size< Characteristics >::value;
93 using type =
typename add_type<
95 with_cccd_position< cccd_position, Characteristic >
99 template <
typename Characteristics,
typename Characteristic >
100 struct add_cccd_handle
102 template < std::
size_t CCCD,
typename HandlePair >
103 struct with_cccd_handle : HandlePair
105 static constexpr std::size_t cccd_handle = CCCD;
108 static constexpr std::size_t cccd_handle = std::tuple_size< Characteristics >::value;
110 using type =
typename add_type<
112 with_cccd_handle< cccd_handle, Characteristic >
116 template <
class Characteristic >
117 struct select_cccd_position {
118 using type = std::integral_constant< std::size_t, Characteristic::cccd_position >;
127 struct find_notification_data_in_list
129 template <
typename Characteristics,
typename Service >
130 struct characteristics_from_service
132 template <
typename C >
133 struct add_service_offset
135 using type = std::tuple<>;
140 template <
typename C,
typename ...Cs >
141 struct add_service_offset< std::tuple< C, Cs... > >
143 using type = std::tuple<
144 impl::characteristic_with_service_attribute_offset< C, Service::number_of_service_attributes, Priorities::template characteristic_priority< Services, Service, C >::value >,
145 impl::characteristic_with_service_attribute_offset< Cs, 0, Priorities::template characteristic_priority< Services, Service, Cs >::value >... >;
148 using type =
typename add_type< Characteristics, typename add_service_offset< typename Service::characteristics >::type >::type;
151 using services = Services;
152 using all_characteristics =
typename fold_left< services, characteristics_from_service >::type;
153 using characteristics_with_attribute_indizes =
typename fold_left< all_characteristics, impl::add_index_to_characteristic >::type;
154 using characteristics_only_with_cccd =
typename fold_left< characteristics_with_attribute_indizes, impl::filter_characteristics_with_cccd >::type;
155 using characteristics_with_cccd_position =
typename fold_left< characteristics_only_with_cccd, impl::add_cccd_position >::type;
156 using characteristics_sorted_by_priority =
typename stable_sort< impl::order_by_prio, characteristics_with_cccd_position >::type;
157 using characteristics_with_cccd_handle =
typename fold_left< characteristics_sorted_by_priority, impl::add_cccd_handle >::type;
159 static notification_data find_notification_data_by_index( std::size_t notification_index )
161 std::size_t attribute_index = 0;
162 for_< characteristics_sorted_by_priority >::each( impl::attribute_at( attribute_index, notification_index ) );
164 return notification_data( attribute_index + 1, notification_index );
167 struct attribute_value
169 constexpr attribute_value( notification_data& r,
const void* v )
175 template<
typename O >
178 if ( O::characteristic_t::value_type::is_this( value ) )
179 result = notification_data( O::first_attribute_index + 1, index );
184 notification_data& result;
189 static notification_data find_notification_data(
const void* value )
191 notification_data result;
192 for_< characteristics_only_with_cccd >::each( attribute_value( result, value ) );
197 using cccd_indices =
typename transform_list< characteristics_with_cccd_handle, impl::select_cccd_position >::type;
203 typename Characteristic
205 struct find_notification_by_uuid
207 using find = find_notification_data_in_list< Priorities, Services >;
209 template <
typename Other >
212 static constexpr bool value = std::is_same< typename Other::characteristic_t, Characteristic >::value;
215 using char_infos =
typename find_if<
216 typename find::characteristics_with_cccd_handle,
219 static notification_data data()
221 return notification_data( char_infos::first_attribute_index + 1, char_infos::cccd_handle );