gmio_core: add gmio_task_iface structure

This commit is contained in:
Hugues Delorme 2015-04-02 16:08:11 +02:00
parent 06bf919a3a
commit ef3beb2b50
4 changed files with 107 additions and 30 deletions

View File

@ -0,0 +1,40 @@
/****************************************************************************
** 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/licences/Licence_CeCILL-B_V1-en.html".
****************************************************************************/
#ifndef GMIO_INTERNAL_HELPER_TASK_IFACE_H
#define GMIO_INTERNAL_HELPER_TASK_IFACE_H
#include "../task_iface.h"
#include <stddef.h>
/*! Safe and convenient function for gmio_task_iface::is_stop_requested_func() */
GMIO_INLINE gmio_bool_t gmio_task_iface_is_stop_requested(
const gmio_task_iface_t* itask)
{
if (itask != NULL && itask->is_stop_requested_func != NULL)
return itask->is_stop_requested_func(itask->cookie);
return GMIO_FALSE;
}
/*! Safe and convenient function for gmio_task_iface::handle_progress_func() */
GMIO_INLINE void gmio_task_iface_handle_progress(
const gmio_task_iface_t* itask, size_t value, size_t max_value)
{
if (itask != NULL && itask->handle_progress_func != NULL)
itask->handle_progress_func(itask->cookie, value, max_value);
}
#endif /* GMIO_INTERNAL_HELPER_TASK_IFACE_H */

View File

@ -17,24 +17,27 @@
#define GMIO_INTERNAL_HELPER_TRANSFER_H
#include "../transfer.h"
#include "helper_task_iface.h"
#include <stddef.h>
/*! Safe and convenient function for gmio_transfer::is_stop_requested_func() */
/*! Safe and convenient function for gmio_task_iface::is_stop_requested_func()
* through gmio_transfer::task_iface
*/
GMIO_INLINE gmio_bool_t gmio_transfer_is_stop_requested(
const gmio_transfer_t* trsf)
{
if (trsf != NULL && trsf->is_stop_requested_func != NULL)
return trsf->is_stop_requested_func(trsf->cookie);
if (trsf != NULL)
return gmio_task_iface_is_stop_requested(&trsf->task_iface);
return GMIO_FALSE;
}
/*! Safe and convenient function for gmio_transfer::handle_progress_func() */
/*! Safe and convenient function for gmio_task_iface::handle_progress_func()
* through gmio_transfer::task_iface
*/
GMIO_INLINE void gmio_transfer_handle_progress(
const gmio_transfer_t* trsf, size_t value, size_t max_value)
{
if (trsf != NULL && trsf->handle_progress_func != NULL)
trsf->handle_progress_func(trsf->cookie, value, max_value);
if (trsf != NULL)
gmio_task_iface_handle_progress(&trsf->task_iface, value, max_value);
}
#endif /* GMIO_INTERNAL_HELPER_TRANSFER_H */

View File

@ -0,0 +1,51 @@
/****************************************************************************
** 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/licences/Licence_CeCILL-B_V1-en.html".
****************************************************************************/
/*! \file task_iface.h
* Declaration of gmio_task_iface
*/
#ifndef GMIO_TASK_IFACE_H
#define GMIO_TASK_IFACE_H
#include "global.h"
struct gmio_task_iface
{
/*! 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
* task must stop
*
* If \c 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);
/*! Optional pointer on a function that is called anytime some new progress
* was done
*
* \param cookie The cookie set inside the gmio_task_iface object
* \param value Current value of the task progress (<= \p max_value )
* \param max_value Maximum value of the task progress
*/
void (*handle_progress_func)(void* cookie, size_t value, size_t max_value);
};
typedef struct gmio_task_iface gmio_task_iface_t;
#endif /* GMIO_TASK_IFACE_H */

View File

@ -23,36 +23,19 @@
#include "buffer.h"
#include "global.h"
#include "stream.h"
#include "task_iface.h"
/*! 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 \c 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);
/*! Optional pointer on a function that is called anytime some progress
* was done during transfer
*
* \param cookie The cookie set inside the gmio_transfer object
* \param value Current value of the transfer progress (<= \p max_value )
* \param max_value Maximum value of the transfer progress
*/
void (*handle_progress_func)(void* cookie, size_t value, size_t max_value);
/*! The stream object to be used for I/O */
gmio_stream_t stream;
/*! The memory buffer used by the transfer for stream operations */
/*! The memory block used by the transfer for stream buffering */
gmio_buffer_t buffer;
/*! The interface object by which the transfer task can be controlled */
gmio_task_iface_t task_iface;
};
typedef struct gmio_transfer gmio_transfer_t;