lttng-ctl: separate support of named/unnamed trigger registration
[lttng-tools.git] / include / lttng / trigger / trigger-internal.h
index 6942ece78d7a88d9b15a2585fdb200e43f0261f8..c58787ceb2cfb506a7280e02ccf6b6425783ea19 100644 (file)
@@ -8,13 +8,14 @@
 #ifndef LTTNG_TRIGGER_INTERNAL_H
 #define LTTNG_TRIGGER_INTERNAL_H
 
-#include <lttng/trigger/trigger.h>
 #include <common/credentials.h>
 #include <common/dynamic-array.h>
 #include <common/macros.h>
 #include <common/optional.h>
-#include <stdint.h>
+#include <lttng/lttng.h>
+#include <pthread.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <sys/types.h>
 #include <urcu/ref.h>
 
@@ -36,6 +37,25 @@ struct lttng_trigger {
         * notification.
         */
        LTTNG_OPTIONAL(uint64_t) tracer_token;
+
+       /*
+        * Is the trigger registered?
+        *
+        * This is necessary since a reference holder might be interested in the
+        * overall state of the trigger from the point of view of its owner.
+        *
+        * The main user is the action executor since we want to prevent the
+        * execution of actions related to a trigger that is unregistered.
+        *
+        * Not considered for `is_equal`.
+        */
+       bool registered;
+
+       /*
+        * The lock is used to protect against concurrent trigger execution and
+        * trigger removal.
+        */
+       pthread_mutex_t lock;
 };
 
 struct lttng_triggers {
@@ -75,15 +95,7 @@ int lttng_trigger_serialize(const struct lttng_trigger *trigger,
                struct lttng_payload *payload);
 
 LTTNG_HIDDEN
-const struct lttng_condition *lttng_trigger_get_const_condition(
-               const struct lttng_trigger *trigger);
-
-LTTNG_HIDDEN
-const struct lttng_action *lttng_trigger_get_const_action(
-               const struct lttng_trigger *trigger);
-
-LTTNG_HIDDEN
-bool lttng_trigger_validate(struct lttng_trigger *trigger);
+bool lttng_trigger_validate(const struct lttng_trigger *trigger);
 
 LTTNG_HIDDEN
 int lttng_trigger_assign_name(
@@ -161,4 +173,88 @@ LTTNG_HIDDEN
 void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
                const struct lttng_credentials *creds);
 
+/*
+ * Return the type of any underlying domain restriction. If no particular
+ * requirement is present, returns LTTNG_DOMAIN_NONE.
+ */
+LTTNG_HIDDEN
+enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
+               const struct lttng_trigger *trigger);
+
+/*
+ * Generate any bytecode related to the trigger.
+ * On success LTTNG_OK. On error, returns lttng_error code.
+ */
+LTTNG_HIDDEN
+enum lttng_error_code lttng_trigger_generate_bytecode(
+               struct lttng_trigger *trigger,
+               const struct lttng_credentials *creds);
+
+/*
+ * Note that the trigger object is not locked by "copy" as it is const and
+ * used with a number of 'const' triggers. If the trigger could be shared at
+ * the moment of the copy, it is the caller's responsability to lock it for
+ * the duration of the copy.
+ */
+LTTNG_HIDDEN
+struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger);
+
+/*
+ * A given trigger needs a tracer notifier if
+ *  it has an event-rule condition,
+ *  AND
+ *  it has one or more sessiond-execution action.
+ */
+LTTNG_HIDDEN
+bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+void lttng_trigger_set_as_registered(struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger);
+
+/*
+ * The trigger must be locked before calling lttng_trigger_is_registered.
+ *
+ * The lock is necessary since a trigger can be unregistered at any time.
+ *
+ * Manipulations requiring that the trigger be registered must always acquire
+ * the trigger lock for the duration of the manipulation using
+ * `lttng_trigger_lock` and `lttng_trigger_unlock`.
+ */
+LTTNG_HIDDEN
+bool lttng_trigger_is_registered(struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+void lttng_trigger_lock(struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+void lttng_trigger_unlock(struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+enum lttng_trigger_status lttng_trigger_add_error_results(
+               const struct lttng_trigger *trigger,
+               struct lttng_error_query_results *results);
+
+LTTNG_HIDDEN
+enum lttng_trigger_status lttng_trigger_add_action_error_query_results(
+               struct lttng_trigger *trigger,
+               struct lttng_error_query_results *results);
+
+/*
+ * Set the trigger name.
+ *
+ * A name is optional.
+ * A name will be assigned on trigger registration if no name is set.
+ *
+ * The name is copied.
+ *
+ * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
+ * if invalid parameters are passed.
+ */
+LTTNG_HIDDEN
+enum lttng_trigger_status lttng_trigger_set_name(
+               struct lttng_trigger *trigger, const char *name);
+
 #endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.025361 seconds and 5 git commands to generate.