fsm.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* $Id: fsm.h,v 1.3.2.2 2001/09/23 22:24:47 kai Exp $
  2. *
  3. * Finite state machine
  4. *
  5. * Author Karsten Keil
  6. * Copyright by Karsten Keil <keil@isdn4linux.de>
  7. * by Kai Germaschewski <kai.germaschewski@gmx.de>
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. */
  13. #ifndef __FSM_H__
  14. #define __FSM_H__
  15. #include <linux/timer.h>
  16. struct FsmInst;
  17. typedef void (*FSMFNPTR)(struct FsmInst *, int, void *);
  18. struct Fsm {
  19. FSMFNPTR *jumpmatrix;
  20. int state_count, event_count;
  21. char **strEvent, **strState;
  22. };
  23. struct FsmInst {
  24. struct Fsm *fsm;
  25. int state;
  26. int debug;
  27. void *userdata;
  28. int userint;
  29. void (*printdebug) (struct FsmInst *, char *, ...);
  30. };
  31. struct FsmNode {
  32. int state, event;
  33. void (*routine) (struct FsmInst *, int, void *);
  34. };
  35. struct FsmTimer {
  36. struct FsmInst *fi;
  37. struct timer_list tl;
  38. int event;
  39. void *arg;
  40. };
  41. int FsmNew(struct Fsm *fsm, struct FsmNode *fnlist, int fncount);
  42. void FsmFree(struct Fsm *fsm);
  43. int FsmEvent(struct FsmInst *fi, int event, void *arg);
  44. void FsmChangeState(struct FsmInst *fi, int newstate);
  45. void FsmInitTimer(struct FsmInst *fi, struct FsmTimer *ft);
  46. int FsmAddTimer(struct FsmTimer *ft, int millisec, int event,
  47. void *arg, int where);
  48. void FsmRestartTimer(struct FsmTimer *ft, int millisec, int event,
  49. void *arg, int where);
  50. void FsmDelTimer(struct FsmTimer *ft, int where);
  51. #endif