zpp
Zephyr C++20 Framework
zpp::fifo_base< T_BaseFifoType, T_BaseItemType > Class Template Reference

Fifo CRTP base class. More...

#include <fifo.hpp>

Public Types

using native_type = struct k_fifo
 
using native_pointer = native_type *
 
using native_const_pointer = native_type const *
 
using item_type = T_BaseItemType
 
using item_pointer = item_type *
 
using item_const_pointer = item_type const *
 

Public Member Functions

constexpr auto native_handle () noexcept -> native_pointer
 get the Zephyr native fifo handle More...
 
constexpr auto native_handle () const noexcept -> native_const_pointer
 get the Zephyr native fifo handle More...
 
void cancel_wait () noexcept
 force a waiting thread to return with a timeout error More...
 
void push_back (item_pointer item) noexcept
 push an item on the back of the fifo More...
 
item_pointer pop_front () noexcept
 pop item from fifo waiting for ever More...
 
item_pointer try_pop_front () noexcept
 try to pop item from the fifo without waiting More...
 
template<class T_Rep , class T_Period >
item_pointer try_pop_front_for (const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
 try to pop item from the fifo waiting a certain amount of time More...
 
item_pointer front () noexcept
 get item at the front without removing it from the fifo More...
 
item_pointer back () noexcept
 get item at the back without removing it from the fifo More...
 
bool empty () noexcept
 check if the fifo is empty More...
 
 fifo_base (const fifo_base &)=delete
 
 fifo_base (fifo_base &&)=delete
 
fifo_baseoperator= (const fifo_base &)=delete
 
fifo_baseoperator= (fifo_base &&)=delete
 

Protected Member Functions

 fifo_base () noexcept
 default constructor, can only be called from derived types More...
 

Detailed Description

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType>
class zpp::fifo_base< T_BaseFifoType, T_BaseItemType >

Fifo CRTP base class.

Parameters
T_BaseFifoTypethe CRTP derived type
T_BaseItemTypethe item to store in this fifo

Definition at line 27 of file fifo.hpp.

Member Typedef Documentation

◆ item_const_pointer

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
using zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::item_const_pointer = item_type const *

Definition at line 35 of file fifo.hpp.

◆ item_pointer

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
using zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::item_pointer = item_type*

Definition at line 34 of file fifo.hpp.

◆ item_type

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
using zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::item_type = T_BaseItemType

Definition at line 33 of file fifo.hpp.

◆ native_const_pointer

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
using zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_const_pointer = native_type const *

Definition at line 31 of file fifo.hpp.

◆ native_pointer

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
using zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_pointer = native_type *

Definition at line 30 of file fifo.hpp.

◆ native_type

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
using zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_type = struct k_fifo

Definition at line 29 of file fifo.hpp.

Constructor & Destructor Documentation

◆ fifo_base() [1/3]

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::fifo_base ( )
inlineprotectednoexcept

default constructor, can only be called from derived types

Definition at line 40 of file fifo.hpp.

41  {
42  static_assert(std::is_standard_layout_v<item_type>);
43  static_assert(std::is_same_v<void*, decltype(item_type::fifo_reserved)>);
44  static_assert(offsetof(item_type, fifo_reserved) == 0);
45  }
T_BaseItemType item_type
Definition: fifo.hpp:33

◆ fifo_base() [2/3]

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::fifo_base ( const fifo_base< T_BaseFifoType, T_BaseItemType > &  )
delete

◆ fifo_base() [3/3]

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::fifo_base ( fifo_base< T_BaseFifoType, T_BaseItemType > &&  )
delete

Member Function Documentation

◆ back()

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
item_pointer zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::back ( )
inlinenoexcept

get item at the back without removing it from the fifo

Returns
the item or nullptr on error/timeout

Definition at line 144 of file fifo.hpp.

145  {
146  return static_cast<item_pointer>(
147  k_fifo_peek_tail(native_handle()));
148  }
item_type * item_pointer
Definition: fifo.hpp:34
constexpr auto native_handle() noexcept -> native_pointer
get the Zephyr native fifo handle
Definition: fifo.hpp:52

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().

◆ cancel_wait()

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
void zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::cancel_wait ( )
inlinenoexcept

force a waiting thread to return with a timeout error

Definition at line 70 of file fifo.hpp.

71  {
72  k_fifo_cancel_wait(native_handle());
73  }

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().

◆ empty()

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
bool zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::empty ( )
inlinenoexcept

check if the fifo is empty

Returns
true if the fifo is empty

Definition at line 155 of file fifo.hpp.

156  {
157  auto res = k_fifo_is_empty(native_handle());
158  if (res == 0) {
159  return false;
160  } else {
161  return true;
162  }
163  }

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().

◆ front()

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
item_pointer zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::front ( )
inlinenoexcept

get item at the front without removing it from the fifo

Returns
the item or nullptr on error/timeout

Definition at line 133 of file fifo.hpp.

134  {
135  return static_cast<item_pointer>(
136  k_fifo_peek_head(native_handle()));
137  }

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().

◆ native_handle() [1/2]

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
constexpr auto zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle ( ) const -> native_const_pointer
inlineconstexprnoexcept

get the Zephyr native fifo handle

Returns
pointer to a k_fifo

Definition at line 62 of file fifo.hpp.

63  {
64  return static_cast<const T_BaseFifoType<item_type>*>(this)->native_handle();
65  }

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().

◆ native_handle() [2/2]

◆ operator=() [1/2]

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
fifo_base& zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::operator= ( const fifo_base< T_BaseFifoType, T_BaseItemType > &  )
delete

◆ operator=() [2/2]

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
fifo_base& zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::operator= ( fifo_base< T_BaseFifoType, T_BaseItemType > &&  )
delete

◆ pop_front()

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
item_pointer zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::pop_front ( )
inlinenoexcept

pop item from fifo waiting for ever

Returns
the item or nullptr on error

Definition at line 91 of file fifo.hpp.

92  {
93  return static_cast<item_pointer>(
94  k_fifo_get(native_handle(), K_FOREVER));
95  }

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().

◆ push_back()

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
void zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::push_back ( item_pointer  item)
inlinenoexcept

push an item on the back of the fifo

Parameters
itemPointer to a item, the fifo does not take ownership

Definition at line 80 of file fifo.hpp.

81  {
82  k_fifo_put(native_handle(), item);
83  }

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().

◆ try_pop_front()

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
item_pointer zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::try_pop_front ( )
inlinenoexcept

try to pop item from the fifo without waiting

Returns
the item or nullptr on error/timeout

Definition at line 103 of file fifo.hpp.

104  {
105  return static_cast<item_pointer>(
106  k_fifo_get(native_handle(), K_NO_WAIT));
107  }

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().

◆ try_pop_front_for()

template<template< typename > typename T_BaseFifoType, typename T_BaseItemType >
template<class T_Rep , class T_Period >
item_pointer zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::try_pop_front_for ( const std::chrono::duration< T_Rep, T_Period > &  timeout)
inlinenoexcept

try to pop item from the fifo waiting a certain amount of time

Parameters
timeoutThe timeout before returning
Returns
the item or nullptr on error/timeout

Definition at line 118 of file fifo.hpp.

119  {
120  using namespace std::chrono;
121 
122  return static_cast<item_pointer>(
123  k_fifo_get(native_handle(),
124  duration_cast<milliseconds>(timeout).count()));
125  }

References zpp::fifo_base< T_BaseFifoType, T_BaseItemType >::native_handle().


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