star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

commit e5518528bf5673a6a41f74ccba4e8f847a7b0953
parent b4973869cbb836d5f9c21c6a1645e6346609620f
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Thu,  6 Feb 2025 16:47:49 +0100

Start implementation of sphin_surface parsing

Diffstat:
MMakefile | 2+-
Msrc/sphin.h | 10+++++++++-
Asrc/sphin_surface.c | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/sphin_surface.h | 39+++++++++++++++++++++++++++++++++++++++
4 files changed, 198 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -34,7 +34,7 @@ default: build_library ################################################################################ # Library building ################################################################################ -SRC = src/sphin.c src/sphin_config.c src/sphin_volume.c +SRC = src/sphin.c src/sphin_config.c src/sphin_volume.c src/sphin_surface.c OBJ = $(SRC:.c=.o) DEP = $(SRC:.c=.d) diff --git a/src/sphin.h b/src/sphin.h @@ -60,7 +60,7 @@ static const struct sphin_create_args SPHIN_CREATE_ARGS_DEFAULT = { struct sphin; /* Library handler */ struct sphin_config; /* Physical configuration */ struct sphin_volume; -// struct sphin_surface; +struct sphin_surface; BEGIN_DECLS @@ -120,6 +120,14 @@ SPHIN_API res_T sphin_volume_ref_put (struct sphin_volume* volume); +SPHIN_API res_T +sphin_surface_ref_get + (struct sphin_surface* surface); + +SPHIN_API res_T +sphin_surface_ref_put + (struct sphin_surface* surface); + END_DECLS #endif /* SPHIN_H */ diff --git a/src/sphin_surface.c b/src/sphin_surface.c @@ -0,0 +1,149 @@ + +/* Copyright (C) 2024 Centre National de la Recherche Scientifique + * Copyright (C) 2024 Clermont Auvergne INP + * Copyright (C) 2024 INSA Lyon + * Copyright (C) 2024 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024 Institut National Polytechnique de Toulouse + * Copyright (C) 2024 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024 Université de Lorraine + * Copyright (C) 2024 Université Paul Sabatier + * Copyright (C) 2024 Université Toulouse - Jean Jaurès + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "sphin.h" +#include "sphin_c.h" +#include "sphin_config.h" +#include "sphin_surface.h" + +#include <rsys/ref_count.h> +#include <rsys/str.h> +#include <rsys/text_reader.h> + +struct sphin_surface { + struct str name; + + struct sphin* sphin; + ref_T ref; +}; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static res_T +surface_create + (struct sphin* sphin, + const char* name, + struct sphin_surface** out_surface) +{ + struct sphin_surface* surface = NULL; + res_T res = RES_OK; + + ASSERT(NULL != sphin); + ASSERT(NULL != out_surface); + ASSERT(NULL != name); + ASSERT('\0' != name[0]); /* Name can't be empty */ + + surface = MEM_CALLOC(sphin->allocator, 1, sizeof(struct sphin_surface)); + if (NULL == surface) { + res = RES_MEM_ERR; + goto error; + } + ref_init(&surface->ref); + SPHIN(ref_get(sphin)); + surface->sphin = sphin; + + str_init(sphin->allocator, &surface->name); + res = str_set(&surface->name, name); + if (RES_OK != res) { + goto error; + } + +exit: + *out_surface = surface; + return res; +error: + if (NULL != surface) { + SPHIN(surface_ref_put(surface)); + surface = NULL; + } + goto exit; +} + +static void +release_surface(ref_T* address) +{ + struct sphin_surface* surface = NULL; + struct sphin* sphin = NULL; + + ASSERT(NULL != address); + + surface = CONTAINER_OF(address, struct sphin_surface, ref); + str_release(&surface->name); + sphin = surface->sphin; + MEM_RM(sphin->allocator, surface); + SPHIN(ref_put(sphin)); +} + +/******************************************************************************* + * Local functions + ******************************************************************************/ +res_T +parse_surface + (struct sphin_config* config, + struct txtrdr* txtrdr, + const char* name) +{ + struct sphin_surface* surface = NULL; + res_T res = RES_OK; + + ASSERT(NULL != config); + ASSERT(NULL != txtrdr); + ASSERT(NULL != name); + ASSERT('\0' != name[0]); /* Name can't be empty */ + + res = surface_create(config->sphin, name, &surface); + if (RES_OK != res) { + goto error; + } + +exit: + return res; +error: + goto exit; +} + +/******************************************************************************* + * Exported functions + ******************************************************************************/ +res_T +sphin_surface_ref_get(struct sphin_surface* surface) +{ + if(NULL == surface) { + return RES_BAD_ARG; + } + ref_get(&surface->ref); + return RES_OK; +} + +res_T +sphin_surface_ref_put(struct sphin_surface* surface) +{ + if(NULL == surface) { + return RES_BAD_ARG; + } + ref_put(&surface->ref, release_surface); + return RES_OK; +} diff --git a/src/sphin_surface.h b/src/sphin_surface.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2024 Centre National de la Recherche Scientifique + * Copyright (C) 2024 Clermont Auvergne INP + * Copyright (C) 2024 INSA Lyon + * Copyright (C) 2024 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024 Institut National Polytechnique de Toulouse + * Copyright (C) 2024 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024 Université de Lorraine + * Copyright (C) 2024 Université Paul Sabatier + * Copyright (C) 2024 Université Toulouse - Jean Jaurès + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SPHIN_SURFACE_H +#define SPHIN_SURFACE_H + +#include <rsys/rsys.h> + +struct sphin_config; +struct txtrdr; + +extern LOCAL_SYM res_T +parse_surface + (struct sphin_config* config, + struct txtrdr* txtrdr, + const char* name); + +#endif /* SPHIN_SURFACE_H */