gmio_core: merge gmio_task_control into gmio_transfer
This commit is contained in:
parent
8396eab3d6
commit
8d81cf5922
@ -42,9 +42,9 @@ enum gmio_error
|
|||||||
/*! An error occurred with the argument gmio_stream_t */
|
/*! An error occurred with the argument gmio_stream_t */
|
||||||
GMIO_STREAM_ERROR = -4,
|
GMIO_STREAM_ERROR = -4,
|
||||||
|
|
||||||
/*! Operation was stopped by user, that is to say
|
/*! Transfer was stopped by user, that is to say
|
||||||
* gmio_task_control::is_stop_requested_func() returned GMIO_FALSE */
|
* gmio_transfer::is_stop_requested_func() returned GMIO_TRUE */
|
||||||
GMIO_TASK_STOPPED_ERROR = -5
|
GMIO_TRANSFER_STOPPED_ERROR = -5
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum gmio_error gmio_error_t;
|
typedef enum gmio_error gmio_error_t;
|
||||||
|
@ -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 */
|
|
@ -13,13 +13,13 @@
|
|||||||
** "http://www.cecill.info".
|
** "http://www.cecill.info".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "task_control.h"
|
#include "transfer.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
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)
|
if (trsf != NULL && trsf->is_stop_requested_func != NULL)
|
||||||
return task_ctrl->is_stop_requested_func(task_ctrl->cookie);
|
return trsf->is_stop_requested_func(trsf->cookie);
|
||||||
return GMIO_FALSE;
|
return GMIO_FALSE;
|
||||||
}
|
}
|
@ -22,18 +22,29 @@
|
|||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "task_control.h"
|
|
||||||
|
GMIO_C_LINKAGE_BEGIN
|
||||||
|
|
||||||
/*! Defines objects required for any transfer(read/write) operation */
|
/*! Defines objects required for any transfer(read/write) operation */
|
||||||
struct gmio_transfer
|
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 */
|
/*! 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 */
|
/*! Pointer on a memory buffer used by the transfer for stream
|
||||||
gmio_task_control_t task_control;
|
* operations */
|
||||||
|
|
||||||
/*! Pointer on a memory buffer used by the transfer for stream operations */
|
|
||||||
void* buffer;
|
void* buffer;
|
||||||
|
|
||||||
/*! Size (in bytes) of the memory buffer */
|
/*! Size (in bytes) of the memory buffer */
|
||||||
@ -42,4 +53,9 @@ struct gmio_transfer
|
|||||||
|
|
||||||
typedef struct gmio_transfer gmio_transfer_t;
|
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 */
|
#endif /* GMIO_TRANSFER_H */
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
/* gmio_stream_fwd_iterator_stla_cookie */
|
/* gmio_stream_fwd_iterator_stla_cookie */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
gmio_task_control_t* task_control;
|
gmio_transfer_t* transfer;
|
||||||
size_t stream_offset;
|
size_t stream_offset;
|
||||||
gmio_bool_t is_stop_requested;
|
gmio_bool_t is_stop_requested;
|
||||||
} gmio_string_stream_fwd_iterator_cookie_t;
|
} gmio_string_stream_fwd_iterator_cookie_t;
|
||||||
@ -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* tcookie =
|
||||||
(gmio_string_stream_fwd_iterator_cookie_t*)(cookie);
|
(gmio_string_stream_fwd_iterator_cookie_t*)(cookie);
|
||||||
const gmio_task_control_t* ctrl = tcookie != NULL ? tcookie->task_control : NULL;
|
const gmio_transfer_t* trsf = tcookie != NULL ? tcookie->transfer : NULL;
|
||||||
if (ctrl != NULL)
|
if (trsf != NULL)
|
||||||
tcookie->is_stop_requested = gmio_task_control_is_stop_requested(ctrl);
|
tcookie->is_stop_requested = gmio_transfer_is_stop_requested(trsf);
|
||||||
if (tcookie != NULL)
|
if (tcookie != NULL)
|
||||||
tcookie->stream_offset += buffer->len;
|
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.token = unknown_token;
|
||||||
parse_data.error = GMIO_FALSE;
|
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.stream_offset = 0;
|
||||||
parse_data.stream_iterator_cookie.is_stop_requested = GMIO_FALSE;
|
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)
|
if (parse_data.error)
|
||||||
return GMIO_STLA_READ_PARSE_ERROR;
|
return GMIO_STLA_READ_PARSE_ERROR;
|
||||||
return parse_data.stream_iterator_cookie.is_stop_requested ? GMIO_TASK_STOPPED_ERROR :
|
if (parse_data.stream_iterator_cookie.is_stop_requested)
|
||||||
GMIO_NO_ERROR;
|
return GMIO_TRANSFER_STOPPED_ERROR;
|
||||||
|
return GMIO_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -194,8 +194,8 @@ int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
|||||||
error = GMIO_STREAM_ERROR;
|
error = GMIO_STREAM_ERROR;
|
||||||
|
|
||||||
/* Task control */
|
/* Task control */
|
||||||
if (gmio_no_error(error) && gmio_task_control_is_stop_requested(&trsf->task_control))
|
if (gmio_no_error(error) && gmio_transfer_is_stop_requested(trsf))
|
||||||
error = GMIO_TASK_STOPPED_ERROR;
|
error = GMIO_TRANSFER_STOPPED_ERROR;
|
||||||
} /* end for (ifacet) */
|
} /* end for (ifacet) */
|
||||||
|
|
||||||
/* Write end of solid */
|
/* Write end of solid */
|
||||||
|
@ -124,8 +124,8 @@ int gmio_stlb_read(gmio_stl_mesh_creator_t *creator,
|
|||||||
if (gmio_no_error(error)) {
|
if (gmio_no_error(error)) {
|
||||||
gmio_stlb_read_facets(creator, trsf->buffer, &rparams);
|
gmio_stlb_read_facets(creator, trsf->buffer, &rparams);
|
||||||
rparams.i_facet_offset += rparams.facet_count;
|
rparams.i_facet_offset += rparams.facet_count;
|
||||||
if (gmio_task_control_is_stop_requested(&trsf->task_control))
|
if (gmio_transfer_is_stop_requested(trsf))
|
||||||
error = GMIO_TASK_STOPPED_ERROR;
|
error = GMIO_TRANSFER_STOPPED_ERROR;
|
||||||
}
|
}
|
||||||
} /* end while */
|
} /* end while */
|
||||||
|
|
||||||
|
@ -114,15 +114,19 @@ int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
|||||||
wparams.i_facet_offset += wparams.facet_count;
|
wparams.i_facet_offset += wparams.facet_count;
|
||||||
|
|
||||||
/* Write buffer to stream */
|
/* 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)
|
!= wparams.facet_count)
|
||||||
{
|
{
|
||||||
error = GMIO_STREAM_ERROR;
|
error = GMIO_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Task control */
|
/* Handle stop request */
|
||||||
if (gmio_no_error(error) && gmio_task_control_is_stop_requested(&trsf->task_control))
|
if (gmio_no_error(error) && gmio_transfer_is_stop_requested(trsf))
|
||||||
error = GMIO_TASK_STOPPED_ERROR;
|
error = GMIO_TRANSFER_STOPPED_ERROR;
|
||||||
} /* end for */
|
} /* end for */
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
Loading…
Reference in New Issue
Block a user