NCDModule.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <misc/debug.h>
  25. #include <system/BReactor.h>
  26. #include <system/BPending.h>
  27. #include <system/BLog.h>
  28. #include <process/BProcess.h>
  29. #include <ncd/NCDValue.h>
  30. #define NCDMODULE_EVENT_UP 1
  31. #define NCDMODULE_EVENT_DOWN 2
  32. #define NCDMODULE_EVENT_DEAD 3
  33. #define NCDMODULE_TOEVENT_DIE 101
  34. #define NCDMODULE_TOEVENT_CLEAN 102
  35. typedef void (*NCDModule_handler_event) (void *user, int event);
  36. typedef int (*NCDModule_handler_getvar) (void *user, const char *modname, const char *varname, NCDValue *out);
  37. struct NCDModule;
  38. struct NCDModuleInitParams {
  39. BReactor *reactor;
  40. BProcessManager *manager;
  41. };
  42. typedef struct {
  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_getvar handler_getvar;
  50. void *user;
  51. BPending init_job;
  52. BPending uninit_job;
  53. BPending die_job;
  54. BPending clean_job;
  55. int state;
  56. void *inst_user;
  57. int is_error;
  58. DebugObject d_obj;
  59. } NCDModuleInst;
  60. void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, NCDValue *args, const char *logprefix, BReactor *reactor, BProcessManager *manager,
  61. NCDModule_handler_event handler_event, NCDModule_handler_getvar handler_getvar, 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) WARN_UNUSED;
  65. int NCDModuleInst_HaveError (NCDModuleInst *n);
  66. void NCDModuleInst_Backend_SetUser (NCDModuleInst *n, void *user);
  67. void NCDModuleInst_Backend_Event (NCDModuleInst *n, int event);
  68. int NCDModuleInst_Backend_GetVar (NCDModuleInst *n, const char *modname, const char *varname, NCDValue *out) WARN_UNUSED;
  69. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  70. void NCDModuleInst_Backend_SetError (NCDModuleInst *n);
  71. typedef int (*NCDModule_func_globalinit) (const struct NCDModuleInitParams params);
  72. typedef void (*NCDModule_func_globalfree) (void);
  73. typedef void (*NCDModule_func_new) (NCDModuleInst *params);
  74. typedef void (*NCDModule_func_die) (void *o);
  75. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValue *out);
  76. typedef void (*NCDModule_func_clean) (void *o);
  77. struct NCDModule {
  78. const char *type;
  79. NCDModule_func_new func_new;
  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. NCDModule_func_globalfree func_globalfree;
  87. const struct NCDModule *modules;
  88. };
  89. #endif