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

engine_activate.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: engine_activate.c,v 1.4 2005/12/18 00:15:10 klmitch Exp $
00019 */
00027 #include "engines_int.h"
00028 
00029 RCSTAG("@(#)$Id: engine_activate.c,v 1.4 2005/12/18 00:15:10 klmitch Exp $");
00030 
00044 #define eng_link(ctx, engine, comp)                                           \
00045 do {                                                                          \
00046   ev_ctx_t *_ctx = (ctx);                                                     \
00047   ev_engine_t *_eng = (engine);                                               \
00048   if (!_ctx->ec_ ## comp.el_last) { /* no items in list yet... */             \
00049     /* initialize the context list pointers... */                             \
00050     _ctx->ec_ ## comp.el_first = _ctx->ec_ ## comp.el_last = _eng;            \
00051     /* now initialize the engine list pointers...the cast is ugly, but        \
00052      * keeps us from having to specify the structure prefix, too              \
00053      */                                                                       \
00054     ((_ev_englink_t *)&_eng->eng_ ## comp)->el_next = 0;                      \
00055     ((_ev_englink_t *)&_eng->eng_ ## comp)->el_prev = 0;                      \
00056   } else { /* ok, link engine at end of list */                               \
00057     ev_engine_t *_last = _ctx->ec_ ## comp.el_last; /* save some typing */    \
00058     ((_ev_englink_t *)&_last->eng_ ## comp)->el_next = _eng; /* add to list */\
00059     ((_ev_englink_t *)&_eng->eng_ ## comp)->el_prev = _last; /* link engine */\
00060     ((_ev_englink_t *)&_eng->eng_ ## comp)->el_next = 0;                      \
00061     _ctx->ec_ ## comp.el_last = _eng; /* update last pointer */               \
00062   }                                                                           \
00063 } while (0)
00064 
00065 ev_err_t
00066 engine_activate(ev_ctx_t *ctx, ev_engine_t *engine, ev_flags_t comps)
00067 {
00068   ev_init(); /* make sure library is initialized... */
00069 
00070   /* mask components specifier... */
00071   comps &= EV_ENGINE_COMPMASK;
00072 
00073   if (!ec_verify(ctx) || !eng_verify(engine) ||
00074       !(engine->eng_runfl & EV_ENGINE_REGISTERED) ||
00075       (engine->eng_runfl & EV_ENGINE_RUNNING) || !comps)
00076     ev_return(EINVAL); /* sanity-check arguments */
00077 
00078   if (comps & EV_ENGINE_SOCKET) /* perform the links... */
00079     eng_link(ctx, engine, socket);
00080   if (comps & EV_ENGINE_SIGNAL)
00081     eng_link(ctx, engine, signal);
00082   if (comps & EV_ENGINE_TIMER)
00083     eng_link(ctx, engine, timer);
00084 
00085   /* Now set the run flags */
00086   eng_runfl_set(engine, comps | EV_ENGINE_RUNNING);
00087 
00088   ev_return(0); /* all done! */
00089 }

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