stardis-ssconnect.c (2109B)
1 /* Copyright (C) 2018-2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "stardis-app.h" 17 #include "stardis-ssconnect.h" 18 19 #include <rsys/rsys.h> 20 #include <rsys/mem_allocator.h> 21 #include <rsys/str.h> 22 23 #include <sdis.h> 24 25 #include <limits.h> 26 27 /******************************************************************************* 28 * Public Functions 29 ******************************************************************************/ 30 res_T 31 init_ss_connect 32 (struct mem_allocator* allocator, 33 struct solid_solid_connect** dst) 34 { 35 res_T res = RES_OK; 36 int str_initialized = 0; 37 ASSERT(allocator && dst && *dst == NULL); 38 *dst = MEM_CALLOC(allocator, 1, sizeof(**dst)); 39 if(! *dst) { 40 res = RES_MEM_ERR; 41 goto error; 42 } 43 str_init(allocator, &(*dst)->name); 44 str_initialized = 1; 45 (*dst)->connection_id = UINT_MAX; 46 end: 47 return res; 48 error: 49 if(str_initialized) str_release(&(*dst)->name); 50 if(*dst) MEM_RM(allocator, *dst); 51 goto end; 52 } 53 54 void 55 release_ss_connect 56 (struct solid_solid_connect* connect, 57 struct mem_allocator* allocator) 58 { 59 ASSERT(connect && allocator); 60 str_release(&connect->name); 61 MEM_RM(allocator, connect); 62 } 63 64 res_T 65 str_print_ss_connect 66 (struct str* str, 67 const struct solid_solid_connect* connect) 68 { 69 res_T res = RES_OK; 70 ASSERT(str && connect); 71 ERR(str_append_printf(str, 72 "Solid-Solid connection '%s': contact resistance=%g", 73 str_cget(&connect->name), connect->tcr)); 74 end: 75 return res; 76 error: 77 goto end; 78 } 79