From 8d81cf5922b1f29acd70f8683cc732e6cacac242 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 12 Mar 2015 17:46:40 +0100 Subject: [PATCH] gmio_core: merge gmio_task_control into gmio_transfer --- src/gmio_core/error.h | 6 +-- src/gmio_core/task_control.h | 52 -------------------- src/gmio_core/{task_control.c => transfer.c} | 8 +-- src/gmio_core/transfer.h | 32 +++++++++--- src/gmio_stl/stla_read.c | 19 +++---- src/gmio_stl/stla_write.c | 4 +- src/gmio_stl/stlb_read.c | 4 +- src/gmio_stl/stlb_write.c | 12 +++-- 8 files changed, 53 insertions(+), 84 deletions(-) delete mode 100644 src/gmio_core/task_control.h rename src/gmio_core/{task_control.c => transfer.c} (74%) diff --git a/src/gmio_core/error.h b/src/gmio_core/error.h index 4adb77a..8861adc 100644 --- a/src/gmio_core/error.h +++ b/src/gmio_core/error.h @@ -42,9 +42,9 @@ enum gmio_error /*! An error occurred with the argument gmio_stream_t */ GMIO_STREAM_ERROR = -4, - /*! Operation was stopped by user, that is to say - * gmio_task_control::is_stop_requested_func() returned GMIO_FALSE */ - GMIO_TASK_STOPPED_ERROR = -5 + /*! Transfer was stopped by user, that is to say + * gmio_transfer::is_stop_requested_func() returned GMIO_TRUE */ + GMIO_TRANSFER_STOPPED_ERROR = -5 }; typedef enum gmio_error gmio_error_t; diff --git a/src/gmio_core/task_control.h b/src/gmio_core/task_control.h deleted file mode 100644 index 2afe2ff..0000000 --- a/src/gmio_core/task_control.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** GeomIO Library -** Copyright FougSys (2 Mar. 2015) -** contact@fougsys.fr -** -** This software is a reusable library whose purpose is to provide complete -** I/O support for various CAD file formats (eg. STL) -** -** This software is governed by the CeCILL-B 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-B -** license as circulated by CEA, CNRS and INRIA at the following URL -** "http://www.cecill.info". -****************************************************************************/ - -/*! \file task_control.h - * Declaration of gmio_task_control and utility functions - */ - -#ifndef GMIO_TASK_CONTROL_H -#define GMIO_TASK_CONTROL_H - -#include "global.h" - -GMIO_C_LINKAGE_BEGIN - -/*! Provides control over a general task. - * - * "Control" here means task interruption request (abort). - */ -struct gmio_task_control -{ - /*! Opaque pointer on a user task object, passed as first argument to hook - * functions */ - void* cookie; - - /*! Pointer on a function that says if the current task must stop - * - * If GMIO_TRUE is returned then the current task should abort as soon as - * possible, otherwise it can continue execution. - */ - gmio_bool_t (*is_stop_requested_func)(void* cookie); -}; - -typedef struct gmio_task_control gmio_task_control_t; - -GMIO_LIB_EXPORT -gmio_bool_t gmio_task_control_is_stop_requested(const gmio_task_control_t* task_ctrl); - -GMIO_C_LINKAGE_END - -#endif /* GMIO_TASK_CONTROL_H */ diff --git a/src/gmio_core/task_control.c b/src/gmio_core/transfer.c similarity index 74% rename from src/gmio_core/task_control.c rename to src/gmio_core/transfer.c index 00789ad..db1af5e 100644 --- a/src/gmio_core/task_control.c +++ b/src/gmio_core/transfer.c @@ -13,13 +13,13 @@ ** "http://www.cecill.info". ****************************************************************************/ -#include "task_control.h" +#include "transfer.h" #include -gmio_bool_t gmio_task_control_is_stop_requested(const gmio_task_control_t* task_ctrl) +gmio_bool_t gmio_transfer_is_stop_requested(const gmio_transfer_t* trsf) { - if (task_ctrl != NULL && task_ctrl->is_stop_requested_func != NULL) - return task_ctrl->is_stop_requested_func(task_ctrl->cookie); + if (trsf != NULL && trsf->is_stop_requested_func != NULL) + return trsf->is_stop_requested_func(trsf->cookie); return GMIO_FALSE; } diff --git a/src/gmio_core/transfer.h b/src/gmio_core/transfer.h index d88d7a5..165e52a 100644 --- a/src/gmio_core/transfer.h +++ b/src/gmio_core/transfer.h @@ -22,24 +22,40 @@ #include "global.h" #include "stream.h" -#include "task_control.h" + +GMIO_C_LINKAGE_BEGIN /*! Defines objects required for any transfer(read/write) operation */ struct gmio_transfer { + /*! Optional opaque pointer on a user task object, passed as first + * argument to hook functions */ + void* cookie; + + /*! Optional pointer on a function that says if the currently running + * operation must stop + * + * If GMIO_TRUE is returned then the current transfer should abort as + * soon as possible, otherwise it can continue execution. + */ + gmio_bool_t (*is_stop_requested_func)(void* cookie); + /*! The stream object to be used for I/O */ - gmio_stream_t stream; + gmio_stream_t stream; - /*! The optional object used to control execution of the transfer */ - gmio_task_control_t task_control; - - /*! Pointer on a memory buffer used by the transfer for stream operations */ - void* buffer; + /*! Pointer on a memory buffer used by the transfer for stream + * operations */ + void* buffer; /*! Size (in bytes) of the memory buffer */ - size_t buffer_size; + size_t buffer_size; }; typedef struct gmio_transfer gmio_transfer_t; +GMIO_LIB_EXPORT +gmio_bool_t gmio_transfer_is_stop_requested(const gmio_transfer_t* trsf); + +GMIO_C_LINKAGE_END + #endif /* GMIO_TRANSFER_H */ diff --git a/src/gmio_stl/stla_read.c b/src/gmio_stl/stla_read.c index 8cea799..66f6b03 100644 --- a/src/gmio_stl/stla_read.c +++ b/src/gmio_stl/stla_read.c @@ -78,9 +78,9 @@ /* gmio_stream_fwd_iterator_stla_cookie */ typedef struct { - gmio_task_control_t* task_control; - size_t stream_offset; - gmio_bool_t is_stop_requested; + gmio_transfer_t* transfer; + size_t stream_offset; + gmio_bool_t is_stop_requested; } gmio_string_stream_fwd_iterator_cookie_t; /* gmio_stla_token */ @@ -117,9 +117,9 @@ static void gmio_stream_fwd_iterator_stla_read_hook(void* cookie, { gmio_string_stream_fwd_iterator_cookie_t* tcookie = (gmio_string_stream_fwd_iterator_cookie_t*)(cookie); - const gmio_task_control_t* ctrl = tcookie != NULL ? tcookie->task_control : NULL; - if (ctrl != NULL) - tcookie->is_stop_requested = gmio_task_control_is_stop_requested(ctrl); + const gmio_transfer_t* trsf = tcookie != NULL ? tcookie->transfer : NULL; + if (trsf != NULL) + tcookie->is_stop_requested = gmio_transfer_is_stop_requested(trsf); if (tcookie != NULL) tcookie->stream_offset += buffer->len; } @@ -420,7 +420,7 @@ int gmio_stla_read(gmio_stl_mesh_creator_t* creator, parse_data.token = unknown_token; parse_data.error = GMIO_FALSE; - parse_data.stream_iterator_cookie.task_control = &trsf->task_control; + parse_data.stream_iterator_cookie.transfer = trsf; parse_data.stream_iterator_cookie.stream_offset = 0; parse_data.stream_iterator_cookie.is_stop_requested = GMIO_FALSE; @@ -442,6 +442,7 @@ int gmio_stla_read(gmio_stl_mesh_creator_t* creator, if (parse_data.error) return GMIO_STLA_READ_PARSE_ERROR; - return parse_data.stream_iterator_cookie.is_stop_requested ? GMIO_TASK_STOPPED_ERROR : - GMIO_NO_ERROR; + if (parse_data.stream_iterator_cookie.is_stop_requested) + return GMIO_TRANSFER_STOPPED_ERROR; + return GMIO_NO_ERROR; } diff --git a/src/gmio_stl/stla_write.c b/src/gmio_stl/stla_write.c index 6ef3c63..ab16c7f 100644 --- a/src/gmio_stl/stla_write.c +++ b/src/gmio_stl/stla_write.c @@ -194,8 +194,8 @@ int gmio_stla_write(const gmio_stl_mesh_t* mesh, error = GMIO_STREAM_ERROR; /* Task control */ - if (gmio_no_error(error) && gmio_task_control_is_stop_requested(&trsf->task_control)) - error = GMIO_TASK_STOPPED_ERROR; + if (gmio_no_error(error) && gmio_transfer_is_stop_requested(trsf)) + error = GMIO_TRANSFER_STOPPED_ERROR; } /* end for (ifacet) */ /* Write end of solid */ diff --git a/src/gmio_stl/stlb_read.c b/src/gmio_stl/stlb_read.c index 110c5bc..cd07986 100644 --- a/src/gmio_stl/stlb_read.c +++ b/src/gmio_stl/stlb_read.c @@ -124,8 +124,8 @@ int gmio_stlb_read(gmio_stl_mesh_creator_t *creator, if (gmio_no_error(error)) { gmio_stlb_read_facets(creator, trsf->buffer, &rparams); rparams.i_facet_offset += rparams.facet_count; - if (gmio_task_control_is_stop_requested(&trsf->task_control)) - error = GMIO_TASK_STOPPED_ERROR; + if (gmio_transfer_is_stop_requested(trsf)) + error = GMIO_TRANSFER_STOPPED_ERROR; } } /* end while */ diff --git a/src/gmio_stl/stlb_write.c b/src/gmio_stl/stlb_write.c index 252eb34..bd2e10f 100644 --- a/src/gmio_stl/stlb_write.c +++ b/src/gmio_stl/stlb_write.c @@ -114,15 +114,19 @@ int gmio_stlb_write(const gmio_stl_mesh_t* mesh, wparams.i_facet_offset += wparams.facet_count; /* Write buffer to stream */ - if (gmio_stream_write(&trsf->stream, trsf->buffer, GMIO_STLB_TRIANGLE_RAWSIZE, wparams.facet_count) + if (gmio_stream_write( + &trsf->stream, + trsf->buffer, + GMIO_STLB_TRIANGLE_RAWSIZE, + wparams.facet_count) != wparams.facet_count) { error = GMIO_STREAM_ERROR; } - /* Task control */ - if (gmio_no_error(error) && gmio_task_control_is_stop_requested(&trsf->task_control)) - error = GMIO_TASK_STOPPED_ERROR; + /* Handle stop request */ + if (gmio_no_error(error) && gmio_transfer_is_stop_requested(trsf)) + error = GMIO_TRANSFER_STOPPED_ERROR; } /* end for */ return error;