commit 7e9a2c944cd75337a6e2536581d746216ca81369
parent 57569615366a8ee30223b083742e4e48beb75c90
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Mon, 24 Feb 2025 11:19:06 +0100
Add surface and volume to sphin.config once it has been parsed
- Implement dynamic arrays for sphin_surface and sphin_volume pointers;
- Append new volumes and surfaces to sphin->volumes and sphin->
surfaces;
- Put the reference counter for each one of the volumes and surfaces
when the config is released.
Diffstat:
6 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/src/sphin_config.c b/src/sphin_config.c
@@ -76,12 +76,38 @@ release_config(ref_T* address)
{
struct sphin_config* config = NULL;
struct sphin* sphin = NULL;
+ size_t i, nvolumes, nsurfaces;
+ struct sphin_volume** volumes;
+ struct sphin_surface** surfaces;
ASSERT(NULL != address);
-
config = CONTAINER_OF(address, struct sphin_config, ref);
+
+ /* Retrieve the number of volumes in the config and the array of pointers to
+ * each one of the volumes */
+ nvolumes = darray_sphin_volume_ptr_size_get(&config->volumes);
+ volumes = darray_sphin_volume_ptr_data_get(&config->volumes);
+ ASSERT(NULL != volumes);
+ /* Put references for each one of the volumes */
+ for (i=nvolumes; i; i--) {
+ SPHIN(volume_ref_put(volumes[i-1]));
+ };
+
+ /* Retrieve the number of surfaces in the config and the array of pointers to
+ * each one of the surfaces */
+ nsurfaces = darray_sphin_surface_ptr_size_get(&config->surfaces);
+ surfaces = darray_sphin_surface_ptr_data_get(&config->surfaces);
+ ASSERT(NULL != surfaces);
+ /* Put references for each one of the surfaces */
+ for (i=nsurfaces; i; i--) {
+ SPHIN(surface_ref_put(surfaces[i-1]));
+ };
+
+ /* Release the memory for config */
sphin = config->sphin;
MEM_RM(sphin->allocator, config);
+
+ /* Put the reference for sphin */
SPHIN(ref_put(sphin));
}
diff --git a/src/sphin_config.h b/src/sphin_config.h
@@ -25,6 +25,9 @@
#ifndef SPHIN_CONFIG_H
#define SPHIN_CONFIG_H
+#include "sphin_surface.h"
+#include "sphin_volume.h"
+
#include <rsys/ref_count.h> /* ref_T */
#include <rsys/rsys.h>
@@ -33,6 +36,8 @@ struct sphin;
struct sphin_config {
/* Put the fun things here */
+ struct darray_sphin_surface_ptr surfaces;
+ struct darray_sphin_volume_ptr volumes;
struct sphin* sphin;
ref_T ref;
};
diff --git a/src/sphin_surface.c b/src/sphin_surface.c
@@ -190,6 +190,8 @@ parse_surface
ASSERT(NULL != name);
ASSERT('\0' != name[0]); /* Name can't be empty */
+ str_init(config->sphin->allocator, &line);
+
res = surface_create(config->sphin, name, &surface);
if (RES_OK != res) { goto error; }
@@ -223,6 +225,11 @@ parse_surface
break;
}
}
+
+ /* Append a new element to the end of the sphin_config->surfaces array */
+ res = darray_sphin_surface_ptr_push_back(&config->surfaces, &surface);
+ if (RES_OK != res) {goto error; }
+
exit:
str_release(&line);
return res;
diff --git a/src/sphin_surface.h b/src/sphin_surface.h
@@ -25,6 +25,7 @@
#ifndef SPHIN_SURFACE_H
#define SPHIN_SURFACE_H
+#include <rsys/dynamic_array.h>
#include <rsys/rsys.h>
struct sphin_config;
@@ -36,4 +37,11 @@ parse_surface
struct txtrdr* txtrdr,
const char* name);
+/* Generate the dynamic array of pointers for the structure sphin_surface */
+#define DARRAY_NAME sphin_surface_ptr /* Prefix for api functions and structures:
+ darray_sphin_surface_ptr */
+#define DARRAY_DATA struct sphin_surface*
+
+/* Generate the code */
+#include <rsys/dynamic_array.h>
#endif /* SPHIN_SURFACE_H */
diff --git a/src/sphin_volume.c b/src/sphin_volume.c
@@ -210,7 +210,9 @@ parse_volume
}
}
- /* TODO add the volume to the config */
+ /* Append a new element to the end of the sphin_config->volumes array */
+ res = darray_sphin_volume_ptr_push_back(&config->volumes, &volume);
+ if (RES_OK != res) {goto error; }
exit:
str_release(&line);
diff --git a/src/sphin_volume.h b/src/sphin_volume.h
@@ -25,6 +25,7 @@
#ifndef SPHIN_VOLUME_H
#define SPHIN_VOLUME_H
+#include <rsys/dynamic_array.h>
#include <rsys/rsys.h>
struct sphin_config;
@@ -36,4 +37,12 @@ parse_volume
struct txtrdr* txtrdr,
const char* name);
+/* Generate the dynamic array of pointers for the structure sphin_volume */
+#define DARRAY_NAME sphin_volume_ptr /* Prefix for api functions and structures:
+ darray_sphin_volume_ptr */
+#define DARRAY_DATA struct sphin_volume*
+
+/* Generate the code */
+#include <rsys/dynamic_array.h>
+
#endif /* SPHIN_VOLUME_H */