NCDModule.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_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. typedef int (*NCDModule_handler_getvar) (void *user, const char *modname, const char *varname, NCDValue *out);
  39. struct NCDModule;
  40. struct NCDModuleInitParams {
  41. BReactor *reactor;
  42. BProcessManager *manager;
  43. };
  44. typedef struct {
  45. const char *name;
  46. const struct NCDModule *m;
  47. NCDValue *args;
  48. const char *logprefix;
  49. BReactor *reactor;
  50. BProcessManager *manager;
  51. NCDModule_handler_event handler_event;
  52. NCDModule_handler_died handler_died;
  53. NCDModule_handler_getvar handler_getvar;
  54. void *user;
  55. BPending event_job;
  56. int event_job_event;
  57. BPending toevent_job;
  58. int toevent_job_event;
  59. int state;
  60. void *inst_user;
  61. DebugObject d_obj;
  62. DebugError d_err;
  63. } NCDModuleInst;
  64. int NCDModuleInst_Init (NCDModuleInst *n, const char *name, const struct NCDModule *m, NCDValue *args, const char *logprefix, BReactor *reactor, BProcessManager *manager,
  65. NCDModule_handler_event handler_event, NCDModule_handler_died handler_died, NCDModule_handler_getvar handler_getvar, 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);
  69. void NCDModuleInst_Backend_Event (NCDModuleInst *n, int event);
  70. void NCDModuleInst_Backend_Died (NCDModuleInst *n, int is_error);
  71. int NCDModuleInst_Backend_GetVar (NCDModuleInst *n, const char *modname, const char *varname, NCDValue *out);
  72. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  73. typedef int (*NCDModule_func_globalinit) (const struct NCDModuleInitParams params);
  74. typedef void (*NCDModule_func_globalfree) (void);
  75. typedef void * (*NCDModule_func_new) (NCDModuleInst *params);
  76. typedef void (*NCDModule_func_free) (void *o);
  77. typedef void (*NCDModule_func_die) (void *o);
  78. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValue *out);
  79. typedef void (*NCDModule_func_clean) (void *o);
  80. struct NCDModule {
  81. const char *type;
  82. NCDModule_func_new func_new;
  83. NCDModule_func_free func_free;
  84. NCDModule_func_die func_die;
  85. NCDModule_func_getvar func_getvar;
  86. NCDModule_func_clean func_clean;
  87. };
  88. struct NCDModuleGroup {
  89. NCDModule_func_globalinit func_globalinit;
  90. NCDModule_func_globalfree func_globalfree;
  91. const struct NCDModule *modules;
  92. };
  93. #endif