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
meshx::MeshXIoFactory Class Reference

IO Factory Class. More...

#include <meshx_io_factory.hpp>

Public Member Functions

bool registerType (IoType type, IoFactoryFunction factory_func)
 Register IO type factory function.
std::unique_ptr< MeshXIoInterfacecreate (const IoConfig &config)
 Create IO instance.
std::unique_ptr< MeshXIoInterfacecreateFromYaml (const void *yaml_config)
 Create IO instance from YAML configuration.
bool isTypeSupported (IoType type) const
 Check if IO type is supported.

Static Public Member Functions

static MeshXIoFactorygetInstance ()
 Get singleton instance.

Private Member Functions

 MeshXIoFactory ()=default
 ~MeshXIoFactory ()=default
 MeshXIoFactory (const MeshXIoFactory &)=delete
MeshXIoFactoryoperator= (const MeshXIoFactory &)=delete

Private Attributes

std::unordered_map< IoType, IoFactoryFunctionfactory_registry_

Detailed Description

IO Factory Class.

This factory creates IO instances based on configuration.

Constructor & Destructor Documentation

◆ MeshXIoFactory() [1/2]

meshx::MeshXIoFactory::MeshXIoFactory ( )
privatedefault

◆ ~MeshXIoFactory()

meshx::MeshXIoFactory::~MeshXIoFactory ( )
privatedefault

◆ MeshXIoFactory() [2/2]

meshx::MeshXIoFactory::MeshXIoFactory ( const MeshXIoFactory & )
privatedelete

Member Function Documentation

◆ create()

std::unique_ptr< MeshXIoInterface > meshx::MeshXIoFactory::create ( const IoConfig & config)

Create IO instance.

Parameters
configIO configuration
Returns
std::unique_ptr<MeshXIoInterface> IO instance pointer
69 {
70 // Check if type is supported
71 auto it = factory_registry_.find(config.type);
72 if (it == factory_registry_.end()) {
73 // Type not supported
74 return nullptr;
75 }
76
77 // Call factory function
78 return it->second(config.logical_pin, config.name.c_str());
79}
std::unordered_map< IoType, IoFactoryFunction > factory_registry_
Definition meshx_io_factory.hpp:122

◆ createFromYaml()

std::unique_ptr< MeshXIoInterface > meshx::MeshXIoFactory::createFromYaml ( const void * yaml_config)

Create IO instance from YAML configuration.

Parameters
yaml_configYAML configuration node
Returns
std::unique_ptr<MeshXIoInterface> IO instance pointer
87 {
88 // Note: YAML parsing would be implemented here
89 // For now, this is a placeholder implementation
90 (void)yaml_config;
91 return nullptr;
92}

◆ getInstance()

MeshXIoFactory & meshx::MeshXIoFactory::getInstance ( )
static

Get singleton instance.

Returns
MeshXIoFactory& Reference to singleton instance
26 {
27 static MeshXIoFactory instance;
28
29 // Register default factory functions on first call
30 static bool initialized = false;
31 if (!initialized) {
32 instance.registerType(IoType::GPIO, createGpioInstance);
33 instance.registerType(IoType::PWM, createPwmInstance);
34 initialized = true;
35 }
36
37 return instance;
38}
bool initialized
Definition meshx_shell.c:27
@ PWM
Definition meshx_io_factory.hpp:26
@ GPIO
Definition meshx_io_factory.hpp:25
std::unique_ptr< MeshXIoInterface > createPwmInstance(uint8_t logical_pin, const char *name)
Factory function for creating PWM instances.
Definition meshx_pwm_impl.cpp:297
std::unique_ptr< MeshXIoInterface > createGpioInstance(uint8_t logical_pin, const char *name)
Factory function for creating GPIO instances.
Definition meshx_gpio_impl.cpp:354

◆ isTypeSupported()

bool meshx::MeshXIoFactory::isTypeSupported ( IoType type) const

Check if IO type is supported.

Parameters
typeIO type to check
Returns
true if type is supported
false if type is not supported
101 {
102 return factory_registry_.find(type) != factory_registry_.end();
103}

◆ operator=()

MeshXIoFactory & meshx::MeshXIoFactory::operator= ( const MeshXIoFactory & )
privatedelete

◆ registerType()

bool meshx::MeshXIoFactory::registerType ( IoType type,
IoFactoryFunction factory_func )

Register IO type factory function.

Parameters
typeIO type
factory_funcFactory function
Returns
true if registration successful
false if registration failed (type already registered)
48 {
49 if (factory_func == nullptr) {
50 return false;
51 }
52
53 auto it = factory_registry_.find(type);
54 if (it != factory_registry_.end()) {
55 // Type already registered
56 return false;
57 }
58
59 factory_registry_[type] = factory_func;
60 return true;
61}

Field Documentation

◆ factory_registry_

std::unordered_map<IoType, IoFactoryFunction> meshx::MeshXIoFactory::factory_registry_
private

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