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

engine_register.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_register.c,v 1.5 2005/07/18 22:01:40 klmitch Exp $
00019 */
00027 #include "engines_int.h"
00028 
00029 #include <string.h>
00030 
00031 RCSTAG("@(#)$Id: engine_register.c,v 1.5 2005/07/18 22:01:40 klmitch Exp $");
00032 
00033 ev_err_t
00034 engine_register(ev_ctx_t *ctx, ev_engine_t *engine)
00035 {
00036   int cmp;
00037   ev_engine_t *englist, *last;
00038 
00039   ev_init(); /* make sure library is initialized... */
00040 
00041 
00042   if (!ec_verify(ctx) || !eng_verify(engine) || /* verify magic numbers... */
00043 
00044       /* make sure engine is valid... */
00045       !engine->eng_name || !engine->eng_init || !engine->eng_poll ||
00046 
00047       /* If it has a socket component, does it have the socket methods? */
00048       ((engine->eng_flags & EV_ENGINE_SOCKET) &&
00049        (!engine->eng_socket.eso_add || !engine->eng_socket.eso_rem ||
00050         !engine->eng_socket.eso_ev)) ||
00051 
00052       /* If it has a signal component, does it have the signal methods? */
00053       ((engine->eng_flags & EV_ENGINE_SIGNAL) &&
00054        (!engine->eng_signal.esi_add || !engine->eng_signal.esi_rem)))
00055     /* timer components don't necessarily need add/remove callbacks */
00056     ev_return(EINVAL); /* verify arguments */
00057 
00058   if ((engine->eng_runfl & EV_ENGINE_REGISTERED) ||
00059       engine->eng_list.el_next || engine->eng_list.el_prev)
00060     ev_return(EBUSY); /* already registered... */
00061 
00062   /* walk through the list of engines... */
00063   for (englist = ctx->ec_engine, last = 0; englist;
00064        last = englist, englist = englist->eng_list.el_next)
00065     if (!(cmp = strcmp(englist->eng_name, engine->eng_name)))
00066       ev_return(EEXIST); /* hmmm, already registered? */
00067     else if (cmp > 0) /* larger than what we're inserting... */
00068       break; /* so here's where we'll insert the new engine */
00069 
00070   engine->eng_list.el_next = englist; /* link it into the list... */
00071   engine->eng_list.el_prev = last;
00072 
00073   if (englist) /* update everyone else's link pointers */
00074     englist->eng_list.el_prev = engine;
00075   if (last)
00076     last->eng_list.el_next = engine;
00077   else
00078     ctx->ec_engine = engine;
00079 
00080   /* Now, clear all other engine descriptor data... */
00081   engine->eng_runfl = EV_ENGINE_REGISTERED; /* engine's been registered */
00082   engine->eng_data = 0;
00083 
00084   /* socket data... */
00085   englink_clr(&engine->eng_socket.eso_active);
00086   engine->eng_socket.eso_data = 0;
00087 
00088   /* signal data... */
00089   englink_clr(&engine->eng_signal.esi_active);
00090   engine->eng_signal.esi_data = 0;
00091 
00092   /* timer data... */
00093   englink_clr(&engine->eng_timer.eti_active);
00094   engine->eng_timer.eti_data = 0;
00095 
00096   ev_return(0);
00097 }

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