[dhcp-agent-commits] dhcp-agent dhcp-timer.c,NONE,1.1 dhcp-timer.h,NONE,1.1 Makefile.am,1.31,1.32 Ma
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-10-26 14:26:44
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv23167 Modified Files: Makefile.am Makefile.in dhcp-list.c Added Files: dhcp-timer.c dhcp-timer.h Log Message: new dhcp-timer object; not tested yet --- NEW FILE: dhcp-timer.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/dhcp-timer.c,v 1.1 2002/10/26 14:26:41 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Timer keeper object to keep track of an infinite number of timers. * We can add new timers to it, activate it when we want to, * deactivate it, and remove timers. * * All timers have an unsigned 32-bit integer ID assigned to them. */ #define MODULE_NAME "dhcp-timer" #include <dhcp-agent.h> #include <dhcp-util.h> #include <dhcp-timer.h> /* create a new trigger. */ static trigger_t *create_trigger(uint32_t id, uint32_t trigger_time) { trigger_t *trigger; trigger = xmalloc(sizeof(trigger_t)); trigger->trigger_id = id; trigger->trigger_timer = trigger_time; return trigger; } /* destroy a trigger. */ static void destroy_trigger(trigger_t *trigger) { xfree(trigger); return; } /* utility routine to get trigger by its id -- pass this to * list_find_datum_by */ static uint32_t get_trigger_id(trigger_t *trigger) { return trigger->trigger_id; } /* utility to pass to purge_list. */ static void destroy_trigger_l(void *p) { trigger_t *trigger = p; destroy_trigger(trigger); return; } /* utility list find routine. */ int find_trigger_by_id(void *trigger_p, void *id_p) { uint32_t *id = id_p; trigger_t *trigger = trigger_p; if(get_trigger_id(trigger) == *id) return 1; return 0; } /* create a new timer keeper. */ timer_keeper_t *create_timer(void) { timer_keeper_t *timer; timer = xmalloc(sizeof(timer_keeper_t)); timer->triggers = NULL; timer->active = 0; return timer; } /* destroy a timer keeper. */ void destroy_timer(timer_keeper_t *timer) { purge_list(timer->triggers, destroy_trigger_l); xfree(timer); return; } /* add a new trigger. */ void timer_add_trigger(timer_keeper_t *timer, uint32_t id, uint32_t time) { trigger_t *trigger = create_trigger(id, time); timer->triggers = add_to_list(timer->triggers, trigger); return; } /* delete a trigger by its id. */ int timer_delete_trigger(timer_keeper_t *timer, uint32_t id) { list_t *trigger_l; trigger_t *trigger; trigger_l = list_find_datum_by(timer->triggers, find_trigger_by_id, &id); if(trigger_l == NULL) return 1; trigger = trigger_l->data; timer->triggers = remove_from_list(timer->triggers, trigger); return 0; } --- NEW FILE: dhcp-timer.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/dhcp-timer.h,v 1.1 2002/10/26 14:26:41 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Timer keeper object to keep track of an infinite number of * time triggers. We can add new time trigger to it, activate it * when we want to, deactivate it, and remove triggers. * * All timers have an unsigned 32-bit integer ID assigned to them. */ #ifndef DHCP_TIMER_H #define DHCP_TIMER_H typedef struct { list_t *triggers; uint8_t active; } timer_keeper_t; typedef struct { uint32_t trigger_id; uint32_t trigger_timer; } trigger_t; extern timer_keeper_t *create_timer(void); extern void destroy_timer(timer_keeper_t *timer); extern void timer_add_trigger(timer_keeper_t *timer, uint32_t id, uint32_t time); extern int timer_delete_trigger(timer_keeper_t *timer, uint32_t id); #endif /* DHCP_TIMER_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Makefile.am 21 Oct 2002 01:02:48 -0000 1.31 --- Makefile.am 26 Oct 2002 14:26:41 -0000 1.32 *************** *** 21,25 **** dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ dhcp-arp-discovery.c dhcp-route.c dhcp-globconf.c dhcp-stringbuffer.c \ ! dhcp-parser.c dhcp-varfile.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ --- 21,25 ---- dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ dhcp-arp-discovery.c dhcp-route.c dhcp-globconf.c dhcp-stringbuffer.c \ ! dhcp-parser.c dhcp-varfile.c dhcp-timer.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** Makefile.in 21 Oct 2002 01:02:48 -0000 1.33 --- Makefile.in 26 Oct 2002 14:26:41 -0000 1.34 *************** *** 103,107 **** dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ dhcp-arp-discovery.c dhcp-route.c dhcp-globconf.c dhcp-stringbuffer.c \ ! dhcp-parser.c dhcp-varfile.c --- 103,107 ---- dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ dhcp-arp-discovery.c dhcp-route.c dhcp-globconf.c dhcp-stringbuffer.c \ ! dhcp-parser.c dhcp-varfile.c dhcp-timer.c *************** *** 142,146 **** dhcp-arp-discovery.$(OBJEXT) dhcp-route.$(OBJEXT) \ dhcp-globconf.$(OBJEXT) dhcp-stringbuffer.$(OBJEXT) \ ! dhcp-parser.$(OBJEXT) dhcp-varfile.$(OBJEXT) dhcpclient_OBJECTS = $(am_dhcpclient_OBJECTS) dhcpclient_DEPENDENCIES = --- 142,147 ---- dhcp-arp-discovery.$(OBJEXT) dhcp-route.$(OBJEXT) \ dhcp-globconf.$(OBJEXT) dhcp-stringbuffer.$(OBJEXT) \ ! dhcp-parser.$(OBJEXT) dhcp-varfile.$(OBJEXT) \ ! dhcp-timer.$(OBJEXT) dhcpclient_OBJECTS = $(am_dhcpclient_OBJECTS) dhcpclient_DEPENDENCIES = *************** *** 188,192 **** @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-snprintf.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-stringbuffer.Po \ ! @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-sysconf.Po ./$(DEPDIR)/dhcp-udp.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-util.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-varfile.Po --- 189,194 ---- @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-snprintf.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-stringbuffer.Po \ ! @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-sysconf.Po \ ! @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-timer.Po ./$(DEPDIR)/dhcp-udp.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-util.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-varfile.Po *************** *** 314,317 **** --- 316,320 ---- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-stringbuffer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-sysconf.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-timer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-udp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-util.Po@am__quote@ Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-list.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-list.c 25 Oct 2002 13:20:08 -0000 1.8 --- dhcp-list.c 26 Oct 2002 14:26:41 -0000 1.9 *************** *** 138,141 **** return NULL; } - - --- 138,139 ---- |