| 1 | /* |
| 2 | * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef LTTNG_UST_REGISTRY_CHANNEL_H |
| 9 | #define LTTNG_UST_REGISTRY_CHANNEL_H |
| 10 | |
| 11 | #include "stream-class.hpp" |
| 12 | #include "trace-class.hpp" |
| 13 | |
| 14 | #include <common/hashtable/hashtable.hpp> |
| 15 | |
| 16 | #include <lttng/lttng.h> |
| 17 | |
| 18 | #include <functional> |
| 19 | #include <urcu.h> |
| 20 | |
| 21 | struct ust_app; |
| 22 | |
| 23 | namespace lttng { |
| 24 | namespace sessiond { |
| 25 | namespace ust { |
| 26 | |
| 27 | class registry_event; |
| 28 | |
| 29 | class registry_channel : public lttng::sessiond::trace::stream_class { |
| 30 | public: |
| 31 | using registered_listener_fn = std::function<void(const registry_channel&)>; |
| 32 | using event_added_listener_fn = |
| 33 | std::function<void(const registry_channel&, const registry_event&)>; |
| 34 | |
| 35 | registry_channel(uint32_t channel_id, |
| 36 | const lttng::sessiond::trace::abi& trace_abi, |
| 37 | std::string default_clock_class_name, |
| 38 | registered_listener_fn channel_registered_listener, |
| 39 | event_added_listener_fn new_event_listener); |
| 40 | void add_event(int session_objd, |
| 41 | int channel_objd, |
| 42 | std::string name, |
| 43 | std::string signature, |
| 44 | std::vector<lttng::sessiond::trace::field::cuptr> event_fields, |
| 45 | int loglevel_value, |
| 46 | nonstd::optional<std::string> model_emf_uri, |
| 47 | lttng_buffer_type buffer_type, |
| 48 | const ust_app& app, |
| 49 | uint32_t& out_event_id); |
| 50 | ~registry_channel() override; |
| 51 | registry_channel(const registry_channel&) = delete; |
| 52 | registry_channel(registry_channel&&) = delete; |
| 53 | registry_channel& operator=(registry_channel&&) = delete; |
| 54 | registry_channel& operator=(const registry_channel&) = delete; |
| 55 | |
| 56 | const lttng::sessiond::trace::type *event_context() const final; |
| 57 | void event_context(lttng::sessiond::trace::type::cuptr context); |
| 58 | |
| 59 | /* Channel was registered to at least one application. */ |
| 60 | bool is_registered() const; |
| 61 | void set_as_registered(); |
| 62 | |
| 63 | uint64_t _key; |
| 64 | uint64_t _consumer_key; |
| 65 | |
| 66 | /* |
| 67 | * Hash table containing events sent by the UST tracer. MUST be accessed |
| 68 | * with a RCU read side lock acquired. |
| 69 | */ |
| 70 | struct lttng_ht *_events; |
| 71 | struct lttng_ht_node_u64 _node; |
| 72 | /* For delayed reclaim */ |
| 73 | struct rcu_head _rcu_head; |
| 74 | /* Once this value reaches UINT32_MAX, no more id can be allocated. */ |
| 75 | uint32_t _next_event_id; |
| 76 | |
| 77 | private: |
| 78 | void _accept_on_event_classes( |
| 79 | lttng::sessiond::trace::trace_class_visitor& trace_class_visitor) const final; |
| 80 | |
| 81 | registered_listener_fn _is_registered_listener; |
| 82 | event_added_listener_fn _event_added_listener; |
| 83 | /* Indicates if this channel registry has already been registered. */ |
| 84 | bool _is_registered; |
| 85 | }; |
| 86 | |
| 87 | } /* namespace ust */ |
| 88 | } /* namespace sessiond */ |
| 89 | } /* namespace lttng */ |
| 90 | |
| 91 | #endif /* LTTNG_UST_REGISTRY_CHANNEL_H */ |