Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

signal_create.c

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2005 by Kevin L. Mitchell <klmitch@mit.edu>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 **
00018 ** @(#)$Id: signal_create.c,v 1.2 2005/10/25 01:46:17 klmitch Exp $
00019 */
00027 #include "engines_int.h"
00028 
00029 #include <string.h>
00030 
00031 RCSTAG("@(#)$Id: signal_create.c,v 1.2 2005/10/25 01:46:17 klmitch Exp $");
00032 
00033 ev_err_t
00034 signal_create(ev_ctx_t *ctx, int signal, ev_call_t call, void *data,
00035               ev_sig_t **sig_p)
00036 {
00037   ev_engine_t *eng;
00038   ev_err_t err = 0;
00039   ev_sig_t *sig;
00040 
00041   ev_init(); /* make sure library is initialized... */
00042 
00043   /* sanity-check the arguments... */
00044   if (!ec_verify(ctx))
00045     ev_return(EINVAL);
00046 
00047   /* Let's allocate a generator... */
00048   if ((err = event_gen_alloc(ctx, EGT_SIGNAL, &sig)))
00049     ev_return(err);
00050 
00051   /* Set callback information */
00052   eg_callback_set(sig, call);
00053   eg_calldata_set(sig, data);
00054 
00055   /* Now initialize the signal fields... */
00056   memset(&sig->si_oact, 0, sizeof(sig->si_oact)); /* zero old action field */
00057   sig->si_signal = signal; /* set the signal */
00058 
00059   /* Walk through all signal engines... */
00060   for (eng = ctx->ec_signal.el_first; eng;
00061        eng = eng->eng_signal.esi_active.el_next)
00062     if ((err = eng_sig_add(ctx, eng, sig))) { /* add to engine... */
00063       /* oops!  Error occurred.  Walk engines backwards and remove signal */
00064       for (; eng; eng = eng->eng_signal.esi_active.el_prev)
00065         eng_sig_rem(ctx, eng, sig);
00066 
00067       event_gen_release(ctx, (ev_genhdr_t *)sig); /* release signal memory */
00068 
00069       ev_return(err); /* return the error */
00070     }
00071 
00072   eg_ref_inc(ctx, sig); /* increment the reference count */
00073 
00074   if (sig_p) /* did caller want signal? */
00075     *sig_p = sig; /* then return it */
00076 
00077   ev_return(0);
00078 }

Generated on Wed Dec 28 23:36:56 2005 for event by  doxygen 1.4.4