NCDModule.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/BProcess.h>
  28. #include <system/BPending.h>
  29. #include <system/BLog.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. struct NCDModule;
  40. typedef struct {
  41. const char *name;
  42. const struct NCDModule *m;
  43. NCDValue *args;
  44. const char *logprefix;
  45. BReactor *reactor;
  46. BProcessManager *manager;
  47. NCDModule_handler_event handler_event;
  48. NCDModule_handler_died handler_died;
  49. void *user;
  50. BPending event_job;
  51. int event_job_event;
  52. BPending toevent_job;
  53. int toevent_job_event;
  54. int state;
  55. void *inst_user;
  56. DebugObject d_obj;
  57. DebugError d_err;
  58. } NCDModuleInst;
  59. int NCDModuleInst_Init (NCDModuleInst *n, const char *name, const struct NCDModule *m, NCDValue *args, const char *logprefix, BReactor *reactor, BProcessManager *manager,
  60. NCDModule_handler_event handler_event, NCDModule_handler_died handler_died, void *user);
  61. void NCDModuleInst_Free (NCDModuleInst *n);
  62. void NCDModuleInst_Event (NCDModuleInst *n, int event);
  63. int NCDModuleInst_GetVar (NCDModuleInst *n, const char *name, NCDValue *out);
  64. void NCDModuleInst_Backend_Event (NCDModuleInst *n, int event);
  65. void NCDModuleInst_Backend_Died (NCDModuleInst *n, int is_error);
  66. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  67. typedef int (*NCDModule_func_globalinit) (void);
  68. typedef void * (*NCDModule_func_new) (NCDModuleInst *params);
  69. typedef void (*NCDModule_func_free) (void *o);
  70. typedef void (*NCDModule_func_die) (void *o);
  71. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValue *out);
  72. typedef void (*NCDModule_func_clean) (void *o);
  73. struct NCDModule {
  74. const char *type;
  75. NCDModule_func_new func_new;
  76. NCDModule_func_free func_free;
  77. NCDModule_func_die func_die;
  78. NCDModule_func_getvar func_getvar;
  79. NCDModule_func_clean func_clean;
  80. };
  81. struct NCDModuleGroup {
  82. NCDModule_func_globalinit func_globalinit;
  83. const struct NCDModule *modules;
  84. };
  85. #endif