2 * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef LTTNG_TSDL_TRACE_CLASS_VISITOR_H
9 #define LTTNG_TSDL_TRACE_CLASS_VISITOR_H
11 #include "event-class.hpp"
12 #include "stream-class.hpp"
13 #include "trace-class.hpp"
15 #include <vendor/optional.hpp>
18 #include <unordered_map>
24 using append_metadata_fragment_function = std::function<void(const std::string& fragment)>;
28 * Register types to be overriden. For example, a TSDL-safe copy of a type can
29 * be added to be overriden whenever the original type is encountered.
31 * Note that this class assumes no ownership of the original types. It assumes
32 * that the original types live as long as the original trace.
34 class type_overrider {
36 type_overrider() = default;
38 void publish(const lttng::sessiond::trace::type& original,
39 lttng::sessiond::trace::type::cuptr new_type_override);
40 const lttng::sessiond::trace::type&
41 type(const lttng::sessiond::trace::type& original) const noexcept;
44 std::unordered_map<const lttng::sessiond::trace::type *, lttng::sessiond::trace::type::cuptr>
47 } /* namespace details. */
50 * TSDL-producing trace class visitor.
52 * An instance of this class must not be used on multiple trace class instances.
53 * The `append_metadata` callback is automatically invoked when a coherent
54 * fragment of TSDL is available.
56 class trace_class_visitor : public lttng::sessiond::trace::trace_class_visitor {
58 trace_class_visitor(const lttng::sessiond::trace::abi& trace_abi,
59 append_metadata_fragment_function append_metadata);
61 void visit(const lttng::sessiond::trace::trace_class& trace_class) final;
62 void visit(const lttng::sessiond::trace::clock_class& clock_class) final;
63 void visit(const lttng::sessiond::trace::stream_class& stream_class) final;
64 void visit(const lttng::sessiond::trace::event_class& event_class) final;
67 /* Coherent (parseable) fragments must be appended. */
68 void append_metadata_fragment(const std::string& fragment) const;
69 const lttng::sessiond::trace::type&
70 _lookup_field_type(const lttng::sessiond::trace::field_location& field_location) const;
72 const lttng::sessiond::trace::abi& _trace_abi;
73 const append_metadata_fragment_function _append_metadata_fragment;
74 details::type_overrider _sanitized_types_overrides;
77 * Current visit context.
79 * The members of a trace class hierarchy do not provide back-references
80 * up the hierarchy (e.g. stream class to its parent trace class).
82 * This context allows the visitor to evaluate a "field location".
84 * _current_trace_class is set the first time a trace class is visited and
85 * remains valid until the destruction of this object.
87 * _current_stream_class and _current_event_class are set only in the
88 * context of the visit of a stream class and of its event class(es).
90 const lttng::sessiond::trace::trace_class *_current_trace_class = nullptr;
91 const lttng::sessiond::trace::stream_class *_current_stream_class = nullptr;
92 const lttng::sessiond::trace::event_class *_current_event_class = nullptr;
95 } /* namespace tsdl */
96 } /* namespace sessiond */
97 } /* namespace lttng */
99 #endif /* LTTNG_TSDL_TRACE_CLASS_VISITOR_H */