star-stl

Load STereo Lithography (StL) file format
git clone git://git.meso-star.fr/star-stl.git
Log | Files | Refs | README | LICENSE

commit ebfa4c3ae1c5ca3acc38debb8609c681429aece0
parent 879975e146846773586e6b140149c0f2e10e06c8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 18 Dec 2015 11:26:28 +0100

Implement the sstl management functions

Implement the sstl_create, sstl_ref_get and sstl_ref_put functions

Diffstat:
Mcmake/CMakeLists.txt | 3++-
Asrc/sstl.c | 119+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/sstl.h | 9++++++++-
3 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -54,10 +54,11 @@ rcmake_append_runtime_dirs(_runtime_dirs RSys) ################################################################################ set(SSTL_FILES_INC_API sstl.h) set(SSTL_FILES_INC ) -set(SSTL_FILES_SRC ) +set(SSTL_FILES_SRC sstl.c) set(SSTL_FILES_DOC COPYING.fr COPYING.en README.md) rcmake_prepend_path(SSTL_FILES_SRC ${SSTL_SOURCE_DIR}) rcmake_prepend_path(SSTL_FILES_INC ${SSTL_SOURCE_DIR}) +rcmake_prepend_path(SSTL_FILES_INC_API ${SSTL_SOURCE_DIR}) rcmake_prepend_path(SSTL_FILES_DOC ${SSTL_SOURCE_DIR}/../) add_library(sstl SHARED ${SSTL_FILES_SRC} ${SSTL_FILES_INC} ${SSTL_FILES_INC_API}) diff --git a/src/sstl.c b/src/sstl.c @@ -0,0 +1,119 @@ +/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com) + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#include "sstl.h" + +#include <rsys/logger.h> +#include <rsys/mem_allocator.h> +#include <rsys/ref_count.h> + +struct sstl { + int verbose; + struct logger* logger; + struct mem_allocator* allocator; + ref_T ref; +}; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +sstl_release(ref_T* ref) +{ + struct sstl* sstl; + ASSERT(ref); + sstl = CONTAINER_OF(ref, struct sstl, ref); + MEM_RM(sstl->allocator, sstl); +} + +/******************************************************************************* + * Exported functions + ******************************************************************************/ +res_T +sstl_create + (struct logger* log, + struct mem_allocator* mem_allocator, + const int verbose, + struct sstl** out_sstl) +{ + struct mem_allocator* allocator = NULL; + struct logger* logger = NULL; + struct sstl* sstl = NULL; + res_T res = RES_OK; + + if(!out_sstl) { + res = RES_BAD_ARG; + goto error; + } + + allocator = mem_allocator ? mem_allocator : &mem_default_allocator; + logger = log ? log : LOGGER_DEFAULT; + + sstl = MEM_CALLOC(mem_allocator, 1, sizeof(struct sstl)); + if(!sstl) { + if(verbose) { + logger_print(logger, LOG_ERROR, + "Couldn't allocate the Star-Heat device.\n"); + } + res = RES_MEM_ERR; + goto error; + } + + ref_init(&sstl->ref); + sstl->allocator = allocator; + sstl->logger = logger; + sstl->verbose = verbose; + +exit: + if(out_sstl) *out_sstl = sstl; + return res; +error: + if(sstl) { + SSTL(ref_put(sstl)); + sstl = NULL; + } + goto exit; +} + +res_T +sstl_ref_get(struct sstl* sstl) +{ + if(!sstl) return RES_BAD_ARG; + ref_get(&sstl->ref); + return RES_OK; +} + +res_T +sstl_ref_put(struct sstl* sstl) +{ + if(!sstl) return RES_BAD_ARG; + ref_put(&sstl->ref, sstl_release); + return RES_OK; + +} + diff --git a/src/sstl.h b/src/sstl.h @@ -49,6 +49,13 @@ #define SSTL(Func) sstl_ ## Func #endif +/* Forward declaration of external types */ +struct logger; +struct mem_allocator; + +/* Forward declaration of opaque data types */ +struct sstl; + /******************************************************************************* * Star-STL API ******************************************************************************/ @@ -59,7 +66,7 @@ sstl_create (struct logger* logger, /* NULL <=> use default logger*/ struct mem_allocator* allocator, /* NULL <=> use default allocator */ const int verbose, /* Verbosity level */ - struct sstl** obj); + struct sstl** sstl); SSTL_API res_T sstl_ref_get