NCDModule.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 <base/BPending.h>
  27. #include <base/BLog.h>
  28. #include <system/BProcess.h>
  29. #include <udevmonitor/NCDUdevManager.h>
  30. #include <ncd/NCDValue.h>
  31. #define NCDMODULE_EVENT_UP 1
  32. #define NCDMODULE_EVENT_DOWN 2
  33. #define NCDMODULE_EVENT_DEAD 3
  34. #define NCDMODULE_TOEVENT_DIE 101
  35. #define NCDMODULE_TOEVENT_CLEAN 102
  36. struct NCDModuleInst_s;
  37. struct NCDModuleProcess_s;
  38. typedef void (*NCDModule_handler_event) (void *user, int event);
  39. typedef int (*NCDModule_handler_getvar) (void *user, const char *varname, NCDValue *out);
  40. typedef struct NCDModuleInst_s * (*NCDModule_handler_getobj) (void *user, const char *objname);
  41. typedef int (*NCDModule_handler_initprocess) (void *user, struct NCDModuleProcess_s *p, const char *template_name, NCDValue args);
  42. typedef void (*NCDModule_handler_log) (void *user);
  43. typedef void (*NCDModuleProcess_handler_dead) (void *user);
  44. typedef void (*NCDModuleProcess_interp_handler_die) (void *user);
  45. struct NCDModule;
  46. struct NCDModuleInitParams {
  47. BReactor *reactor;
  48. BProcessManager *manager;
  49. NCDUdevManager *umanager;
  50. };
  51. typedef struct NCDModuleInst_s {
  52. const struct NCDModule *m;
  53. struct NCDModuleInst_s *method_object;
  54. NCDValue *args;
  55. BReactor *reactor;
  56. BProcessManager *manager;
  57. NCDUdevManager *umanager;
  58. void *user;
  59. NCDModule_handler_event handler_event;
  60. NCDModule_handler_getvar handler_getvar;
  61. NCDModule_handler_getobj handler_getobj;
  62. NCDModule_handler_initprocess handler_initprocess;
  63. NCDModule_handler_log handler_log;
  64. BPending init_job;
  65. BPending uninit_job;
  66. BPending die_job;
  67. BPending clean_job;
  68. int state;
  69. void *inst_user;
  70. int is_error;
  71. DebugObject d_obj;
  72. } NCDModuleInst;
  73. typedef struct NCDModuleProcess_s {
  74. NCDModuleInst *n;
  75. void *user;
  76. NCDModuleProcess_handler_dead handler_dead;
  77. void *interp_user;
  78. NCDModuleProcess_interp_handler_die interp_handler_die;
  79. BPending die_job;
  80. BPending dead_job;
  81. int state;
  82. DebugObject d_obj;
  83. } NCDModuleProcess;
  84. void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, NCDModuleInst *method_object, NCDValue *args, BReactor *reactor, BProcessManager *manager, NCDUdevManager *umanager, void *user,
  85. NCDModule_handler_event handler_event,
  86. NCDModule_handler_getvar handler_getvar,
  87. NCDModule_handler_getobj handler_getobj,
  88. NCDModule_handler_initprocess handler_initprocess,
  89. NCDModule_handler_log handler_log);
  90. void NCDModuleInst_Free (NCDModuleInst *n);
  91. void NCDModuleInst_Event (NCDModuleInst *n, int event);
  92. int NCDModuleInst_GetVar (NCDModuleInst *n, const char *name, NCDValue *out) WARN_UNUSED;
  93. NCDModuleInst * NCDModuleInst_GetObj (NCDModuleInst *n, const char *objname) WARN_UNUSED;
  94. int NCDModuleInst_HaveError (NCDModuleInst *n);
  95. void NCDModuleInst_Backend_SetUser (NCDModuleInst *n, void *user);
  96. void NCDModuleInst_Backend_Event (NCDModuleInst *n, int event);
  97. int NCDModuleInst_Backend_GetVar (NCDModuleInst *n, const char *varname, NCDValue *out) WARN_UNUSED;
  98. NCDModuleInst * NCDModuleInst_Backend_GetObj (NCDModuleInst *n, const char *objname) WARN_UNUSED;
  99. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  100. void NCDModuleInst_Backend_SetError (NCDModuleInst *n);
  101. int NCDModuleProcess_Init (NCDModuleProcess *o, NCDModuleInst *n, const char *template_name, NCDValue args, void *user, NCDModuleProcess_handler_dead handler_dead);
  102. void NCDModuleProcess_Free (NCDModuleProcess *o);
  103. void NCDModuleProcess_Die (NCDModuleProcess *o);
  104. void NCDModuleProcess_Interp_SetHandlers (NCDModuleProcess *o, void *interp_user, NCDModuleProcess_interp_handler_die interp_handler_die);
  105. void NCDModuleProcess_Interp_Dead (NCDModuleProcess *o);
  106. typedef int (*NCDModule_func_globalinit) (const struct NCDModuleInitParams params);
  107. typedef void (*NCDModule_func_globalfree) (void);
  108. typedef void (*NCDModule_func_new) (NCDModuleInst *params);
  109. typedef void (*NCDModule_func_die) (void *o);
  110. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValue *out);
  111. typedef NCDModuleInst * (*NCDModule_func_getobj) (void *o, const char *objname);
  112. typedef void (*NCDModule_func_clean) (void *o);
  113. struct NCDModule {
  114. const char *type;
  115. NCDModule_func_new func_new;
  116. NCDModule_func_die func_die;
  117. NCDModule_func_getvar func_getvar;
  118. NCDModule_func_getobj func_getobj;
  119. NCDModule_func_clean func_clean;
  120. };
  121. struct NCDModuleGroup {
  122. NCDModule_func_globalinit func_globalinit;
  123. NCDModule_func_globalfree func_globalfree;
  124. const struct NCDModule *modules;
  125. };
  126. #endif