Flow 1.0.0
Flow project: Full implementation reference.
|
Convenience class that simply stores a Logger and/or Component passed into a constructor; and returns this Logger and Component via get_logger() and get_log_component() public accessors. More...
#include <log.hpp>
Public Member Functions | |
Log_context (Logger *logger=0) | |
Constructs Log_context by storing the given pointer to a Logger and a null Component. More... | |
template<typename Component_payload > | |
Log_context (Logger *logger, Component_payload component_payload) | |
Constructs Log_context by storing the given pointer to a Logger and a new Component storing the specified generically typed payload (an enum value). More... | |
Log_context (const Log_context &src) | |
Copy constructor that stores equal Logger* and Component values as the source. More... | |
Log_context (Log_context &&src) | |
Move constructor that makes this equal to src , while the latter becomes as-if default-constructed. More... | |
Log_context & | operator= (const Log_context &src) |
Assignment operator that behaves similarly to the copy constructor. More... | |
Log_context & | operator= (Log_context &&src) |
Move assignment operator that behaves similarly to the move constructor. More... | |
void | swap (Log_context &other) |
Swaps Logger pointers and Component objects held by *this and other . More... | |
Logger * | get_logger () const |
Returns the stored Logger pointer, particularly as many FLOW_LOG_*() macros expect. More... | |
const Component & | get_log_component () const |
Returns reference to the stored Component object, particularly as many FLOW_LOG_*() macros expect. More... | |
Private Attributes | |
Logger * | m_logger |
The held Logger pointer. Making the pointer itself non-const to allow operator=() to work. More... | |
Component | m_component |
The held Component object. Making the object non-const to allow operator=() to work. More... | |
Convenience class that simply stores a Logger and/or Component passed into a constructor; and returns this Logger and Component via get_logger() and get_log_component() public accessors.
It's extremely useful (almost mandatory in conventional practice) for classes that want to log, as they can simply derive from it (passing in the desired Logger*
and Component payload (an enum
value) into the Log_context superclass constructor), at which point the get_logger() and get_log_component() functions the FLOW_LOG_...()
macros expect automatically become available without any additional code having to be written in the logging class. Here is how:
Note that the operator=()
allows one to change the underlying Logger anytime after construction (e.g., existing_log_context = Log_context(&some_logger, Some_enum::S_SOME_COMPONENT);
).
The code could be shorter by getting rid of non-copy constuctor in favor of direct member initialization by user; and by simply omitting the API for the auto-generated copy constructor and assignment. However, in this case, I wanted to clearly document the API; and since there are more than 1 constructors, it seemed better to explicitly declare them all instead of replacing some with implicitly required direct initialization (again to make API more clearly documented).
The only operation of interest w/r/t threads is the aforementioned implicit assignment operator. Thread safety is the same as for any struct
with no locking done therein.
|
explicit |
Constructs Log_context by storing the given pointer to a Logger and a null Component.
logger | Pointer to store. Rationale for providing the null default: To facilitate subclass = default no-arg ctors. |
|
explicit |
Constructs Log_context by storing the given pointer to a Logger and a new Component storing the specified generically typed payload (an enum
value).
For more background on Component see its doc header.
Component_payload | See Component constructor doc header: Payload template arg specifically. |
logger | Pointer to store. |
component_payload | See Component constructor doc header: payload arg specifically. |
|
explicitdefault |
Copy constructor that stores equal Logger*
and Component values as the source.
This is explicit
, even though an unintentional copy (e.g., in a bind
sans cref
or ref
) would just internally involve the copying a pointer (as of this writing). The reason is that it's unlikely one wants to blithely copy these objects or objects of a sub-type; most likely (at least in scenarios seen so far, as of this writing) a cref
or ref
is in order instead. (I am open to counter-examples and thus removing this explicit
keyword if convinced by one.)
src | Source object. |
flow::log::Log_context::Log_context | ( | Log_context && | src | ) |
Move constructor that makes this equal to src
, while the latter becomes as-if default-constructed.
src | Source object. |
Definition at line 203 of file log.cpp.
References operator=().
const Component & flow::log::Log_context::get_log_component | ( | ) | const |
Returns reference to the stored Component object, particularly as many FLOW_LOG_*()
macros expect.
Definition at line 229 of file log.cpp.
References m_component.
Referenced by flow::net_flow::Node::categorize_pkts_as_dropped_on_acks(), flow::perf::Checkpointing_timer::Checkpointing_timer(), flow::net_flow::Low_lvl_packet::create_from_raw_data_packet(), flow::net_flow::Node::handle_syn_ack_ack_to_syn_rcvd(), flow::net_flow::Node::log_accumulated_acks(), flow::net_flow::Node::log_rcv_window(), flow::net_flow::Node::log_snd_window(), flow::net_flow::Node::low_lvl_packet_sent(), flow::net_flow::Node::mark_data_packet_sent(), flow::async::Cross_thread_task_loop::schedule_from_now(), flow::async::Segregated_thread_task_loop::schedule_from_now_impl(), flow::net_flow::Low_lvl_packet::serialize_to_raw_data_and_log(), flow::net_flow::Node::snd_flying_pkts_erase_one(), flow::net_flow::Node::snd_flying_pkts_push_one(), and flow::net_flow::Drop_timer::start_timer().
Logger * flow::log::Log_context::get_logger | ( | ) | const |
Returns the stored Logger pointer, particularly as many FLOW_LOG_*()
macros expect.
Definition at line 224 of file log.cpp.
References m_logger.
Referenced by flow::net_flow::Node::async_low_lvl_ack_send(), flow::net_flow::Node::async_low_lvl_syn_ack_ack_send_or_close_immediately(), flow::net_flow::Node::async_no_sock_low_lvl_rst_send(), flow::net_flow::asio::Node::async_op(), flow::net_flow::Node::async_rcv_wnd_recovery(), flow::net_flow::Node::async_sock_low_lvl_rst_send(), flow::net_flow::Node::async_wait_latency_then_handle_incoming(), flow::net_flow::Node::cancel_timers(), flow::net_flow::Node::categorize_pkts_as_dropped_on_acks(), flow::net_flow::Node::close_abruptly(), flow::cfg::Config_manager< S_d_value_set >::Config_manager(), flow::net_flow::Node::connect_with_metadata(), flow::net_flow::Node::connect_worker(), flow::perf::Checkpointing_timer::Aggregator::create_aggregated_result(), flow::net_flow::Node::create_syn(), flow::net_flow::Node::create_syn_ack(), flow::net_flow::Node::event_set_close(), flow::net_flow::Node::event_set_create(), flow::net_flow::Socket_buffer::feed_buf_move(), flow::net_flow::Socket_buffer::feed_bufs_copy(), flow::net_flow::Node::handle_incoming(), flow::net_flow::Node::handle_incoming_with_simulation(), flow::net_flow::Node::handle_syn_ack_ack_to_syn_rcvd(), flow::net_flow::Node::handle_syn_to_listening_server(), flow::net_flow::Node::listen(), flow::net_flow::Node::log_accumulated_acks(), flow::net_flow::Node::log_rcv_window(), flow::net_flow::Node::log_snd_window(), flow::net_flow::Node::low_lvl_packet_sent(), flow::net_flow::Node::mark_data_packet_sent(), flow::net_flow::Node::perform_regular_infrequent_tasks(), flow::async::Cross_thread_task_loop::post(), flow::async::Segregated_thread_task_loop::post_impl(), flow::net_flow::Node::receive_wnd_recovery_data_received(), flow::async::Cross_thread_task_loop::schedule_from_now(), flow::async::Segregated_thread_task_loop::schedule_from_now_impl(), flow::async::Segregated_thread_task_loop::Segregated_thread_task_loop(), flow::net_flow::Node::send_worker(), flow::net_flow::Low_lvl_packet::serialize_to_raw_data_and_log(), flow::net_flow::Node::serv_create_forward_plus_ctor_args(), flow::net_flow::Node::setup_connection_timers(), flow::net_flow::Node::setup_drop_timer(), flow::net_flow::Node::snd_flying_pkts_erase_one(), flow::net_flow::Node::snd_flying_pkts_push_one(), flow::net_flow::Node::sock_create_forward_plus_ctor_args(), flow::net_flow::Node::sock_data_to_reassembly_q_unless_overflow(), flow::net_flow::Node::sock_info(), flow::net_flow::Node::sock_track_new_data_after_gap_rexmit_off(), flow::async::Segregated_thread_task_loop::start(), flow::async::Cross_thread_task_loop::start(), flow::net_flow::Drop_timer::start_timer(), flow::net_flow::Node::sync_sock_low_lvl_rst_send(), flow::async::Task_qing_thread::Task_qing_thread(), flow::net_flow::Node::this_thread_init_logger_setup(), and flow::net_flow::Node::worker_run().
|
default |
Assignment operator that behaves similarly to the copy constructor.
src | Source object. |
*this
. Referenced by Log_context().
Log_context & flow::log::Log_context::operator= | ( | Log_context && | src | ) |
Move assignment operator that behaves similarly to the move constructor.
src | Source object. |
*this
. Definition at line 210 of file log.cpp.
References m_component, m_logger, swap(), and flow::log::swap().
void flow::log::Log_context::swap | ( | Log_context & | other | ) |
Swaps Logger pointers and Component objects held by *this
and other
.
No-op if this == &other
.
other | Other object. |
Definition at line 234 of file log.cpp.
References m_component, m_logger, swap(), and flow::log::swap().
Referenced by operator=(), swap(), and flow::log::swap().
|
private |
The held Component object. Making the object non-const
to allow operator=()
to work.
Definition at line 1721 of file log.hpp.
Referenced by get_log_component(), operator=(), and swap().
|
private |
The held Logger pointer. Making the pointer itself non-const
to allow operator=()
to work.
Definition at line 1719 of file log.hpp.
Referenced by get_logger(), operator=(), and swap().