NCDModule.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /**
  2. * @file NCDModule.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef BADVPN_NCD_NCDMODULE_H
  30. #define BADVPN_NCD_NCDMODULE_H
  31. #include <stdarg.h>
  32. #include <misc/debug.h>
  33. #include <system/BReactor.h>
  34. #include <base/BLog.h>
  35. #include <ncd/NCDVal.h>
  36. #include <ncd/NCDObject.h>
  37. #include <ncd/NCDStringIndex.h>
  38. #ifndef BADVPN_NO_PROCESS
  39. #include <system/BProcess.h>
  40. #endif
  41. #ifndef BADVPN_NO_UDEV
  42. #include <udevmonitor/NCDUdevManager.h>
  43. #endif
  44. #ifndef BADVPN_NO_RANDOM
  45. #include <random/BRandom2.h>
  46. #endif
  47. #define NCDMODULE_EVENT_UP 1
  48. #define NCDMODULE_EVENT_DOWN 2
  49. #define NCDMODULE_EVENT_DOWNUP 3
  50. #define NCDMODULE_EVENT_DEAD 4
  51. #define NCDMODULE_EVENT_DEADERROR 5
  52. struct NCDModuleInst_s;
  53. struct NCDModuleProcess_s;
  54. struct NCDModuleGroup;
  55. struct NCDInterpModule;
  56. struct NCDInterpModuleGroup;
  57. struct NCDCall_interp_shared;
  58. struct NCDInterpFunction;
  59. /**
  60. * Function called to inform the interpeter of state changes of the
  61. * module instance.
  62. * Possible events are:
  63. *
  64. * - NCDMODULE_EVENT_UP: the instance came up.
  65. * The instance was in down state.
  66. * The instance enters up state.
  67. *
  68. * - NCDMODULE_EVENT_DOWN: the instance went down.
  69. * The instance was in up state.
  70. * The instance enters down state.
  71. *
  72. * After the instance goes down, the interpreter should eventually call
  73. * {@link NCDModuleInst_Clean} or {@link NCDModuleInst_Die}, unless
  74. * the module goes up again.
  75. *
  76. * - NCDMODULE_EVENT_DEAD: the module died. To determine if the module
  77. * died with error, read the is_error member of {@link NCDModuleInst}.
  78. * The instance enters dead state.
  79. *
  80. * This function is not being called in event context. The interpreter should
  81. * only update its internal state, and visibly react only via jobs that it pushes
  82. * from within this function. The only exception is that it may free the
  83. * instance from within the NCDMODULE_EVENT_DEAD event.
  84. *
  85. * @param inst the module instance
  86. * @param event event number
  87. */
  88. typedef void (*NCDModuleInst_func_event) (struct NCDModuleInst_s *inst, int event);
  89. /**
  90. * Function called when the module instance wants the interpreter to
  91. * resolve an object from the point of view of its statement.
  92. * The instance will not be in dead state.
  93. * This function must not have any side effects.
  94. *
  95. * @param inst the module instance
  96. * @param name name of the object as an {@link NCDStringIndex} identifier
  97. * @param out_object the object will be returned here
  98. * @return 1 on success, 0 on failure
  99. */
  100. typedef int (*NCDModuleInst_func_getobj) (struct NCDModuleInst_s *inst, NCD_string_id_t name, NCDObject *out_object);
  101. /**
  102. * Function called when the module instance wants the interpreter to
  103. * create a new process backend from a process template.
  104. * The instance will not be in dead state.
  105. *
  106. * On success, the interpreter must have called {@link NCDModuleProcess_Interp_SetHandlers}
  107. * from within this function, to allow communication with the controller of the process.
  108. * On success, the new process backend enters down state.
  109. *
  110. * This function is not being called in event context. The interpreter should
  111. * only update its internal state, and visibly react only via jobs that it pushes
  112. * from within this function.
  113. *
  114. * @param user value of 'user' member of {@link NCDModuleInst_iparams}
  115. * @param p handle for the new process backend
  116. * @param template_name name of the template to create the process from,
  117. * as an {@link NCDStringIndex} identifier
  118. * @return 1 on success, 0 on failure
  119. */
  120. typedef int (*NCDModuleInst_func_initprocess) (void *user, struct NCDModuleProcess_s *p, NCD_string_id_t template_name);
  121. /**
  122. * Function called when the module instance wants the interpreter to
  123. * initiate termination, as if it received an external terminatio request (signal).
  124. *
  125. * @param user value of 'user' member of {@link NCDModuleInst_iparams}
  126. * @param exit_code exit code to return the the operating system. This overrides any previously
  127. * set exit code, and will be overriden by a signal to the value 1.
  128. *
  129. */
  130. typedef void (*NCDModuleInst_func_interp_exit) (void *user, int exit_code);
  131. /**
  132. * Function called when the module instance wants the interpreter to
  133. * provide its extra command line arguments.
  134. *
  135. * @param user value of 'user' member of {@link NCDModuleInst_iparams}
  136. * @param mem value memory to use
  137. * @param out_value write value reference here on success
  138. * @return 1 if available, 0 if not available. If available, but out of memory, return 1
  139. * and an invalid value.
  140. */
  141. typedef int (*NCDModuleInst_func_interp_getargs) (void *user, NCDValMem *mem, NCDValRef *out_value);
  142. /**
  143. * Function called when the module instance wants the interpreter to
  144. * provide its retry time.
  145. *
  146. * @param user value of 'user' member of {@link NCDModuleInst_iparams}
  147. * @return retry time in milliseconds
  148. */
  149. typedef btime_t (*NCDModuleInst_func_interp_getretrytime) (void *user);
  150. /**
  151. * Function called when the module instance wants the interpreter to
  152. * load a new module group.
  153. *
  154. * @param user value of 'user' member of {@link NCDModuleInst_iparams}
  155. * @param group module group to load
  156. * @return 1 on success, 0 on failure
  157. */
  158. typedef int (*NCDModuleInst_func_interp_loadgroup) (void *user, const struct NCDModuleGroup *group);
  159. #define NCDMODULEPROCESS_EVENT_UP 1
  160. #define NCDMODULEPROCESS_EVENT_DOWN 2
  161. #define NCDMODULEPROCESS_EVENT_TERMINATED 3
  162. /**
  163. * Handler which reports process state changes from the interpreter.
  164. * Possible events are:
  165. *
  166. * - NCDMODULEPROCESS_EVENT_UP: the process went up.
  167. * The process was in down state.
  168. * The process enters up state.
  169. *
  170. * - NCDMODULEPROCESS_EVENT_DOWN: the process went down.
  171. * The process was in up state.
  172. * The process enters waiting state.
  173. *
  174. * NOTE: the process enters waiting state, NOT down state, and is paused.
  175. * To allow the process to continue, call {@link NCDModuleProcess_Continue}.
  176. *
  177. * - NCDMODULEPROCESS_EVENT_TERMINATED: the process terminated.
  178. * The process was in terminating state.
  179. * The process enters terminated state.
  180. *
  181. * @param user pointer to the process. Use {@link UPPER_OBJECT} to retrieve the pointer
  182. * to the containing struct.
  183. * @param event event number
  184. */
  185. typedef void (*NCDModuleProcess_handler_event) (struct NCDModuleProcess_s *process, int event);
  186. /**
  187. * Function called when the interpreter wants to resolve a special
  188. * object in the process.
  189. * This function must have no side effects.
  190. *
  191. * @param user pointer to the process. Use {@link UPPER_OBJECT} to retrieve the pointer
  192. * to the containing struct.
  193. * @param name name of the object as an {@link NCDStringIndex} identifier
  194. * @param out_object the object will be returned here
  195. * @return 1 on success, 0 on failure
  196. */
  197. typedef int (*NCDModuleProcess_func_getspecialobj) (struct NCDModuleProcess_s *process, NCD_string_id_t name, NCDObject *out_object);
  198. #define NCDMODULEPROCESS_INTERP_EVENT_CONTINUE 1
  199. #define NCDMODULEPROCESS_INTERP_EVENT_TERMINATE 2
  200. /**
  201. * Function called to report process backend requests to the interpreter.
  202. * Possible events are:
  203. *
  204. * - NCDMODULEPROCESS_INTERP_EVENT_CONTINUE: the process can continue.
  205. * The process backend was in waiting state.
  206. * The process backend enters down state.
  207. *
  208. * - NCDMODULEPROCESS_INTERP_EVENT_TERMINATE: the process should terminate.
  209. * The process backend was in down, up or waiting state.
  210. * The process backend enters terminating state.
  211. *
  212. * The interpreter should call {@link NCDModuleProcess_Interp_Terminated}
  213. * when the process terminates.
  214. *
  215. * This function is not being called in event context. The interpreter should
  216. * only update its internal state, and visibly react only via jobs that it pushes
  217. * from within this function.
  218. *
  219. * @param user as in {@link NCDModuleProcess_Interp_SetHandlers}
  220. * @param event event number
  221. */
  222. typedef void (*NCDModuleProcess_interp_func_event) (void *user, int event);
  223. /**
  224. * Function called to have the interpreter resolve an object within the process
  225. * of a process backend.
  226. * This function must not have any side effects.
  227. *
  228. * @param user as in {@link NCDModuleProcess_Interp_SetHandlers}
  229. * @param name name of the object as an {@link NCDStringIndex} identifier
  230. * @param out_object the object will be returned here
  231. * @return 1 on success, 0 in failure
  232. */
  233. typedef int (*NCDModuleProcess_interp_func_getobj) (void *user, NCD_string_id_t name, NCDObject *out_object);
  234. struct NCDModule;
  235. /**
  236. * Contains parameters to the module initialization function
  237. * ({@link NCDModule_func_new2}) that are passed indirectly.
  238. */
  239. struct NCDModuleInst_new_params {
  240. /**
  241. * A reference to the argument list for the module instance.
  242. * The reference remains valid as long as the backend instance
  243. * exists.
  244. */
  245. NCDValRef args;
  246. /**
  247. * If the module instance corresponds to a method-like statement,
  248. * this pointer identifies the object it is being invoked with.
  249. * If the object is a statement (i.e. a {@link NCDModuleInst}), then this
  250. * will be the NCDModuleInst pointer, and {@link NCDModuleInst_Backend_GetUser}
  251. * can be called on this to retrieve the pointer to preallocated memory for
  252. * the backend instance; *unless* {@link NCDModuleInst_Backend_PassMemToMethods}
  253. * was called for the object on which the method is being called, in which case
  254. * this will directly point to the preallocated memory.
  255. * On the other hand, if this is a method on an internal object built using
  256. * only {@link NCDObject_Build} or {@link NCDObject_BuildFull},
  257. * this pointer will be whatever was passed as the "data_ptr" argument, for the
  258. * first function, and as "method_user", for the latter function.
  259. */
  260. void *method_user;
  261. };
  262. /**
  263. * Contains parameters to {@link NCDModuleInst_Init} that are passed indirectly.
  264. * This itself only contains parameters related to communication between the
  265. * backend and the creator of the module instance; other parameters are passed
  266. * via the iparams member;
  267. */
  268. struct NCDModuleInst_params {
  269. /**
  270. * Callback to report state changes.
  271. */
  272. NCDModuleInst_func_event func_event;
  273. /**
  274. * Callback to resolve objects from the viewpoint of the instance.
  275. */
  276. NCDModuleInst_func_getobj func_getobj;
  277. /**
  278. * Log function which appends a log prefix with {@link BLog_Append}.
  279. */
  280. BLog_logfunc logfunc;
  281. /**
  282. * Pointer to an {@link NCDModuleInst_iparams} structure, which exposes
  283. * services provided by the interpreter.
  284. */
  285. const struct NCDModuleInst_iparams *iparams;
  286. };
  287. /**
  288. * Contains parameters to {@link NCDModuleInst_Init} that are passed indirectly.
  289. * This only contains parameters related to services provided by the interpreter.
  290. */
  291. struct NCDModuleInst_iparams {
  292. /**
  293. * Reactor we live in.
  294. */
  295. BReactor *reactor;
  296. #ifndef BADVPN_NO_PROCESS
  297. /**
  298. * Process manager.
  299. */
  300. BProcessManager *manager;
  301. #endif
  302. #ifndef BADVPN_NO_UDEV
  303. /**
  304. * Udev manager.
  305. */
  306. NCDUdevManager *umanager;
  307. #endif
  308. #ifndef BADVPN_NO_RANDOM
  309. /**
  310. * Random number generator.
  311. */
  312. BRandom2 *random2;
  313. #endif
  314. /**
  315. * String index which keeps a mapping between strings and string identifiers.
  316. */
  317. NCDStringIndex *string_index;
  318. /**
  319. * Pointer passed to the interpreter callbacks below, for state keeping.
  320. */
  321. void *user;
  322. /**
  323. * Callback to create a new template process.
  324. */
  325. NCDModuleInst_func_initprocess func_initprocess;
  326. /**
  327. * Callback to request interpreter termination.
  328. */
  329. NCDModuleInst_func_interp_exit func_interp_exit;
  330. /**
  331. * Callback to get extra command line arguments.
  332. */
  333. NCDModuleInst_func_interp_getargs func_interp_getargs;
  334. /**
  335. * Callback to get retry time.
  336. */
  337. NCDModuleInst_func_interp_getretrytime func_interp_getretrytime;
  338. /**
  339. * Callback to load a module group.
  340. */
  341. NCDModuleInst_func_interp_loadgroup func_loadgroup;
  342. };
  343. /**
  344. * Module instance.
  345. * The module instance is initialized by the interpreter by calling
  346. * {@link NCDModuleInst_Init}. It is implemented by a module backend
  347. * specified in a {@link NCDModule}.
  348. */
  349. typedef struct NCDModuleInst_s {
  350. const struct NCDInterpModule *m;
  351. const struct NCDModuleInst_params *params;
  352. void *mem; // not modified by NCDModuleInst (but passed to module)
  353. unsigned int state:3;
  354. unsigned int pass_mem_to_methods:1;
  355. unsigned int istate:3; // untouched by NCDModuleInst
  356. NCDPersistentObj pobj;
  357. DebugObject d_obj;
  358. } NCDModuleInst;
  359. /**
  360. * Process created from a process template on behalf of a module backend
  361. * instance, implemented by the interpreter.
  362. */
  363. typedef struct NCDModuleProcess_s {
  364. NCDValRef args;
  365. NCDModuleProcess_handler_event handler_event;
  366. NCDModuleProcess_func_getspecialobj func_getspecialobj;
  367. void *interp_user;
  368. NCDModuleProcess_interp_func_event interp_func_event;
  369. NCDModuleProcess_interp_func_getobj interp_func_getobj;
  370. #ifndef NDEBUG
  371. int state;
  372. #endif
  373. DebugObject d_obj;
  374. } NCDModuleProcess;
  375. /**
  376. * Initializes an instance of an NCD module.
  377. * The instance is initialized in down state.
  378. * WARNING: this directly calls the module backend; expect to be called back
  379. *
  380. * This and other non-Backend methods are the interpreter interface.
  381. * The Backend methods are the module backend interface and are documented
  382. * independently with their own logical states.
  383. *
  384. * NOTE: the instance structure \a n should have the member 'mem' initialized
  385. * to point to preallocated memory for the statement. This memory must be
  386. * at least m->prealloc_size big and must be properly aligned for any object.
  387. * The 'mem' pointer is never modified by NCDModuleInst, so that the interpreter
  388. * can use it as outside the lifetime of NCDModuleInst.
  389. *
  390. * @param n the instance
  391. * @param m pointer to the {@link NCDInterpModule} structure representing the module
  392. * to be instantiated
  393. * @param method_context a context pointer passed to the module backend, applicable to method-like
  394. * statements only. This should be set to the 'user' member of the
  395. * {@link NCDObject} which represents the base object for the method.
  396. * The caller must ensure that the NCDObject that was used is of the type
  397. * expected by the module being instanciated.
  398. * @param args arguments to the module. Must be a list value. Must be available and unchanged
  399. * as long as the instance exists.
  400. * @param user argument to callback functions
  401. * @param params more parameters, see {@link NCDModuleInst_params}
  402. */
  403. void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDInterpModule *m, void *method_context, NCDValRef args, const struct NCDModuleInst_params *params);
  404. /**
  405. * Frees the instance.
  406. * The instance must be in dead state.
  407. *
  408. * @param n the instance
  409. */
  410. void NCDModuleInst_Free (NCDModuleInst *n);
  411. /**
  412. * Requests the instance to die.
  413. * The instance must be in down or up state.
  414. * The instance enters dying state.
  415. * WARNING: this directly calls the module backend; expect to be called back
  416. *
  417. * @param n the instance
  418. */
  419. void NCDModuleInst_Die (NCDModuleInst *n);
  420. /**
  421. * Attempts to destroy the instance immediately.
  422. * This function can be used to optimize destroying instances of modules which
  423. * don't specify any {@link NCDModule_func_die} handler. If immediate destruction
  424. * is not possible, this does nothing and returns 0; {@link NCDModuleInst_Die}
  425. * should be used to destroy the instance instead. If however immediate destruction
  426. * is possible, this destroys the module instance and returns 1; {@link NCDModuleInst_Free}
  427. * must not be called after that.
  428. * The instance must be in down or up state, as for {@link NCDModuleInst_Die}.
  429. *
  430. * @param n the instance
  431. * @return 1 if destruction was performed, 0 if not
  432. */
  433. int NCDModuleInst_TryFree (NCDModuleInst *n);
  434. /**
  435. * Informs the module that it is in a clean state to proceed.
  436. * The instance must be in down state.
  437. * WARNING: this directly calls the module backend; expect to be called back
  438. *
  439. * @param n the instance
  440. */
  441. void NCDModuleInst_Clean (NCDModuleInst *n);
  442. /**
  443. * Returns an {@link NCDObject} which can be used to resolve variables and objects
  444. * within this instance, as well as call its methods. The resulting object may only
  445. * be used immediately, and becomes invalid when the instance is freed.
  446. *
  447. * @param n the instance
  448. * @return an NCDObject for this instance
  449. */
  450. NCDObject NCDModuleInst_Object (NCDModuleInst *n);
  451. /**
  452. * If this is called, any methods called on this object will receive the preallocated
  453. * memory pointer as the object state pointer. This means that in the
  454. * {@link NCDModule_func_getvar2} function which is called when a method is created,
  455. * the preallocated memory should be accessed as params->method_user.
  456. * By default, however, params->method_user points to the NCDModuleInst of the base
  457. * object, and {@link NCDModuleInst_Backend_GetUser} is needed to retrieve the
  458. * preallocated memory pointer.
  459. */
  460. void NCDModuleInst_Backend_PassMemToMethods (NCDModuleInst *n);
  461. /**
  462. * Retuns the state pointer passed to handlers of a module backend instance;
  463. * see {@link NCDModule_func_new2}.
  464. *
  465. * @param n backend instance handle
  466. * @return argument passed to handlers
  467. */
  468. void * NCDModuleInst_Backend_GetUser (NCDModuleInst *n);
  469. /**
  470. * Puts the backend instance into up state.
  471. * The instance must be in down state.
  472. * The instance enters up state.
  473. *
  474. * @param n backend instance handle
  475. */
  476. void NCDModuleInst_Backend_Up (NCDModuleInst *n);
  477. /**
  478. * Puts the backend instance into down state.
  479. * The instance must be in up state.
  480. * The instance enters down state.
  481. *
  482. * @param n backend instance handle
  483. */
  484. void NCDModuleInst_Backend_Down (NCDModuleInst *n);
  485. /**
  486. * Puts the backend instance into down state, then immediatly back into the up state.
  487. * This effectively causes the interpreter to start backtracking to this statement.
  488. * The instance must be in up state, and remains in up state.
  489. *
  490. * @param n backend instance handle
  491. */
  492. void NCDModuleInst_Backend_DownUp (NCDModuleInst *n);
  493. /**
  494. * Destroys the backend instance.
  495. * The backend instance handle becomes invalid and must not be used from
  496. * the backend any longer.
  497. *
  498. * @param n backend instance handle
  499. */
  500. void NCDModuleInst_Backend_Dead (NCDModuleInst *n);
  501. /**
  502. * Like {@link NCDModuleInst_Backend_Dead}, but also reports an error condition
  503. * to the interpreter.
  504. */
  505. void NCDModuleInst_Backend_DeadError (NCDModuleInst *n);
  506. /**
  507. * Resolves an object for a backend instance, from the point of the instance's
  508. * statement in the containing process.
  509. *
  510. * @param n backend instance handle
  511. * @param name name of the object to resolve as an {@link NCDStringIndex} identifier
  512. * @param out_object the object will be returned here
  513. * @return 1 on success, 0 on failure
  514. */
  515. int NCDModuleInst_Backend_GetObj (NCDModuleInst *n, NCD_string_id_t name, NCDObject *out_object) WARN_UNUSED;
  516. /**
  517. * Logs a backend instance message.
  518. *
  519. * @param n backend instance handle
  520. * @param channel log channel
  521. * @param level loglevel
  522. * @param fmt format string as in printf, arguments follow
  523. */
  524. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  525. /**
  526. * Like {@link NCDModuleInst_Backend_Log}, but the extra arguments are passed
  527. * as a va_list. This allows creation of logging wrappers.
  528. */
  529. void NCDModuleInst_Backend_LogVarArg (NCDModuleInst *n, int channel, int level, const char *fmt, va_list vl);
  530. /**
  531. * Returns a logging context. The context is valid until the backend dies.
  532. */
  533. BLogContext NCDModuleInst_Backend_LogContext (NCDModuleInst *n);
  534. /**
  535. * Initiates interpreter termination.
  536. *
  537. * @param n backend instance handle
  538. * @param exit_code exit code to return to the operating system. This overrides
  539. * any previously set exit code, and will be overriden by a
  540. * termination signal to the value 1.
  541. */
  542. void NCDModuleInst_Backend_InterpExit (NCDModuleInst *n, int exit_code);
  543. /**
  544. * Retrieves extra command line arguments passed to the interpreter.
  545. *
  546. * @param n backend instance handle
  547. * @param mem value memory to use
  548. * @param out_value the arguments will be written here on success as a list value
  549. * @return 1 if available, 0 if not available. If available, but out of memory, returns 1
  550. * and an invalid value.
  551. */
  552. int NCDModuleInst_Backend_InterpGetArgs (NCDModuleInst *n, NCDValMem *mem, NCDValRef *out_value);
  553. /**
  554. * Returns the retry time of the intepreter.
  555. *
  556. * @param n backend instance handle
  557. * @return retry time in milliseconds
  558. */
  559. btime_t NCDModuleInst_Backend_InterpGetRetryTime (NCDModuleInst *n);
  560. /**
  561. * Loads a module group into the interpreter.
  562. *
  563. * @param n backend instance handle
  564. * @param group module group to load
  565. * @return 1 on success, 0 on failure
  566. */
  567. int NCDModuleInst_Backend_InterpLoadGroup (NCDModuleInst *n, const struct NCDModuleGroup *group);
  568. /**
  569. * Initializes a process in the interpreter from a process template.
  570. * This must be called on behalf of a module backend instance.
  571. * The process is initializes in down state.
  572. *
  573. * @param o the process
  574. * @param n backend instance whose interpreter will be providing the process
  575. * @param template_name name of the process template as an {@link NCDStringIndex} identifier
  576. * @param args arguments to the process. Must be an invalid value or a list value.
  577. * The value must be available and unchanged while the process exists.
  578. * @param handler_event handler which reports events about the process from the
  579. * interpreter
  580. * @return 1 on success, 0 on failure
  581. */
  582. int NCDModuleProcess_InitId (NCDModuleProcess *o, NCDModuleInst *n, NCD_string_id_t template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event) WARN_UNUSED;
  583. /**
  584. * Wrapper around {@link NCDModuleProcess_InitId} which takes the template name as an
  585. * {@link NCDValRef}, which must point to a string value.
  586. */
  587. int NCDModuleProcess_InitValue (NCDModuleProcess *o, NCDModuleInst *n, NCDValRef template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event) WARN_UNUSED;
  588. /**
  589. * Frees the process.
  590. * The process must be in terminated state.
  591. *
  592. * @param o the process
  593. */
  594. void NCDModuleProcess_Free (NCDModuleProcess *o);
  595. /**
  596. * Does nothing.
  597. * The process must be in terminated state.
  598. *
  599. * @param o the process
  600. */
  601. void NCDModuleProcess_AssertFree (NCDModuleProcess *o);
  602. /**
  603. * Sets callback functions for providing special objects within the process.
  604. *
  605. * @param o the process
  606. * @param func_getspecialobj function for resolving special objects, or NULL
  607. */
  608. void NCDModuleProcess_SetSpecialFuncs (NCDModuleProcess *o, NCDModuleProcess_func_getspecialobj func_getspecialobj);
  609. /**
  610. * Continues the process after the process went down.
  611. * The process must be in waiting state.
  612. * The process enters down state.
  613. *
  614. * @param o the process
  615. */
  616. void NCDModuleProcess_Continue (NCDModuleProcess *o);
  617. /**
  618. * Requests the process to terminate.
  619. * The process must be in down, up or waiting state.
  620. * The process enters terminating state.
  621. *
  622. * @param o the process
  623. */
  624. void NCDModuleProcess_Terminate (NCDModuleProcess *o);
  625. /**
  626. * Resolves an object within the process from the point
  627. * at the end of the process.
  628. * This function has no side effects.
  629. *
  630. * @param o the process
  631. * @param name name of the object to resolve as an {@link NCDStringIndex} identifier
  632. * @param out_object the object will be returned here
  633. * @return 1 on success, 0 on failure
  634. */
  635. int NCDModuleProcess_GetObj (NCDModuleProcess *o, NCD_string_id_t name, NCDObject *out_object) WARN_UNUSED;
  636. /**
  637. * Sets callback functions for the interpreter to implement the
  638. * process backend.
  639. * Must be called from within {@link NCDModuleInst_func_initprocess}
  640. * if success is to be reported there.
  641. *
  642. * @param o process backend handle, as in {@link NCDModuleInst_func_initprocess}
  643. * @param interp_user argument to callback functions
  644. * @param interp_func_event function for reporting continue/terminate requests
  645. * @param interp_func_getobj function for resolving objects within the process
  646. */
  647. void NCDModuleProcess_Interp_SetHandlers (NCDModuleProcess *o, void *interp_user,
  648. NCDModuleProcess_interp_func_event interp_func_event,
  649. NCDModuleProcess_interp_func_getobj interp_func_getobj);
  650. /**
  651. * Reports the process backend as up.
  652. * The process backend must be in down state.
  653. * The process backend enters up state.
  654. * WARNING: this directly calls the process creator; expect to be called back
  655. *
  656. * @param o process backend handle
  657. */
  658. void NCDModuleProcess_Interp_Up (NCDModuleProcess *o);
  659. /**
  660. * Reports the process backend as down.
  661. * The process backend must be in up state.
  662. * The process backend enters waiting state.
  663. * WARNING: this directly calls the process creator; expect to be called back
  664. *
  665. * NOTE: the backend enters waiting state, NOT down state. The interpreter should
  666. * pause the process until {@link NCDModuleProcess_interp_func_event} reports
  667. * NCDMODULEPROCESS_INTERP_EVENT_CONTINUE, unless termination is requested via
  668. * NCDMODULEPROCESS_INTERP_EVENT_TERMINATE.
  669. *
  670. * @param o process backend handle
  671. */
  672. void NCDModuleProcess_Interp_Down (NCDModuleProcess *o);
  673. /**
  674. * Reports termination of the process backend.
  675. * The process backend must be in terminating state.
  676. * The process backend handle becomes invalid and must not be used
  677. * by the interpreter any longer.
  678. * WARNING: this directly calls the process creator; expect to be called back
  679. *
  680. * @param o process backend handle
  681. */
  682. void NCDModuleProcess_Interp_Terminated (NCDModuleProcess *o);
  683. /**
  684. * Resolves a special process object for the process backend.
  685. *
  686. * @param o process backend handle
  687. * @param name name of the object as an {@link NCDStringIndex} identifier
  688. * @param out_object the object will be returned here
  689. * @return 1 on success, 0 on failure
  690. */
  691. int NCDModuleProcess_Interp_GetSpecialObj (NCDModuleProcess *o, NCD_string_id_t name, NCDObject *out_object) WARN_UNUSED;
  692. /**
  693. * Function called before any instance of any backend in a module
  694. * group is created;
  695. *
  696. * @param params structure containing global resources, such as
  697. * {@link BReactor}, {@link BProcessManager} and {@link NCDUdevManager}.
  698. * @return 1 on success, 0 on failure
  699. */
  700. typedef int (*NCDModule_func_globalinit) (struct NCDInterpModuleGroup *group, const struct NCDModuleInst_iparams *params);
  701. /**
  702. * Function called to clean up after {@link NCDModule_func_globalinit} and modules
  703. * in a module group.
  704. * There are no backend instances alive from this module group.
  705. */
  706. typedef void (*NCDModule_func_globalfree) (struct NCDInterpModuleGroup *group);
  707. /**
  708. * Handler called to create an new module backend instance.
  709. * The backend is initialized in down state.
  710. *
  711. * If the backend fails initialization, this function should report the backend
  712. * instance to have died with error by calling {@link NCDModuleInst_Backend_DeadError}.
  713. *
  714. * @param o if the module specifies a positive alloc_size value in the {@link NCDModule}
  715. * structure, this will point to the allocated memory that can be used by the
  716. * module instance while it exists. If the alloc_size is 0 (default), this may or
  717. * may not be NULL.
  718. * @param i module backend instance handler. The backend may only use this handle via
  719. * the Backend functions of {@link NCDModuleInst}.
  720. */
  721. typedef void (*NCDModule_func_new2) (void *o, NCDModuleInst *i, const struct NCDModuleInst_new_params *params);
  722. /**
  723. * Handler called to request termination of a backend instance.
  724. * The backend instance was in down or up state.
  725. * The backend instance enters dying state.
  726. *
  727. * @param o state pointer, as in {@link NCDModule_func_new2}
  728. */
  729. typedef void (*NCDModule_func_die) (void *o);
  730. /**
  731. * Function called to resolve a variable within a backend instance.
  732. * The backend instance is in up state, or in up or down state if can_resolve_when_down=1.
  733. * This function must not have any side effects.
  734. *
  735. * @param o state pointer, as in {@link NCDModule_func_new2}
  736. * @param name name of the variable to resolve
  737. * @param mem value memory to use
  738. * @param out on success, the backend should initialize the value here
  739. * @return 1 if exists, 0 if not exists. If exists, but out of memory, return 1
  740. * and an invalid value.
  741. */
  742. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValMem *mem, NCDValRef *out);
  743. /**
  744. * Function called to resolve a variable within a backend instance.
  745. * The backend instance is in up state, or in up or down state if can_resolve_when_down=1.
  746. * This function must not have any side effects.
  747. *
  748. * @param o state pointer, as in {@link NCDModule_func_new2}
  749. * @param name name of the variable to resolve as an {@link NCDStringIndex} identifier
  750. * @param mem value memory to use
  751. * @param out on success, the backend should initialize the value here
  752. * @return 1 if exists, 0 if not exists. If exists, but out of memory, return 1
  753. * and an invalid value.
  754. */
  755. typedef int (*NCDModule_func_getvar2) (void *o, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out);
  756. /**
  757. * Function called to resolve an object within a backend instance.
  758. * The backend instance is in up state, or in up or down state if can_resolve_when_down=1.
  759. * This function must not have any side effects.
  760. *
  761. * @param o state pointer, as in {@link NCDModule_func_new2}
  762. * @param name name of the object to resolve as an {@link NCDStringIndex} identifier
  763. * @param out_object the object will be returned here
  764. * @return 1 on success, 0 on failure
  765. */
  766. typedef int (*NCDModule_func_getobj) (void *o, NCD_string_id_t name, NCDObject *out_object);
  767. /**
  768. * Handler called when the module instance is in a clean state.
  769. * This means that all statements preceding it in the process are
  770. * up, this statement is down, and all following statements are
  771. * uninitialized. When a backend instance goes down, it is guaranteed,
  772. * as long as it stays down, that either this will be called or
  773. * termination will be requested with {@link NCDModule_func_die}.
  774. * The backend instance was in down state.
  775. *
  776. * @param o state pointer, as in {@link NCDModule_func_new2}
  777. */
  778. typedef void (*NCDModule_func_clean) (void *o);
  779. #define NCDMODULE_FLAG_CAN_RESOLVE_WHEN_DOWN (1 << 0)
  780. /**
  781. * Structure encapsulating the implementation of a module backend.
  782. */
  783. struct NCDModule {
  784. /**
  785. * If this implements a plain statement, the name of the statement.
  786. * If this implements a method, then "base_type::method_name".
  787. */
  788. const char *type;
  789. /**
  790. * The base type for methods operating on instances of this backend.
  791. * Any module with type of form "base_type::method_name" is considered
  792. * a method of instances of this backend.
  793. * If this is NULL, the base type will default to type.
  794. */
  795. const char *base_type;
  796. /**
  797. * Function called to create an new backend instance.
  798. */
  799. NCDModule_func_new2 func_new2;
  800. /**
  801. * Function called to request termination of a backend instance.
  802. * May be NULL, in which case the default is to call NCDModuleInst_Backend_Dead().
  803. */
  804. NCDModule_func_die func_die;
  805. /**
  806. * Function called to resolve a variable within the backend instance.
  807. * May be NULL.
  808. */
  809. NCDModule_func_getvar func_getvar;
  810. /**
  811. * Function called to resolve a variable within the backend instance.
  812. * May be NULL.
  813. */
  814. NCDModule_func_getvar2 func_getvar2;
  815. /**
  816. * Function called to resolve an object within the backend instance.
  817. * May be NULL.
  818. */
  819. NCDModule_func_getobj func_getobj;
  820. /**
  821. * Function called when the backend instance is in a clean state.
  822. * May be NULL.
  823. */
  824. NCDModule_func_clean func_clean;
  825. /**
  826. * Various flags.
  827. *
  828. * - NCDMODULE_FLAG_CAN_RESOLVE_WHEN_DOWN
  829. * Whether the interpreter is allowed to call func_getvar and func_getobj
  830. * even when the backend instance is in down state (as opposed to just
  831. * in up state.
  832. */
  833. int flags;
  834. /**
  835. * The amount of memory to preallocate for each module instance.
  836. * Preallocation can be used to avoid having to allocate memory from
  837. * module initialization. The memory can be accessed via the first
  838. * argument to {@link NCDModule_func_new2} and other calls.
  839. */
  840. int alloc_size;
  841. };
  842. /**
  843. * Structure encapsulating a group of module backend implementations,
  844. * with global init and free functions.
  845. */
  846. struct NCDModuleGroup {
  847. /**
  848. * Function called before any instance of any module backend in this
  849. * group is crated. May be NULL.
  850. */
  851. NCDModule_func_globalinit func_globalinit;
  852. /**
  853. * Function called to clean up after {@link NCDModule_func_globalinit}.
  854. * May be NULL.
  855. */
  856. NCDModule_func_globalfree func_globalfree;
  857. /**
  858. * Array of module backends. The array must be terminated with a
  859. * structure that has a NULL type member.
  860. */
  861. const struct NCDModule *modules;
  862. /**
  863. * A pointer to an array of strings which will be mapped to
  864. * {@link NCDStringIndex} string identifiers for the module to use.
  865. * The array must be terminated by NULL. The resulting string
  866. * identifiers will be available in the 'strings' member in
  867. * {@link NCDInterpModuleGroup}.
  868. */
  869. const char *const*strings;
  870. /**
  871. * A pointer to an array of global functions implemented by this module
  872. * group. The array must be terminated with a structure that has a NULL
  873. * func_name member. May be NULL.
  874. */
  875. struct NCDModuleFunction const *functions;
  876. };
  877. /**
  878. * Represents an {@link NCDModule} within an interpreter.
  879. * This structure is initialized by the interpreter when it loads a module group.
  880. */
  881. struct NCDInterpModule {
  882. /**
  883. * A copy of the original NCDModule structure,
  884. */
  885. struct NCDModule module;
  886. /**
  887. * The string identifier of this module's base_type (or type if base_type is
  888. * not specified) according to {@link NCDStringIndex}.
  889. */
  890. NCD_string_id_t base_type_id;
  891. /**
  892. * A pointer to the {@link NCDInterpModuleGroup} representing the group
  893. * this module belongs to.
  894. */
  895. struct NCDInterpModuleGroup *group;
  896. };
  897. /**
  898. * Represents an {@link NCDModuleGroup} within an interpreter.
  899. * This structure is initialized by the interpreter when it loads a module group.
  900. */
  901. struct NCDInterpModuleGroup {
  902. /**
  903. * A copy of the original NCDModuleGroup structure.
  904. */
  905. struct NCDModuleGroup group;
  906. /**
  907. * An array of string identifiers corresponding to the strings
  908. * in the 'strings' member of NCDModuleGroup. May be NULL if there
  909. * are no strings in the NCDModuleGroup.
  910. */
  911. NCD_string_id_t *strings;
  912. /**
  913. * Pointer which allows the module to keep private interpreter-wide state.
  914. * This can be freely modified by the module; the interpeter will not
  915. * read or write it.
  916. */
  917. void *group_state;
  918. };
  919. /**
  920. * An abstraction of function call evaluations, mutually decoupling the
  921. * interpreter and the function implementations.
  922. *
  923. * The function implementation is given an instance of this structure
  924. * in the evaluation callback (func_eval), and uses it to request
  925. * information and submit results. The function implementation does these
  926. * things by calling the various NCDCall functions with the NCDCall
  927. * instance. Note that function arguments are evaluated on demand from
  928. * the function implementation. This enables behavior such as
  929. * short-circuit evaluation of logical operators.
  930. *
  931. * The NCDCall struct has a value semantic - it can be copied
  932. * around freely by the function implementation during the
  933. * lifetime of the evaluation call.
  934. */
  935. typedef struct {
  936. struct NCDCall_interp_shared const *interp_shared;
  937. void *interp_user;
  938. struct NCDInterpFunction const *interp_function;
  939. size_t arg_count;
  940. NCDValMem *res_mem;
  941. NCDValRef *out_ref;
  942. } NCDCall;
  943. /**
  944. * Used by the intepreter to call a function.
  945. *
  946. * It calls the func_eval callback of the function implementation
  947. * with an appropriately initialized NCDCall value. This is the only
  948. * NCDCall related function used by the interpreter.
  949. *
  950. * As part of the call, callbacks to the interpreter (given in interp_shared)
  951. * may occur. All of these callbacks are passed interp_user as the first
  952. * argument. The callbacks are:
  953. * - logfunc (to log a message),
  954. * - func_eval_arg (to evaluate a particular function argument).
  955. *
  956. * @param interp_shared pointer to things expected to be the same for all
  957. * function calls by the interpreter. This includes interpreter callbacks.
  958. * @param interp_user pointer to be passed through to interpreter callbacks
  959. * @param interp_function the function to call. The evaluation function of
  960. * the function implementation that will be called is taken from here
  961. * (interp_function->function.func_eval), but this is also exposed to the
  962. * function implementation, so it should be initialized appropriately.
  963. * @param arg_count number of arguments passed to the function.
  964. * The function implementation is only permitted to attempt evaluation
  965. * of arguments with indices lesser than arg_count.
  966. * @param res_mem the (initialized) value memory object for the result to
  967. * be stored into. However this may also be used as storage for temporary
  968. * values computed as part of the call.
  969. * @param res_out on success, *res_out will be set to the result of the call
  970. * @return 1 on success, 0 on error
  971. */
  972. int NCDCall_DoIt (
  973. struct NCDCall_interp_shared const *interp_shared, void *interp_user,
  974. struct NCDInterpFunction const *interp_function,
  975. size_t arg_count, NCDValMem *res_mem, NCDValRef *res_out
  976. ) WARN_UNUSED;
  977. /**
  978. * Returns a pointer to the NCDInterpFunction object for the function,
  979. * initialized by the interpreter. This alows, among other things,
  980. * determining which function is being called, and getting the module
  981. * group's private data pointer.
  982. */
  983. struct NCDInterpFunction const * NCDCall_InterpFunction (NCDCall const *o);
  984. /**
  985. * Returns a pointer to an NCDModuleInst_iparams structure, exposing
  986. * services provided by the interpreter.
  987. */
  988. struct NCDModuleInst_iparams const * NCDCall_Iparams (NCDCall const *o);
  989. /**
  990. * Returns the number of arguments for the function call.
  991. */
  992. size_t NCDCall_ArgCount (NCDCall const *o);
  993. /**
  994. * Attempts to evaluate a function argument.
  995. *
  996. * @param index the index of the argument to be evaluated. Must be
  997. * in the range [0, ArgCount).
  998. * @param mem the value memory object for the value to be stored into.
  999. * However temporary value data may also be stored here.
  1000. * @return on success, the value reference to the argument value;
  1001. * on failure, an invalid value reference
  1002. */
  1003. NCDValRef NCDCall_EvalArg (NCDCall const *o, size_t index, NCDValMem *mem);
  1004. /**
  1005. * Returns a pointer to the value memory object that the result
  1006. * of the call should be stored into. The memory object may also
  1007. * be used to store temporary value data.
  1008. */
  1009. NCDValMem * NCDCall_ResMem (NCDCall const *o);
  1010. /**
  1011. * Provides result value of the evaluation to the interpreter.
  1012. * Note that this only stores the result without any immediate
  1013. * action.
  1014. *
  1015. * Passing an invalid value reference indicates failure of the
  1016. * call, though failure is also assumed if this function is
  1017. * not called at all during the call. When a non-invalid
  1018. * value reference is passed (indicating success), it must point
  1019. * to a value stored within the memory object returned by
  1020. * NCDCall_ResMem.
  1021. *
  1022. * @param ref the result value for the call, or an invalid
  1023. * value reference to indicate failure of the call
  1024. */
  1025. void NCDCall_SetResult (NCDCall const *o, NCDValRef ref);
  1026. /**
  1027. * Returns a log context that can be used to log messages
  1028. * associated with the call.
  1029. */
  1030. BLogContext NCDCall_LogContext (NCDCall const *o);
  1031. /**
  1032. * A structure initialized by the interpreter and passed
  1033. * to NCDCall_DoIt for function evaluations.
  1034. * It contains a pointer to things expected to be the same for all
  1035. * function calls by the interpreter, so it can be initialized once
  1036. * and not for every call.
  1037. */
  1038. struct NCDCall_interp_shared {
  1039. /**
  1040. * A callack for log messages originating from the function call.
  1041. * The first argument is the interp_user argument to NCDCall_DoIt.
  1042. */
  1043. BLog_logfunc logfunc;
  1044. /**
  1045. * A callback for evaluating function arguments.
  1046. *
  1047. * @param user interpreter private data (the interp_user argument
  1048. * to NCDCall_DoIt)
  1049. * @param index the index of the argument to be evaluated.
  1050. * This will be in the range [0, arg_count).
  1051. * @param mem the value memory object where the result of the
  1052. * evaluation should be stored. Temporary value data may also
  1053. * be stored here.
  1054. * @param out on success, *out should be set to the value reference
  1055. * to the result of the evaluation. An invalid value reference is
  1056. * permitted, in which case failure is assumed.
  1057. * @return 1 on success (but see above), 0 on failure
  1058. */
  1059. int (*func_eval_arg) (void *user, size_t index, NCDValMem *mem, NCDValRef *out);
  1060. /**
  1061. * A pointer to an NCDModuleInst_iparams structure, exposing
  1062. * services provided by the interpreter.
  1063. */
  1064. struct NCDModuleInst_iparams const *iparams;
  1065. };
  1066. /**
  1067. * This structure is initialized statically by a function
  1068. * implementation to describe the function and provide
  1069. * the resources required for its evaluation by the interpreter.
  1070. *
  1071. * These structures always appear in arrays, pointed to by
  1072. * the functions pointer in the NCDModuleGroup structure.
  1073. */
  1074. struct NCDModuleFunction {
  1075. /**
  1076. * The name of the function.
  1077. * NULL to terminate the array of functions.
  1078. */
  1079. char const *func_name;
  1080. /**
  1081. * Callback for evaluating the function.
  1082. */
  1083. void (*func_eval) (NCDCall call);
  1084. };
  1085. /**
  1086. * Represents an {@link NCDModuleFunction} within an interpreter.
  1087. * This structure is initialized by the interpreter when it loads a module group.
  1088. */
  1089. struct NCDInterpFunction {
  1090. /**
  1091. * A copy of the original NCDModuleFunction structure.
  1092. * We could just use a pointer to the original statically defined structure,
  1093. * but then we wouldn't be annoying the premature-optimization hipsters.
  1094. */
  1095. struct NCDModuleFunction function;
  1096. /**
  1097. * The string identifier of this functions's name. according to
  1098. * {@link NCDStringIndex}.
  1099. */
  1100. NCD_string_id_t func_name_id;
  1101. /**
  1102. * A pointer to the {@link NCDInterpModuleGroup} representing the group
  1103. * this function belongs to.
  1104. */
  1105. struct NCDInterpModuleGroup *group;
  1106. };
  1107. #endif