HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
event_scheduling.h
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 #ifndef HF_CORE_EVENT_SCHEDULING_H
17 #define HF_CORE_EVENT_SCHEDULING_H
18 
19 #include "hanfun/protocol.h"
20 #include "hanfun/core.h"
21 
22 #include "hanfun/core/scheduling.h"
23 
24 namespace HF
25 {
26  namespace Core
27  {
28  namespace Scheduling
29  {
30  // Forward declaration
31  namespace Event
32  {
33  struct IServer;
34  }
35  }
36 
52 
53  namespace Scheduling
54  {
58  namespace Event
59  {
69  struct Interval
71  {
72  uint32_t start;
73  uint32_t end;
74  uint32_t repeat;
75 
83  Interval(uint32_t _start, uint32_t _end, uint32_t _repeat):
84  start(_start), end(_end), repeat(_repeat)
85  {}
86 
87  Interval() = default;
88 
94  uint32_t first() const
95  {
96  return start;
97  }
98 
104  uint32_t step() const
105  {
106  return repeat;
107  }
108 
117  bool active(uint32_t _time) const
118  {
119  return (start <= _time && _time <= end);
120  }
121 
123  static constexpr uint16_t min_size = sizeof(uint32_t) // Start Date.
124  + sizeof(uint32_t) // End Date.
125  + sizeof(uint32_t); // Repeat interval.
126 
128  uint16_t size() const
129  {
130  return min_size;
131  }
132 
134  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
135 
137  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
138  };
139 
142 
145 
151  {
152  MaximumNumberOfEntries(uint8_t value = 0, HF::Interface *owner = nullptr):
154  value, owner)
155  {}
156  };
157 
163  {
164  NumberOfEntries(uint8_t value = 0, HF::Interface *owner = nullptr):
166  {}
167  };
168 
172  struct Status: public Scheduling::Status
173  {
174  Status(uint8_t value = 0, HF::Interface *owner = nullptr):
176  {}
177  };
178 
190 
193 
196 
202  struct IClient: public IClientBase
203  {
206  {}
207 
209  virtual ~IClient() {}
210 
212 
219  virtual void activate_scheduler(const Protocol::Address &addr, bool enabled)
220  {
221  Scheduling::IClient::activate_scheduler(addr, ITF, enabled);
222  }
223 
234  virtual void define_event(const Protocol::Address &addr, uint8_t id,
235  uint8_t status, Interval &time, uint8_t pid);
236 
237 #ifdef HF_CORE_EVENT_SCHEDULING_UPDATE_EVENT_STATUS_CMD
238 
246  virtual void update_event_status(const Protocol::Address &addr,
247  uint8_t id, bool enabled)
248  {
249  Scheduling::IClient::update_event_status(addr, ITF, id, enabled);
250  }
251 #endif
252 
253 #ifdef HF_CORE_EVENT_SCHEDULING_GET_EVENT_ENTRY_CMD
254 
260  virtual void get_event_entry(const Protocol::Address &addr, uint8_t id)
261  {
262  Scheduling::IClient::get_event_entry(addr, ITF, id);
263  }
264 #endif
265 
272  virtual void delete_event(const Protocol::Address &addr, uint8_t id)
273  {
274  Scheduling::IClient::delete_event(addr, ITF, id);
275  }
276 
277 #ifdef HF_CORE_EVENT_SCHEDULING_DELETE_ALL_EVENTS_CMD
278 
283  virtual void delete_all_events(const Protocol::Address &addr)
284  {
285  Scheduling::IClient::delete_all_events(addr, ITF);
286  }
287 #endif
288 
289  using IClientBase::send;
290  };
291 
297  struct Client: public IClient
298  {
303  {}
304 
305  virtual ~Client()
306  {}
307  };
308 
314  struct IServer: public IServerBase
315  {
316  uint16_t uid() const
317  {
318  return IServerBase::uid();
319  }
320 
321  HF::Attributes::UIDS attributes(uint8_t uid = HF::Attributes::Pack::MANDATORY) const
322  {
324  }
325 
326  uint8_t number_of_entries() const;
327 
328  // ======================================================================
329  // Events
330  // ======================================================================
333 
346  virtual Common::Result define_event(const Protocol::Packet &packet,
348 
360  const UpdateStatus &msg);
361 
372  virtual Common::Result get_event_entry(const Protocol::Packet &packet,
373  const GetEntry &msg);
374 
385  virtual Common::Result delete_event(const Protocol::Packet &packet,
386  const DeleteEvent &msg);
387 
396  virtual Common::Result delete_all_events(const Protocol::Packet &packet);
397 
399  // ======================================================================
400 
401  void periodic(uint32_t time);
402 
404  IServer(Unit0 &unit): IServerBase(unit)
405  {}
406 
408  virtual ~IServer() {}
409 
410  // =============================================================================
411  // Entries API
412  // =============================================================================
413 
420  virtual IEntries<Interval> &entries() const = 0;
421 
430  Common::Pointer<Entry> entry(const uint8_t id) const
431  {
432  return entries().find(id);
433  }
434 
438  uint8_t next_id() const
439  {
440  return entries().next_id();
441  }
442 
443  using IServerBase::notify;
444 
445  // =============================================================================
446  // Protected types and methods
447  // =============================================================================
448 
449  protected:
450 
451  Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload,
452  uint16_t offset);
453 
454  };
455 
461  template<typename _Entries>
462  struct Server: public IServer
463  {
464  static_assert(std::is_base_of<HF::Core::Scheduling::IEntries<Interval>,
465  _Entries>::value,
466  "_Entries must be of type HF::Core::Scheduling::IEntries<Interval>");
467 
468  protected:
469 
470  _Entries _entries;
471 
472  public:
473 
479  Server(Unit0 &unit): IServer(unit)
480  {}
481 
482  virtual ~Server()
483  {}
484 
486  _Entries &entries() const
487  {
488  return const_cast<_Entries &>(_entries);
489  }
490  };
491 
497 
500  } // namespace Event
501  } // namespace Scheduling
502  } // namespace Core
503 } // namespace HF
504 
505 #endif /* HF_CORE_EVENT_SCHEDULING_H */
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Core::Scheduling::Eve...
Scheduling Service : Parent.
Definition: scheduling.h:738
UID
Interfaces Unique Identifiers (UID).
Definition: interface.h:57
This represent the special unit with ID/UID = 0.
Definition: core.h:67
uint16_t size() const
Number bytes needed to serialize the message.
List of attributes UIDs.
Definition: attributes.h:176
Return all mandatory attributes for the interface.
Definition: attributes.h:842
Scheduling Service : Client side implementation.
Definition: scheduling.h:876
This file contains the forward declarations of the core services and interfaces implementing classes...
Helper class template for parent class implementation of the interfaces.
Definition: interface.h:371
Server< Entries< Interval > > DefaultServer
Event Scheduling Service : Server side with default persistence implementation.
virtual void define_event(const Protocol::Address &addr, uint8_t id, uint8_t status, Interval &time, uint8_t pid)
Send a HAN-FUN message containing a Scheduling::DEFINE_EVENT_CMD, to the given network address...
Event Scheduling Service : Client side implementation.
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.
virtual void delete_event(const Protocol::Address &addr, uint8_t id)
Send a HAN-FUN message containing a Scheduling::DELETE_CMD, to the given network address.
Helper class to handle the Maximum Number Of Entries attribute for the scheduling services...
Definition: scheduling.h:119
Base class for scheduling services entries.
Definition: scheduling.h:175
virtual void activate_scheduler(const Protocol::Address &addr, bool enabled)
Send a HAN-FUN message containing a Scheduling::ACTIVATE_SCHEDULER_CMD, to the given network address...
Interval(uint32_t _start, uint32_t _end, uint32_t _repeat)
Constructor.
This file contains the common definitions for the scheduling services.
Scheduling Service : Server side implementation.
IServer(Unit0 &unit)
Constructor.
Message payload for a Scheduling::GET_ENTRY_CMD request.
Definition: scheduling.h:372
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Server(Unit0 &unit)
Constructor.
Scheduling::GetEntryResponse< Interval > GetEntryResponse
Specific part for the Event Scheduler of the HF::Scheduling::GetEntryResponse.
uint16_t uid() const
This method returns the interface UID.
Definition: core.h:191
Event Scheduler specific part for the HF::Scheduling::Entry.
HF::Interface const * owner() const
Definition: attributes.h:414
Helper class to handle the Status attribute for the scheduling services.
Definition: scheduling.h:146
Scheduling - Persistent Storage API.
Definition: scheduling.h:483
This class represents a byte array.
Helper class to handle the Status attribute for the Event Scheduling service.
uint32_t repeat
Repeat interval (in seconds).
virtual Common::Result update_event_status(const Protocol::Packet &packet, const UpdateStatus &msg)
Callback that is called when a Scheduling::UPDATE_STATUS_CMD, is received.
Network Address.
Definition: protocol.h:201
Common::Pointer< Entry > entry(const uint8_t id) const
Get the Event Scheduling entry given by id.
bool active(uint32_t _time) const
Check if entry is active.
Scheduling Service : Client side implementation.
Event Scheduling interface UID.
Definition: interface.h:67
Helper class to handle the Maximum Number Of Entries attribute for the Event Scheduling service...
HAN-FUN Protocol Packet.
Definition: protocol.h:298
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...
virtual IEntries< Interval > & entries() const =0
Get a reference to the current object implementing the persistence API, for the device information...
Helper class to handle the Number Of Entries attribute for the scheduling services.
Definition: scheduling.h:133
Interface/Service Attribute API.
Definition: attributes.h:44
Scheduling Service : Server side implementation.
Definition: scheduling.h:753
Simple raw pointer wrapper.
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.
Message payload for a Scheduling::UPDATE_STATUS_CMD request.
Definition: scheduling.h:342
virtual Common::Result get_event_entry(const Protocol::Packet &packet, const GetEntry &msg)
Callback that is called when a Scheduling::GET_ENTRY_CMD, is received.
uint8_t next_id() const
Return next available id for event.
virtual Common::Result delete_event(const Protocol::Packet &packet, const DeleteEvent &msg)
Callback that is called when a Scheduling::DELETE_CMD, is received.
virtual Common::Result delete_all_events(const Protocol::Packet &packet)
Callback that is called when a Scheduling::DELETE_ALL_CMD, is received.
Common interface for all Interfaces.
Definition: interface.h:43
virtual Common::Result define_event(const Protocol::Packet &packet, Scheduling::Entry< Interval > &msg)
Callback that is called when a Scheduling::DEFINE_EVENT_CMD, is received.
Event Scheduling Service : Server side implementation.
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 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.
uint32_t first() const
Get the initial value for the next_run entry attribute.
_Entries & entries() const
Get a reference to the current object implementing the persistence API, for the device information...
Result
Commands result codes.
Response message payload for a Scheduling::GET_ENTRY_CMD request.
Definition: scheduling.h:402
Helper class to handle the Number Of Entries attribute for the Event Scheduling service.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
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.
uint32_t step() const
Get the step between executions.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22