+
+static
+enum lttng_error_code lttng_condition_session_rotation_mi_serialize(
+ const struct lttng_condition *condition,
+ struct mi_writer *writer)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+ enum lttng_condition_status status;
+ const char *session_name = NULL;
+ const char *type_element_str = NULL;
+
+ assert(condition);
+ assert(writer);
+ assert(is_rotation_condition(condition));
+
+ switch (lttng_condition_get_type(condition)) {
+ case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
+ type_element_str =
+ mi_lttng_element_condition_session_rotation_completed;
+ break;
+ case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
+ type_element_str =
+ mi_lttng_element_condition_session_rotation_ongoing;
+ break;
+ default:
+ abort();
+ break;
+ }
+
+ status = lttng_condition_session_rotation_get_session_name(
+ condition, &session_name);
+ assert(status == LTTNG_CONDITION_STATUS_OK);
+ assert(session_name);
+
+ /* Open condition session rotation_* element. */
+ ret = mi_lttng_writer_open_element(writer, type_element_str);
+ 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;
+ }
+
+ /* Close condition session rotation 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;
+}