HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::Core::Scheduling::Entries< _Type > Struct Template Reference

Default implementation of the persistence API. More...

#include <scheduling.h>

+ Inheritance diagram for HF::Core::Scheduling::Entries< _Type >:
+ Collaboration diagram for HF::Core::Scheduling::Entries< _Type >:

Public Member Functions

uint16_t size () const
 Return the number of entries in the container. More...
 
Common::Result save (const EntryType &entry)
 Store the given entry to persistent storage. More...
 
Common::Result save (uint8_t id, uint8_t status, _Type &time, uint8_t pid)
 Store the given entry to persistent storage. More...
 
void clear (void)
 Erase all the DB entries.
 
Common::Result destroy (const uint8_t id)
 Destroy the given entry in the persistent storage. More...
 
Common::Result destroy (const EntryType &entry)
 Destroy the given entry in the persistent storage. More...
 
EntryPointer find (uint8_t id) const
 Find the Event with the given id. More...
 
void for_each (std::function< void(Entry< _Type > &)> func)
 Call the given function with each entry in the DB as argument. More...
 
uint8_t next_id () const
 Return next available id for event. More...
 
iterator begin ()
 Get an iterator to the start of the entries in this container. More...
 
iterator end ()
 Get an iterator to the end of the entries in this container. More...
 
const_iterator begin () const
 Get a constant iterator to the start of the entries in this container. More...
 
const_iterator end () const
 Get a constant iterator to the start of the entries in this container. More...
 
- Public Member Functions inherited from HF::Core::Scheduling::IEntries< _Type >
virtual void for_each (std::function< void(EntryType &e)> func)=0
 Call the given function with each entry in the DB as argument. More...
 
- Public Member Functions inherited from HF::Common::IEntries< Entry< _Type > >
virtual Result save (const Entry< _Type > &entry)=0
 Store the given entry to persistent storage. More...
 
virtual Result destroy (const Entry< _Type > &entry)=0
 Destroy the given entry in the persistent storage. More...
 

Protected Member Functions

bool exists (const uint8_t id) const
 Check if entry with given id exists. More...
 

Protected Attributes

Container db
 Actual container for the entries.
 

Additional Inherited Members

- Public Types inherited from HF::Core::Scheduling::IEntries< _Type >
typedef Entry< _Type > EntryType
 Entry helper type. More...
 
typedef Common::Pointer< EntryTypeEntryPointer
 Entry pointer helper. More...
 

Detailed Description

template<typename _Type>
struct HF::Core::Scheduling::Entries< _Type >

Default implementation of the persistence API.

Template Parameters
_Typethe specific type of the scheduling entry.

Definition at line 536 of file scheduling.h.

Member Function Documentation

◆ begin() [1/2]

template<typename _Type >
iterator HF::Core::Scheduling::Entries< _Type >::begin ( )
inline

Get an iterator to the start of the entries in this container.

Returns
iterator to the start of the entries present in this container.

Definition at line 672 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db.

673  {
674  return db.begin();
675  }
Container db
Actual container for the entries.
Definition: scheduling.h:725

◆ begin() [2/2]

template<typename _Type >
const_iterator HF::Core::Scheduling::Entries< _Type >::begin ( ) const
inline

Get a constant iterator to the start of the entries in this container.

Returns
constant iterator to the start of the entries present in this container.

Definition at line 692 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db.

693  {
694  return db.cbegin();
695  }
Container db
Actual container for the entries.
Definition: scheduling.h:725

◆ destroy() [1/2]

template<typename _Type >
Common::Result HF::Core::Scheduling::Entries< _Type >::destroy ( const uint8_t  id)
inline

Destroy the given entry in the persistent storage.

Parameters
[in]idthe Event ID to destroy
Return values
Common::Result::OK,ifthe entry was destroyed.
Common::Result::FAIL_ARGotherwise.

Definition at line 601 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db, HF::Core::Scheduling::Entries< _Type >::exists(), HF::Common::FAIL_ARG, HF::Core::Scheduling::Entry< _Type >::id, and HF::Common::OK.

Referenced by HF::Core::Scheduling::Entries< _Type >::destroy().

602  {
603  if (exists(id))
604  {
605  db.remove_if([id](const EntryType &e) {return e.id == id;});
606  return Common::Result::OK;
607  }
608  else
609  {
611  }
612  }
Container db
Actual container for the entries.
Definition: scheduling.h:725
bool exists(const uint8_t id) const
Check if entry with given id exists.
Definition: scheduling.h:717
Fail - Invalid Argument.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy() [2/2]

template<typename _Type >
Common::Result HF::Core::Scheduling::Entries< _Type >::destroy ( const EntryType entry)
inline

Destroy the given entry in the persistent storage.

Parameters
[in]entryreference to the entry to erase.
Return values
Common::Result::OK,ifthe entry was destroyed.
Common::Result::FAIL_ARGotherwise.
Warning
the reference passed into this method SHOULD NOT be considered valid if it was obtained by calling the find method.

Definition at line 620 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::destroy(), and HF::Core::Scheduling::Entry< _Type >::id.

621  {
622  return destroy(entry.id);
623  }
Common::Result destroy(const uint8_t id)
Destroy the given entry in the persistent storage.
Definition: scheduling.h:601
+ Here is the call graph for this function:

◆ end() [1/2]

template<typename _Type >
iterator HF::Core::Scheduling::Entries< _Type >::end ( )
inline

Get an iterator to the end of the entries in this container.

Returns
iterator to the end of the entries present in this container.

Definition at line 682 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db.

683  {
684  return db.end();
685  }
Container db
Actual container for the entries.
Definition: scheduling.h:725

◆ end() [2/2]

template<typename _Type >
const_iterator HF::Core::Scheduling::Entries< _Type >::end ( ) const
inline

Get a constant iterator to the start of the entries in this container.

Returns
constant iterator to the start of the entries present in this container.

Definition at line 702 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db.

703  {
704  return db.cend();
705  }
Container db
Actual container for the entries.
Definition: scheduling.h:725

◆ exists()

template<typename _Type >
bool HF::Core::Scheduling::Entries< _Type >::exists ( const uint8_t  id) const
inlineprotected

Check if entry with given id exists.

Parameters
[in]idthe entry ID to search for.
Return values
trueif the entry already exists,
falseotherwise.

Definition at line 717 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db.

Referenced by HF::Core::Scheduling::Entries< _Type >::destroy(), HF::Core::Scheduling::Entries< _Type >::next_id(), and HF::Core::Scheduling::Entries< _Type >::save().

718  {
719  return std::any_of(db.begin(), db.end(), [id](const EntryType &e) {
720  return e.id == id;
721  });
722  }
Container db
Actual container for the entries.
Definition: scheduling.h:725
+ Here is the caller graph for this function:

◆ find()

template<typename _Type >
EntryPointer HF::Core::Scheduling::Entries< _Type >::find ( uint8_t  id) const
inlinevirtual

Find the Event with the given id.

Parameters
[in]idEvent ID to search for.
Returns
pointer to the entry with the given id, nullptr otherwise.

Implements HF::Core::Scheduling::IEntries< _Type >.

Definition at line 626 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db.

627  {
628  auto it = std::find_if(db.begin(), db.end(),
629  [id](const EntryType &e)
630  {return e.id == id;});
631 
632  if (it == db.end())
633  {
634  return EntryPointer();
635  }
636  else
637  {
638  return EntryPointer(const_cast<EntryType *>(&(*it)));
639  }
640  }
Container db
Actual container for the entries.
Definition: scheduling.h:725

◆ for_each()

template<typename _Type >
void HF::Core::Scheduling::Entries< _Type >::for_each ( std::function< void(Entry< _Type > &)>  func)
inline

Call the given function with each entry in the DB as argument.

Parameters
[in]funcfunction to apply to all entries in the store.

Definition at line 643 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db.

644  {
645  std::for_each(db.begin(), db.end(), func);
646  }
Container db
Actual container for the entries.
Definition: scheduling.h:725

◆ next_id()

template<typename _Type >
uint8_t HF::Core::Scheduling::Entries< _Type >::next_id ( ) const
inlinevirtual

Return next available id for event.

Returns
the id to use in the next event, or Scheduler::Entry::AVAILABLE_ID if no id is available.

Implements HF::Core::Scheduling::IEntries< _Type >.

Definition at line 649 of file scheduling.h.

References HF::Core::Scheduling::Entry< _Type >::AVAILABLE_ID, HF::Core::Scheduling::Entries< _Type >::db, HF::Core::Scheduling::Entries< _Type >::exists(), HF::Core::Scheduling::Entry< _Type >::MAX_ID, and HF::Core::Scheduling::Entry< _Type >::START_ID.

650  {
651  if (std::distance(db.begin(), db.end()) > EntryType::MAX_ID)
652  {
654  }
655 
656  for (uint8_t id = EntryType::START_ID; id <= EntryType::MAX_ID; ++id)
657  {
658  if (!exists(id))
659  {
660  return id;
661  }
662  }
663 
665  }
static constexpr uint16_t START_ID
Lower bound for the entries ID.
Definition: scheduling.h:199
Container db
Actual container for the entries.
Definition: scheduling.h:725
static constexpr uint16_t MAX_ID
Upper bound for the entries ID.
Definition: scheduling.h:200
bool exists(const uint8_t id) const
Check if entry with given id exists.
Definition: scheduling.h:717
static constexpr uint16_t AVAILABLE_ID
Special ID for system allocated ID.
Definition: scheduling.h:201
+ Here is the call graph for this function:

◆ save() [1/2]

template<typename _Type >
Common::Result HF::Core::Scheduling::Entries< _Type >::save ( const EntryType entry)
inlinevirtual

Store the given entry to persistent storage.

Parameters
[in]entrythe entry to save to storage.
Return values
Common::Result::OKif the entry was saved,
Common::Result::FAIL_UNKNOWNotherwise.

Implements HF::Core::Scheduling::IEntries< _Type >.

Definition at line 555 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db, HF::Core::Scheduling::Entries< _Type >::exists(), HF::Common::FAIL_ARG, HF::Core::Scheduling::Entry< _Type >::id, and HF::Common::OK.

Referenced by HF::Core::Scheduling::Entries< _Type >::save().

556  {
557  if (exists(entry.id))
558  {
560  }
561  else
562  {
563  db.push_front(entry);
564  return Common::Result::OK;
565  }
566  }
Container db
Actual container for the entries.
Definition: scheduling.h:725
bool exists(const uint8_t id) const
Check if entry with given id exists.
Definition: scheduling.h:717
Fail - Invalid Argument.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save() [2/2]

template<typename _Type >
Common::Result HF::Core::Scheduling::Entries< _Type >::save ( uint8_t  id,
uint8_t  status,
_Type &  time,
uint8_t  pid 
)
inline

Store the given entry to persistent storage.

Parameters
[in]identry's ID.
[in]statusentry's status.
[in]timeentry's time.
[in]pidentry's PID.
Return values
Common::Result::OKif the entry was saved,
Common::Result::FAIL_UNKNOWNotherwise.

Definition at line 579 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::save().

580  {
581  EntryType entry(id, status, time, pid);
582  return save(entry);
583  }
Common::Result save(const EntryType &entry)
Store the given entry to persistent storage.
Definition: scheduling.h:555
+ Here is the call graph for this function:

◆ size()

template<typename _Type >
uint16_t HF::Core::Scheduling::Entries< _Type >::size ( ) const
inlinevirtual

Return the number of entries in the container.

Returns
the number of entries in the container.

Implements HF::Common::IEntries< Entry< _Type > >.

Definition at line 549 of file scheduling.h.

References HF::Core::Scheduling::Entries< _Type >::db.

550  {
551  return std::distance(db.begin(), db.end());
552  }
Container db
Actual container for the entries.
Definition: scheduling.h:725

The documentation for this struct was generated from the following file: