HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::Interfaces::Container< Base, Proxies > Class Template Reference

Helper class to add optional interfaces to other classes. More...

#include <interface.h>

+ Collaboration diagram for HF::Interfaces::Container< Base, Proxies >:

Public Member Functions

 Container (Base &base)
 Constructor. More...
 
Common::Result handle (Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
 Handle incoming messages from the network. More...
 
void attributes (HF::Attributes::List &attr_list, Common::Interface itf, uint8_t pack_id, const HF::Attributes::UIDS &uids) const
 Return a list of all the attributes for a given interface, pack id and list of attributes UID's. More...
 
std::vector< Common::Interfaceinterfaces () const
 Return the list of interfaces present in the wrapper. More...
 
template<uint8_t N>
const std::tuple_element< N, interfaces_t >::type::base * get () const
 Retrieve a pointer to the N optional interface implemented by this unit. More...
 

Protected Member Functions

void for_each (std::function< void(HF::Interface &)> func) const
 Call the given function for all the interfaces. More...
 
void for_each (std::function< void(HF::Interface &)> func)
 Call the given function for all the interfaces. More...
 
template<uint8_t N, typename Head , typename... Tail>
HF::Interfacefind (uint16_t itf_uid) const
 Find the interface with the given UID. More...
 
template<uint8_t N>
HF::Interfacefind (uint16_t itf_uid) const
 Final template instantiation that finds the wrapped interface with the given UID. More...
 
template<uint8_t N, typename Head , typename... Tail>
void for_each (std::function< void(HF::Interface &)> func) const
 Helper template function to implement the HF::Units::Unit::for_each functionality. More...
 
template<uint8_t N>
void for_each (std::function< void(HF::Interface &)> func) const
 Helper template function to implement the HF::Units::Unit::for_each functionality. More...
 
template<uint8_t N, typename Head , typename... Tail>
void attributes_itf (HF::Attributes::List &attrs, Common::Interface itf, uint8_t pack_id, const HF::Attributes::UIDS &uids) const
 Helper function used to provide HF::Units::Unit::attributes functionality. More...
 
template<uint8_t N>
void attributes_itf (HF::Attributes::List &attrs, Common::Interface itf, uint8_t pack_id, const HF::Attributes::UIDS &uids) const
 Helper function used to provide HF::Units::Unit::attributes functionality. More...
 

Detailed Description

template<typename Base, typename... Proxies>
class HF::Interfaces::Container< Base, Proxies >

Helper class to add optional interfaces to other classes.

Definition at line 445 of file interface.h.

Constructor & Destructor Documentation

◆ Container()

template<typename Base, typename... Proxies>
HF::Interfaces::Container< Base, Proxies >::Container ( Base base)
inline

Constructor.

Parameters
[in]basereference to the object containing the interfaces.

Definition at line 459 of file interface.h.

459  : _interfaces(Proxies(base) ...)
460  {}

Member Function Documentation

◆ attributes()

template<typename Base, typename... Proxies>
void HF::Interfaces::Container< Base, Proxies >::attributes ( HF::Attributes::List attr_list,
Common::Interface  itf,
uint8_t  pack_id,
const HF::Attributes::UIDS uids 
) const
inline

Return a list of all the attributes for a given interface, pack id and list of attributes UID's.

Parameters
[in]itfinterface UID.
[in]pack_idattribute pack id.
[in]uidslist of attributes UID's.
Returns
attribute list.
Parameters
[in,out]attr_listlist to place the attributes UIDs.

Definition at line 483 of file interface.h.

Referenced by HF::Profiles::ProfileN< DIMMABLE_COLOUR_BULB, OnOffServer, ColourControlServer, LevelControlServer >::attributes().

485  {
486  attributes_itf<0, Proxies...>(attr_list, itf, pack_id, uids);
487  }
void attributes_itf(HF::Attributes::List &attrs, Common::Interface itf, uint8_t pack_id, const HF::Attributes::UIDS &uids) const
Helper function used to provide HF::Units::Unit::attributes functionality.
Definition: interface.h:653
+ Here is the caller graph for this function:

◆ attributes_itf() [1/2]

template<typename Base, typename... Proxies>
template<uint8_t N, typename Head , typename... Tail>
void HF::Interfaces::Container< Base, Proxies >::attributes_itf ( HF::Attributes::List attrs,
Common::Interface  itf,
uint8_t  pack_id,
const HF::Attributes::UIDS uids 
) const
inlineprotected

Helper function used to provide HF::Units::Unit::attributes functionality.

Parameters
[out]attrsattribute list to append the attributes for the interface to.
[in]itfinterface to get the attributes for.
[in]pack_idattributes pack id to use when retrieving the attributes.
[in]uidslist of attribute uids to get attributes for if pack_id is HF::Attributes::Pack::DYNAMIC.
Template Parameters
Nindex in the wrapped interfaces tuple to check if UID matches.
Headclass for the wrapped interface at the given index.
Tailthe classes associated with the remaining wrapped interfaces.

Definition at line 653 of file interface.h.

Referenced by HF::Interfaces::Container< HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... >, Proxy< ITF, HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... > >... >::attributes(), and HF::Interfaces::Container< HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... >, Proxy< ITF, HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... > >... >::attributes_itf().

655  {
656  const auto &head = std::get<N>(this->_interfaces);
657 
658  if (head.uid() == itf.id)
659  {
660  auto result = HF::Attributes::get(head, pack_id, uids);
661  attrs.merge(result);
662  }
663  else
664  {
665  attributes_itf<N + 1, Tail...>(attrs, itf, pack_id, uids);
666  }
667  }
List get(const HF::Interface &itf, uint8_t pack_id, const UIDS &uids)
Get a list with the attributes for the given interface, pack id or the uids passed in...
void attributes_itf(HF::Attributes::List &attrs, Common::Interface itf, uint8_t pack_id, const HF::Attributes::UIDS &uids) const
Helper function used to provide HF::Units::Unit::attributes functionality.
Definition: interface.h:653
+ Here is the caller graph for this function:

◆ attributes_itf() [2/2]

template<typename Base, typename... Proxies>
template<uint8_t N>
void HF::Interfaces::Container< Base, Proxies >::attributes_itf ( HF::Attributes::List attrs,
Common::Interface  itf,
uint8_t  pack_id,
const HF::Attributes::UIDS uids 
) const
inlineprotected

Helper function used to provide HF::Units::Unit::attributes functionality.

Template expansion end.

Parameters
[out]attrsattribute list to append the attributes for the interface to.
[in]itfinterface to get the attributes for.
[in]pack_idattributes pack id to use when retrieving the attributes.
[in]uidslist of attribute uids to get attributes for if pack_id is HF::Attributes::Pack::DYNAMIC.
Template Parameters
Nindex in the wrapped interfaces tuple to check if UID matches.

Definition at line 683 of file interface.h.

685  {
686  UNUSED(attrs);
687  UNUSED(itf);
688  UNUSED(pack_id);
689  UNUSED(uids);
690  }
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.

◆ find() [1/2]

template<typename Base, typename... Proxies>
template<uint8_t N, typename Head , typename... Tail>
HF::Interface* HF::Interfaces::Container< Base, Proxies >::find ( uint16_t  itf_uid) const
inlineprotected

Find the interface with the given UID.

Parameters
itf_uidthe interface UID to search for in the wrapped interfaces.
Template Parameters
Nindex in the interfaces tuple to check if UID matches.
Headclass for the interface at the given index.
Tailthe classes associated with the remaining optional interfaces.
Returns
a pointer to the interface or nullptr if the interface is not present.

Definition at line 570 of file interface.h.

Referenced by HF::Interfaces::Container< HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... >, Proxy< ITF, HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... > >... >::find(), and HF::Interfaces::Container< HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... >, Proxy< ITF, HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... > >... >::handle().

571  {
572  static_assert(std::is_base_of<HF::Interface, Head>::value,
573  "Head must be of type HF::Interface");
574 
575  const Head &head = std::get<N>(_interfaces);
576 
577  if (head.uid() == itf_uid)
578  {
579  return const_cast<Head *>(&head);
580  }
581  else
582  {
583  return find<N + 1, Tail...>(itf_uid);
584  }
585  }
HF::Interface * find(uint16_t itf_uid) const
Find the interface with the given UID.
Definition: interface.h:570
+ Here is the caller graph for this function:

◆ find() [2/2]

template<typename Base, typename... Proxies>
template<uint8_t N>
HF::Interface* HF::Interfaces::Container< Base, Proxies >::find ( uint16_t  itf_uid) const
inlineprotected

Final template instantiation that finds the wrapped interface with the given UID.

Parameters
itf_uidthe interface UID to search for in the wrapped interfaces.
Template Parameters
Nindex in the interfaces tuple to check if UID matches.
Returns
nullptr, i.e. the interface is not present.

Definition at line 598 of file interface.h.

599  {
600  UNUSED(itf_uid);
601  return nullptr;
602  }
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.

◆ for_each() [1/4]

template<typename Base, typename... Proxies>
void HF::Interfaces::Container< Base, Proxies >::for_each ( std::function< void(HF::Interface &)>  func) const
inlineprotected

Call the given function for all the interfaces.

Parameters
[in]funcfunction to call with each of the optional implemented interfaces.

Definition at line 540 of file interface.h.

Referenced by HF::Interfaces::Container< HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... >, Proxy< ITF, HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... > >... >::for_each(), and HF::Interfaces::Container< HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... >, Proxy< ITF, HF::Units::Unit< HF::Profiles::SimpleOnOffSwitch, ITF... > >... >::interfaces().

541  {
542  for_each<0, Proxies...>(func);
543  }
void for_each(std::function< void(HF::Interface &)> func) const
Call the given function for all the interfaces.
Definition: interface.h:540
+ Here is the caller graph for this function:

◆ for_each() [2/4]

template<typename Base, typename... Proxies>
void HF::Interfaces::Container< Base, Proxies >::for_each ( std::function< void(HF::Interface &)>  func)
inlineprotected

Call the given function for all the interfaces.

Parameters
[in]funcfunction to call with each of the optional implemented interfaces.

Definition at line 550 of file interface.h.

551  {
552  for_each<0, Proxies...>(func);
553  }
void for_each(std::function< void(HF::Interface &)> func) const
Call the given function for all the interfaces.
Definition: interface.h:540

◆ for_each() [3/4]

template<typename Base, typename... Proxies>
template<uint8_t N, typename Head , typename... Tail>
void HF::Interfaces::Container< Base, Proxies >::for_each ( std::function< void(HF::Interface &)>  func) const
inlineprotected

Helper template function to implement the HF::Units::Unit::for_each functionality.

Parameters
[in]funcfunction to call with the reference for the wrapped interface at index N.
Template Parameters
Nindex in the wrapped interfaces tuple to check if UID matches.
Headclass for the wrapped interface at the given index.
Tailthe classes associated with the remaining wrapped interfaces.

Definition at line 615 of file interface.h.

616  {
617  const auto &head = std::get<N>(this->_interfaces);
618 
619  func(*(const_cast<HF::Interface *>(static_cast<const HF::Interface *>(&head))));
620 
621  for_each<N + 1, Tail...>(func);
622  }
void for_each(std::function< void(HF::Interface &)> func) const
Call the given function for all the interfaces.
Definition: interface.h:540

◆ for_each() [4/4]

template<typename Base, typename... Proxies>
template<uint8_t N>
void HF::Interfaces::Container< Base, Proxies >::for_each ( std::function< void(HF::Interface &)>  func) const
inlineprotected

Helper template function to implement the HF::Units::Unit::for_each functionality.

Parameters
[in]funcfunction to call with the reference for the wrapped interface at index N.
Template Parameters
Nindex in the wrapped interfaces tuple to check if UID matches.

Definition at line 633 of file interface.h.

634  {
635  UNUSED(func);
636  }
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.

◆ get()

template<typename Base, typename... Proxies>
template<uint8_t N>
const std::tuple_element<N, interfaces_t>::type::base* HF::Interfaces::Container< Base, Proxies >::get ( ) const
inline

Retrieve a pointer to the N optional interface implemented by this unit.

Template Parameters
Nindex of the interface to retrieve the pointer to.
Returns
a pointer to the optional implemented interface.

Definition at line 528 of file interface.h.

529  {
530  return &std::get<N>(_interfaces);
531  }

◆ handle()

template<typename Base, typename... Proxies>
Common::Result HF::Interfaces::Container< Base, Proxies >::handle ( Protocol::Packet packet,
Common::ByteArray payload,
uint16_t  offset 
)
inline

Handle incoming messages from the network.

Parameters
[in]packetthe packet receive from the network.
[in]payloadthe byte array containing the data received from the network.
[in]offsetthe offset the payload start at in the byte array.
Returns
the result of the message processing.

Definition at line 463 of file interface.h.

Referenced by HF::Profiles::ProfileN< DIMMABLE_COLOUR_BULB, OnOffServer, ColourControlServer, LevelControlServer >::handle().

465  {
466  HF::Interface *itf = find<0, Proxies...>(packet.message.itf.id);
467 
468  if (itf != nullptr)
469  {
470  return itf->handle(packet, payload, offset);
471  }
472  else
473  {
475  }
476  }
HF::Interface * find(uint16_t itf_uid) const
Find the interface with the given UID.
Definition: interface.h:570
Fail - Not Supported.
virtual Common::Result handle(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)=0
Handle incoming messages from the network.
Common interface for all Interfaces.
Definition: interface.h:43
+ Here is the caller graph for this function:

◆ interfaces()

template<typename Base, typename... Proxies>
std::vector<Common::Interface> HF::Interfaces::Container< Base, Proxies >::interfaces ( ) const
inline

Return the list of interfaces present in the wrapper.

Returns
a vector containing the UIDs for the interfaces wrapped by this class.

Definition at line 495 of file interface.h.

496  {
497  std::vector<Common::Interface> result;
498  result.reserve(sizeof ... (Proxies));
499 
500  Common::Interface temp;
501  /* *INDENT-OFF* */
502  for_each ([&result, &temp](HF::Interface &itf)
503  {
504  temp.id = itf.uid ();
505  temp.role = itf.role ();
506  result.push_back (temp);
507  });
508  /* *INDENT-ON* */
509 
510  return result;
511  }
void for_each(std::function< void(HF::Interface &)> func) const
Call the given function for all the interfaces.
Definition: interface.h:540
virtual Interface::Role role() const =0
Return the Interface::Role this interface implements.
Common interface for all Interfaces.
Definition: interface.h:43
virtual uint16_t uid() const =0
This method returns the interface UID.

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