Annotation of embedaddon/strongswan/src/libstrongswan/processing/jobs/callback_job.h, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2012 Tobias Brunner
        !             3:  * Copyright (C) 2007-2011 Martin Willi
        !             4:  * Copyright (C) 2011 revosec AG
        !             5:  * HSR Hochschule fuer Technik Rapperswil
        !             6:  *
        !             7:  * This program is free software; you can redistribute it and/or modify it
        !             8:  * under the terms of the GNU General Public License as published by the
        !             9:  * Free Software Foundation; either version 2 of the License, or (at your
        !            10:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !            11:  *
        !            12:  * This program is distributed in the hope that it will be useful, but
        !            13:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            14:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            15:  * for more details.
        !            16:  */
        !            17: 
        !            18: /**
        !            19:  * @defgroup callback_job callback_job
        !            20:  * @{ @ingroup jobs
        !            21:  */
        !            22: 
        !            23: #ifndef CALLBACK_JOB_H_
        !            24: #define CALLBACK_JOB_H_
        !            25: 
        !            26: typedef struct callback_job_t callback_job_t;
        !            27: 
        !            28: #include <library.h>
        !            29: #include <processing/jobs/job.h>
        !            30: 
        !            31: /**
        !            32:  * The callback function to use for the callback job.
        !            33:  *
        !            34:  * This is the function to use as callback for a callback job. It receives
        !            35:  * a parameter supplied to the callback jobs constructor.
        !            36:  *
        !            37:  * @param data                 param supplied to job
        !            38:  * @return                             requeing policy how to requeue the job
        !            39:  */
        !            40: typedef job_requeue_t (*callback_job_cb_t)(void *data);
        !            41: 
        !            42: /**
        !            43:  * Cleanup function to use for data cleanup.
        !            44:  *
        !            45:  * The callback has an optional user argument which receives data. However,
        !            46:  * this data may be cleaned up if it is allocated. This is the function
        !            47:  * to supply to the constructor.
        !            48:  *
        !            49:  * @param data                 param supplied to job
        !            50:  */
        !            51: typedef void (*callback_job_cleanup_t)(void *data);
        !            52: 
        !            53: /**
        !            54:  * Cancellation function to use for the callback job.
        !            55:  *
        !            56:  * Optional function to be called when a job has to be canceled.
        !            57:  *
        !            58:  * See job_t.cancel() for details on the return value.
        !            59:  *
        !            60:  * @param data                 param supplied to job
        !            61:  * @return                             TRUE if canceled, FALSE to explicitly cancel the thread
        !            62:  */
        !            63: typedef bool (*callback_job_cancel_t)(void *data);
        !            64: 
        !            65: /**
        !            66:  * Class representing an callback Job.
        !            67:  *
        !            68:  * This is a special job which allows a simple callback function to
        !            69:  * be executed by a thread of the thread pool. This allows simple execution
        !            70:  * of asynchronous methods, without to manage threads.
        !            71:  */
        !            72: struct callback_job_t {
        !            73: 
        !            74:        /**
        !            75:         * The job_t interface.
        !            76:         */
        !            77:        job_t job;
        !            78: 
        !            79: };
        !            80: 
        !            81: /**
        !            82:  * Creates a callback job.
        !            83:  *
        !            84:  * The cleanup function is called when the job gets destroyed to destroy
        !            85:  * the associated data.
        !            86:  *
        !            87:  * The cancel function is optional and should only be provided if the callback
        !            88:  * function calls potentially blocking functions and/or always returns
        !            89:  * JOB_REQUEUE_DIRECT.
        !            90:  *
        !            91:  * @param cb                           callback to call from the processor
        !            92:  * @param data                         user data to supply to callback
        !            93:  * @param cleanup                      destructor for data on destruction, or NULL
        !            94:  * @param cancel                       function to cancel the job, or NULL
        !            95:  * @return                                     callback_job_t object
        !            96:  */
        !            97: callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
        !            98:                                                                        callback_job_cleanup_t cleanup,
        !            99:                                                                        callback_job_cancel_t cancel);
        !           100: 
        !           101: /**
        !           102:  * Creates a callback job, with priority.
        !           103:  *
        !           104:  * Same as callback_job_create(), but with different priorities than default.
        !           105:  *
        !           106:  * @param cb                           callback to call from the processor
        !           107:  * @param data                         user data to supply to callback
        !           108:  * @param cleanup                      destructor for data on destruction, or NULL
        !           109:  * @param cancel                       function to cancel the job, or NULL
        !           110:  * @param prio                         job priority
        !           111:  * @return                                     callback_job_t object
        !           112:  */
        !           113: callback_job_t *callback_job_create_with_prio(callback_job_cb_t cb, void *data,
        !           114:                                callback_job_cleanup_t cleanup, callback_job_cancel_t cancel,
        !           115:                                job_priority_t prio);
        !           116: 
        !           117: #endif /** CALLBACK_JOB_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>