Annotation of embedaddon/strongswan/src/libstrongswan/processing/jobs/callback_job.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2009-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: #include "callback_job.h"
                     19: 
                     20: #include <threading/thread.h>
                     21: #include <threading/condvar.h>
                     22: #include <threading/semaphore.h>
                     23: #include <threading/mutex.h>
                     24: #include <collections/linked_list.h>
                     25: 
                     26: typedef struct private_callback_job_t private_callback_job_t;
                     27: 
                     28: /**
                     29:  * Private data of an callback_job_t Object.
                     30:  */
                     31: struct private_callback_job_t {
                     32: 
                     33:        /**
                     34:         * Public callback_job_t interface.
                     35:         */
                     36:        callback_job_t public;
                     37: 
                     38:        /**
                     39:         * Callback to call on execution
                     40:         */
                     41:        callback_job_cb_t callback;
                     42: 
                     43:        /**
                     44:         * parameter to supply to callback
                     45:         */
                     46:        void *data;
                     47: 
                     48:        /**
                     49:         * cleanup function for data
                     50:         */
                     51:        callback_job_cleanup_t cleanup;
                     52: 
                     53:        /**
                     54:         * cancel function
                     55:         */
                     56:        callback_job_cancel_t cancel;
                     57: 
                     58:        /**
                     59:         * Priority of this job
                     60:         */
                     61:        job_priority_t prio;
                     62: };
                     63: 
                     64: METHOD(job_t, destroy, void,
                     65:        private_callback_job_t *this)
                     66: {
                     67:        if (this->cleanup)
                     68:        {
                     69:                this->cleanup(this->data);
                     70:        }
                     71:        free(this);
                     72: }
                     73: 
                     74: METHOD(job_t, execute, job_requeue_t,
                     75:        private_callback_job_t *this)
                     76: {
                     77:        return this->callback(this->data);
                     78: }
                     79: 
                     80: METHOD(job_t, cancel, bool,
                     81:        private_callback_job_t *this)
                     82: {
                     83:        return this->cancel(this->data);
                     84: }
                     85: 
                     86: METHOD(job_t, get_priority, job_priority_t,
                     87:        private_callback_job_t *this)
                     88: {
                     89:        return this->prio;
                     90: }
                     91: 
                     92: /*
                     93:  * Described in header.
                     94:  */
                     95: callback_job_t *callback_job_create_with_prio(callback_job_cb_t cb, void *data,
                     96:                                callback_job_cleanup_t cleanup, callback_job_cancel_t cancel,
                     97:                                job_priority_t prio)
                     98: {
                     99:        private_callback_job_t *this;
                    100: 
                    101:        INIT(this,
                    102:                .public = {
                    103:                        .job = {
                    104:                                .execute = _execute,
                    105:                                .get_priority = _get_priority,
                    106:                                .destroy = _destroy,
                    107:                        },
                    108:                },
                    109:                .callback = cb,
                    110:                .data = data,
                    111:                .cleanup = cleanup,
                    112:                .cancel = cancel,
                    113:                .prio = prio,
                    114:        );
                    115: 
                    116:        if (cancel)
                    117:        {
                    118:                this->public.job.cancel = _cancel;
                    119:        }
                    120: 
                    121:        return &this->public;
                    122: }
                    123: 
                    124: /*
                    125:  * Described in header.
                    126:  */
                    127: callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
                    128:                                                                        callback_job_cleanup_t cleanup,
                    129:                                                                        callback_job_cancel_t cancel)
                    130: {
                    131:        return callback_job_create_with_prio(cb, data, cleanup, cancel,
                    132:                                                                                 JOB_PRIO_MEDIUM);
                    133: }

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