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

A class that is a base for user-defined application. More...

#include <ksApplication.h>

Public Member Functions

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 is a base for user-defined application.

ksApplication implements core application logic. It is responsible for initializing and running components.

You must override init method to build component stack. You can return false to stop the initialization. In this case, application will be stopped and ksAppRotator will move to the next application.

Do not override loop method until you have a good reason. If you do so, keep in mind that you should call base loop method and return the result properly. If any component returns false, application logic should be stopped. The best way is to add only small piece of code and return the reult of the base loop method. It is also safe to return false early, before calling base loop method.

When init or loop returns false, application will be stopped.

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: