Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / src / common / conditions / condition.c
index 1abb2030bb41b6b66201cace7252e5d2beb0dadc..564b9c344cb4b1b1590e846c62815e2305708d49 100644 (file)
@@ -5,17 +5,18 @@
  *
  */
 
-#include <lttng/condition/condition-internal.h>
+#include <common/buffer-view.h>
+#include <common/dynamic-buffer.h>
+#include <common/error.h>
+#include <common/macros.h>
+#include <common/mi-lttng.h>
 #include <lttng/condition/buffer-usage-internal.h>
+#include <lttng/condition/condition-internal.h>
 #include <lttng/condition/event-rule-matches-internal.h>
 #include <lttng/condition/session-consumed-size-internal.h>
 #include <lttng/condition/session-rotation-internal.h>
-#include <common/macros.h>
-#include <common/error.h>
-#include <common/dynamic-buffer.h>
-#include <common/buffer-view.h>
+#include <lttng/error-query-internal.h>
 #include <stdbool.h>
-#include <assert.h>
 
 enum lttng_condition_type lttng_condition_get_type(
                const struct lttng_condition *condition)
@@ -49,7 +50,7 @@ void lttng_condition_put(struct lttng_condition *condition)
                return;
        }
 
-       assert(condition->destroy);
+       LTTNG_ASSERT(condition->destroy);
        urcu_ref_put(&condition->ref, condition_destroy_ref);
 }
 
@@ -170,8 +171,9 @@ ssize_t lttng_condition_create_from_payload(
        case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
                create_from_payload = lttng_condition_session_rotation_completed_create_from_payload;
                break;
-       case LTTNG_CONDITION_TYPE_ON_EVENT:
-               create_from_payload = lttng_condition_on_event_create_from_payload;
+       case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES:
+               create_from_payload =
+                               lttng_condition_event_rule_matches_create_from_payload;
                break;
        default:
                ERR("Attempted to create condition of unknown type (%i)",
@@ -230,10 +232,68 @@ const char *lttng_condition_type_str(enum lttng_condition_type type)
        case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
                return "session rotation completed";
 
-       case LTTNG_CONDITION_TYPE_ON_EVENT:
-               return "event rule hit";
+       case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES:
+               return "event rule matches";
 
        default:
                return "???";
        }
 }
+
+LTTNG_HIDDEN
+enum lttng_error_code lttng_condition_mi_serialize(
+               const struct lttng_trigger *trigger,
+               const struct lttng_condition *condition,
+               struct mi_writer *writer,
+               const struct mi_lttng_error_query_callbacks *error_query_callbacks)
+{
+       int ret;
+       enum lttng_error_code ret_code;
+       struct lttng_error_query_results *error_query_results = NULL;
+
+       LTTNG_ASSERT(condition);
+       LTTNG_ASSERT(writer);
+       LTTNG_ASSERT(condition->mi_serialize);
+
+       /* Open condition element. */
+       ret = mi_lttng_writer_open_element(writer, mi_lttng_element_condition);
+       if (ret) {
+               goto mi_error;
+       }
+
+       /* Serialize underlying condition. */
+       ret_code = condition->mi_serialize(condition, writer);
+       if (ret_code != LTTNG_OK) {
+               goto end;
+       }
+
+       /* Serialize error query results for the action. */
+       if (error_query_callbacks && error_query_callbacks->action_cb) {
+               ret_code = error_query_callbacks->condition_cb(
+                               trigger, &error_query_results);
+               if (ret_code != LTTNG_OK) {
+                       goto end;
+               }
+
+               ret_code = lttng_error_query_results_mi_serialize(
+                               error_query_results, writer);
+               if (ret_code != LTTNG_OK) {
+                       goto end;
+               }
+       }
+
+       /* Close condition element. */
+       ret = mi_lttng_writer_close_element(writer);
+       if (ret) {
+               goto mi_error;
+       }
+
+       ret_code = LTTNG_OK;
+       goto end;
+
+mi_error:
+       ret_code = LTTNG_ERR_MI_IO_FAIL;
+end:
+       lttng_error_query_results_destroy(error_query_results);
+       return ret_code;
+}
This page took 0.025494 seconds and 4 git commands to generate.