17 #ifndef HF_CORE_GROUP_TABLE_H 18 #define HF_CORE_GROUP_TABLE_H 72 typedef enum _Attributes
88 Entry(uint16_t _group = 0, uint8_t _unit = 0):
94 static constexpr uint16_t
min_size =
sizeof(uint16_t)
98 uint16_t
size()
const;
166 uint16_t
group = 0x0000, uint8_t
unit = 0x00):
197 uint16_t start = offset;
202 return offset - start;
210 uint16_t start = offset;
215 return offset - start;
228 ReadEntries(uint8_t _start = 0, uint8_t _count = 1):
235 static constexpr uint16_t min_size =
sizeof(uint8_t)
284 uint8_t _start = 0, uint8_t _count = 0):
319 uint16_t _start = offset;
324 offset += array.
write(offset, (uint8_t)
entries.size());
327 [&array, &offset](
const Entry &entry)
329 offset += entry.pack(array, offset);
332 return offset - _start;
340 uint16_t _start = offset;
347 offset += array.
read(offset, count);
353 for (
int i = 0; i < count; ++i)
356 offset += entry.
unpack(array, offset);
360 return offset - _start;
380 virtual void clear() = 0;
388 virtual void for_each(uint16_t group,
389 std::function<
void(
const Entry &)> func)
const = 0;
406 typedef std::vector<Entry> Container;
408 uint16_t
size()
const;
416 void for_each(uint16_t group, std::function<
void(
const Entry &)> func)
const;
434 bool any_of(uint16_t group, uint8_t unit)
const;
571 virtual IEntries &entries()
const = 0;
582 template<
typename _Entries = GroupTable::Entries>
583 class Server:
public IServer
593 IEntries &entries()
const 595 return *(
const_cast<_Entries *
>(&db));
638 void add(
const uint16_t device,
const Entry &entry)
667 void add(
const uint16_t device, uint16_t group, uint8_t
unit)
690 void remove(
const uint16_t device,
const Entry &entry)
719 void remove(
const uint16_t device, uint16_t group, uint8_t
unit)
792 void read_entries(
const uint16_t device,
const uint8_t offset,
const uint8_t count)
859 inline bool operator==(
const Entry &lhs,
const Entry &rhs)
861 return lhs.group == rhs.group && lhs.unit == rhs.unit;
864 inline bool operator!=(
const Entry &lhs,
const Entry &rhs)
866 return !(lhs == rhs);
904 std::ostream &
operator<<(std::ostream &stream,
IServer(Unit0 &unit)
Constructor.
Entry const & operator[](uint8_t index) const
Retrive the entry at the given index.
Group Table Service : Parent.
static constexpr uint8_t ID
Attribute UID.
uint16_t write(uint16_t offset, uint8_t data)
Write a byte into the array at the given offset.
static constexpr bool WRITABLE
Attribute Read/Write.
bool response(Message::Type type)
Check if message is a response.
std::ostream & operator<<(std::ostream &stream, const HF::Core::GroupTable::CMD command)
Convert the given command into a string and write it to the given stream.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Core::GroupTable::Ser...
Server DefaultServer
Helper typedef.
void read_entries(const uint16_t device, const uint8_t offset, const uint8_t count)
Send a HAN-FUN message containing a GroupTable::REMOVE_ALL_CMD, to the device with the given address...
This represent the special unit with ID/UID = 0.
void read_entries(const Protocol::Address &addr, const ReadEntries ¶ms)
Send a HAN-FUN message containing a GroupTable::READ_ENTRIES_CMD, to the given network address...
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
Default implementation of the IEntries API.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Group Table persistent storage API.
Helper class to handle the Number Of Entries attribute for the Group Table service.
Return all mandatory attributes for the interface.
This file contains the forward declarations of the core services and interfaces implementing classes...
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
HF::Attributes::UIDS attributes(uint8_t pack_id=HF::Attributes::Pack::MANDATORY) const
Return a vector containing the attribute UIDs, for the given pack ID.
void remove_all(uint16_t device)
Send a HAN-FUN message containing a GroupTable::REMOVE_ALL_CMD, to the device with the given address...
virtual Entry const & operator[](uint8_t index) const =0
Retrive the entry at the given index.
uint8_t _number_of_max_entries
Number Of Max Entries.
void add(const uint16_t device, const Entry &entry)
Send a HAN-FUN message containing a GroupTable::ADD_CMD, to the given device and the given entry...
Scheduling::Entry< Interval > Entry
Specific part for the Event Scheduler of the HF::Scheduling::Entry.
This class the response for a GroupTable::READ_ENTRIES_CMD command.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
uint16_t size() const
Number bytes needed to serialize the message.
Helper class to handle the Number Of Max Entries attribute for the Group Table service.
void add(const Protocol::Address &addr, const Entry &entry)
Send a HAN-FUN message containing a GroupTable::ADD_CMD, to the given network address.
uint8_t number_of_max_entries() const
Get the Number Of Max Entries for the Group Table server.
This file contains the definitions for the HAN-FUN protocol messages.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
virtual void removed_all(const Protocol::Address &addr, const Protocol::Response &response)
Callback for processing the response of a GroupTable::REMOVE_ALL_CMD.
Group Table Service : Client side implementation.
bool any_of(uint16_t group, uint8_t unit) const
Check if there exists any entry for the group/unit address given.
uint8_t number_of_entries() const
Get the Number Of Entries for the Group Table server.
virtual void removed(const Protocol::Address &addr, const GroupTable::Response &response)
Callback for processing the response of a GroupTable::REMOVE_CMD.
std::vector< Entry > entries
Vector containing the entries in the response.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Group Table Service : Server side implementation.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
Read Entries command UID.
uint16_t size() const
Number bytes needed to serialize the message.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
void clear()
Clear all entries in database.
Base(Unit0 &unit)
Constructor.
Number Of Entries attribute UID.
uint16_t uid() const
This method returns the interface UID.
This represents a group table entry data structure.
uint8_t unit
Unit ID to route the group messages to.
HF::Interface const * owner() const
Unit0 & unit() const
The device this unit is associated with.
uint16_t size() const
Number bytes needed to serialize the message.
virtual ReadEntriesResponse read_entries(const Protocol::Address &addr, const ReadEntries ¶ms)
Callback that is called when a GroupTable::READ_ENTRIES_CMD, is received.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
This class represents a byte array.
Number Of Max Entries attribute UID.
uint8_t count
Number of entries to read.
virtual Common::Result add(const Protocol::Address &addr, const Entry &entry)
Callback that is called when a GroupTable::ADD_CMD, is received.
void add(const uint16_t device, uint16_t group, uint8_t unit)
Send a HAN-FUN message containing a GroupTable::ADD_CMD, to the given device, for the given group and...
static constexpr uint16_t min_size
Minimum required data size for pack/unpack.
uint16_t payload_size(Protocol::Message::Interface &itf) const
Return the minimal payload size that a message should hold when addressed at the given interface...
Group Table interface UID.
void for_each(uint16_t group, std::function< void(const Entry &)> func) const
Call the given function for all the entries with given group address.
void add(const Protocol::Address &addr, uint16_t group, uint8_t unit)
Send a HAN-FUN message containing a GroupTable::ADD_CMD, to the given network address, for the given group and unit.
This class contains the required parameters for a GroupTable::READ_ENTRIES_CMD command.
Container db
Group table entries database.
Base class for responses.
virtual Common::Result remove_all(const Protocol::Address &addr)
Callback that is called when a GroupTable::REMOVE_ALL_CMD, is received.
virtual void for_each(uint16_t group, std::function< void(const Entry &)> func) const =0
Call the given function for all the entries with given group address.
void read_entries(const uint16_t device, const ReadEntries ¶ms)
Send a HAN-FUN message containing a GroupTable::REMOVE_ALL_CMD, to the device with the given address...
virtual void added(const Protocol::Address &addr, const GroupTable::Response &response)
Callback for processing the response of a GroupTable::ADD_CMD.
Response(Common::Result code, const Entry &entry)
Constructor.
Interface/Service Attribute API.
uint16_t size() const
Number bytes needed to serialize the message.
uint16_t read(uint16_t offset, uint8_t &data) const
Read the byte at offset into data.
uint16_t size() const
Number bytes needed to serialize the message.
Parent class for the response messages.
Class template for all interfaces role implementations.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
uint8_t start
Offset to start reading entries from.
Response(Common::Result code=Common::Result::FAIL_UNKNOWN, uint16_t group=0x0000, uint8_t unit=0x00)
Constructor.
static constexpr bool WRITABLE
Attribute Read/Write.
Helper template class to declare an attribute with the given T type.
static constexpr uint8_t ID
Attribute UID.
uint8_t start
Offset to start reading entries from.
Attribute(const uint16_t interface, const uint8_t uid, const HF::Interface *__owner, uint8_t data, bool writable=false)
Attribute template constructor.
static constexpr uint16_t min_size
Minimum number of bytes required by this message.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
ReadEntriesResponse(Common::Result _code=Common::Result::OK, uint8_t _start=0, uint8_t _count=0)
Constructor.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
virtual ~IServer()
Destructor.
Common interface for all Interfaces.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
void read_entries(const Protocol::Address &addr, const uint8_t offset, const uint8_t count)
Send a HAN-FUN message containing a GroupTable::READ_ENTRIES_CMD, to the given network address...
Class template for all core services implementations.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t group
Group address the entry belongs to.
Result
Commands result codes.
uint16_t size() const
Return the number of entries in the container.
HF::Attributes::IAttribute * create_attribute(HF::Core::AttributeReporting::IServer *server, uint8_t uid)
Create an attribute object that can hold the attribute with the given uid.
virtual void clear()=0
Clear all entries in database.
void remove_all(const Protocol::Address &addr)
Send a HAN-FUN message containing a GroupTable::REMOVE_ALL_CMD, to the given network address...
uint16_t payload_size(Protocol::Message::Interface &itf) const
Return the minimal payload size that a message should hold when addressed at the given interface...
Basic API for persistent storage implementations.
Top-level namespace for the HAN-FUN library.