17 #ifndef HF_CORE_BATCH_PROGRAM_MANAGEMENT_H 18 #define HF_CORE_BATCH_PROGRAM_MANAGEMENT_H 25 #include <forward_list> 32 namespace BatchProgramManagement
57 namespace BatchProgramManagement
78 typedef enum _Attributes
102 uint8_t _itf_type, uint16_t _itf_uid, uint8_t _itf_member,
107 itf.
role = _itf_type;
118 Action(
void) =
default;
135 std::vector<Action> actions;
143 Entry(uint8_t _pid, std::string _name):
144 pid(_pid), name(_name)
154 Entry(uint8_t _pid, std::string _name, std::vector<Action> &_actions):
155 pid(_pid), name(_name), actions(_actions)
163 Entry(
void) =
default;
165 static constexpr uint16_t START_PID = 0x00;
166 static constexpr uint16_t MAX_PID = 0xFE;
167 static constexpr uint16_t AVAILABLE_PID = 0xFF;
173 static constexpr uint16_t min_size =
sizeof(uint8_t)
178 uint16_t size()
const;
181 uint16_t pack(Common::ByteArray &array, uint16_t offset = 0)
const;
184 uint16_t unpack(
const Common::ByteArray &array, uint16_t offset = 0);
187 typedef Common::Pointer<Entry> EntryPtr;
193 typedef Entry DefineProgram;
195 struct DefineProgramResponse:
public Protocol::Response
207 Protocol::Response(_code), pid(_pid)
218 uint16_t size()
const;
221 uint16_t pack(Common::ByteArray &array, uint16_t offset = 0)
const;
224 uint16_t unpack(
const Common::ByteArray &array, uint16_t offset = 0);
236 InvokeProgram(uint8_t _pid = 0):
245 static constexpr uint16_t min_size =
sizeof(uint8_t);
248 uint16_t size()
const;
251 uint16_t pack(Common::ByteArray &array, uint16_t offset = 0)
const;
254 uint16_t unpack(
const Common::ByteArray &array, uint16_t offset = 0);
257 typedef DefineProgramResponse InvokeProgramResponse;
259 typedef InvokeProgram DeleteProgram;
260 typedef InvokeProgramResponse DeleteProgramResponse;
262 typedef Protocol::Response DeleteAllProgramsResponse;
264 typedef InvokeProgram GetProgramActions;
266 struct GetProgramActionsResponse:
public Protocol::Response
278 Protocol::Response(_code), program(_program)
282 Protocol::Response(_code)
290 uint16_t size()
const;
293 uint16_t pack(Common::ByteArray &array, uint16_t offset = 0)
const;
296 uint16_t unpack(
const Common::ByteArray &array, uint16_t offset = 0);
362 std::vector<Action> &actions) = 0;
380 virtual void clear(
void) = 0;
400 virtual EntryPtr find(
const std::string &name)
const = 0;
408 virtual uint8_t
next_pid()
const = 0;
416 typedef std::map<uint8_t, Entry> Container;
417 typedef Container::iterator iterator;
418 typedef Container::const_iterator const_iterator;
419 typedef Container::value_type value_type;
423 uint16_t
size()
const;
428 std::vector<Action> &actions);
483 const_iterator
end()
const 499 struct Base:
public Service<HF::Interface::BATCH_PROGRAM_MANAGEMENT>
513 HF::Interface::SERVER_ROLE>
599 GetProgramActions &msg);
696 template<
typename _Entries = Entries>
707 return const_cast<_Entries &
>(_entries);
724 HF::Interface::CLIENT_ROLE>
750 const std::string name, std::vector<Action> &actions)
752 DefineProgram
request(pid, name, actions);
795 #ifdef HF_CORE_BATCH_PROGRAM_MANAGEMENT_GET_PROGRAM_ACTIONS_CMD 891 std::ostream &
operator<<(std::ostream &stream,
902 std::ostream &
operator<<(std::ostream &stream,
virtual ~IServer()
Destructor.
Maximum Number Of Entries attribute UID.
virtual void got_actions(GetProgramActionsResponse &response)=0
This method is called when a response to a get info message is received.
const_iterator begin() const
Get a constant iterator to the start of the entries in this container.
bool request(Message::Type type, bool response=false)
Check if message type is a request.
virtual EntryPtr find(const uint8_t pid) const =0
Find the program with the given pid.
bool response(Message::Type type)
Check if message is a response.
virtual Common::Result invoke_program(const Protocol::Packet &packet, InvokeProgram &msg)
Callback that is called when a BatchProgramManagement::INVOKE_PROGRAM_CMD, is received.
Server DefaultServer
Helper typedef.
This represent the special unit with ID/UID = 0.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
virtual void deleted(DeleteProgramResponse &response)=0
This method is called when a response to a delete program is received.
virtual IEntries & entries() const =0
Get a reference to the current object implementing the persistence API, for the device information...
_Entries & entries() const
Get a reference to the current object implementing the persistence API, for the device information...
Return all mandatory attributes for the interface.
Container db
Actual container for the entries.
This file contains the forward declarations of the core services and interfaces implementing classes...
static constexpr uint8_t ID
Attribute UID.
uint8_t _maximum_number_of_entries
Maximum Number Of Entries.
Common::Result destroy(const uint8_t pid)
Remove the program with the given pid ftom.
uint16_t id
Identifier of the interface.
void delete_all_programs(const Protocol::Address &addr)
Send a HAN-FUN message containing a BatchProgramManagement::DELETE_ALL_PROGRAMS_CMD, to the given network address.
Scheduling::Entry< Interval > Entry
Specific part for the Event Scheduler of the HF::Scheduling::Entry.
This file contains the definitions for the HAN-FUN protocol messages.
Helper template to declare a Batch Program server with custom entries backend.
uint8_t maximum_number_of_entries() const
Get the Maximum Number Of Entries for the Batch Program Management server.
virtual uint8_t next_pid() const =0
Return next available PID for the program.
Common::Result define_program(const Protocol::Address &addr, const uint8_t pid, const std::string name, std::vector< Action > &actions)
Send a HAN-FUN message containing a BatchProgramManagement::DEFINE_PROGRAM_CMD, to the given network ...
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
Batch Program Management - Persistent Storage API.
virtual Common::Result save(const uint8_t pid, const std::string &name, std::vector< Action > &actions)=0
Store the given entry to persistent storage.
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...
EntryPtr entry(const std::string &name) const
Get the program entry given by name.
uint8_t next_pid() const
Return next available PID for the program.
static constexpr bool WRITABLE
Attribute Read/Write.
Batch Program Management Interfaces::Interface : Parent.
Base(Unit0 &unit)
Constructor.
EntryPtr find(const uint8_t pid) const
Find the program with the given pid.
Batch Program Management Interfaces::Interface : Server side implementation.
virtual Common::Result destroy(const uint8_t pid)=0
Remove the program with the given pid ftom.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Core::BatchProgramMan...
virtual void defined(DefineProgramResponse &response)=0
This method is called when a response to a create program is received.
static constexpr bool WRITABLE
Attribute Read/Write.
iterator end()
Get an iterator to the end of the entries in this container.
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.
uint16_t uid() const
This method returns the interface UID.
uint16_t role
Interface role : Server or Client.
HF::Interface const * owner() const
Helper class to handle the Maximum Number Of Entries attribute for the Batch Program Management inter...
Unit0 & unit() const
The device this unit is associated with.
This class represents a byte array.
void clear(void)
Erase all the DB entries.
void invoke_program(const Protocol::Address &addr, uint8_t pid)
Send a HAN-FUN message containing a BatchProgramManagement::INVOKE_PROGRAM_CMD, to the given network ...
uint8_t member
Interface destination member.
Delete Program command UID.
Number Of Entries attribute UID.
Invoke Program command UID.
const_iterator end() const
Get a constant iterator to the start of the entries in this container.
static constexpr uint8_t ID
Attribute UID.
virtual void invoked(InvokeProgramResponse &response)=0
This method is called when a response to a invoke program message is received.
Batch Program Management Interfaces::Interface : Client side implementation.
Delete All Programs command UID.
iterator begin()
Get an iterator to the start of the entries in this container.
Interface/Service Attribute API.
EntryPtr entry(const uint8_t pid) const
Get the program entry given by pid.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Helper class to handle the Number Of Entries attribute for the Batch Program Management interface...
Parent class for the response messages.
Define Program command UID.
IServer(Unit0 &unit)
Constructor.
Class template for all interfaces role implementations.
Simple raw pointer wrapper.
void delete_program(const Protocol::Address &addr, uint8_t pid)
Send a HAN-FUN message containing a BatchProgramManagement::DELETE_PROGRAM_CMD, to the given network ...
Helper template class to declare an attribute with the given T type.
virtual Common::Result delete_program(const Protocol::Packet &packet, DeleteProgram &msg)
Callback that is called when a BatchProgramManagement::DELETE_PROGRAM_CMD, is received.
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.
virtual Common::Result get_program_actions(const Protocol::Packet &packet, GetProgramActions &msg)
Callback that is called when a BatchProgramManagement::GET_PROGRAM_ACTIONS_CMD, is received...
Get Program Actions command UID.
uint8_t next_pid() const
Return next available PID for the program.
Common interface for all Interfaces.
Default implementation of the persistence API.
uint16_t size() const
Return the number of entries in the container.
virtual Common::Result delete_all_programs(const Protocol::Packet &packet)
Callback that is called when a BatchProgramManagement::DELETE_ALL_PROGRAMS_CMD, is received...
virtual void clear(void)=0
Erase all the DB entries.
Class template for all core services implementations.
std::ostream & operator<<(std::ostream &stream, const HF::Core::BatchProgramManagement::CMD command)
Convert the given command into a string and write it to the given stream.
Batch Program Management interface UID.
Result
Commands result codes.
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.
uint8_t number_of_entries() const
Get the Number Of Entries for the Batch Program Management server.
virtual Common::Result define_program(const Protocol::Packet &packet, DefineProgram &msg)
Callback that is called when a BatchProgramManagement::DEFINE_PROGRAM_CMD, is received.
Basic API for persistent storage implementations.
Top-level namespace for the HAN-FUN library.