1#ifndef BLUETOE_LINK_LAYER_CONNECTION_CALLBACKS_HPP
2#define BLUETOE_LINK_LAYER_CONNECTION_CALLBACKS_HPP
4#include <bluetoe/meta_types.hpp>
8 class connection_details;
11 struct connection_callbacks_meta_type {};
34 template <
typename T, T& Obj >
38 details::connection_callbacks_meta_type,
39 details::valid_link_layer_option_meta_type {};
46 , connection_(
nullptr )
52 addresses_ = addresses;
57 template <
class Connection,
class Radio >
58 void connection_established(
60 Connection& connection,
63 event_type_ = established;
64 connection_ = &connection;
70 template <
class Connection,
class Radio >
73 event_type_ = changed;
74 connection_ = &connection;
80 template <
class Connection,
class Radio >
81 void connection_closed( Connection& connection, Radio& r )
84 connection_ = &connection;
89 template <
class LinkLayer >
90 void handle_connection_events() {
91 if ( event_type_ == established )
93 call_ll_connection_established< T >( Obj, details_, addresses_, connection_data< LinkLayer >() );
95 else if ( event_type_ == changed )
97 call_ll_connection_changed< T >( Obj, details_, connection_data< LinkLayer >() );
99 else if ( event_type_ == closed )
101 call_ll_connection_closed< T >( Obj, connection_data< LinkLayer >() );
105 connection_ =
nullptr;
120 template <
typename LinkLayer >
121 typename LinkLayer::connection_data_t& connection_data()
123 assert( connection_ );
124 return *
static_cast< typename LinkLayer::connection_data_t*
>( connection_ );
127 template <
typename TT,
typename Connection >
128 auto call_ll_connection_established(
132 Connection& connection )
133 ->
decltype(&TT::template ll_connection_established< Connection >)
135 obj.ll_connection_established( details, addr, connection );
140 template <
typename TT,
typename Connection >
142 ->
decltype(&TT::template ll_connection_changed< Connection >)
144 obj.ll_connection_changed( details, connection );
149 template <
typename TT,
typename Connection >
150 auto call_ll_connection_closed( TT& obj, Connection& connection )
151 ->
decltype(&TT::template ll_connection_closed< Connection >)
153 obj.ll_connection_closed( connection );
158 template <
typename TT >
159 void call_ll_connection_established( ... )
163 template <
typename TT >
164 void call_ll_connection_changed( ... )
168 template <
typename TT >
169 void call_ll_connection_closed( ... )
178 struct no_connection_callbacks {
180 details::connection_callbacks_meta_type,
181 details::valid_link_layer_option_meta_type {};
184 void connection_request(
const connection_addresses& ) {}
186 template <
class Connection,
class Radio >
187 void connection_established(
188 const connection_details&,
192 template <
class Connection,
class Radio >
195 template <
class Connection,
class Radio >
196 void connection_closed( Connection&, Radio& ) {}
198 template <
class LinkLayer >
199 void handle_connection_events() {}
local and remote address of a connection
Definition: connection_details.hpp:79
data type to store details of an established link layer connection
Definition: connection_details.hpp:15
provides a type and an instance to call connection related callbacks on.
Definition: connection_callbacks.hpp:35