NCDModule.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. struct NCDModuleInst_s;
  35. struct NCDModuleProcess_s;
  36. /**
  37. * Function called to inform the interpeter of state changes of the
  38. * module instance.
  39. * Possible events are:
  40. *
  41. * - NCDMODULE_EVENT_UP: the instance came up.
  42. * The instance was in down state.
  43. * The instance enters up state.
  44. *
  45. * - NCDMODULE_EVENT_DOWN: the instance went down.
  46. * The instance was in up state.
  47. * The instance enters down state.
  48. *
  49. * After the instance goes down, the interpreter should eventually call
  50. * {@link NCDModuleInst_Clean} or {@link NCDModuleInst_Die}, unless
  51. * the module goes up again.
  52. *
  53. * - NCDMODULE_EVENT_DEAD: the module died.
  54. * The instance enters dead state.
  55. *
  56. * This function is not being called in event context. The interpreter should
  57. * only update its internal state, and visibly react only via jobs that it pushes
  58. * from within this function. The only exception is that it may free the
  59. * instance from within the NCDMODULE_EVENT_DEAD event.
  60. *
  61. * @param user as in {@link NCDModuleInst_Init}
  62. * @param event event number
  63. */
  64. typedef void (*NCDModuleInst_func_event) (void *user, int event);
  65. /**
  66. * Function called when the module instance wants the interpreter to
  67. * resolve a variable from the point of view of its statement.
  68. * The instance will not be in dead state.
  69. * This function must not have any side effects.
  70. *
  71. * @param user as in {@link NCDModuleInst_Init}
  72. * @param name name of the variable
  73. * @param out on success, the interpreter should initialize the value here
  74. * @return 1 on success, 0 on failure
  75. */
  76. typedef int (*NCDModuleInst_func_getvar) (void *user, const char *name, NCDValue *out);
  77. /**
  78. * Function called when the module instance wants the interpreter to
  79. * resolve an object from the point of view of its statement.
  80. * The instance will not be in dead state.
  81. * This function must not have any side effects.
  82. *
  83. * @param user as in {@link NCDModuleInst_Init}
  84. * @param name name of the object
  85. * @return object, or NULL on failure
  86. */
  87. typedef struct NCDModuleInst_s * (*NCDModuleInst_func_getobj) (void *user, const char *name);
  88. /**
  89. * Function called when the module instance wants the interpreter to
  90. * create a new process backend from a process template.
  91. * The instance will not be in dead state.
  92. *
  93. * On success, the interpreter must have called {@link NCDModuleProcess_Interp_SetHandlers}
  94. * from within this function, to allow communication with the controller of the process.
  95. * On success, the new process backend enters down state.
  96. *
  97. * This function is not being called in event context. The interpreter should
  98. * only update its internal state, and visibly react only via jobs that it pushes
  99. * from within this function.
  100. *
  101. * @param user as in {@link NCDModuleInst_Init}
  102. * @param p handle for the new process backend
  103. * @param template_name name of the template to create the process from
  104. * @param args process arguments. On success, the arguments become owned
  105. * by the interpreter. On failure, the interpreter must leave
  106. * them unchanged.
  107. * @return 1 on success, 0 on failure
  108. */
  109. typedef int (*NCDModuleInst_func_initprocess) (void *user, struct NCDModuleProcess_s *p, const char *template_name, NCDValue args);
  110. #define NCDMODULEPROCESS_EVENT_UP 1
  111. #define NCDMODULEPROCESS_EVENT_DOWN 2
  112. #define NCDMODULEPROCESS_EVENT_TERMINATED 3
  113. /**
  114. * Handler which reports process state changes from the interpreter.
  115. * Possible events are:
  116. *
  117. * - NCDMODULEPROCESS_EVENT_UP: the process went up.
  118. * The process was in down state.
  119. * The process enters up state.
  120. *
  121. * - NCDMODULEPROCESS_EVENT_DOWN: the process went down.
  122. * The process was in up state.
  123. * The process enters waiting state.
  124. *
  125. * NOTE: the process enters waiting state, NOT down state, and is paused.
  126. * To allow the process to continue, call {@link NCDModuleProcess_Continue}.
  127. *
  128. * - NCDMODULEPROCESS_EVENT_TERMINATED: the process terminated.
  129. * The process was in terminating state.
  130. * The process enters terminated state.
  131. *
  132. * @param user as in {@link NCDModuleProcess_Init}
  133. * @param event event number
  134. */
  135. typedef void (*NCDModuleProcess_handler_event) (void *user, int event);
  136. #define NCDMODULEPROCESS_INTERP_EVENT_CONTINUE 1
  137. #define NCDMODULEPROCESS_INTERP_EVENT_TERMINATE 2
  138. /**
  139. * Function called to report process backend requests to the interpreter.
  140. * Possible events are:
  141. *
  142. * - NCDMODULEPROCESS_INTERP_EVENT_CONTINUE: the process can continue.
  143. * The process backend was in waiting state.
  144. * The process backend enters down state.
  145. *
  146. * - NCDMODULEPROCESS_INTERP_EVENT_TERMINATE: the process should terminate.
  147. * The process backend was in down, up or waiting state.
  148. * The process backend enters terminating state.
  149. *
  150. * The interpreter should call {@link NCDModuleProcess_Interp_Terminated}
  151. * when the process terminates.
  152. *
  153. * This function is not being called in event context. The interpreter should
  154. * only update its internal state, and visibly react only via jobs that it pushes
  155. * from within this function.
  156. *
  157. * @param user as in {@link NCDModuleProcess_Interp_SetHandlers}
  158. * @param event event number
  159. */
  160. typedef void (*NCDModuleProcess_interp_func_event) (void *user, int event);
  161. /**
  162. * Function called to have the interpreter resolve a variable within the process
  163. * of a process backend.
  164. * This function must not have any side effects.
  165. *
  166. * @param user as in {@link NCDModuleProcess_Interp_SetHandlers}
  167. * @param name name of the variable
  168. * @param out on success, the interpreter should initialize the value here
  169. * @return 1 on success, 0 on failure
  170. */
  171. typedef int (*NCDModuleProcess_interp_func_getvar) (void *user, const char *name, NCDValue *out);
  172. /**
  173. * Function called to have the interpreter resolve an object within the process
  174. * of a process backend.
  175. * This function must not have any side effects.
  176. *
  177. * @param user as in {@link NCDModuleProcess_Interp_SetHandlers}
  178. * @param name name of the object
  179. * @return object, or NULL on failure
  180. */
  181. typedef struct NCDModuleInst_s * (*NCDModuleProcess_interp_func_getobj) (void *user, const char *name);
  182. struct NCDModule;
  183. struct NCDModuleInitParams {
  184. BReactor *reactor;
  185. BProcessManager *manager;
  186. NCDUdevManager *umanager;
  187. };
  188. /**
  189. * Module instance.
  190. * The module instance is initialized by the interpreter by calling
  191. * {@link NCDModuleInst_Init}. It is implemented by a module backend
  192. * specified in a {@link NCDModule}.
  193. */
  194. typedef struct NCDModuleInst_s {
  195. const struct NCDModule *m;
  196. struct NCDModuleInst_s *method_object;
  197. NCDValue *args;
  198. BReactor *reactor;
  199. BProcessManager *manager;
  200. NCDUdevManager *umanager;
  201. void *user;
  202. NCDModuleInst_func_event func_event;
  203. NCDModuleInst_func_getvar func_getvar;
  204. NCDModuleInst_func_getobj func_getobj;
  205. NCDModuleInst_func_initprocess func_initprocess;
  206. BLog_logfunc logfunc;
  207. BPending init_job;
  208. BPending uninit_job;
  209. BPending die_job;
  210. BPending clean_job;
  211. int state;
  212. void *inst_user;
  213. int is_error;
  214. DebugObject d_obj;
  215. } NCDModuleInst;
  216. /**
  217. * Process created from a process template on behalf of a module backend
  218. * instance, implemented by the interpreter.
  219. */
  220. typedef struct NCDModuleProcess_s {
  221. NCDModuleInst *n;
  222. void *user;
  223. NCDModuleProcess_handler_event handler_event;
  224. BPending event_job;
  225. int state;
  226. void *interp_user;
  227. NCDModuleProcess_interp_func_event interp_func_event;
  228. NCDModuleProcess_interp_func_getvar interp_func_getvar;
  229. NCDModuleProcess_interp_func_getobj interp_func_getobj;
  230. DebugObject d_obj;
  231. } NCDModuleProcess;
  232. /**
  233. * Initializes an instance of an NCD module.
  234. * The instance is initialized in down state.
  235. *
  236. * This and other non-Backend methods are the interpreter interface.
  237. * The Backend methods are the module backend interface and are documented
  238. * independently with their own logical states.
  239. *
  240. * @param n the instance
  241. * @param m structure of module functions implementing the module backend
  242. * @param method_object the base module if the module being initialized is a method, otherwise NULL.
  243. * The caller must ensure that this module is of the type expected by the module
  244. * being initialized.
  245. * @param args arguments to the module. Must be a NCDVALUE_LIST value. Must be available as long as
  246. * the instance is freed.
  247. * @param reactor reactor we live in
  248. * @param manager process manager
  249. * @param umanager udev manager
  250. * @param user argument to callback functions
  251. * @param func_event callback to report state changes
  252. * @param func_getvar callback to resolve variables from the viewpoint of the instance
  253. * @param func_getobj callback to resolve objects from the viewpoint of the instance
  254. * @param logfunc log function which appends a log prefix with {@link BLog_Append}
  255. */
  256. void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, NCDModuleInst *method_object, NCDValue *args, BReactor *reactor, BProcessManager *manager, NCDUdevManager *umanager, void *user,
  257. NCDModuleInst_func_event func_event,
  258. NCDModuleInst_func_getvar func_getvar,
  259. NCDModuleInst_func_getobj func_getobj,
  260. NCDModuleInst_func_initprocess func_initprocess,
  261. BLog_logfunc logfunc);
  262. /**
  263. * Frees the instance.
  264. * The instance must be in dead state.
  265. *
  266. * @param n the instance
  267. */
  268. void NCDModuleInst_Free (NCDModuleInst *n);
  269. /**
  270. * Requests the instance to die.
  271. * The instance must be in down or up state.
  272. * The instance enters dying state.
  273. *
  274. * @param n the instance
  275. */
  276. void NCDModuleInst_Die (NCDModuleInst *n);
  277. /**
  278. * Informs the module that it is in a clean state to proceed.
  279. * The instance must be in down state.
  280. *
  281. * @param n the instance
  282. */
  283. void NCDModuleInst_Clean (NCDModuleInst *n);
  284. /**
  285. * Resolves a variable within the instance.
  286. * The instance must be in up state.
  287. * This function does not have any side effects.
  288. *
  289. * @param n the instance
  290. * @param name name of the variable to resolve
  291. * @param out the value will be initialized here if successful
  292. * @return 1 on success, 0 on failure
  293. */
  294. int NCDModuleInst_GetVar (NCDModuleInst *n, const char *name, NCDValue *out) WARN_UNUSED;
  295. /**
  296. * Resolves an object within the instance.
  297. * The instance must be in up state.
  298. * This function does not have any side effects.
  299. *
  300. * @param n the instance
  301. * @param name name of the object to resolve
  302. * @return module instance, or NULL on failure
  303. */
  304. NCDModuleInst * NCDModuleInst_GetObj (NCDModuleInst *n, const char *name) WARN_UNUSED;
  305. /**
  306. * Checks whether the module terminated unsuccessfully.
  307. * The instance must be in dead state.
  308. *
  309. * @param n the instance
  310. * @return 1 if module terminated unsuccessfully, 0 if successfully
  311. */
  312. int NCDModuleInst_HaveError (NCDModuleInst *n);
  313. /**
  314. * Sets the argument passed to handlers of a module backend instance.
  315. *
  316. * @param n backend instance handle
  317. * @param user value to pass to future handlers for this backend instance
  318. */
  319. void NCDModuleInst_Backend_SetUser (NCDModuleInst *n, void *user);
  320. /**
  321. * Puts the backend instance into up state.
  322. * The instance must be in down state.
  323. * The instance enters up state.
  324. *
  325. * @param n backend instance handle
  326. */
  327. void NCDModuleInst_Backend_Up (NCDModuleInst *n);
  328. /**
  329. * Puts the backend instance into down state.
  330. * The instance must be in up state.
  331. * The instance enters down state.
  332. *
  333. * @param n backend instance handle
  334. */
  335. void NCDModuleInst_Backend_Down (NCDModuleInst *n);
  336. /**
  337. * Destroys the backend instance.
  338. * The backend instance handle becomes invalid and must not be used from
  339. * the backend any longer.
  340. *
  341. * @param n backend instance handle
  342. */
  343. void NCDModuleInst_Backend_Dead (NCDModuleInst *n);
  344. /**
  345. * Resolves a variable for a backend instance, from the point of the instance's
  346. * statement in the containing process.
  347. *
  348. * @param n backend instance handle
  349. * @param name name of the variable to resolve
  350. * @param out the value will be initialized here if successful
  351. * @return 1 on success, 0 on failure
  352. */
  353. int NCDModuleInst_Backend_GetVar (NCDModuleInst *n, const char *name, NCDValue *out) WARN_UNUSED;
  354. /**
  355. * Resolves an object for a backend instance, from the point of the instance's
  356. * statement in the containing process.
  357. *
  358. * @param n backend instance handle
  359. * @param name name of the object to resolve
  360. * @return module instance, or NULL on failure
  361. */
  362. NCDModuleInst * NCDModuleInst_Backend_GetObj (NCDModuleInst *n, const char *name) WARN_UNUSED;
  363. /**
  364. * Logs a backend instance message.
  365. *
  366. * @param n backend instance handle
  367. * @param channel log channel
  368. * @param level loglevel
  369. * @param fmt format string as in printf, arguments follow
  370. */
  371. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  372. /**
  373. * Sets the error flag for the module instance.
  374. * The error flag only has no effect until the backend calls
  375. * {@link NCDModuleInst_Backend_Dead}.
  376. *
  377. * @param n backend instance handle
  378. */
  379. void NCDModuleInst_Backend_SetError (NCDModuleInst *n);
  380. /**
  381. * Initializes a process in the interpreter from a process template.
  382. * This must be called on behalf of a module backend instance.
  383. * The process is initializes in down state.
  384. *
  385. * @param o the process
  386. * @param n backend instance whose interpreter will be providing the process
  387. * @param template_name name of the process template
  388. * @param args arguments to the process. On success, the arguments become owned
  389. * by the interpreter. On failure, they are left untouched.
  390. * @param user argument to handlers
  391. * @param handler_event handler which reports events about the process from the
  392. * interpreter
  393. * @return 1 on success, 0 on failure
  394. */
  395. int NCDModuleProcess_Init (NCDModuleProcess *o, NCDModuleInst *n, const char *template_name, NCDValue args, void *user, NCDModuleProcess_handler_event handler_event);
  396. /**
  397. * Frees the process.
  398. * The process must be in terminated state.
  399. *
  400. * @param o the process
  401. */
  402. void NCDModuleProcess_Free (NCDModuleProcess *o);
  403. /**
  404. * Continues the process after the process went down.
  405. * The process must be in waiting state.
  406. * The process enters down state.
  407. *
  408. * @param o the process
  409. */
  410. void NCDModuleProcess_Continue (NCDModuleProcess *o);
  411. /**
  412. * Requests the process to terminate.
  413. * The process must be in down, up or waiting state.
  414. * The process enters terminating state.
  415. *
  416. * @param o the process
  417. */
  418. void NCDModuleProcess_Terminate (NCDModuleProcess *o);
  419. /**
  420. * Resolves a variable within the process from the point
  421. * at the end of the process.
  422. * This function has no side effects.
  423. *
  424. * @param o the process
  425. * @param name name of the variable to resolve
  426. * @param out the value will be initialized here if successful
  427. * @return 1 on success, 0 on failure
  428. */
  429. int NCDModuleProcess_GetVar (NCDModuleProcess *o, const char *name, NCDValue *out) WARN_UNUSED;
  430. /**
  431. * Resolves an object within the process from the point
  432. * at the end of the process.
  433. * This function has no side effects.
  434. *
  435. * @param o the process
  436. * @param name name of the object to resolve
  437. * @return module instance, or NULL on failure
  438. */
  439. NCDModuleInst * NCDModuleProcess_GetObj (NCDModuleProcess *o, const char *name) WARN_UNUSED;
  440. /**
  441. * Sets callback functions for the interpreter to implement the
  442. * process backend.
  443. * Must be called from within {@link NCDModuleInst_func_initprocess}
  444. * if success is to be reported there.
  445. *
  446. * @param o process backend handle, as in {@link NCDModuleInst_func_initprocess}
  447. * @param interp_user argument to callback functions
  448. * @param interp_func_event function for reporting continue/terminate requests
  449. * @param interp_func_getvar function for resolving variables within the process
  450. * @param interp_func_getobj function for resolving objects within the process
  451. */
  452. void NCDModuleProcess_Interp_SetHandlers (NCDModuleProcess *o, void *interp_user,
  453. NCDModuleProcess_interp_func_event interp_func_event,
  454. NCDModuleProcess_interp_func_getvar interp_func_getvar,
  455. NCDModuleProcess_interp_func_getobj interp_func_getobj);
  456. /**
  457. * Reports the process backend as up.
  458. * The process backend must be in down state.
  459. * The process backend enters up state.
  460. *
  461. * @param o process backend handle
  462. */
  463. void NCDModuleProcess_Interp_Up (NCDModuleProcess *o);
  464. /**
  465. * Reports the process backend as down.
  466. * The process backend must be in up state.
  467. * The process backend enters waiting state.
  468. *
  469. * NOTE: the backend enters waiting state, NOT down state. The interpreter should
  470. * pause the process until {@link NCDModuleProcess_interp_func_event} reports
  471. * NCDMODULEPROCESS_INTERP_EVENT_CONTINUE, unless termination is requested via
  472. * NCDMODULEPROCESS_INTERP_EVENT_TERMINATE.
  473. *
  474. * @param o process backend handle
  475. */
  476. void NCDModuleProcess_Interp_Down (NCDModuleProcess *o);
  477. /**
  478. * Reports termination of the process backend.
  479. * The process backend must be in terminating state.
  480. * The process backend handle becomes invalid and must not be used
  481. * by the interpreter any longer.
  482. *
  483. * @param o process backend handle
  484. */
  485. void NCDModuleProcess_Interp_Terminated (NCDModuleProcess *o);
  486. /**
  487. * Function called before any instance of any backend in a module
  488. * group is created;
  489. *
  490. * @param params structure containing global resources, in particular
  491. * {@link BReactor}, {@link BProcessManager} and {@link NCDUdevManager}
  492. * @return 1 on success, 0 on failure
  493. */
  494. typedef int (*NCDModule_func_globalinit) (const struct NCDModuleInitParams params);
  495. /**
  496. * Function called to clean up after {@link NCDModule_func_globalinit} and modules
  497. * in a module group.
  498. * There are no backend instances alive from this module group.
  499. */
  500. typedef void (*NCDModule_func_globalfree) (void);
  501. /**
  502. * Handler called to create an new module backend instance.
  503. * The backend is initialized in down state.
  504. *
  505. * This handler should call {@link NCDModuleInst_Backend_SetUser} to provide
  506. * an argument for handlers of this backend instance.
  507. *
  508. * If the backend fails initialization, this function should report the backend
  509. * instance to have died with error by calling {@link NCDModuleInst_Backend_SetError}
  510. * and {@link NCDModuleInst_Backend_Dead}.
  511. *
  512. * @param i module backend instance handler. The backend may only use this handle via
  513. * the Backend functions of {@link NCDModuleInst}.
  514. */
  515. typedef void (*NCDModule_func_new) (NCDModuleInst *i);
  516. /**
  517. * Handler called to request termination of a backend instance.
  518. * The backend instance was in down or up state.
  519. * The backend instance enters dying state.
  520. *
  521. * @param o as in {@link NCDModuleInst_Backend_SetUser}, or NULL by default
  522. */
  523. typedef void (*NCDModule_func_die) (void *o);
  524. /**
  525. * Function called to resolve a variable within a backend instance.
  526. * The backend instance is in up state.
  527. * This function must not have any side effects.
  528. *
  529. * @param o as in {@link NCDModuleInst_Backend_SetUser}, or NULL by default
  530. * @param name name of the variable to resolve
  531. * @param out on success, the backend should initialize the value here
  532. * @return 1 on success, 0 on failure
  533. */
  534. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValue *out);
  535. /**
  536. * Function called to resolve an object within a backend instance.
  537. * The backend instance is in up state.
  538. * This function must not have any side effects.
  539. *
  540. * @param o as in {@link NCDModuleInst_Backend_SetUser}, or NULL by default
  541. * @param name name of the object to resolve
  542. * @return object, or NULL on failure
  543. */
  544. typedef NCDModuleInst * (*NCDModule_func_getobj) (void *o, const char *name);
  545. /**
  546. * Handler called when the module instance is in a clean state.
  547. * This means that all statements preceding it in the process are
  548. * up, this statement is down, and all following statements are
  549. * uninitialized. When a backend instance goes down, it is guaranteed,
  550. * as long as it stays down, that either this will be called or
  551. * termination will be requested with {@link NCDModule_func_die}.
  552. * The backend instance was in down state.
  553. *
  554. * @param o as in {@link NCDModuleInst_Backend_SetUser}, or NULL by default
  555. */
  556. typedef void (*NCDModule_func_clean) (void *o);
  557. /**
  558. * Structure encapsulating the implementation of a module backend.
  559. */
  560. struct NCDModule {
  561. /**
  562. * Type string of the backend. This is either a plain name,
  563. * or "type_name::method_name" for a method operating on a backend instance
  564. * of type type_name.
  565. */
  566. const char *type;
  567. /**
  568. * Function called to create an new backend instance.
  569. */
  570. NCDModule_func_new func_new;
  571. /**
  572. * Function called to request termination of a backend instance.
  573. */
  574. NCDModule_func_die func_die;
  575. /**
  576. * Function called to resolve a variable within the backend instance.
  577. * May be NULL.
  578. */
  579. NCDModule_func_getvar func_getvar;
  580. /**
  581. * Function called to resolve an object within the backend instance.
  582. * May be NULL.
  583. */
  584. NCDModule_func_getobj func_getobj;
  585. /**
  586. * Function called when the backend instance is in a clean state.
  587. * May be NULL.
  588. */
  589. NCDModule_func_clean func_clean;
  590. };
  591. /**
  592. * Structure encapsulating a group of module backend implementations,
  593. * with global init and free functions.
  594. */
  595. struct NCDModuleGroup {
  596. /**
  597. * Function called before any instance of any module backend in this
  598. * group is crated. May be NULL.
  599. */
  600. NCDModule_func_globalinit func_globalinit;
  601. /**
  602. * Function called to clean up after {@link NCDModule_func_globalinit}.
  603. * May be NULL.
  604. */
  605. NCDModule_func_globalfree func_globalfree;
  606. /**
  607. * Array of module backends. The array must be terminated with a
  608. * structure that has a NULL type member.
  609. */
  610. const struct NCDModule *modules;
  611. };
  612. #endif