MI: implement all objects related to trigger machine interface
[lttng-tools.git] / src / common / actions / snapshot-session.c
index 776615003a1120073e90f1408c2383299433b94b..6c765edeac12cf90b71202aab1d91439d7a1797d 100644 (file)
@@ -8,6 +8,7 @@
 #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>
@@ -373,6 +374,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;
+
+       assert(action);
+       assert(IS_SNAPSHOT_SESSION_ACTION(action));
+
+       status = lttng_action_snapshot_session_get_session_name(
+                       action, &session_name);
+       assert(status == LTTNG_ACTION_STATUS_OK);
+       assert(session_name != NULL);
+
+       status = lttng_action_snapshot_session_get_rate_policy(action, &policy);
+       assert(status == LTTNG_ACTION_STATUS_OK);
+       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) {
+               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 +467,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.024212 seconds and 4 git commands to generate.