1#ifndef BLUETOE_OUTGOING_PRIORITY_HPP
2#define BLUETOE_OUTGOING_PRIORITY_HPP
9 struct outgoing_priority_meta_type {};
11 template <
typename Services,
typename ServiceUUID >
12 struct number_of_additional_priorities
14 template <
typename Service >
15 using has_uuid = std::is_same< typename Service::uuid, ServiceUUID >;
18 using service =
typename find_if< Services, has_uuid >::type;
19 static constexpr int size = service::notification_priority::size;
23 static constexpr int size_with_default = size == service::number_of_client_configs
29 using type = std::integral_constant< int, size_with_default == 0 ? 1 : size_with_default >;
32 template <
typename ... Us >
33 struct check_server_parameter
35 static_assert( details::count_by_meta_type< details::service_uuid_meta_type, Us... >::count ==
sizeof...( Us ),
36 "Only service UUIDs are acceptable parameters to higher_outgoing_priority<> as server parameter." );
38 static constexpr bool check =
true;
41 template <
typename ... Us >
42 struct check_service_parameter
44 static_assert( details::count_by_meta_type< details::characteristic_uuid_meta_type, Us... >::count ==
sizeof...( Us ),
45 "Only characteristic UUIDs are acceptable parameters to higher_outgoing_priority<> as service parameter." );
47 static constexpr bool check =
true;
50 template <
typename T,
int Prio >
54 struct add_prio< std::tuple<>, 0 >
56 using type = std::tuple< std::integral_constant< int, 1 > >;
59 template <
int N,
typename ...Ts >
60 struct add_prio< std::tuple< std::integral_constant< int, N >, Ts... >, 0 >
62 using type = std::tuple< std::integral_constant< int, N + 1 >, Ts... >;
66 struct add_prio< std::tuple<>, Prio >
68 using type =
typename add_type<
69 std::integral_constant< int, 0 >,
70 typename add_prio< std::tuple<>, Prio -1 >::type >::type;
73 template <
int N,
typename ...Ts,
int Prio >
74 struct add_prio< std::tuple< std::integral_constant< int, N >, Ts... >, Prio >
76 using type =
typename add_type<
77 std::integral_constant< int, N >,
78 typename add_prio< std::tuple< Ts... >, Prio -1 >::type >::type;
159 template <
typename ... UUIDs >
163 details::outgoing_priority_meta_type,
164 details::valid_service_option_meta_type,
165 details::valid_server_option_meta_type {};
167 template <
typename Services,
typename Service >
168 struct service_base_priority
170 template <
typename Sum,
typename ServiceUUID >
171 struct optional_sum_prio
173 using found = std::integral_constant< bool, Sum::first_type::value || std::is_same< ServiceUUID, typename Service::uuid >::value >;
174 using prio =
typename Sum::second_type;
179 typename details::number_of_additional_priorities< Services, ServiceUUID >::type >::type;
181 using type = details::pair< found, sum >;
185 using type =
typename details::fold_left<
186 std::tuple< UUIDs... >,
188 details::pair< std::false_type, std::integral_constant< int, 0 > > >::type;
190 static constexpr int value = type::second_type::value;
193 template <
typename Sum,
typename Service >
194 struct expand_shared_priorities
196 static constexpr int sum = Sum::value;
199 static constexpr bool shared = details::index_of<
typename Service::uuid, UUIDs... >::value ==
sizeof...( UUIDs );
201 static constexpr int prios = Service::notification_priority::size;
203 static constexpr int shared_value = prios > sum ? prios : sum;
204 static constexpr int value = shared ? shared_value : sum;
206 using type = std::integral_constant< int, value >;
210 template <
typename Services,
typename Service,
typename Characteristic >
211 struct characteristic_priority
213 static constexpr auto checked = details::check_server_parameter< UUIDs... >::check;
215 static constexpr int service_prio = service_base_priority< Services, Service >::value;
219 static constexpr bool priorized_service = details::index_of<
typename Service::uuid, UUIDs... >::value !=
sizeof...( UUIDs );
222 static constexpr int shared_priorities = details::fold< Services, expand_shared_priorities, std::integral_constant< int, 0 > >::type::value;
224 static constexpr int char_prio = Service::notification_priority::template characteristic_position< Characteristic, priorized_service, shared_priorities >::value;
226 static constexpr int value = service_prio + char_prio;
229 template <
typename Services,
typename Service >
230 struct numbers_from_char
232 template <
typename Numbers,
typename Characteristic >
235 static constexpr int prio = characteristic_priority< Services, Service, Characteristic >::value;
236 using type =
typename details::add_prio< Numbers, prio >::type;
241 template <
typename Services >
244 template <
typename List,
typename Characteristic >
246 Characteristic::number_of_client_configs,
247 typename details::add_type< List, Characteristic >::type,
250 template <
typename Numbers,
typename Service >
251 using numbers_from_services = details::fold<
252 typename details::fold<
253 typename Service::characteristics,
254 characteristics_with_cccd >::type,
255 numbers_from_char< Services, Service >::template impl,
258 using type =
typename details::fold< Services, numbers_from_services, std::tuple<> >::type;
261 static constexpr std::size_t size =
sizeof...( UUIDs );
264 template <
typename Characteristic,
bool WithinPriorizedService,
int SharedPriorities >
265 struct characteristic_position
267 static constexpr auto checked = details::check_service_parameter< UUIDs... >::check;
269 static constexpr int pos = details::index_of<
typename Characteristic::configured_uuid, UUIDs... >::value;
270 static constexpr int value = WithinPriorizedService
272 : pos + SharedPriorities - size;
283 template <
class ... UUIDs >
287 details::outgoing_priority_meta_type,
288 details::valid_service_option_meta_type,
289 details::valid_server_option_meta_type {};
Defines priorities of notified or indicated characteristics.
Definition: outgoing_priority.hpp:160
Defines priorities of notified or indicated characteristics.
Definition: outgoing_priority.hpp:284