Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / src / common / actions / snapshot-session.c
index 776615003a1120073e90f1408c2383299433b94b..26ddd1ba693465139e8466958a14ba2aeb13cf6e 100644 (file)
@@ -5,9 +5,9 @@
  *
  */
 
-#include <assert.h>
 #include <common/error.h>
 #include <common/macros.h>
+#include <common/mi-lttng.h>
 #include <common/payload-view.h>
 #include <common/payload.h>
 #include <common/snapshot.h>
@@ -62,7 +62,7 @@ lttng_action_snapshot_session_internal_get_rate_policy(
 static struct lttng_action_snapshot_session *
 action_snapshot_session_from_action(struct lttng_action *action)
 {
-       assert(action);
+       LTTNG_ASSERT(action);
 
        return container_of(
                        action, struct lttng_action_snapshot_session, parent);
@@ -71,7 +71,7 @@ action_snapshot_session_from_action(struct lttng_action *action)
 static const struct lttng_action_snapshot_session *
 action_snapshot_session_from_action_const(const struct lttng_action *action)
 {
-       assert(action);
+       LTTNG_ASSERT(action);
 
        return container_of(
                        action, struct lttng_action_snapshot_session, parent);
@@ -114,8 +114,8 @@ static bool lttng_action_snapshot_session_is_equal(
        b = action_snapshot_session_from_action_const(_b);
 
        /* Action is not valid if this is not true. */
-       assert(a->session_name);
-       assert(b->session_name);
+       LTTNG_ASSERT(a->session_name);
+       LTTNG_ASSERT(b->session_name);
        if (strcmp(a->session_name, b->session_name)) {
                goto end;
        }
@@ -145,8 +145,8 @@ static int lttng_action_snapshot_session_serialize(
        int ret;
        size_t size_before_comm;
 
-       assert(action);
-       assert(payload);
+       LTTNG_ASSERT(action);
+       LTTNG_ASSERT(payload);
 
        size_before_comm = payload->buffer.size;
 
@@ -161,7 +161,7 @@ static int lttng_action_snapshot_session_serialize(
                goto end;
        }
 
-       assert(action_snapshot_session->session_name);
+       LTTNG_ASSERT(action_snapshot_session->session_name);
        DBG("Serializing snapshot session action: session-name: %s",
                        action_snapshot_session->session_name);
 
@@ -373,6 +373,76 @@ end:
        return consumed_len;
 }
 
+static enum lttng_error_code lttng_action_snapshot_session_mi_serialize(
+               const struct lttng_action *action, struct mi_writer *writer)
+{
+       int ret;
+       enum lttng_error_code ret_code;
+       enum lttng_action_status status;
+       const char *session_name = NULL;
+       const struct lttng_snapshot_output *output = NULL;
+       const struct lttng_rate_policy *policy = NULL;
+
+       LTTNG_ASSERT(action);
+       LTTNG_ASSERT(IS_SNAPSHOT_SESSION_ACTION(action));
+
+       status = lttng_action_snapshot_session_get_session_name(
+                       action, &session_name);
+       LTTNG_ASSERT(status == LTTNG_ACTION_STATUS_OK);
+       LTTNG_ASSERT(session_name != NULL);
+
+       status = lttng_action_snapshot_session_get_rate_policy(action, &policy);
+       LTTNG_ASSERT(status == LTTNG_ACTION_STATUS_OK);
+       LTTNG_ASSERT(policy != NULL);
+
+       /* Open action snapshot session element. */
+       ret = mi_lttng_writer_open_element(
+                       writer, mi_lttng_element_action_snapshot_session);
+       if (ret) {
+               goto mi_error;
+       }
+
+       /* Session name. */
+       ret = mi_lttng_writer_write_element_string(
+                       writer, mi_lttng_element_session_name, session_name);
+       if (ret) {
+               goto mi_error;
+       }
+
+       /* Output if any. */
+       status = lttng_action_snapshot_session_get_output(action, &output);
+       if (status == LTTNG_ACTION_STATUS_OK) {
+               LTTNG_ASSERT(output != NULL);
+               ret_code = lttng_snapshot_output_mi_serialize(output, writer);
+               if (ret_code != LTTNG_OK) {
+                       goto end;
+               }
+       } else if (status != LTTNG_ACTION_STATUS_UNSET) {
+               /* This should not happen at this point. */
+               abort();
+       }
+
+       /* Rate policy. */
+       ret_code = lttng_rate_policy_mi_serialize(policy, writer);
+       if (ret_code != LTTNG_OK) {
+               goto end;
+       }
+
+       /* Close action_snapshot_session 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:
+       return ret_code;
+}
+
 struct lttng_action *lttng_action_snapshot_session_create(void)
 {
        struct lttng_action *action = NULL;
@@ -396,7 +466,8 @@ struct lttng_action *lttng_action_snapshot_session_create(void)
                        lttng_action_snapshot_session_is_equal,
                        lttng_action_snapshot_session_destroy,
                        lttng_action_snapshot_session_internal_get_rate_policy,
-                       lttng_action_generic_add_error_query_results);
+                       lttng_action_generic_add_error_query_results,
+                       lttng_action_snapshot_session_mi_serialize);
 
        status = lttng_action_snapshot_session_set_rate_policy(action, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
This page took 0.025469 seconds and 4 git commands to generate.