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

event_attr_engine.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: event_attr_engine.c,v 1.4 2005/07/18 22:01:40 klmitch Exp $
00019 */
00027 #include "engines_int.h"
00028 
00029 #include <stdlib.h>
00030 #include <string.h>
00031 
00032 RCSTAG("@(#)$Id: event_attr_engine.c,v 1.4 2005/07/18 22:01:40 klmitch Exp $");
00033 
00034 ev_err_t
00035 event_attr_engine(ev_attr_t *attr, ev_engine_t *engine)
00036 {
00037   int cmp;
00038   ev_engine_t *englist, *last;
00039 
00040   ev_init(); /* initialize library... */
00041 
00042   if (!ea_verify(attr) || !eng_verify(engine) || /* attr valid?  engine? */
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);
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 = ea_engines(attr), 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     ea_engines(attr) = engine;
00079 
00080   ev_return(0);
00081 }

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