22#include <flow/error/error.hpp> 
   23#include <boost/move/make_unique.hpp> 
   32  m_nickname(nickname_str),
 
   33  m_worker(get_logger(), std::string(
"tmr_ev-") + m_nickname)
 
   36  FLOW_LOG_TRACE(
"Timer_event_emitter [" << *
this << 
"]: Idle timer-emitter thread started.");
 
   41  using flow::util::Timer;
 
   43  return Timer(*(
m_worker.task_engine()));
 
   48  using boost::asio::writable_pipe;
 
   49  using boost::asio::connect_pipe;
 
   50  using boost::movelib::make_unique;
 
   52  auto read_end = make_unique<Timer_fired_read_end>(*(
m_worker.task_engine()));
 
   53  auto write_end = make_unique<writable_pipe>(*(
m_worker.task_engine()));
 
   55  connect_pipe(*read_end, *write_end, sys_err_code);
 
   60    FLOW_LOG_FATAL(
"connect_pipe() failed; this should never happen.  Details follow.");
 
   61    FLOW_ERROR_SYS_ERROR_LOG_FATAL();
 
   62    assert(
false && 
"connect_pipe() failed; this should never happen.  Details follow."); std::abort();
 
   73                                 std::move(write_end) });
 
   74  assert(result.second);
 
   76  FLOW_LOG_TRACE(
"Timer_event_emitter [" << *
this << 
"]: Pipe created; read-end ptr = [" << read_end_ref.get() << 
"].");
 
   78  return read_end_ref.get();
 
   83  FLOW_LOG_TRACE(
"Timer_event_emitter [" << *
this << 
"]: Starting timer async-wait; when/if it fires, " 
   84                 "we will write to write-end corresponding to read-end ptr = [" << read_end << 
"].");
 
   92  assert((it != 
m_signal_pipe_writers.end()) && 
"timer_async_wait() invoked on read_end from another *this?");
 
   93  const auto write_end = it->second.get();
 
   95  timer->async_wait([
this, write_end, read_end](
const Error_code& async_err_code)
 
   97    auto sys_err_code = async_err_code;
 
   99    if (sys_err_code == boost::asio::error::operation_aborted)
 
  110      FLOW_ERROR_SYS_ERROR_LOG_WARNING();
 
  111      FLOW_LOG_WARNING(
"Timer_event_emitter [" << *
this << 
"]: " 
  112                       "Timer system error; just logged; totally unexpected; pretending it fired normally.");
 
  115    FLOW_LOG_TRACE(
"Timer_event_emitter [" << *
this << 
"]: Timer fired.  Pushing byte to pipe; " 
  116                   "read_end ptr = [" << read_end << 
"].  User code should detect event soon and cause byte " 
  125  FLOW_LOG_TRACE(
"Timer_event_emitter [" << *
this << 
"]: Timer presumably fired and pushed byte to pipe; " 
  134    os << 
'[' << val.
m_nickname << 
"]@" << 
static_cast<const void*
>(&val);
 
An object of this type, used internally to implement sync_io-pattern objects that require timer event...
boost::asio::readable_pipe Timer_fired_read_end
Object representing the read end of IPC mechanism, where readable status indicates the associated tim...
const std::string m_nickname
Nickname as passed to ctor.
void consume_timer_firing_signal(Timer_fired_read_end *read_end)
Must be called after a timer_async_wait()-triggered timer fired, before invoking that method for the ...
void timer_async_wait(flow::util::Timer *timer, Timer_fired_read_end *read_end)
To be used on a timer T returned by create_timer(), this is the replacement for the usual T....
Timer_event_emitter(flow::log::Logger *logger_ptr, String_view nickname_str)
Constructs emitter, creating idle thread managing no timers.
flow::util::Timer create_timer()
Creates idle timer for use with timer_async_wait() subsequently.
boost::unordered_map< Timer_fired_read_end *, boost::movelib::unique_ptr< boost::asio::writable_pipe > > m_signal_pipe_writers
Stores the write-ends of the pipes created in create_timer_signal_pipe(), indexed by pointer to their...
flow::async::Single_thread_task_loop m_worker
The thread where (only) timer-firing events (from create_timer()-created Timers) execute.
Timer_fired_read_end * create_timer_signal_pipe()
Creates, and internally stores, an IPC mechanism instance intended for use with a given create_timer(...
std::vector< boost::movelib::unique_ptr< Timer_fired_read_end > > m_signal_pipe_readers
The readers (never null) returned by create_timer_signal_pipe().
Contains common code, as well as important explanatory documentation in the following text,...
std::ostream & operator<<(std::ostream &os, const Timer_event_emitter &val)
Prints string representation of the given Timer_event_emitter to the given ostream.
void pipe_produce(flow::log::Logger *logger_ptr, Pipe_writer *pipe)
Writes a byte to the given pipe writer.
void pipe_consume(flow::log::Logger *logger_ptr, Pipe_reader *pipe)
Reads a byte via the given pipe reader.
flow::util::String_view String_view
Short-hand for Flow's String_view.
Log_component
The flow::log::Component payload enumeration containing various log components used by Flow-IPC inter...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.