+
+enum lttng_rotation_schedule_type lttng_rotation_schedule_get_type(
+ const struct lttng_rotation_schedule *schedule)
+{
+ return schedule ? schedule->type : LTTNG_ROTATION_SCHEDULE_TYPE_UNKNOWN;
+}
+
+struct lttng_rotation_schedule *
+lttng_rotation_schedule_size_threshold_create(void)
+{
+ struct lttng_rotation_schedule_size_threshold *schedule;
+
+ schedule = zmalloc(sizeof(*schedule));
+ if (!schedule) {
+ goto end;
+ }
+
+ schedule->parent.type = LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD;
+end:
+ return &schedule->parent;
+}
+
+enum lttng_rotation_status
+lttng_rotation_schedule_size_threshold_get_threshold(
+ const struct lttng_rotation_schedule *schedule,
+ uint64_t *size_threshold_bytes)
+{
+ enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
+ struct lttng_rotation_schedule_size_threshold *size_schedule;
+
+ if (!schedule || !size_threshold_bytes ||
+ schedule->type != LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD) {
+ status = LTTNG_ROTATION_STATUS_INVALID;
+ goto end;
+ }
+
+ size_schedule = container_of(schedule,
+ struct lttng_rotation_schedule_size_threshold,
+ parent);
+ if (size_schedule->size.set) {
+ *size_threshold_bytes = size_schedule->size.bytes;
+ } else {
+ status = LTTNG_ROTATION_STATUS_UNAVAILABLE;
+ goto end;
+ }
+end:
+ return status;
+}
+
+enum lttng_rotation_status
+lttng_rotation_schedule_size_threshold_set_threshold(
+ struct lttng_rotation_schedule *schedule,
+ uint64_t size_threshold_bytes)
+{
+ enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
+ struct lttng_rotation_schedule_size_threshold *size_schedule;
+
+ if (!schedule || size_threshold_bytes == 0 ||
+ size_threshold_bytes == -1ULL ||
+ schedule->type != LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD) {
+ status = LTTNG_ROTATION_STATUS_INVALID;
+ goto end;
+ }
+
+ size_schedule = container_of(schedule,
+ struct lttng_rotation_schedule_size_threshold,
+ parent);
+ size_schedule->size.bytes = size_threshold_bytes;
+ size_schedule->size.set = true;
+end:
+ return status;
+}
+
+struct lttng_rotation_schedule *
+lttng_rotation_schedule_periodic_create(void)
+{
+ struct lttng_rotation_schedule_periodic *schedule;
+
+ schedule = zmalloc(sizeof(*schedule));
+ if (!schedule) {
+ goto end;
+ }
+
+ schedule->parent.type = LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC;
+end:
+ return &schedule->parent;
+}
+
+enum lttng_rotation_status
+lttng_rotation_schedule_periodic_get_period(
+ const struct lttng_rotation_schedule *schedule,
+ uint64_t *period_us)
+{
+ enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
+ struct lttng_rotation_schedule_periodic *periodic_schedule;
+
+ if (!schedule || !period_us ||
+ schedule->type != LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC) {
+ status = LTTNG_ROTATION_STATUS_INVALID;
+ goto end;
+ }
+
+ periodic_schedule = container_of(schedule,
+ struct lttng_rotation_schedule_periodic,
+ parent);
+ if (periodic_schedule->period.set) {
+ *period_us = periodic_schedule->period.us;
+ } else {
+ status = LTTNG_ROTATION_STATUS_UNAVAILABLE;
+ goto end;
+ }
+end:
+ return status;
+}
+
+enum lttng_rotation_status
+lttng_rotation_schedule_periodic_set_period(
+ struct lttng_rotation_schedule *schedule,
+ uint64_t period_us)
+{
+ enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
+ struct lttng_rotation_schedule_periodic *periodic_schedule;
+
+ if (!schedule || period_us == 0 || period_us == -1ULL ||
+ schedule->type != LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC) {
+ status = LTTNG_ROTATION_STATUS_INVALID;
+ goto end;
+ }
+
+ periodic_schedule = container_of(schedule,
+ struct lttng_rotation_schedule_periodic,
+ parent);
+ periodic_schedule->period.us = period_us;
+ periodic_schedule->period.set = true;
+end:
+ return status;
+}
+
+void lttng_rotation_schedule_destroy(struct lttng_rotation_schedule *schedule)
+{
+ if (!schedule) {
+ return;
+ }
+ free(schedule);
+}
+
+void lttng_rotation_schedules_destroy(
+ struct lttng_rotation_schedules *schedules)
+{
+ unsigned int i;
+
+ if (!schedules) {
+ return;
+ }
+
+ for (i = 0; i < schedules->count; i++) {
+ lttng_rotation_schedule_destroy(schedules->schedules[i]);
+ }
+ free(schedules);
+}
+
+
+enum lttng_rotation_status lttng_rotation_schedules_get_count(
+ const struct lttng_rotation_schedules *schedules,
+ unsigned int *count)
+{
+ enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK;
+
+ if (!schedules || !count) {
+ status = LTTNG_ROTATION_STATUS_INVALID;
+ goto end;
+ }
+
+ *count = schedules->count;
+end:
+ return status;
+}
+
+const struct lttng_rotation_schedule *lttng_rotation_schedules_get_at_index(
+ const struct lttng_rotation_schedules *schedules,
+ unsigned int index)
+{
+ const struct lttng_rotation_schedule *schedule = NULL;
+
+ if (!schedules || index >= schedules->count) {
+ goto end;
+ }
+
+ schedule = schedules->schedules[index];
+end:
+ return schedule;
+}
+
+enum lttng_rotation_status lttng_session_add_rotation_schedule(
+ const char *session_name,
+ const struct lttng_rotation_schedule *schedule)
+{
+ return lttng_rotation_update_schedule(session_name, schedule, true);
+}
+
+enum lttng_rotation_status lttng_session_remove_rotation_schedule(
+ const char *session_name,
+ const struct lttng_rotation_schedule *schedule)
+{
+ return lttng_rotation_update_schedule(session_name, schedule, false);
+}
+
+int lttng_session_list_rotation_schedules(
+ const char *session_name,
+ struct lttng_rotation_schedules **schedules)
+{
+ return get_schedules(session_name, schedules);
+}