From 3d14ce4eaa999d881b7497ff12b7388661c13a08 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 17 May 2018 12:19:54 +0100 Subject: [PATCH] capture: use uint for requested counter id Also document this thing so it is more obvious what is going on with the resulting counter ranges. --- lib/capture/sp-capture-writer.c | 18 +++++++++++++++++- lib/capture/sp-capture-writer.h | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/capture/sp-capture-writer.c b/lib/capture/sp-capture-writer.c index 8ccc5342..d61490d2 100644 --- a/lib/capture/sp-capture-writer.c +++ b/lib/capture/sp-capture-writer.c @@ -1150,7 +1150,20 @@ sp_capture_writer_set_counters (SpCaptureWriter *self, return TRUE; } -gint +/** + * sp_capture_writer_request_counter: + * + * This requests a series of counter identifiers for the capture. + * + * The returning number is always greater than zero. The resulting counter + * values are monotonic starting from the resulting value. + * + * For example, if you are returned 5, and requested 3 counters, the counter + * ids you should use are 5, 6, and 7. + * + * Returns: The next series of counter values or zero on failure. + */ +guint sp_capture_writer_request_counter (SpCaptureWriter *self, guint n_counters) { @@ -1158,6 +1171,9 @@ sp_capture_writer_request_counter (SpCaptureWriter *self, g_assert (self != NULL); + if (G_MAXUINT - n_counters < self->next_counter_id) + return 0; + ret = self->next_counter_id; self->next_counter_id += n_counters; diff --git a/lib/capture/sp-capture-writer.h b/lib/capture/sp-capture-writer.h index 18670589..c2d2ae9c 100644 --- a/lib/capture/sp-capture-writer.h +++ b/lib/capture/sp-capture-writer.h @@ -106,7 +106,7 @@ gboolean sp_capture_writer_flush (SpCaptureWriter * gboolean sp_capture_writer_save_as (SpCaptureWriter *self, const gchar *filename, GError **error); -gint sp_capture_writer_request_counter (SpCaptureWriter *self, +guint sp_capture_writer_request_counter (SpCaptureWriter *self, guint n_counters); SpCaptureReader *sp_capture_writer_create_reader (SpCaptureWriter *self, GError **error);