Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ble::Connections Class Reference

Singleton container of all the active connections. More...

#include <Connection.hxx>

Inheritance diagram for ble::Connections:
Singleton< Connections >

Public Member Functions

 Connections ()
 Constructor.
 
void register_connection (Defs::ConnHandle handle, Defs::Addr addr, Defs::AddrType addr_type, bool central)
 Register an active connection.
 
void register_disconnect_callback (std::function< void(Connection *connection)> callback)
 Register a callback at disconnection.
 
void disconnect (Connection *conn)
 Called when a connection is disconnected.
 
void disconnect (Defs::ConnHandle handle)
 Called when a connection is disconnected.
 
Connectionlookup_by_address (Defs::Addr addr, Defs::AddrType addr_type)
 Find a connection by its peer address.
 
Connectionlookup_by_handle (Defs::ConnHandle handle)
 Find a connection by its connection handle.
 
size_t get_active_count ()
 Get the number of active connections being tracked by this object.
 

Private Attributes

std::vector< Connectionconnections_
 All the connections managed by the container.
 
std::vector< std::function< void(Connection *connection)> > callbacks_
 Callbacks to be called upon disconnection.
 

Additional Inherited Members

- Static Public Member Functions inherited from Singleton< Connections >
static Connections * instance ()
 
static bool exists ()
 

Detailed Description

Singleton container of all the active connections.

Definition at line 96 of file Connection.hxx.

Constructor & Destructor Documentation

◆ Connections()

ble::Connections::Connections ( )
inline

Constructor.

Definition at line 100 of file Connection.hxx.

Member Function Documentation

◆ disconnect() [1/2]

void ble::Connections::disconnect ( Connection conn)
inline

Called when a connection is disconnected.

Results in the connection being unregistered.

Parameters
connconnection to disconnect

Definition at line 126 of file Connection.hxx.

◆ disconnect() [2/2]

void ble::Connections::disconnect ( Defs::ConnHandle  handle)
inline

Called when a connection is disconnected.

Results in the connection being unregistered.

Parameters
handlehandle belonging to connection to disconnect

Definition at line 148 of file Connection.hxx.

◆ get_active_count()

size_t ble::Connections::get_active_count ( )
inline

Get the number of active connections being tracked by this object.

Returns
number of active connections

Definition at line 203 of file Connection.hxx.

◆ lookup_by_address()

Connection * ble::Connections::lookup_by_address ( Defs::Addr  addr,
Defs::AddrType  addr_type 
)
inline

Find a connection by its peer address.

Parameters
addrpeer address
addr_typepeer address type
Returns
connection instance pointer, else nullptr if not found

Definition at line 171 of file Connection.hxx.

◆ lookup_by_handle()

Connection * ble::Connections::lookup_by_handle ( Defs::ConnHandle  handle)
inline

Find a connection by its connection handle.

Parameters
handleconnection handle
Returns
connection instance pointer, else nullptr if not found

Definition at line 188 of file Connection.hxx.

◆ register_connection()

void ble::Connections::register_connection ( Defs::ConnHandle  handle,
Defs::Addr  addr,
Defs::AddrType  addr_type,
bool  central 
)
inline

Register an active connection.

Parameters
handlehandle to the connection
addrpeer address
addr_typepeer address type
centraltrue if central role, else peripheral role

Definition at line 109 of file Connection.hxx.

◆ register_disconnect_callback()

void ble::Connections::register_disconnect_callback ( std::function< void(Connection *connection)>  callback)
inline

Register a callback at disconnection.

Parameters
callbackcallback to call at disconnection

Definition at line 117 of file Connection.hxx.

Member Data Documentation

◆ callbacks_

std::vector<std::function<void(Connection *connection)> > ble::Connections::callbacks_
private

Callbacks to be called upon disconnection.

Definition at line 212 of file Connection.hxx.

◆ connections_

std::vector<Connection> ble::Connections::connections_
private

All the connections managed by the container.

Definition at line 210 of file Connection.hxx.


The documentation for this class was generated from the following file: