BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
attribute_generator.hpp
1#ifndef BLUETOE_ATTRIBUTE_GENERATOR_HPP
2#define BLUETOE_ATTRIBUTE_GENERATOR_HPP
3
4#include <tuple>
6
7namespace bluetoe {
8namespace details {
9
15 template < typename, typename, std::size_t, typename, typename, typename ... Options >
16 struct generate_attribute;
17
27 template < typename Attributes, typename CCCDIndices, std::size_t ClientCharacteristicIndex, typename Service, typename Server, typename ... Options >
28 struct generate_attribute_list;
29
30 template < typename CCCDIndices,std::size_t ClientCharacteristicIndex, typename Service, typename Server, typename ... Options >
31 struct generate_attribute_list< std::tuple<>, CCCDIndices, ClientCharacteristicIndex, Service, Server, std::tuple< Options... > >
32 {
33 static const attribute attribute_at( std::size_t )
34 {
35 assert( !"should not happen" );
36 return attribute();
37 }
38 };
39
40 template < typename ... Attributes, typename ... CCCDIndices, std::size_t ClientCharacteristicIndex, typename Service, typename Server, typename ... Options >
41 struct generate_attribute_list< std::tuple< Attributes... >, std::tuple< CCCDIndices... >, ClientCharacteristicIndex, Service, Server, std::tuple< Options... > >
42 {
43 static const attribute attribute_at( std::size_t index )
44 {
45 return attributes[ index ];
46 }
47
48 static const attribute attributes[ sizeof ...(Attributes) ];
49 };
50
51 template < typename ... Attributes, typename ... CCCDIndices, std::size_t ClientCharacteristicIndex, typename Service, typename Server, typename ... Options >
52 const attribute generate_attribute_list< std::tuple< Attributes... >, std::tuple< CCCDIndices... >, ClientCharacteristicIndex, Service, Server, std::tuple< Options... > >::attributes[ sizeof ...(Attributes) ] =
53 {
54 generate_attribute< Attributes, std::tuple< CCCDIndices... >, ClientCharacteristicIndex, Service, Server, Options... >::attr...
55 };
56
57 template < typename OptionsList, typename MetaTypeList, typename OptionsDefault = std::tuple<> >
58 struct count_attributes;
59
60 template < typename OptionsList, typename ... MetaTypes, typename OptionsDefault >
61 struct count_attributes< OptionsList, std::tuple< MetaTypes... >, OptionsDefault >
62 {
63 using attribute_generation_parameters = typename group_by_meta_types_without_empty_groups<
64 typename add_type< OptionsList, OptionsDefault >::type,
65 MetaTypes...
66 >::type;
67
68 enum { number_of_attributes = std::tuple_size< attribute_generation_parameters >::value };
69 };
70
71 template < typename OptionsList, typename MetaTypeList, typename CCCDIndices, typename OptionsDefault = std::tuple<> >
72 struct generate_attributes;
73
74 template < typename OptionsList, typename ... MetaTypes, typename CCCDIndices, typename OptionsDefault >
75 struct generate_attributes< OptionsList, std::tuple< MetaTypes... >, CCCDIndices, OptionsDefault >
76 : count_attributes< OptionsList, std::tuple< MetaTypes... >, OptionsDefault >
77 {
78 using attribute_generation_parameters = typename group_by_meta_types_without_empty_groups<
79 typename add_type< OptionsList, OptionsDefault >::type,
80 MetaTypes...
81 >::type;
82
83 attribute_generation_parameters get_attribute_generation_parameters() { return attribute_generation_parameters(); }
84
85 template < std::size_t ClientCharacteristicIndex, typename Service, typename Server >
86 static const attribute attribute_at( std::size_t index )
87 {
88 return generate_attribute_list<
89 attribute_generation_parameters,
90 CCCDIndices,
91 ClientCharacteristicIndex,
92 Service,
93 Server,
94 OptionsList
95 >::attribute_at( index );
96 }
97 };
98
100}
101}
102
103#endif // include guard