*
*/
-#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>
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);
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);
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;
}
int ret;
size_t size_before_comm;
- assert(action);
- assert(payload);
+ LTTNG_ASSERT(action);
+ LTTNG_ASSERT(payload);
size_before_comm = payload->buffer.size;
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);
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;
lttng_action_snapshot_session_serialize,
lttng_action_snapshot_session_is_equal,
lttng_action_snapshot_session_destroy,
- lttng_action_snapshot_session_internal_get_rate_policy);
+ lttng_action_snapshot_session_internal_get_rate_policy,
+ 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) {