NCDModule.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file NCDModule.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef BADVPN_NCD_NCDMODULE_H
  23. #define BADVPN_NCD_NCDMODULE_H
  24. #include <stdarg.h>
  25. #include <system/BReactor.h>
  26. #include <system/BProcess.h>
  27. #include <system/BPending.h>
  28. #include <system/BLog.h>
  29. #include <ncdconfig/NCDConfig.h>
  30. #include <ncd/NCDValue.h>
  31. #define NCDMODULE_EVENT_UP 1
  32. #define NCDMODULE_EVENT_DOWN 2
  33. #define NCDMODULE_EVENT_DYING 3
  34. #define NCDMODULE_TOEVENT_DIE 101
  35. #define NCDMODULE_TOEVENT_CLEAN 102
  36. typedef void (*NCDModule_handler_event) (void *user, int event);
  37. typedef void (*NCDModule_handler_died) (void *user, int is_error);
  38. struct NCDModule;
  39. typedef struct {
  40. const char *name;
  41. const struct NCDModule *m;
  42. NCDValue *args;
  43. const char *logprefix;
  44. BReactor *reactor;
  45. BProcessManager *manager;
  46. NCDModule_handler_event handler_event;
  47. NCDModule_handler_died handler_died;
  48. void *user;
  49. BPending event_job;
  50. int event_job_event;
  51. BPending toevent_job;
  52. int toevent_job_event;
  53. int state;
  54. void *inst_user;
  55. DebugObject d_obj;
  56. #ifndef NDEBUG
  57. dead_t d_dead;
  58. #endif
  59. } NCDModuleInst;
  60. int NCDModuleInst_Init (NCDModuleInst *n, const char *name, const struct NCDModule *m, NCDValue *args, const char *logprefix, BReactor *reactor, BProcessManager *manager,
  61. NCDModule_handler_event handler_event, NCDModule_handler_died handler_died, void *user);
  62. void NCDModuleInst_Free (NCDModuleInst *n);
  63. void NCDModuleInst_Event (NCDModuleInst *n, int event);
  64. int NCDModuleInst_GetVar (NCDModuleInst *n, const char *name, NCDValue *out);
  65. void NCDModuleInst_Backend_Event (NCDModuleInst *n, int event);
  66. void NCDModuleInst_Backend_Died (NCDModuleInst *n, int is_error);
  67. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  68. typedef int (*NCDModule_func_globalinit) (void);
  69. typedef void * (*NCDModule_func_new) (NCDModuleInst *params);
  70. typedef void (*NCDModule_func_free) (void *o);
  71. typedef void (*NCDModule_func_die) (void *o);
  72. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValue *out);
  73. typedef void (*NCDModule_func_clean) (void *o);
  74. struct NCDModule {
  75. const char *type;
  76. NCDModule_func_new func_new;
  77. NCDModule_func_free func_free;
  78. NCDModule_func_die func_die;
  79. NCDModule_func_getvar func_getvar;
  80. NCDModule_func_clean func_clean;
  81. };
  82. struct NCDModuleGroup {
  83. NCDModule_func_globalinit func_globalinit;
  84. const struct NCDModule *modules;
  85. };
  86. #endif