+/*
+ * Find the agent event matching a trigger.
+ *
+ * RCU read side lock MUST be acquired. It must be held for as long as
+ * the returned agent_event is used.
+ *
+ * Return object if found else NULL.
+ */
+struct agent_event *agent_find_event_by_trigger(
+ const struct lttng_trigger *trigger, struct agent *agt)
+{
+ enum lttng_condition_status c_status;
+ enum lttng_event_rule_status er_status;
+ enum lttng_domain_type domain;
+ const struct lttng_condition *condition;
+ const struct lttng_event_rule *rule;
+ const char *name;
+ const char *filter_expression;
+ /* Unused when loglevel_type is 'ALL'. */
+ int loglevel_value = 0;
+ enum lttng_loglevel_type loglevel_type;
+
+ assert(agt);
+ assert(agt->events);
+
+ condition = lttng_trigger_get_const_condition(trigger);
+
+ assert(lttng_condition_get_type(condition) ==
+ LTTNG_CONDITION_TYPE_EVENT_RULE_HIT);
+
+ c_status = lttng_condition_event_rule_get_rule(condition, &rule);
+ assert(c_status == LTTNG_CONDITION_STATUS_OK);
+
+ assert(lttng_event_rule_get_type(rule) ==
+ LTTNG_EVENT_RULE_TYPE_TRACEPOINT);
+
+ domain = lttng_event_rule_get_domain_type(rule);
+ assert(domain == LTTNG_DOMAIN_JUL || domain == LTTNG_DOMAIN_LOG4J ||
+ domain == LTTNG_DOMAIN_PYTHON);
+
+ /* Get the event's pattern ('name' in the legacy terminology). */
+ er_status = lttng_event_rule_tracepoint_get_pattern(rule, &name);
+ assert(er_status == LTTNG_EVENT_RULE_STATUS_OK);
+
+ /* Get the internal filter expression. */
+ filter_expression = lttng_event_rule_get_filter(rule);
+
+ er_status = lttng_event_rule_tracepoint_get_log_level_type(
+ rule, &loglevel_type);
+ assert(er_status == LTTNG_EVENT_RULE_STATUS_OK);
+
+ if (loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
+ er_status = lttng_event_rule_tracepoint_get_log_level(
+ rule, &loglevel_value);
+ assert(er_status == LTTNG_EVENT_RULE_STATUS_OK);
+ }
+
+ return agent_find_event(name, loglevel_type, loglevel_value,
+ filter_expression, agt);
+}
+