NCDModule.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <misc/debugerror.h>
  26. #include <system/BReactor.h>
  27. #include <system/BPending.h>
  28. #include <system/BLog.h>
  29. #include <process/BProcess.h>
  30. #include <ncdconfig/NCDConfig.h>
  31. #include <ncd/NCDValue.h>
  32. #define NCDMODULE_EVENT_UP 1
  33. #define NCDMODULE_EVENT_DOWN 2
  34. #define NCDMODULE_EVENT_DYING 3
  35. #define NCDMODULE_TOEVENT_DIE 101
  36. #define NCDMODULE_TOEVENT_CLEAN 102
  37. typedef void (*NCDModule_handler_event) (void *user, int event);
  38. typedef void (*NCDModule_handler_died) (void *user, int is_error);
  39. typedef int (*NCDModule_handler_getvar) (void *user, const char *modname, const char *varname, NCDValue *out);
  40. struct NCDModule;
  41. typedef struct {
  42. const char *name;
  43. const struct NCDModule *m;
  44. NCDValue *args;
  45. const char *logprefix;
  46. BReactor *reactor;
  47. BProcessManager *manager;
  48. NCDModule_handler_event handler_event;
  49. NCDModule_handler_died handler_died;
  50. NCDModule_handler_getvar handler_getvar;
  51. void *user;
  52. BPending event_job;
  53. int event_job_event;
  54. BPending toevent_job;
  55. int toevent_job_event;
  56. int state;
  57. void *inst_user;
  58. DebugObject d_obj;
  59. DebugError d_err;
  60. } NCDModuleInst;
  61. int NCDModuleInst_Init (NCDModuleInst *n, const char *name, const struct NCDModule *m, NCDValue *args, const char *logprefix, BReactor *reactor, BProcessManager *manager,
  62. NCDModule_handler_event handler_event, NCDModule_handler_died handler_died, NCDModule_handler_getvar handler_getvar, void *user);
  63. void NCDModuleInst_Free (NCDModuleInst *n);
  64. void NCDModuleInst_Event (NCDModuleInst *n, int event);
  65. int NCDModuleInst_GetVar (NCDModuleInst *n, const char *name, NCDValue *out);
  66. void NCDModuleInst_Backend_Event (NCDModuleInst *n, int event);
  67. void NCDModuleInst_Backend_Died (NCDModuleInst *n, int is_error);
  68. int NCDModuleInst_Backend_GetVar (NCDModuleInst *n, const char *modname, const char *varname, NCDValue *out);
  69. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  70. typedef int (*NCDModule_func_globalinit) (void);
  71. typedef void * (*NCDModule_func_new) (NCDModuleInst *params);
  72. typedef void (*NCDModule_func_free) (void *o);
  73. typedef void (*NCDModule_func_die) (void *o);
  74. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValue *out);
  75. typedef void (*NCDModule_func_clean) (void *o);
  76. struct NCDModule {
  77. const char *type;
  78. NCDModule_func_new func_new;
  79. NCDModule_func_free func_free;
  80. NCDModule_func_die func_die;
  81. NCDModule_func_getvar func_getvar;
  82. NCDModule_func_clean func_clean;
  83. };
  84. struct NCDModuleGroup {
  85. NCDModule_func_globalinit func_globalinit;
  86. const struct NCDModule *modules;
  87. };
  88. #endif