src/hcode/tick.c

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 2005 Martin Murray
00004  *
00005  * This is much better than what we had.
00006  *
00007  */
00008 
00009 #include "config.h"
00010 
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <unistd.h>
00014 #include <sys/time.h>
00015 #include <sys/types.h>
00016 #include <string.h>
00017 #include <event.h>
00018 #include "glue_types.h"
00019 #include "mux_tree.h"
00020 #include "mech.h"
00021 #include "autopilot.h"
00022 #include "debug.h"
00023 
00024 static struct event heartbeat_ev;
00025 static struct timeval heartbeat_tv = { 1, 0 };
00026 static int heartbeat_running = 0;
00027 unsigned int global_tick = 0;
00028 extern Tree xcode_tree;
00029 
00030 void GoThruTree(Tree tree, int (*func) (Node *));
00031 void heartbeat_run(int fd, short event, void *arg);
00032 
00033 void heartbeat_init() {
00034     if(heartbeat_running) return;
00035     dprintk("hearbeat initialized, %ds timeout.", (int)heartbeat_tv.tv_sec);
00036     evtimer_set(&heartbeat_ev, heartbeat_run, NULL);
00037     evtimer_add(&heartbeat_ev, &heartbeat_tv);
00038     heartbeat_running = 1;
00039 }
00040 
00041 void heartbeat_stop() {
00042     if(!heartbeat_running) return;
00043     evtimer_del(&heartbeat_ev);
00044     dprintk("heartbeat stopped.\n");
00045     heartbeat_running = 0;
00046 }
00047 
00048 void mech_heartbeat(MECH *);
00049 void auto_heartbeat(AUTO *);
00050 
00051 int heartbeat_dispatch(Node *node) {
00052     switch(NodeType(node)) {
00053         case GTYPE_MECH:
00054             mech_heartbeat((MECH *)NodeData(node));
00055             break;
00056         case GTYPE_AUTO:
00057             auto_heartbeat((AUTO *)NodeData(node));
00058             break;
00059     }
00060     return 1;
00061 }
00062 
00063 void heartbeat_run(int fd, short event, void *arg) {
00064     evtimer_add(&heartbeat_ev, &heartbeat_tv);
00065     GoThruTree(xcode_tree, heartbeat_dispatch);
00066     global_tick++;
00067 }
00068 

Generated on Mon May 28 04:25:24 2007 for BattletechMUX by  doxygen 1.4.7