17 #ifndef HF_CORE_SCHEDULING_H 18 #define HF_CORE_SCHEDULING_H 25 #include <forward_list> 37 #define HF_SCHEDULING_SETTER_HELPER(_Type, _name, _value) \ 39 _Type::value_type old = this->_name; \ 41 this->_name = _value; \ 43 _Type old_attr(static_cast<HF::Interface::UID>(this->uid()), old, this); \ 44 _Type new_attr(static_cast<HF::Interface::UID>(this->uid()), this->_name, this); \ 46 notify(old_attr, new_attr); \ 103 typedef enum _Attributes
174 template<
typename _Type>
193 Entry(uint8_t _id, uint8_t _status, _Type _t, uint8_t _pid):
214 time.active(_time) &&
227 static constexpr uint16_t
min_size =
sizeof(uint8_t)
243 uint16_t start = offset;
245 offset += array.
write(offset,
id);
246 offset += array.
write(offset, static_cast<uint8_t>((
status << 7) & 0x80));
247 offset +=
time.pack(array, offset);
250 return (offset - start);
258 uint16_t start = offset;
260 offset += array.
read(offset,
id);
263 offset += array.
read(offset, flags);
264 status = (flags >> 7) & 0x01;
266 uint16_t
size =
time.unpack(array, offset);
270 offset += array.
read(offset,
pid);
272 return (offset - start);
285 static constexpr uint16_t
min_size =
sizeof(uint8_t);
303 #if __cplusplus >= 201103 309 template<
class _Type>
319 uint8_t _event_id = 0x00):
320 HF::Protocol::Response(_code),
event_id(_event_id)
347 UpdateStatus(uint8_t _event_id = 0x00,
bool _status =
false):
352 static constexpr uint16_t
min_size =
sizeof(uint8_t)
381 static constexpr uint16_t
min_size =
sizeof(uint8_t);
401 template<
typename _Type>
408 HF::Protocol::Response(_code),
entry(_entry)
412 HF::Protocol::Response(_code)
431 uint8_t start = offset;
440 offset +=
entry.pack(array, offset);
443 return offset - start;
451 uint8_t start = offset;
461 offset +=
entry.unpack(array, offset);
464 return offset - start;
482 template<
typename _Type>
502 virtual void clear(
void) = 0;
520 virtual uint8_t
next_id()
const = 0;
535 template<
typename _Type>
541 typedef typename Common::SimpleList<EntryType> Container;
542 typedef typename Container::iterator iterator;
543 typedef typename Container::const_iterator const_iterator;
544 typedef typename Container::value_type value_type;
551 return std::distance(
db.begin(),
db.end());
563 db.push_front(entry);
628 auto it = std::find_if(
db.begin(),
db.end(),
630 {
return e.id == id;});
645 std::for_each(
db.begin(),
db.end(), func);
702 const_iterator
end()
const 719 return std::any_of(
db.begin(),
db.end(), [id](
const EntryType &e) {
737 template<Interface::UID _ITF,
typename _Parent>
844 void status(
bool __value);
877 HF::Interface::CLIENT_ROLE>
901 #ifdef HF_CORE_EVENT_SCHEDULING_UPDATE_EVENT_STATUS_CMD 912 uint8_t
id,
bool enabled);
915 #ifdef HF_CORE_EVENT_SCHEDULING_GET_EVENT_ENTRY_CMD 939 #ifdef HF_CORE_EVENT_SCHEDULING_DELETE_ALL_EVENTS_CMD 989 std::ostream &
operator<<(std::ostream &stream,
Default implementation of the persistence API.
static constexpr uint16_t START_ID
Lower bound for the entries ID.
DefineEventResponse UpdateStatusResponse
Response message payload for a Scheduling::UPDATE_STATUS_CMD request.
uint16_t size() const
Number bytes needed to serialize the message.
bool active(uint32_t _time) const
Check if the current entry is runnable at _time.
Entry< _Type > entry
&Entry data to return to client.
Common::Result destroy(const uint8_t id)
Destroy the given entry in the persistent storage.
Scheduling Service : Parent.
UID
Interfaces Unique Identifiers (UID).
Delete Event command UID.
static constexpr bool WRITABLE
Attribute Read/Write.
uint16_t write(uint16_t offset, uint8_t data)
Write a byte into the array at the given offset.
Number Of Entries attribute UID.
Common::Result save(const EntryType &entry)
Store the given entry to persistent storage.
This represent the special unit with ID/UID = 0.
iterator begin()
Get an iterator to the start of the entries in this container.
uint8_t event_id
Event ID.
virtual uint8_t number_of_entries() const =0
Get the Number Of Entries for the Scheduling server.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
std::ostream & operator<<(std::ostream &stream, const HF::Core::Scheduling::CMD command)
Convert the given command into a string and write it to the given stream.
virtual Common::Result activate_scheduler(const Protocol::Packet &packet, const ActivateScheduler &msg)
Callback that is called when a Scheduling::ACTIVATE_SCHEDULER_CMD, is received.
Container db
Actual container for the entries.
EntryPointer find(uint8_t id) const
Find the Event with the given id.
void step(void)
Increment the next_run attribute.
static constexpr uint8_t ID
Attribute UID.
Return all mandatory attributes for the interface.
Scheduling Service : Client side implementation.
#define HF_ASSERT(_expr, _block)
Helper macro to check for correct assumptions.
This file contains the forward declarations of the core services and interfaces implementing classes...
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint32_t next_run
Next run timestamp.
iterator end()
Get an iterator to the end of the entries in this container.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
virtual void clear(void)=0
Erase all the DB entries.
Response message payload for a Scheduling::DEFINE_EVENT_CMD request.
void enable(bool __value)
Enable/Disable scheduler.
Define Event command UID.
This file contains the definitions for the HAN-FUN protocol messages.
const_iterator end() const
Get a constant iterator to the start of the entries in this container.
bool status
Scheduler status.
This is the parent class for all services implementations.
uint8_t event_id
Event ID.
Helper class to handle the Maximum Number Of Entries attribute for the scheduling services...
Base class for scheduling services entries.
Message payload for a Scheduling::ACTIVATE_SCHEDULER_CMD request.
Base(Unit0 &unit)
Constructor.
virtual void send(const Protocol::Address &addr, Protocol::Message &message)=0
Send message msg to the network address given by addr.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Message payload for a Scheduling::GET_ENTRY_CMD request.
static constexpr bool WRITABLE
Attribute Read/Write.
static constexpr uint16_t MAX_ID
Upper bound for the entries ID.
#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...
uint16_t size() const
Number bytes needed to serialize the message.
virtual void for_each(std::function< void(EntryType &e)> func)=0
Call the given function with each entry in the DB as argument.
Entry< _Type > EntryType
Entry helper type.
uint16_t size() const
Number bytes needed to serialize the message.
Update Event Status command UID.
void clear(void)
Erase all the DB entries.
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::IAttribute * create_attribute(HF::Interface::UID itf_uid, uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Core::Scheduling::ISe...
uint16_t size() const
Number bytes needed to serialize the message.
void for_each(std::function< void(Entry< _Type > &)> func)
Call the given function with each entry in the DB as argument.
Entry(uint8_t _id, uint8_t _status, _Type _t, uint8_t _pid)
Constructor.
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::Interface const * owner() const
DefineEventResponse DeleteEventResponse
Response message payload for a Scheduling::DELETE_CMD request.
Unit0 & unit() const
The device this unit is associated with.
Protocol::Response ActivateSchedulerResponse
Response message payload for a Scheduling::ACTIVATE_SCHEDULER_CMD request.
uint8_t event_id
Event ID.
Activate Scheduler command UID.
Helper class to handle the Status attribute for the scheduling services.
virtual EntryPointer find(uint8_t id) const =0
Find the Event with the given id.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Scheduling - Persistent Storage API.
Delete All Events command UID.
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.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
bool _status
Server Status
virtual Common::Result save(const EntryType &entry)=0
Store the given entry to persistent storage.
_Type time
Scheduler configuration.
uint8_t pid
Program ID to be invoked.
bool exists(const uint8_t id) const
Check if entry with given id exists.
uint8_t maximum_number_of_entries() const
Get the Maximum Number Of Entries for the Scheduling server.
uint16_t size() const
Return the number of entries in the container.
Common::Result save(uint8_t id, uint8_t status, _Type &time, uint8_t pid)
Store the given entry to persistent storage.
void activate_scheduler(const Protocol::Address &addr, const Interface::UID itf_uid, bool enabled=true)
Send a HAN-FUN message containing a Scheduling::ACTIVATE_SCHEDULER_CMD, to the given network address...
GetEntry DeleteEvent
Message payload for a Scheduling::DELETE_CMD request.
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.
Helper class to handle the Number Of Entries attribute for the scheduling services.
Interface/Service Attribute API.
static constexpr uint8_t ID
Attribute UID.
bool status() const
Get the Status for the Scheduling server.
static constexpr bool WRITABLE
Attribute Read/Write.
uint16_t read(uint16_t offset, uint8_t &data) const
Read the byte at offset into data.
Scheduling Service : Server side implementation.
Parent class for the response messages.
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
Class template for all interfaces role implementations.
Simple raw pointer wrapper.
uint16_t size() const
Number bytes needed to serialize the message.
bool enabled() const
Check if scheduler is enabled.
Helper class template for implementing a given interface role.
Message payload for a Scheduling::UPDATE_STATUS_CMD request.
static constexpr uint8_t ID
Attribute UID.
bool status
Scheduler status.
Helper template class to declare an attribute with the given T type.
IServer(Unit0 &unit)
Constructor.
virtual ~IServer()
Destructor.
Common::Result destroy(const EntryType &entry)
Destroy the given entry 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.
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.
Common::Pointer< EntryType > EntryPointer
Entry pointer helper.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
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.
Common interface for all Interfaces.
uint8_t _maximum_number_of_entries
Maximum Number Of Entries.
HF::Protocol::Response DeleteAllResponse
Response Message payload for a Scheduling::DELETE_ALL_CMD request.
virtual uint8_t next_id() const =0
Return next available id for event.
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.
Get Event Entry command UID.
Class template for all core services implementations.
void delete_event(const Protocol::Address &addr, const Interface::UID itf_uid, uint8_t id)
Send a HAN-FUN message containing a Scheduling::DELETE_CMD, to the given network address.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
virtual uint16_t uid() const =0
This method returns the interface UID.
static constexpr uint16_t AVAILABLE_ID
Special ID for system allocated ID.
Result
Commands result codes.
Response message payload for a Scheduling::GET_ENTRY_CMD request.
Maximum Number Of Entries attribute UID.
uint16_t size() const
Number bytes needed to serialize the message.
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.
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.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
const_iterator begin() const
Get a constant iterator to the start of the entries in this container.
uint8_t next_id() const
Return next available id for event.
Basic API for persistent storage implementations.
Top-level namespace for the HAN-FUN library.