| 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 | |
| 13 | #include <common/hashtable/hashtable.hpp> |
| 14 | |
| 15 | #include <lttng/lttng.h> |
| 16 | |
| 17 | #include <urcu.h> |
| 18 | #include <functional> |
| 19 | |
| 20 | struct ust_app; |
| 21 | |
| 22 | namespace lttng { |
| 23 | namespace sessiond { |
| 24 | namespace ust { |
| 25 | |
| 26 | class registry_event; |
| 27 | |
| 28 | class registry_channel : public lttng::sessiond::trace::stream_class { |
| 29 | public: |
| 30 | using registered_listener_fn = std::function<void(const registry_channel&)>; |
| 31 | using event_added_listener_fn = std::function<void(const registry_channel&, const registry_event &)>; |
| 32 | |
| 33 | registry_channel(uint32_t channel_id, |
| 34 | registered_listener_fn channel_registered_listener, |
| 35 | event_added_listener_fn new_event_listener); |
| 36 | void add_event(int session_objd, |
| 37 | int channel_objd, |
| 38 | std::string name, |
| 39 | std::string signature, |
| 40 | std::vector<lttng::sessiond::trace::field::cuptr> event_fields, |
| 41 | int loglevel_value, |
| 42 | nonstd::optional<std::string> model_emf_uri, |
| 43 | lttng_buffer_type buffer_type, |
| 44 | const ust_app& app, |
| 45 | uint32_t& out_event_id); |
| 46 | virtual ~registry_channel(); |
| 47 | |
| 48 | virtual const lttng::sessiond::trace::type& get_context() const override final; |
| 49 | void set_context(lttng::sessiond::trace::type::cuptr context); |
| 50 | |
| 51 | /* Channel was registered to at least one application. */ |
| 52 | bool is_registered() const; |
| 53 | void set_as_registered(); |
| 54 | |
| 55 | uint64_t _key; |
| 56 | uint64_t _consumer_key; |
| 57 | |
| 58 | /* |
| 59 | * Hash table containing events sent by the UST tracer. MUST be accessed |
| 60 | * with a RCU read side lock acquired. |
| 61 | */ |
| 62 | struct lttng_ht *_events; |
| 63 | struct lttng_ht_node_u64 _node; |
| 64 | /* For delayed reclaim */ |
| 65 | struct rcu_head _rcu_head; |
| 66 | /* Once this value reaches UINT32_MAX, no more id can be allocated. */ |
| 67 | uint32_t _next_event_id; |
| 68 | |
| 69 | private: |
| 70 | virtual void _accept_on_event_classes( |
| 71 | lttng::sessiond::trace::trace_class_visitor& trace_class_visitor) const override final; |
| 72 | |
| 73 | registered_listener_fn _is_registered_listener; |
| 74 | event_added_listener_fn _event_added_listener; |
| 75 | /* Indicates if this channel registry has already been registered. */ |
| 76 | bool _is_registered; |
| 77 | }; |
| 78 | |
| 79 | } /* namespace ust */ |
| 80 | } /* namespace sessiond */ |
| 81 | } /* namespace lttng */ |
| 82 | |
| 83 | #endif /* LTTNG_UST_REGISTRY_CHANNEL_H */ |