NCDModule.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. struct NCDModuleInst_s;
  36. typedef void (*NCDModule_handler_event) (void *user, int event);
  37. typedef int (*NCDModule_handler_getvar) (void *user, const char *modname, const char *varname, NCDValue *out);
  38. typedef struct NCDModuleInst_s * (*NCDModule_handler_getobj) (void *user, const char *objname);
  39. struct NCDModule;
  40. struct NCDModuleInitParams {
  41. BReactor *reactor;
  42. BProcessManager *manager;
  43. };
  44. typedef struct NCDModuleInst_s {
  45. const struct NCDModule *m;
  46. struct NCDModuleInst_s *method_object;
  47. NCDValue *args;
  48. const char *logprefix;
  49. BReactor *reactor;
  50. BProcessManager *manager;
  51. NCDModule_handler_event handler_event;
  52. NCDModule_handler_getvar handler_getvar;
  53. NCDModule_handler_getobj handler_getobj;
  54. void *user;
  55. BPending init_job;
  56. BPending uninit_job;
  57. BPending die_job;
  58. BPending clean_job;
  59. int state;
  60. void *inst_user;
  61. int is_error;
  62. DebugObject d_obj;
  63. } NCDModuleInst;
  64. void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, NCDModuleInst *method_object, NCDValue *args, const char *logprefix, BReactor *reactor, BProcessManager *manager,
  65. NCDModule_handler_event handler_event, NCDModule_handler_getvar handler_getvar, NCDModule_handler_getobj handler_getobj, void *user);
  66. void NCDModuleInst_Free (NCDModuleInst *n);
  67. void NCDModuleInst_Event (NCDModuleInst *n, int event);
  68. int NCDModuleInst_GetVar (NCDModuleInst *n, const char *name, NCDValue *out) WARN_UNUSED;
  69. NCDModuleInst * NCDModuleInst_GetObj (NCDModuleInst *n, const char *objname) WARN_UNUSED;
  70. int NCDModuleInst_HaveError (NCDModuleInst *n);
  71. void NCDModuleInst_Backend_SetUser (NCDModuleInst *n, void *user);
  72. void NCDModuleInst_Backend_Event (NCDModuleInst *n, int event);
  73. int NCDModuleInst_Backend_GetVar (NCDModuleInst *n, const char *modname, const char *varname, NCDValue *out) WARN_UNUSED;
  74. NCDModuleInst * NCDModuleInst_Backend_GetObj (NCDModuleInst *n, const char *objname) WARN_UNUSED;
  75. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  76. void NCDModuleInst_Backend_SetError (NCDModuleInst *n);
  77. typedef int (*NCDModule_func_globalinit) (const struct NCDModuleInitParams params);
  78. typedef void (*NCDModule_func_globalfree) (void);
  79. typedef void (*NCDModule_func_new) (NCDModuleInst *params);
  80. typedef void (*NCDModule_func_die) (void *o);
  81. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValue *out);
  82. typedef NCDModuleInst * (*NCDModule_func_getobj) (void *o, const char *objname);
  83. typedef void (*NCDModule_func_clean) (void *o);
  84. struct NCDModule {
  85. const char *type;
  86. NCDModule_func_new func_new;
  87. NCDModule_func_die func_die;
  88. NCDModule_func_getvar func_getvar;
  89. NCDModule_func_getobj func_getobj;
  90. NCDModule_func_clean func_clean;
  91. };
  92. struct NCDModuleGroup {
  93. NCDModule_func_globalinit func_globalinit;
  94. NCDModule_func_globalfree func_globalfree;
  95. const struct NCDModule *modules;
  96. };
  97. #endif