Class LogChannel
Defined in File channel.hpp
Inheritance Relationships
Base Type
public std::enable_shared_from_this< LogChannel >
Class Documentation
-
class LogChannel : public std::enable_shared_from_this<LogChannel>
A LogChannel is a class used to record multiple values in a single “snapshot”. Taking a snapshot is usually done in a periodic loop.
Instances of LogChannel are accessed through the ChannelsRegistry.
There is no limit to the number of tracked values, but sometimes you may want to use different LogChannels in your application to:
aggregate them logically or
take snapshots at different frequencies.
Use the methods LogChannel::registerValue or LogChannel::createLoggedValue to add a new value. All you values must be registered before calling takeSnapshot for the first time.
Public Functions
-
~LogChannel()
-
LogChannel(const LogChannel&) = delete
-
LogChannel &operator=(const LogChannel&) = delete
-
LogChannel(LogChannel&&) = delete
-
LogChannel &operator=(LogChannel&&) = delete
-
template<typename T>
inline RegistrationID registerValue(const std::string &name, const T *value) registerValue add a value to be monitored. You must guaranty that the pointer to the value is still valid, when calling takeSnapshot. If you want to change the pointer T* to a new one, you must first call unregister(), otherwise this method will throw an exception.
- Parameters:
name – name of the value
value – pointer to the value
- Returns:
the ID to be used to unregister or enable/disable this value.
-
template<template<class, class> class Container, class T, class ...TArgs>
inline RegistrationID registerValue(const std::string &name, const Container<T, TArgs...> *value) registerValue add a vectors of values. You must guaranty that the pointer to each value is still valid, when calling takeSnapshot.
- Parameters:
name – name of the vector
value – pointer to the vectors of values.
- Returns:
the ID to be used to unregister or enable/disable the values.
-
template<typename T, size_t N>
inline RegistrationID registerValue(const std::string &name, const std::array<T, N> *value) registerValue add an array of values. You must guaranty that the pointer to the array is still valid, when calling takeSnapshot.
- Parameters:
name – name of the array
value – pointer to the array of values.
- Returns:
the ID to be used to unregister or enable/disable the values.
-
template<typename T>
inline RegistrationID registerCustomValue(const std::string &name, const T *value, CustomSerializer::Ptr type_info) registerCustomValue should be used when you want to “bypass” the serialization provided by DataTamer and use your own.
This is an ADVANCED usage: using this approach does not guaranty that the application parsing the data is able to deserialize it correctly. Sink mayl save the custom schema, but it may or may not be enough. Prefer the template specialization of RegisterVariable<T>, if you can.
- Parameters:
name – name of the array
value – pointer to the array of values.
type_info – information needed to serialize this specific type.
- Returns:
the ID to be used to unregister or enable/disable the values.
createLoggedValue is similar to registerValue(), but the value is wrapped in a safer RAII interface. See LoggedValue for details.
- Parameters:
name – of the value
initial_value – initial value to give to the LoggedValue
- Returns:
the instance of LoggedValue, wrapped in a shared_ptr
-
const std::string &channelName() const
Name of this channel (passed to the constructor)
-
void setEnabled(const RegistrationID &id, bool enable)
Enabling / disabling a value is much faster than registering / unregistering. It should be preferred when we want to temporary remove a value from the snapshot.
-
void unregister(const RegistrationID &id)
NOTE: the unregistered value will not be removed from the Schema.
addDataSink add a sink, i.e. a class collecting our snapshots.
-
bool takeSnapshot(std::chrono::nanoseconds timestamp = NsecSinceEpoch())
takeSnapshot copies the current value of all your registered values and send an instance of Snapshot to all your Sinks.
- Parameters:
timestamp – is the time since epoch, by default.
- Returns:
true is succesfully pushed to all its sinks.
-
const ActiveMask &getActiveFlags()
getActiveFlags returns a serialized buffer, where each bit represents if a series is enabled or not. Therefore the vector size will be ceiling(series_count/8).
Even if technically we may use vector<bool>, this data structure is already serialized.
-
Mutex &writeMutex()
You will need to use this if:
your variables were registered using LogChannel::registerValue AND
the variables are being modified in a thread different than the one calling takeSnapshot()
No need to worry about LoggedValues (they use the mutex internally)
Public Static Functions
-
static std::shared_ptr<LogChannel> create(std::string name)
Use this static mentod do create an instance of LogChannel. it is recommended to use ChannelsRegistry::getChannel() instead
Protected Functions
-
LogChannel(std::string name)