+ struct cds_list_head head = CDS_LIST_HEAD_INIT(head);
+};
+
+namespace lttng {
+namespace sessiond {
+class user_space_consumer_channel_keys {
+ friend ltt_session;
+
+public:
+ class iterator;
+
+ enum class consumer_bitness : std::uint8_t {
+ ABI_32 = 32,
+ ABI_64 = 64,
+ };
+
+ enum class channel_type : std::uint8_t {
+ METADATA,
+ DATA,
+ };
+
+ iterator begin() const noexcept;
+ iterator end() const noexcept;
+
+private:
+ enum class _iteration_mode : std::uint8_t {
+ PER_PID,
+ PER_UID,
+
+ };
+
+ struct _iterator_creation_context {
+ const _iteration_mode _mode;
+ const ltt_ust_session& _session;
+ union {
+ lttng_ht *apps;
+ const cds_list_head *buffer_registry;
+ } _container;
+ };
+
+public:
+ class iterator : public std::iterator<std::input_iterator_tag, std::uint64_t> {
+ friend user_space_consumer_channel_keys;
+
+ public:
+ struct key {
+ /* Bitness is needed to query the appropriate consumer daemon. */
+ consumer_bitness bitness;
+ std::uint64_t key_value;
+ channel_type type;
+
+ bool operator==(const key& other)
+ {
+ return bitness == other.bitness && key_value == other.key_value &&
+ type == other.type;
+ }
+ };
+
+ /*
+ * Copy constructor disabled since it would require handling the copy of locked
+ * references.
+ */
+ iterator(const iterator& other) = delete;
+ iterator(iterator&& other) = default;
+ ~iterator() = default;
+ iterator& operator=(const iterator&) = delete;
+ iterator& operator=(iterator&&) noexcept = delete;
+
+ iterator& operator++();
+ bool operator==(const iterator& other) const noexcept;
+ bool operator!=(const iterator& other) const noexcept;
+ key operator*() const;
+
+ /*
+ * Get the session registry of the channel currently
+ * pointed by the iterator. Never returns nullptr.
+ */
+ lttng::sessiond::ust::registry_session *get_registry_session();
+
+ private:
+ struct _iterator_position {
+ struct {
+ lttng_ht_iter app_iterator = {};
+ nonstd::optional<ust_app_session::locked_weak_ref>
+ current_app_session;
+ lttng::sessiond::ust::registry_session *current_registry_session =
+ nullptr;
+ } _per_pid;
+ struct {
+ buffer_reg_uid *current_registry = nullptr;
+ } _per_uid;
+
+ lttng_ht_iter channel_iterator = {};
+ };
+
+ explicit iterator(const _iterator_creation_context& creation_context,
+ bool is_end = false);
+
+ void _init_per_pid() noexcept;
+ void _skip_to_next_app_per_pid(bool try_current) noexcept;
+ void _advance_one_per_pid();
+ key _get_current_value_per_pid() const noexcept;
+ lttng::sessiond::ust::registry_session *_get_registry_session_per_pid();
+
+ void _init_per_uid() noexcept;
+ void _advance_one_per_uid();
+ key _get_current_value_per_uid() const noexcept;
+ lttng::sessiond::ust::registry_session *_get_registry_session_per_uid();
+
+ const _iterator_creation_context& _creation_context;
+ _iterator_position _position;
+ bool _is_end;
+ };
+
+private:
+ user_space_consumer_channel_keys(const ltt_ust_session& ust_session, lttng_ht& apps) :
+ _creation_context{ _iteration_mode::PER_PID, ust_session, { .apps = &apps } }
+ {
+ }
+
+ user_space_consumer_channel_keys(const ltt_ust_session& ust_session,
+ const cds_list_head& buffer_registry) :
+ _creation_context{ _iteration_mode::PER_UID,
+ ust_session,
+ { .buffer_registry = &buffer_registry } }
+ {
+ }
+
+ class _scoped_rcu_read_lock {
+ public:
+ _scoped_rcu_read_lock()
+ {
+ rcu_read_lock();
+ }
+
+ ~_scoped_rcu_read_lock()
+ {
+ if (_armed) {
+ rcu_read_unlock();
+ }
+ }
+
+ _scoped_rcu_read_lock(_scoped_rcu_read_lock&& other) noexcept
+ {
+ other._armed = false;
+ }
+
+ _scoped_rcu_read_lock(_scoped_rcu_read_lock& other) = delete;
+ _scoped_rcu_read_lock& operator=(const _scoped_rcu_read_lock&) = delete;
+ _scoped_rcu_read_lock& operator=(_scoped_rcu_read_lock&&) noexcept = delete;
+
+ private:
+ bool _armed = true;
+ };
+
+ _scoped_rcu_read_lock _read_lock;
+ _iterator_creation_context _creation_context;