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 dc1cb16ef8e2e78d9287a9b727133170ef3321bc
parent 62ea89b06d106d5b0cdf7b419d2e109f58a8dc13
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Tue,  4 Feb 2025 13:58:15 +0100

Continue the implementation of sphin_volume parsing

Diffstat:
Asrc/sphin_volume.c | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/sphin_volume.h | 39+++++++++++++++++++++++++++++++++++++++
2 files changed, 187 insertions(+), 0 deletions(-)

diff --git a/src/sphin_volume.c b/src/sphin_volume.c @@ -0,0 +1,148 @@ +/* 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_volume.h" + +#include <rsys/ref_count.h> +#include <rsys/str.h> +#include <rsys/text_reader.h> + +struct sphin_volume { + struct str name; + double ka; + struct sphin* sphin; + ref_T ref; +}; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static res_T +volume_create + (struct sphin* sphin, + const char* name, + struct sphin_volume** out_volume) +{ + struct sphin_volume* volume = NULL; + res_T res = RES_OK; + + ASSERT(NULL != sphin); + ASSERT(NULL != out_volume); + ASSERT(NULL != name); + ASSERT('\0' != name[0]); /* Name can't be empty */ + + volume = MEM_CALLOC(sphin->allocator, 1, sizeof(struct sphin_volume)); + if (NULL == volume) { + res = RES_MEM_ERR; + goto error; + } + ref_init(&volume->ref); + SPHIN(ref_get(sphin)); + volume->sphin = sphin; + + str_init(sphin->allocator, &volume->name); + res = str_set(&volume->name, name); + if (RES_OK != res) { + goto error; + } + +exit: + *out_volume = volume; + return res; +error: + if (NULL != volume) { + SPHIN(volume_ref_put(volume)); + volume = NULL; + } + goto exit; +} + +static void +release_volume(ref_T* address) +{ + struct sphin_volume* volume = NULL; + struct sphin* sphin = NULL; + + ASSERT(NULL != address); + + volume = CONTAINER_OF(address, struct sphin_volume, ref); + str_release(&volume->name); + sphin = volume->sphin; + MEM_RM(sphin->allocator, volume); + SPHIN(ref_put(sphin)); +} + +/******************************************************************************* + * Local functions + ******************************************************************************/ +res_T +parse_volume + (struct sphin_config* config, + struct txtrdr* txtrdr, + const char* name) +{ + struct sphin_volume* volume = 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 = volume_create(config->sphin, name, &volume); + if (RES_OK != res) { + goto error; + } + +exit: + return res; +error: + goto exit; +} + +/******************************************************************************* + * Exported functions + ******************************************************************************/ +res_T +sphin_volume_ref_get(struct sphin_volume* volume) +{ + if(NULL == volume) { + return RES_BAD_ARG; + } + ref_get(&volume->ref); + return RES_OK; +} + +res_T +sphin_volume_ref_put(struct sphin_volume* volume) +{ + if(NULL == volume) { + return RES_BAD_ARG; + } + ref_put(&volume->ref, release_volume); + return RES_OK; +} diff --git a/src/sphin_volume.h b/src/sphin_volume.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_VOLUME_H +#define SPHIN_VOLUME_H + +#include <rsys/rsys.h> + +struct sphin_config; +struct txtrdr; + +extern LOCAL_SYM res_T +parse_volume + (struct sphin_config* config, + struct txtrdr* txtrdr, + const char* name); + +#endif /* SPHIN_VOLUME_H */