]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
uuid: add basic uuid set functions
authorJaroslav Kysela <perex@perex.cz>
Tue, 5 Dec 2017 20:06:24 +0000 (21:06 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 6 Dec 2017 10:11:30 +0000 (11:11 +0100)
src/uuid.c
src/uuid.h

index 80684151a41fe73f4ee3e8b150c418587af0b48a..bccab106792e63059647b01939b87b15c2cb1b24 100644 (file)
@@ -155,3 +155,47 @@ uuid_hexvalid ( const char *uuid )
       return 0;
   return 1;
 }
+
+/* Init uuid set */
+void
+uuid_set_init( tvh_uuid_set_t *us, uint32_t alloc_chunk )
+{
+  memset(us, 0, sizeof(*us));
+  us->us_alloc_chunk = alloc_chunk ?: 10;
+}
+
+/* Add an uuid to set */
+tvh_uuid_t *
+uuid_set_add ( tvh_uuid_set_t *us, const tvh_uuid_t *u ) 
+{
+  tvh_uuid_t *nu;
+
+  if (us->us_count >= us->us_size) {
+    nu = realloc(us->us_array, sizeof(*u) * (us->us_size + us->us_alloc_chunk));
+    if (nu == NULL)
+      return NULL;
+    us->us_size += us->us_alloc_chunk;
+  }
+  nu = &us->us_array[us->us_count++];
+  *nu = *u;
+  return nu;
+}
+
+/* Free uuid set */
+void
+uuid_set_free ( tvh_uuid_set_t *us )
+{
+  if (us) {
+    free(us->us_array);
+  }
+}
+
+/* Destroy uuid set */
+void
+uuid_set_destroy ( tvh_uuid_set_t *us )
+{
+  if (us) {
+    uuid_set_free(us);
+    free(us);
+  }
+}
index bdd854448d23a9a7cc94bedb7009dc618289b42b..bf174bd6d9dfca91b6bd19865cbb2ff8af6f2037 100644 (file)
@@ -32,6 +32,14 @@ typedef struct uuid {
   uint8_t bin[UUID_BIN_SIZE];
 } tvh_uuid_t;
 
+/* Structure for the uuid set */
+typedef struct uuid_set {
+  tvh_uuid_t *us_array;
+  uint32_t us_count;
+  uint32_t us_size;
+  uint32_t us_alloc_chunk;
+} tvh_uuid_set_t;
+
 /* Initialise subsystem */
 void uuid_init ( void );
 
@@ -73,6 +81,40 @@ static inline int uuid_empty ( const tvh_uuid_t *a )
  */
 int uuid_hexvalid ( const char *uuid );
 
+/**
+ *
+ */
+void uuid_set_init( tvh_uuid_set_t *us, uint32_t alloc_chunk );
+
+/**
+ *
+ */
+tvh_uuid_t *uuid_set_add( tvh_uuid_set_t *us, const tvh_uuid_t *u );
+
+/**
+ *
+ */
+void uuid_set_free( tvh_uuid_set_t *us );
+
+/**
+ *
+ */
+void uuid_set_destroy( tvh_uuid_set_t *us );
+
+/**
+ *
+ */
+static inline int uuid_set_empty( tvh_uuid_set_t *us )
+  { return us->us_count == 0; }
+
+/**
+ *
+ */
+#define UUID_SET_FOREACH(u, us, u32) \
+  if ((us)->us_count > 0) \
+    for ((u32) = 0, (u) = (us)->us_array; \
+         (u32) < (us)->us_count; (u32)++, (u)++)
+
 /**
  * Hex string to binary
  */