17 #ifndef HF_CORE_GROUP_MANAGEMENT_H 18 #define HF_CORE_GROUP_MANAGEMENT_H 27 #include <forward_list> 34 namespace Concentrator
43 namespace GroupManagement
67 namespace GroupManagement
90 typedef enum _Attributes
118 static constexpr uint16_t
min_size =
sizeof(uint16_t);
121 uint16_t
size()
const;
147 typedef std::vector<Member> Container;
205 const Member member(device, unit);
233 bool exists(uint16_t device, uint8_t unit)
235 const Member member(device, unit);
259 bool add(uint16_t device, uint8_t unit)
261 const Member member(device, unit);
298 bool update(uint16_t device, uint8_t unit)
300 const Member member(device, unit);
313 bool remove(
const Member &member);
324 bool remove(uint16_t device, uint8_t unit)
326 const Member member(device, unit);
328 return remove(member);
351 return !(*
this == other);
380 static constexpr uint16_t
min_size =
sizeof(uint8_t);
383 uint16_t
size()
const;
427 uint16_t
size()
const;
477 uint16_t
size()
const;
505 std::vector<Member> members;
514 Protocol::Response(), name(name), members(members)
525 std::vector<Member> &members):
526 Protocol::Response(code), name(name), members(members)
541 uint16_t
size()
const;
617 virtual GroupPtr find(
const uint16_t address)
const = 0;
627 virtual GroupPtr find(
const std::string &name)
const = 0;
643 typedef std::map<uint16_t, Group> Container;
644 typedef Container::iterator iterator;
645 typedef Container::const_iterator const_iterator;
646 typedef Container::value_type value_type;
650 uint16_t
size()
const;
712 const_iterator
end()
const 853 #ifdef HF_CORE_GROUP_MANAGEMENT_GET_INFO_CMD 992 notify(old_attr, new_attr);
1073 typedef std::tuple<Protocol::Address, Message, uint8_t> Entry;
1091 std::forward_list<Entry> requests;
1093 using IGroupTable::added;
1103 template<
typename _Entries = Entries,
typename _GroupTable = GroupTableClient>
1109 _GroupTable _group_table;
1135 return const_cast<_Entries &
>(_entries);
1142 return const_cast<_GroupTable &
>(_group_table);
1146 typedef Server<> DefaultServer;
1172 void create(std::string name);
1180 void remove(uint16_t group);
1191 void add(uint16_t group, uint16_t device, uint8_t
unit);
1202 void remove(uint16_t group, uint16_t device, uint8_t
unit);
1204 #ifdef HF_CORE_GROUP_MANAGEMENT_GET_INFO_CMD 1211 void get_info(uint16_t group);
1268 using ServiceRole::payload_size;
1312 std::ostream &
operator<<(std::ostream &stream,
virtual uint16_t next_address() const =0
Return next available address for device group.
Message payload for a HF::GroupManagement::GET_INFO_CMD response.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Parent class for the message payload for a HF::GroupManagement::ADD_CMD and HF::GroupManagement::REMO...
_GroupTable & group_table() const
Get the Group Table client associated with this Group Management server.
bool request(Message::Type type, bool response=false)
Check if message type is a request.
Group Management interface UID.
IServer(Unit0 &unit)
Constructor.
bool update(uint16_t device, uint8_t unit)
Update a reserved entry with the given member.
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...
bool response(Message::Type type)
Check if message is a response.
Default implementation of the persistence API.
bool reserve()
Reserve a member in group members entries.
Default implementation of the IGroupTable interface.
This represent the special unit with ID/UID = 0.
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.
GroupAddress DeleteMessage
Message payload for a HF::GroupManagement::DELETE_CMD request.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
bool operator==(const Group &other) const
Equals operator.
void number_of_groups_update(int8_t diff) const
Get the Number Of Groups for the Group Management server.
Server(const Server &other)
Copy-Constructor.
virtual void notify(const HF::Attributes::IAttribute &old_value, const HF::Attributes::IAttribute &new_value) const
Notify that an attribute value as changed.
uint16_t size() const
Number bytes needed to serialize the message.
virtual bool authorized(CMD member, const Protocol::Address &source, const Protocol::Address &destination)
This method serves to indicate if a given member of the interface can be used by the source device af...
std::string name
Group Name.
CreateResponse(Common::Result code=Common::Result::OK, uint16_t address=GroupAddress::NO_ADDR)
Constructor.
InfoResponse(const std::string &name, std::vector< Member > &members)
Constructor.
_Entries & entries() const
Get a reference to the current object implementing the persistence API, for the device information...
This class represents a group of devices.
Return all mandatory attributes for the interface.
#define HF_ASSERT(_expr, _block)
Helper macro to check for correct assumptions.
Number Of Groups attribute UID.
This file contains the forward declarations of the core services and interfaces implementing classes...
Common::Result handle(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
virtual void added(AddResponse &response)=0
This method is called when a response to a add message is received.
bool add(const Member &member)
Add the given member to the group.
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.
bool exists(uint16_t device, uint8_t unit)
Check if a member equal to the given member already exists in the group.
virtual Common::Result add(Protocol::Packet &packet, const AddMessage &msg)
Callback that is called when a GroupManagement::ADD_CMD, is received.
Container::iterator find_member(uint16_t device, uint8_t unit)
Find a group member equal to the given member.
Protocol::Response RemoveResponse
Message payload for a HF::GroupManagement::REMOVE_CMD response.
bool exists(const Member &member)
Check if a member equal to the given member already exists in the group.
virtual void removed(RemoveResponse &response)=0
This method is called when a response to a remove message is received.
Message()
Empty Constructor.
Address(uint16_t _dev=BROADCAST_ADDR, uint8_t _unit=BROADCAST_UNIT, Type _mod=DEVICE)
Create a new message address.
static constexpr uint16_t END_ADDR
Last HAN-FUN Group Address.
Group Management Service : Parent.
Group(uint16_t address=0, std::string name="")
Constructor.
CreateMessage(std::string name="")
Constructor.
This file contains the definitions for the HAN-FUN protocol messages.
This class represents a group address.
void remove(const Protocol::Address &addr, const Entry &entry)
Send a HAN-FUN message containing a GroupTable::REMOVE_CMD, to the given network address.
Group Table Service : Client side implementation.
const_iterator end() const
Get a constant iterator to the start of the entries in this container.
Message(uint16_t group, uint16_t device, uint8_t unit)
Constructor.
std::ostream & operator<<(std::ostream &stream, const HF::Core::GroupManagement::CMD command)
Convert the given command into a string and write it to the given stream.
IGroupTable(IServer &_server)
Constructor.
iterator end()
Get an iterator to the end of the entries in this container.
virtual uint16_t size() const =0
Return the number of entries in the container.
Container::iterator find_member(const Member &member)
Find a group member equal to the given member.
Message payload for a HF::GroupManagement::CREATE_CMD request.
InfoResponse(Common::Result code, const std::string &name, std::vector< Member > &members)
Constructor.
virtual void add(const Protocol::Address &source, const Message &request, uint8_t reference)
Send a GroupTable::ADD_CMD to the device given by the AddMessage request.
Helper class to handle the Number Of Groups attribute for the Group Management service.
static constexpr bool WRITABLE
Attribute Read/Write.
HF::Devices::Concentrator::IUnit0 * unit0() const
Return a reference to the unit that this service belongs to.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
uint16_t size() const
Number bytes needed to serialize the 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.
const Container & members() const
Return a reference to the members of the group.
GroupPtr entry(const uint16_t address) const
Get the group entry given by address.
const_iterator begin() const
Get a constant iterator to the start of the entries in this container.
virtual void created(CreateResponse &response)=0
This method is called when a response to a create message is received.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
GroupAddress InfoMessage
Message payload for a HF::GroupManagement::GET_INFO_CMD request.
uint16_t size() const
Number bytes needed to serialize the message.
Message AddMessage
Message payload for a HF::GroupManagement::ADD_CMD request.
Unit 0 interface API for HAN-FUN Concentrators.
uint16_t uid() const
This method returns the interface UID.
HF::Interface const * owner() const
static constexpr uint16_t START_ADDR
First HAN-FUN Group Address.
Container _members
Group Members
bool update(const Member &member)
Update a reserved entry with the given member.
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.
Unit0 & unit() const
The device this unit is associated with.
Unit0 & _unit
Reference to the unit the service belongs to.
virtual IGroupTable & group_table() const =0
Get the Group Table client associated with this Group Management server.
std::string name
Group Name
bool operator!=(const Group &other) const
Not equals operator.
This class represents a byte array.
virtual void deleted(DeleteResponse &response)=0
This method is called when a response to a delete message is received.
Common::Result destroy(const uint16_t address)
Destroy the entry given by address in the persistent storage.
void add(uint16_t group, uint16_t device, uint8_t unit)
Send a HAN-FUN message containing a GroupManagement::ADD_CMD, to the D:0/U:0 network address...
Protocol::Address Member
This class represents a member of a group.
Server(Unit0 &unit)
Constructor.
Protocol::Response DeleteResponse
Message payload for a HF::GroupManagement::DELETE_CMD response.
uint16_t size() const
Number bytes needed to serialize the message.
CreateResponse(uint16_t address)
Constructor.
Base class for responses.
InfoResponse()
Empty Constructor.
uint8_t number_of_groups() const
Get the Number Of Groups for the Group Management server.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
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...
static constexpr uint8_t ID
Attribute UID.
GroupPtr entry(const std::string &name) const
Get the group entry given by name.
bool add(uint16_t device, uint8_t unit)
Add the given member to the group.
virtual void deleted(const Group &group)
Indicate that a group was deleted.
virtual void added(const Protocol::Address &addr, const GroupTable::Response &response)
Callback for processing the response of a GroupTable::ADD_CMD.
virtual GroupPtr find(const uint16_t address) const =0
Find the group with the given group address.
uint16_t next_address() const
Return next available address for device group.
void add(const Protocol::Address &source, const AddMessage &request, uint8_t reference)
Send a GroupTable::ADD_CMD to the device given by the AddMessage request.
GroupPtr find(uint16_t address) const
Find the group with the given group address.
uint16_t address
Group Address
virtual Common::Result create(Protocol::Packet &packet, CreateMessage &msg)
Callback that is called when a GroupManagement::CREATE_CMD, is received.
Interface/Service Attribute API.
Device Management - Persistent Storage API.
virtual Common::Result save(uint16_t address, const std::string &name)=0
Store the given entry to persistent storage.
virtual ~IServer()
Destructor.
virtual void got_info(InfoResponse &response)=0
This method is called when a response to a get info message is received.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Message RemoveMessage
Message payload for a HF::GroupManagement::REMOVE_CMD request.
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Parent class for the response messages.
uint16_t device
Device Address.
Class template for all interfaces role implementations.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
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.
Simple raw pointer wrapper.
Group Management Service : Client side implementation.
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
Protocol::Response AddResponse
Message payload for a HF::GroupManagement::ADD_CMD response.
Helper template class to declare an attribute with the given T type.
virtual void removed(const GroupPtr &group, const Member &member)
Indicate that a device/unit was removed from an existing group.
virtual Common::Result destroy(const uint16_t address)=0
Destroy the entry given by address in the persistent storage.
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.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid.
This file contains the definitions for the Group Table service.
virtual void added(const GroupPtr &group, const Member &member)
Indicate that a new device/unit was added to an existing group.
Common interface for all Interfaces.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
void create(std::string name)
Send a HAN-FUN message containing a GroupManagement::CREATE_CMD, to the D:0/U:0 network address...
iterator begin()
Get an iterator to the start of the entries in this container.
Common::Result handle(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Helper class used to implement custom functionality to the group management server side...
virtual void created(const GroupPtr &group)
Indicate that a new group was created.
virtual IEntries & entries() const =0
Get a reference to the current object implementing the persistence API, for the device information...
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Message payload for a HF::GroupManagement::CREATE_CMD response.
Group Management Service : Server side implementation.
uint16_t size() const
Number bytes needed to serialize the message.
Class template for all core services implementations.
Base(Unit0 &unit)
Constructor.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Result
Commands result codes.
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.
void added(const Protocol::Address &addr, const GroupTable::Response &response)
Callback for processing the response of a GroupTable::ADD_CMD.
Container db
Actual container for the entries.
GroupAddress(uint16_t address=0)
Constructor.
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.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
uint16_t next_address() const
Return next available address for device group.
Interface to the HF::GroupTable API used to update the device's group tables entries on add/remove ev...
static constexpr uint16_t NO_ADDR
Empty Group Address.
uint16_t size() const
Return the number of entries in the container.
Basic API for persistent storage implementations.
Top-level namespace for the HAN-FUN library.