14 #include <unordered_map>
33 static const uint8_t magic[4];
99 using LogEvent = std::variant<KeyAddedEvent, KeyRemovedEvent, GUIEvent, StartEvent>;
111 std::map<std::string, sva::PTransformd>
init;
113 std::map<std::string, std::vector<std::vector<double>>>
init_q;
115 std::map<std::string, std::map<std::string, mc_rtc::Configuration>>
calibs;
127 Logger(
const Policy & policy,
const std::string & directory,
const std::string & tmpl);
140 void setup(
const Policy & policy,
const std::string & directory,
const std::string & tmpl);
146 inline const Meta &
meta() const noexcept {
return meta_; }
162 void start(
const std::string & ctl_name,
double timestep,
bool resume =
false,
double start_t = 0.0);
175 void open(
const std::string & file,
double timestep,
double start_t = 0.0);
205 template<
typename CallbackT,
206 typename SourceT = void,
207 typename std::enable_if<mc_rtc::log::callback_is_serializable<CallbackT>::value,
int>::type = 0>
208 void addLogEntry(
const std::string & name,
const SourceT * source, CallbackT && get_fn,
bool overwrite =
false)
210 using ret_t = decltype(get_fn());
211 using base_t =
typename std::decay<ret_t>::type;
212 auto it = find_entry(name);
213 if(it != log_entries_.end())
217 log::error(
"Already logging an entry named {}", name);
220 else { log_entries_.erase(it); }
243 template<
typename MemberPtrT,
246 typename std::enable_if<mc_rtc::log::is_serializable_member<MemberPtrT>::value,
int>::type = 0>
247 void addLogEntry(
const std::string & name,
const SourceT * source,
bool overwrite =
false)
249 using MemberT = decltype(source->*member);
250 addLogEntry(name, source, [source]() ->
const MemberT & {
return source->*member; }, overwrite);
268 template<
typename MethodPtrT,
271 typename std::enable_if<mc_rtc::log::is_serializable_getter<MethodPtrT>::value,
int>::type = 0>
272 void addLogEntry(
const std::string & name,
const SourceT * source,
bool overwrite =
false)
274 using MethodRetT = decltype((source->*method)());
275 addLogEntry(name, source, [source]() -> MethodRetT {
return (source->*method)(); }, overwrite);
293 template<typename T, typename std::enable_if<mc_rtc::log::callback_is_serializable<T>::value,
int>::type = 0>
294 void addLogEntry(
const std::string & name, T && get_fn,
bool overwrite =
false)
296 addLogEntry(name,
static_cast<const void *
>(
nullptr), std::forward<T>(get_fn), overwrite);
311 template<
typename SourceT,
typename CallbackT,
typename... Args>
312 void addLogEntries(
const SourceT * source,
const std::string & name, CallbackT && get_fn, Args &&... args)
314 addLogEntry(name, source, get_fn);
315 addLogEntries(source, std::forward<Args>(args)...);
349 const std::string &
path()
const;
355 inline size_t size()
const {
return log_entries_.size(); }
379 std::shared_ptr<LoggerImpl> impl_ =
nullptr;
383 std::vector<LogEvent> log_events_;
385 std::vector<LogEntry> log_entries_;
387 std::vector<LogEntry>::iterator find_entry(
const std::string & name);
390 template<
typename SourceT>
391 void addLogEntries(
const SourceT *)
397 #define MC_RTC_LOG_HELPER(NAME, MEMBER) \
399 using ThisT = typename std::remove_pointer<decltype(this)>::type; \
400 logger.addLogEntry<decltype(&ThisT::MEMBER), &ThisT::MEMBER>(NAME, this); \
404 #define MC_RTC_LOG_GETTER(NAME, METHOD) \
406 using MethodRetT = decltype(this->METHOD()); \
407 logger.addLogEntry(NAME, this, [this]() -> MethodRetT { return METHOD(); }); \
void error(Args &&... args)
Definition: logging.h:63
LogType
Definition: utils.h:13
Simplify access to values hold within a JSON file.
Definition: Configuration.h:166
GUI callback event.
Definition: Logger.h:80
std::string name
Definition: Logger.h:84
mc_rtc::Configuration data
Definition: Logger.h:86
std::vector< std::string > category
Definition: Logger.h:82
Data for a key added event.
Definition: Logger.h:64
log::LogType type
Definition: Logger.h:66
std::string key
Definition: Logger.h:68
Data for a key removed event.
Definition: Logger.h:73
std::string key
Definition: Logger.h:75
Start event.
Definition: Logger.h:96
Logs controller data to disk.
Definition: Logger.h:30
const Meta & meta() const noexcept
Access the log's metadata (const)
Definition: Logger.h:146
size_t size() const
Definition: Logger.h:355
Policy
Defines available policies for the logger.
Definition: Logger.h:43
Logger(const Policy &policy, const std::string &directory, const std::string &tmpl)
Constructor.
static const uint8_t version
Definition: Logger.h:38
void removeLogEntry(const std::string &name)
std::variant< KeyAddedEvent, KeyRemovedEvent, GUIEvent, StartEvent > LogEvent
Definition: Logger.h:99
void clear(bool record=true)
void removeLogEntries(const void *source)
void addLogEntry(const std::string &name, T &&get_fn, bool overwrite=false)
Definition: Logger.h:294
void addLogEntries(const SourceT *source, const std::string &name, CallbackT &&get_fn, Args &&... args)
Definition: Logger.h:312
void addGUIEvent(GUIEvent &&event)
Definition: Logger.h:322
std::function< void(mc_rtc::MessagePackBuilder &)> serialize_fn
Definition: Logger.h:40
Meta & meta() noexcept
Access the log's metadata.
Definition: Logger.h:143
const std::string & path() const
void start(const std::string &ctl_name, double timestep, bool resume=false, double start_t=0.0)
Start logging.
void setup(const Policy &policy, const std::string &directory, const std::string &tmpl)
Setup the constructor configuration.
void addLogEntry(const std::string &name, const SourceT *source, bool overwrite=false)
Definition: Logger.h:247
void open(const std::string &file, double timestep, double start_t=0.0)
Open a new file for logging.
void addLogEntry(const std::string &name, const SourceT *source, CallbackT &&get_fn, bool overwrite=false)
Definition: Logger.h:208
void log()
Log controller's data.
Definition: MessagePackBuilder.h:87
static void write(const T &data, mc_rtc::MessagePackBuilder &builder)
Definition: utils.h:185
#define MC_RTC_UTILS_DLLAPI
Definition: utils_api.h:50