Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
PresenceHandler Class Reference

Keeps up all the locations each profile is present in. More...

#include <cs_PresenceHandler.h>

Inheritance diagram for PresenceHandler:
Collaboration diagram for PresenceHandler:

Classes

struct  PresenceRecord
 
struct  ProfileLocation
 

Public Member Functions

 PresenceHandler ()
 
virtual ~PresenceHandler ()
 
virtual cs_ret_code_t init () override
 calls listen(); More...
 
std::optional< PresenceStateDescriptiongetCurrentPresenceDescription ()
 Returns a simplified description of the current presence knowledge, each bit in the description indicates if a person is in that room or not. More...
 
void registerPresence (ProfileLocation profileLocation)
 Validates and administrate a presence update. More...
 
virtual void handleEvent (event_t &evt) override
 receive background messages indicating where users are, record the time and place and update the current presence description when necessary More...
 
- Public Member Functions inherited from EventListener
 EventListener ()
 
virtual ~EventListener ()
 unregisters the listener. More...
 
virtual void handleEvent (event_t &event)=0
 Handle events. More...
 
void listen ()
 Registers this with the EventDispatcher. More...
 
- Public Member Functions inherited from Component
template<class T >
T * getComponent (Component *requester=nullptr)
 Returns a component of type T* from _parent->children(), If not found try again with ancestors: _parent-> ... ->_parent->children(). More...
 
virtual cs_ret_code_t init ()
 Components can implement this if they need to get references to sibling or if they need to do specific initialization. More...
 
void parentAllChildren ()
 utility that loops over all elements of getChildren() and setParent on the non-nullptr ones. More...
 
virtual ~Component ()=default
 

Private Member Functions

PresenceRecordclearOldestRecord (ProfileLocation profileLocation)
 finds oldest record and default constructs its present record, then returns the pointer to it. More...
 
void handlePresenceEvent (ProfileLocation profileLocation, bool forwardToMesh)
 Handle an incoming profile-location combination. More...
 
PresenceMutation handleProfileLocation (ProfileLocation profileLocation, bool forwardToMesh)
 Handle an incoming profile-location combination. More...
 
PresenceMutation getMutationType (std::optional< PresenceStateDescription > prevDescription, std::optional< PresenceStateDescription > nextDescription)
 Resolves the type of mutation from previous and next descriptions. More...
 
void sendMeshMessage (ProfileLocation profileLocation)
 Send a mesh message with profile and location. More...
 
void dispatchPresenceChangeEvent (PresenceChange type, ProfileLocation profileLocation={})
 Sends presence change event. More...
 
void dispatchPresenceMutationEvent (PresenceMutation mutation)
 Sends presence mutation event. More...
 
void tickSecond ()
 To be called every second. More...
 

Private Attributes

Store< PresenceRecord, MAX_RECORDS_store
 Stores presence records. More...
 

Static Private Attributes

static const constexpr uint8_t PRESENCE_TIMEOUT_SECONDS = 10
 Number of seconds before presence times out. More...
 
static const constexpr uint8_t PRESENCE_MESH_SEND_THROTTLE_SECONDS = 10
 For each presence entry, send it max every (x + variation) seconds over the mesh. More...
 
static const constexpr uint8_t PRESENCE_MESH_SEND_THROTTLE_SECONDS_VARIATION = 20
 
static const constexpr uint32_t PRESENCE_UNCERTAIN_SECONDS_AFTER_BOOT = 30
 Number of seconds after boot it is assumed to take to receive the location of all devices. More...
 
static const constexpr uint8_t MAX_RECORDS = 20
 Maximum number of presence records that is kept up. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Component
virtual std::vector< Component * > getChildren ()
 Components with children can override this method to return them. More...
 
cs_ret_code_t initChildren ()
 
void setParent (Component *p)
 Children that are instantiated later can also be added individually. More...
 

Detailed Description

Keeps up all the locations each profile is present in.

Sends out event when this changes. Sends out throttled mesh messages when the location of a profile is received.

Constructor & Destructor Documentation

◆ PresenceHandler()

◆ ~PresenceHandler()

virtual PresenceHandler::~PresenceHandler ( )
virtual

Member Function Documentation

◆ clearOldestRecord()

PresenceRecord * PresenceHandler::clearOldestRecord ( ProfileLocation  profileLocation)
private

finds oldest record and default constructs its present record, then returns the pointer to it.

◆ dispatchPresenceChangeEvent()

void PresenceHandler::dispatchPresenceChangeEvent ( PresenceChange  type,
ProfileLocation  profileLocation = {} 
)
private

Sends presence change event.

Parameters
[in]typeType of change.
[in]profileLocationThe relevant profile ID and location.

◆ dispatchPresenceMutationEvent()

void PresenceHandler::dispatchPresenceMutationEvent ( PresenceMutation  mutation)
private

Sends presence mutation event.

This event is deprecated, but still used.

◆ getCurrentPresenceDescription()

std::optional< PresenceStateDescription > PresenceHandler::getCurrentPresenceDescription ( )

Returns a simplified description of the current presence knowledge, each bit in the description indicates if a person is in that room or not.

◆ getMutationType()

PresenceMutation PresenceHandler::getMutationType ( std::optional< PresenceStateDescription prevDescription,
std::optional< PresenceStateDescription nextDescription 
)
private

Resolves the type of mutation from previous and next descriptions.

◆ handleEvent()

virtual void PresenceHandler::handleEvent ( event_t evt)
overridevirtual

receive background messages indicating where users are, record the time and place and update the current presence description when necessary

Implements EventListener.

◆ handlePresenceEvent()

void PresenceHandler::handlePresenceEvent ( ProfileLocation  profileLocation,
bool  forwardToMesh 
)
private

Handle an incoming profile-location combination.

  • Validates profile and location.
  • Calls handleProfileLocation().
  • Dispatches events based on the returned mutation type.

◆ handleProfileLocation()

PresenceMutation PresenceHandler::handleProfileLocation ( ProfileLocation  profileLocation,
bool  forwardToMesh 
)
private

Handle an incoming profile-location combination.

  • Stores the profile-location.
  • Sends a mesh message.
  • Dispatches change event.
Parameters
[in]profileThe profile ID.
[in]locationThe location ID.
[in]forwardToMeshIf true, the update will be pushed into the mesh (throttled).
Returns
Mutation type.

◆ init()

virtual cs_ret_code_t PresenceHandler::init ( )
overridevirtual

calls listen();

Reimplemented from Component.

◆ registerPresence()

void PresenceHandler::registerPresence ( ProfileLocation  profileLocation)

Validates and administrate a presence update.

May include sending a EVT_PRESENCE_CHANGE

◆ sendMeshMessage()

void PresenceHandler::sendMeshMessage ( ProfileLocation  profileLocation)
private

Send a mesh message with profile and location.

◆ tickSecond()

void PresenceHandler::tickSecond ( )
private

To be called every second.

Decreases timeoutCountdownSeconds of the records and dispatches exit-events when necessary.

Member Data Documentation

◆ _store

Store<PresenceRecord, MAX_RECORDS> PresenceHandler::_store
private

Stores presence records.

◆ MAX_RECORDS

const constexpr uint8_t PresenceHandler::MAX_RECORDS = 20
staticconstexprprivate

Maximum number of presence records that is kept up.

Must be smaller than 0xFF.

◆ PRESENCE_MESH_SEND_THROTTLE_SECONDS

const constexpr uint8_t PresenceHandler::PRESENCE_MESH_SEND_THROTTLE_SECONDS = 10
staticconstexprprivate

For each presence entry, send it max every (x + variation) seconds over the mesh.

◆ PRESENCE_MESH_SEND_THROTTLE_SECONDS_VARIATION

const constexpr uint8_t PresenceHandler::PRESENCE_MESH_SEND_THROTTLE_SECONDS_VARIATION = 20
staticconstexprprivate

◆ PRESENCE_TIMEOUT_SECONDS

const constexpr uint8_t PresenceHandler::PRESENCE_TIMEOUT_SECONDS = 10
staticconstexprprivate

Number of seconds before presence times out.

◆ PRESENCE_UNCERTAIN_SECONDS_AFTER_BOOT

const constexpr uint32_t PresenceHandler::PRESENCE_UNCERTAIN_SECONDS_AFTER_BOOT = 30
staticconstexprprivate

Number of seconds after boot it is assumed to take to receive the location of all devices.


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