MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshXElementRegistry Class Reference

Singleton registry for MeshX elements. More...

#include <meshx_element_registry.hpp>

Public Member Functions

void register_element (meshXElementIF *element)
 Register an element instance.
void unregister_element (uint16_t element_idx)
 Unregister an element instance.
meshXElementIFfind_element (uint16_t element_idx)
 Find an element instance by its index.
template<typename T>
T * find_and_cast (uint16_t element_idx, meshx_element_type_t expected_variant)
 Find and cast an element instance.
std::map< uint16_t, meshXElementIF * > get_all_elements ()
 Get all registered elements.
 meshXElementRegistry (const meshXElementRegistry &)=delete
meshXElementRegistryoperator= (const meshXElementRegistry &)=delete

Static Public Member Functions

static meshXElementRegistryget_instance ()

Private Member Functions

 meshXElementRegistry ()=default

Private Attributes

std::map< uint16_t, meshXElementIF * > element_map
std::mutex registry_mutex

Detailed Description

Singleton registry for MeshX elements.

Constructor & Destructor Documentation

◆ meshXElementRegistry() [1/2]

meshXElementRegistry::meshXElementRegistry ( )
privatedefault

◆ meshXElementRegistry() [2/2]

meshXElementRegistry::meshXElementRegistry ( const meshXElementRegistry & )
delete

Member Function Documentation

◆ find_and_cast()

template<typename T>
T * meshXElementRegistry::find_and_cast ( uint16_t element_idx,
meshx_element_type_t expected_variant )
inline

Find and cast an element instance.

Template Parameters
TThe target element type.
Parameters
element_idxIndex of the element.
expected_variantThe expected variant type discriminator.
Returns
T* Pointer to the casted element instance, or nullptr if not found or type mismatch.
85 {
86 meshXElementIF* base = find_element(element_idx);
87 if (base && base->get_element_variant() == expected_variant)
88 {
89 return static_cast<T*>(base);
90 }
91 return nullptr;
92 }
virtual meshx_element_type_t get_element_variant(void) const =0
Get the element variant.
meshXElementIF * find_element(uint16_t element_idx)
Find an element instance by its index.
Definition meshx_element_registry.hpp:65

◆ find_element()

meshXElementIF * meshXElementRegistry::find_element ( uint16_t element_idx)
inline

Find an element instance by its index.

Parameters
element_idxIndex of the element.
Returns
meshXElementIF* Pointer to the element instance, or nullptr if not found.
66 {
67 std::lock_guard<std::mutex> lock(registry_mutex);
68 auto it = element_map.find(element_idx);
69 if (it != element_map.end())
70 {
71 return it->second;
72 }
73 return nullptr;
74 }
std::mutex registry_mutex
Definition meshx_element_registry.hpp:28
std::map< uint16_t, meshXElementIF * > element_map
Definition meshx_element_registry.hpp:27

◆ get_all_elements()

std::map< uint16_t, meshXElementIF * > meshXElementRegistry::get_all_elements ( )
inline

Get all registered elements.

Returns
std::map<uint16_t, meshXElementIF*> A copy of the element map.
99 {
100 std::lock_guard<std::mutex> lock(registry_mutex);
101 return element_map;
102 }

◆ get_instance()

meshXElementRegistry & meshXElementRegistry::get_instance ( )
inlinestatic
34 {
35 static meshXElementRegistry instance;
36 return instance;
37 }
meshXElementRegistry()=default

◆ operator=()

meshXElementRegistry & meshXElementRegistry::operator= ( const meshXElementRegistry & )
delete

◆ register_element()

void meshXElementRegistry::register_element ( meshXElementIF * element)
inline

Register an element instance.

Parameters
elementPointer to the element interface.
44 {
45 if (!element) return;
46 std::lock_guard<std::mutex> lock(registry_mutex);
47 element_map[element->get_element_idx()] = element;
48 }
uint16_t get_element_idx(void) const
Definition meshx_fwd_decl.hpp:99

◆ unregister_element()

void meshXElementRegistry::unregister_element ( uint16_t element_idx)
inline

Unregister an element instance.

Parameters
element_idxIndex of the element to unregister.
55 {
56 std::lock_guard<std::mutex> lock(registry_mutex);
57 element_map.erase(element_idx);
58 }

Field Documentation

◆ element_map

std::map<uint16_t, meshXElementIF*> meshXElementRegistry::element_map
private

◆ registry_mutex

std::mutex meshXElementRegistry::registry_mutex
private

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