Doxygen with github
Loading...
Searching...
No Matches
ksf::ksApplication Class Referenceabstract

A class that serves as the base for user-defined applications. More...

#include <ksApplication.h>

Public Member Functions

virtual ~ksApplication ()
 Destructor.
 
template<class TComponentType , class... TParams>
std::weak_ptr< TComponentType > addComponent (TParams... arg)
 Instantiates a component of the type defined by the template instance. This function will pass all template-defined parameters to the component constructor.
 
template<class TComponentType >
void findComponents (std::vector< std::weak_ptr< TComponentType > > &outComponents)
 Iterates through all components and returns a vector of weak pointers with components that matches the type passed as a template parameter.
 
template<class TComponentType >
std::weak_ptr< TComponentType > findComponent ()
 Iterates through all components and returns a weak pointer to the first component that matches the type passed as a template parameter.
 
virtual bool init ()=0
 Initializes application.
 
virtual bool loop ()
 Executes application logic loop.
 

Protected Attributes

std::list< std::shared_ptr< ksComponent > > components
 An array with shared_ptr of components (holding main reference).
 

Detailed Description

A class that serves as the base for user-defined applications.

ksApplication implements core application logic, handling the initialization and execution of components.

You must override the init method to build the component stack. Returning false will stop the initialization, and ksAppRotator will move to the next application.

Avoid overriding the loop method unless absolutely necessary. If you do, ensure you call the base loop method and return the result correctly. If any component returns false, the application logic should stop. It is best to add only small pieces of code and return the result of the base loop method, and it's safe to return false early, even before calling the base loop method.

When either init or loop returns false, the application will stop.

Member Function Documentation

◆ addComponent()

template<class TComponentType , class... TParams>
std::weak_ptr< TComponentType > ksf::ksApplication::addComponent ( TParams... arg)
inline

Instantiates a component of the type defined by the template instance. This function will pass all template-defined parameters to the component constructor.

Template Parameters
TComponentTypeA type of the component.
TParams...A list of parameters to be passed to the component constructor.
Parameters
arg...A list of parameters to be passed to the component constructor.
Returns
Weak pointer to the created component.

References components, and ksf::ksComponent::getInstanceType().

Referenced by ksf::comps::ksWifiConfigurator::init().

◆ findComponent()

template<class TComponentType >
std::weak_ptr< TComponentType > ksf::ksApplication::findComponent ( )
inline

Iterates through all components and returns a weak pointer to the first component that matches the type passed as a template parameter.

Template Parameters
TComponentTypeA type of the component to look for.
Returns
Weak pointer to the first component that matches the type passed as a template parameter.

References components, and ksf::ksComponent::getInstanceType().

Referenced by ksf::comps::ksDevicePortal::postInit(), ksf::comps::ksDevStatMqttReporter::postInit(), and ksf::comps::ksMqttConnector::postInit().

◆ findComponents()

template<class TComponentType >
void ksf::ksApplication::findComponents ( std::vector< std::weak_ptr< TComponentType > > & outComponents)
inline

Iterates through all components and returns a vector of weak pointers with components that matches the type passed as a template parameter.

Template Parameters
TComponentTypeA type of the component to look for.
Parameters
outComponentsA vector of weak pointers to components that match the type passed as a template parameter.

References components, and ksf::ksComponent::getInstanceType().

Referenced by ksf::comps::ksDevicePortal::handle_getDeviceParams(), ksf::comps::ksDevicePortal::onWebsocketTextMessage(), and ksf::comps::ksWifiConfigurator::postInit().

◆ init()

virtual bool ksf::ksApplication::init ( )
pure virtual

Initializes application.

Returns
True on success, false otherwise (will break application execution).

◆ loop()

bool ksf::ksApplication::loop ( )
virtual

Executes application logic loop.

Returns
True on success, false otherwise (will break application execution).

References components.


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