NCDModule.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  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. DebugObject d_obj;
  357. } NCDModuleInst;
  358. /**
  359. * Process created from a process template on behalf of a module backend
  360. * instance, implemented by the interpreter.
  361. */
  362. typedef struct NCDModuleProcess_s {
  363. NCDValRef args;
  364. NCDModuleProcess_handler_event handler_event;
  365. NCDModuleProcess_func_getspecialobj func_getspecialobj;
  366. void *interp_user;
  367. NCDModuleProcess_interp_func_event interp_func_event;
  368. NCDModuleProcess_interp_func_getobj interp_func_getobj;
  369. #ifndef NDEBUG
  370. int state;
  371. #endif
  372. DebugObject d_obj;
  373. } NCDModuleProcess;
  374. /**
  375. * Initializes an instance of an NCD module.
  376. * The instance is initialized in down state.
  377. * WARNING: this directly calls the module backend; expect to be called back
  378. *
  379. * This and other non-Backend methods are the interpreter interface.
  380. * The Backend methods are the module backend interface and are documented
  381. * independently with their own logical states.
  382. *
  383. * NOTE: the instance structure \a n should have the member 'mem' initialized
  384. * to point to preallocated memory for the statement. This memory must be
  385. * at least m->prealloc_size big and must be properly aligned for any object.
  386. * The 'mem' pointer is never modified by NCDModuleInst, so that the interpreter
  387. * can use it as outside the lifetime of NCDModuleInst.
  388. *
  389. * @param n the instance
  390. * @param m pointer to the {@link NCDInterpModule} structure representing the module
  391. * to be instantiated
  392. * @param method_context a context pointer passed to the module backend, applicable to method-like
  393. * statements only. This should be set to the 'user' member of the
  394. * {@link NCDObject} which represents the base object for the method.
  395. * The caller must ensure that the NCDObject that was used is of the type
  396. * expected by the module being instanciated.
  397. * @param args arguments to the module. Must be a list value. Must be available and unchanged
  398. * as long as the instance exists.
  399. * @param user argument to callback functions
  400. * @param params more parameters, see {@link NCDModuleInst_params}
  401. */
  402. void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDInterpModule *m, void *method_context, NCDValRef args, const struct NCDModuleInst_params *params);
  403. /**
  404. * Frees the instance.
  405. * The instance must be in dead state.
  406. *
  407. * @param n the instance
  408. */
  409. void NCDModuleInst_Free (NCDModuleInst *n);
  410. /**
  411. * Requests the instance to die.
  412. * The instance must be in down or up state.
  413. * The instance enters dying state.
  414. * WARNING: this directly calls the module backend; expect to be called back
  415. *
  416. * @param n the instance
  417. */
  418. void NCDModuleInst_Die (NCDModuleInst *n);
  419. /**
  420. * Attempts to destroy the instance immediately.
  421. * This function can be used to optimize destroying instances of modules which
  422. * don't specify any {@link NCDModule_func_die} handler. If immediate destruction
  423. * is not possible, this does nothing and returns 0; {@link NCDModuleInst_Die}
  424. * should be used to destroy the instance instead. If however immediate destruction
  425. * is possible, this destroys the module instance and returns 1; {@link NCDModuleInst_Free}
  426. * must not be called after that.
  427. * The instance must be in down or up state, as for {@link NCDModuleInst_Die}.
  428. *
  429. * @param n the instance
  430. * @return 1 if destruction was performed, 0 if not
  431. */
  432. int NCDModuleInst_TryFree (NCDModuleInst *n);
  433. /**
  434. * Informs the module that it is in a clean state to proceed.
  435. * The instance must be in down state.
  436. * WARNING: this directly calls the module backend; expect to be called back
  437. *
  438. * @param n the instance
  439. */
  440. void NCDModuleInst_Clean (NCDModuleInst *n);
  441. /**
  442. * Returns an {@link NCDObject} which can be used to resolve variables and objects
  443. * within this instance, as well as call its methods. The resulting object may only
  444. * be used immediately, and becomes invalid when the instance is freed.
  445. *
  446. * @param n the instance
  447. * @return an NCDObject for this instance
  448. */
  449. NCDObject NCDModuleInst_Object (NCDModuleInst *n);
  450. /**
  451. * If this is called, any methods called on this object will receive the preallocated
  452. * memory pointer as the object state pointer. This means that in the
  453. * {@link NCDModule_func_getvar2} function which is called when a method is created,
  454. * the preallocated memory should be accessed as params->method_user.
  455. * By default, however, params->method_user points to the NCDModuleInst of the base
  456. * object, and {@link NCDModuleInst_Backend_GetUser} is needed to retrieve the
  457. * preallocated memory pointer.
  458. */
  459. void NCDModuleInst_Backend_PassMemToMethods (NCDModuleInst *n);
  460. /**
  461. * Retuns the state pointer passed to handlers of a module backend instance;
  462. * see {@link NCDModule_func_new2}.
  463. *
  464. * @param n backend instance handle
  465. * @return argument passed to handlers
  466. */
  467. void * NCDModuleInst_Backend_GetUser (NCDModuleInst *n);
  468. /**
  469. * Puts the backend instance into up state.
  470. * The instance must be in down state.
  471. * The instance enters up state.
  472. *
  473. * @param n backend instance handle
  474. */
  475. void NCDModuleInst_Backend_Up (NCDModuleInst *n);
  476. /**
  477. * Puts the backend instance into down state.
  478. * The instance must be in up state.
  479. * The instance enters down state.
  480. *
  481. * @param n backend instance handle
  482. */
  483. void NCDModuleInst_Backend_Down (NCDModuleInst *n);
  484. /**
  485. * Puts the backend instance into down state, then immediatly back into the up state.
  486. * This effectively causes the interpreter to start backtracking to this statement.
  487. * The instance must be in up state, and remains in up state.
  488. *
  489. * @param n backend instance handle
  490. */
  491. void NCDModuleInst_Backend_DownUp (NCDModuleInst *n);
  492. /**
  493. * Destroys the backend instance.
  494. * The backend instance handle becomes invalid and must not be used from
  495. * the backend any longer.
  496. *
  497. * @param n backend instance handle
  498. */
  499. void NCDModuleInst_Backend_Dead (NCDModuleInst *n);
  500. /**
  501. * Like {@link NCDModuleInst_Backend_Dead}, but also reports an error condition
  502. * to the interpreter.
  503. */
  504. void NCDModuleInst_Backend_DeadError (NCDModuleInst *n);
  505. /**
  506. * Resolves an object for a backend instance, from the point of the instance's
  507. * statement in the containing process.
  508. *
  509. * @param n backend instance handle
  510. * @param name name of the object to resolve as an {@link NCDStringIndex} identifier
  511. * @param out_object the object will be returned here
  512. * @return 1 on success, 0 on failure
  513. */
  514. int NCDModuleInst_Backend_GetObj (NCDModuleInst *n, NCD_string_id_t name, NCDObject *out_object) WARN_UNUSED;
  515. /**
  516. * Logs a backend instance message.
  517. *
  518. * @param n backend instance handle
  519. * @param channel log channel
  520. * @param level loglevel
  521. * @param fmt format string as in printf, arguments follow
  522. */
  523. void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const char *fmt, ...);
  524. /**
  525. * Like {@link NCDModuleInst_Backend_Log}, but the extra arguments are passed
  526. * as a va_list. This allows creation of logging wrappers.
  527. */
  528. void NCDModuleInst_Backend_LogVarArg (NCDModuleInst *n, int channel, int level, const char *fmt, va_list vl);
  529. /**
  530. * Returns a logging context. The context is valid until the backend dies.
  531. */
  532. BLogContext NCDModuleInst_Backend_LogContext (NCDModuleInst *n);
  533. /**
  534. * Initiates interpreter termination.
  535. *
  536. * @param n backend instance handle
  537. * @param exit_code exit code to return to the operating system. This overrides
  538. * any previously set exit code, and will be overriden by a
  539. * termination signal to the value 1.
  540. */
  541. void NCDModuleInst_Backend_InterpExit (NCDModuleInst *n, int exit_code);
  542. /**
  543. * Retrieves extra command line arguments passed to the interpreter.
  544. *
  545. * @param n backend instance handle
  546. * @param mem value memory to use
  547. * @param out_value the arguments will be written here on success as a list value
  548. * @return 1 if available, 0 if not available. If available, but out of memory, returns 1
  549. * and an invalid value.
  550. */
  551. int NCDModuleInst_Backend_InterpGetArgs (NCDModuleInst *n, NCDValMem *mem, NCDValRef *out_value);
  552. /**
  553. * Returns the retry time of the intepreter.
  554. *
  555. * @param n backend instance handle
  556. * @return retry time in milliseconds
  557. */
  558. btime_t NCDModuleInst_Backend_InterpGetRetryTime (NCDModuleInst *n);
  559. /**
  560. * Loads a module group into the interpreter.
  561. *
  562. * @param n backend instance handle
  563. * @param group module group to load
  564. * @return 1 on success, 0 on failure
  565. */
  566. int NCDModuleInst_Backend_InterpLoadGroup (NCDModuleInst *n, const struct NCDModuleGroup *group);
  567. /**
  568. * Initializes a process in the interpreter from a process template.
  569. * This must be called on behalf of a module backend instance.
  570. * The process is initializes in down state.
  571. *
  572. * @param o the process
  573. * @param n backend instance whose interpreter will be providing the process
  574. * @param template_name name of the process template as an {@link NCDStringIndex} identifier
  575. * @param args arguments to the process. Must be an invalid value or a list value.
  576. * The value must be available and unchanged while the process exists.
  577. * @param handler_event handler which reports events about the process from the
  578. * interpreter
  579. * @return 1 on success, 0 on failure
  580. */
  581. int NCDModuleProcess_InitId (NCDModuleProcess *o, NCDModuleInst *n, NCD_string_id_t template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event) WARN_UNUSED;
  582. /**
  583. * Wrapper around {@link NCDModuleProcess_InitId} which takes the template name as an
  584. * {@link NCDValRef}, which must point to a string value.
  585. */
  586. int NCDModuleProcess_InitValue (NCDModuleProcess *o, NCDModuleInst *n, NCDValRef template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event) WARN_UNUSED;
  587. /**
  588. * Frees the process.
  589. * The process must be in terminated state.
  590. *
  591. * @param o the process
  592. */
  593. void NCDModuleProcess_Free (NCDModuleProcess *o);
  594. /**
  595. * Does nothing.
  596. * The process must be in terminated state.
  597. *
  598. * @param o the process
  599. */
  600. void NCDModuleProcess_AssertFree (NCDModuleProcess *o);
  601. /**
  602. * Sets callback functions for providing special objects within the process.
  603. *
  604. * @param o the process
  605. * @param func_getspecialobj function for resolving special objects, or NULL
  606. */
  607. void NCDModuleProcess_SetSpecialFuncs (NCDModuleProcess *o, NCDModuleProcess_func_getspecialobj func_getspecialobj);
  608. /**
  609. * Continues the process after the process went down.
  610. * The process must be in waiting state.
  611. * The process enters down state.
  612. *
  613. * @param o the process
  614. */
  615. void NCDModuleProcess_Continue (NCDModuleProcess *o);
  616. /**
  617. * Requests the process to terminate.
  618. * The process must be in down, up or waiting state.
  619. * The process enters terminating state.
  620. *
  621. * @param o the process
  622. */
  623. void NCDModuleProcess_Terminate (NCDModuleProcess *o);
  624. /**
  625. * Resolves an object within the process from the point
  626. * at the end of the process.
  627. * This function has no side effects.
  628. *
  629. * @param o the process
  630. * @param name name of the object to resolve as an {@link NCDStringIndex} identifier
  631. * @param out_object the object will be returned here
  632. * @return 1 on success, 0 on failure
  633. */
  634. int NCDModuleProcess_GetObj (NCDModuleProcess *o, NCD_string_id_t name, NCDObject *out_object) WARN_UNUSED;
  635. /**
  636. * Sets callback functions for the interpreter to implement the
  637. * process backend.
  638. * Must be called from within {@link NCDModuleInst_func_initprocess}
  639. * if success is to be reported there.
  640. *
  641. * @param o process backend handle, as in {@link NCDModuleInst_func_initprocess}
  642. * @param interp_user argument to callback functions
  643. * @param interp_func_event function for reporting continue/terminate requests
  644. * @param interp_func_getobj function for resolving objects within the process
  645. */
  646. void NCDModuleProcess_Interp_SetHandlers (NCDModuleProcess *o, void *interp_user,
  647. NCDModuleProcess_interp_func_event interp_func_event,
  648. NCDModuleProcess_interp_func_getobj interp_func_getobj);
  649. /**
  650. * Reports the process backend as up.
  651. * The process backend must be in down state.
  652. * The process backend enters up state.
  653. * WARNING: this directly calls the process creator; expect to be called back
  654. *
  655. * @param o process backend handle
  656. */
  657. void NCDModuleProcess_Interp_Up (NCDModuleProcess *o);
  658. /**
  659. * Reports the process backend as down.
  660. * The process backend must be in up state.
  661. * The process backend enters waiting state.
  662. * WARNING: this directly calls the process creator; expect to be called back
  663. *
  664. * NOTE: the backend enters waiting state, NOT down state. The interpreter should
  665. * pause the process until {@link NCDModuleProcess_interp_func_event} reports
  666. * NCDMODULEPROCESS_INTERP_EVENT_CONTINUE, unless termination is requested via
  667. * NCDMODULEPROCESS_INTERP_EVENT_TERMINATE.
  668. *
  669. * @param o process backend handle
  670. */
  671. void NCDModuleProcess_Interp_Down (NCDModuleProcess *o);
  672. /**
  673. * Reports termination of the process backend.
  674. * The process backend must be in terminating state.
  675. * The process backend handle becomes invalid and must not be used
  676. * by the interpreter any longer.
  677. * WARNING: this directly calls the process creator; expect to be called back
  678. *
  679. * @param o process backend handle
  680. */
  681. void NCDModuleProcess_Interp_Terminated (NCDModuleProcess *o);
  682. /**
  683. * Resolves a special process object for the process backend.
  684. *
  685. * @param o process backend handle
  686. * @param name name of the object as an {@link NCDStringIndex} identifier
  687. * @param out_object the object will be returned here
  688. * @return 1 on success, 0 on failure
  689. */
  690. int NCDModuleProcess_Interp_GetSpecialObj (NCDModuleProcess *o, NCD_string_id_t name, NCDObject *out_object) WARN_UNUSED;
  691. /**
  692. * Function called before any instance of any backend in a module
  693. * group is created;
  694. *
  695. * @param params structure containing global resources, such as
  696. * {@link BReactor}, {@link BProcessManager} and {@link NCDUdevManager}.
  697. * @return 1 on success, 0 on failure
  698. */
  699. typedef int (*NCDModule_func_globalinit) (struct NCDInterpModuleGroup *group, const struct NCDModuleInst_iparams *params);
  700. /**
  701. * Function called to clean up after {@link NCDModule_func_globalinit} and modules
  702. * in a module group.
  703. * There are no backend instances alive from this module group.
  704. */
  705. typedef void (*NCDModule_func_globalfree) (struct NCDInterpModuleGroup *group);
  706. /**
  707. * Handler called to create an new module backend instance.
  708. * The backend is initialized in down state.
  709. *
  710. * If the backend fails initialization, this function should report the backend
  711. * instance to have died with error by calling {@link NCDModuleInst_Backend_DeadError}.
  712. *
  713. * @param o if the module specifies a positive alloc_size value in the {@link NCDModule}
  714. * structure, this will point to the allocated memory that can be used by the
  715. * module instance while it exists. If the alloc_size is 0 (default), this may or
  716. * may not be NULL.
  717. * @param i module backend instance handler. The backend may only use this handle via
  718. * the Backend functions of {@link NCDModuleInst}.
  719. */
  720. typedef void (*NCDModule_func_new2) (void *o, NCDModuleInst *i, const struct NCDModuleInst_new_params *params);
  721. /**
  722. * Handler called to request termination of a backend instance.
  723. * The backend instance was in down or up state.
  724. * The backend instance enters dying state.
  725. *
  726. * @param o state pointer, as in {@link NCDModule_func_new2}
  727. */
  728. typedef void (*NCDModule_func_die) (void *o);
  729. /**
  730. * Function called to resolve a variable within a backend instance.
  731. * The backend instance is in up state, or in up or down state if can_resolve_when_down=1.
  732. * This function must not have any side effects.
  733. *
  734. * @param o state pointer, as in {@link NCDModule_func_new2}
  735. * @param name name of the variable to resolve
  736. * @param mem value memory to use
  737. * @param out on success, the backend should initialize the value here
  738. * @return 1 if exists, 0 if not exists. If exists, but out of memory, return 1
  739. * and an invalid value.
  740. */
  741. typedef int (*NCDModule_func_getvar) (void *o, const char *name, NCDValMem *mem, NCDValRef *out);
  742. /**
  743. * Function called to resolve a variable within a backend instance.
  744. * The backend instance is in up state, or in up or down state if can_resolve_when_down=1.
  745. * This function must not have any side effects.
  746. *
  747. * @param o state pointer, as in {@link NCDModule_func_new2}
  748. * @param name name of the variable to resolve as an {@link NCDStringIndex} identifier
  749. * @param mem value memory to use
  750. * @param out on success, the backend should initialize the value here
  751. * @return 1 if exists, 0 if not exists. If exists, but out of memory, return 1
  752. * and an invalid value.
  753. */
  754. typedef int (*NCDModule_func_getvar2) (void *o, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out);
  755. /**
  756. * Function called to resolve an object within a backend instance.
  757. * The backend instance is in up state, or in up or down state if can_resolve_when_down=1.
  758. * This function must not have any side effects.
  759. *
  760. * @param o state pointer, as in {@link NCDModule_func_new2}
  761. * @param name name of the object to resolve as an {@link NCDStringIndex} identifier
  762. * @param out_object the object will be returned here
  763. * @return 1 on success, 0 on failure
  764. */
  765. typedef int (*NCDModule_func_getobj) (void *o, NCD_string_id_t name, NCDObject *out_object);
  766. /**
  767. * Handler called when the module instance is in a clean state.
  768. * This means that all statements preceding it in the process are
  769. * up, this statement is down, and all following statements are
  770. * uninitialized. When a backend instance goes down, it is guaranteed,
  771. * as long as it stays down, that either this will be called or
  772. * termination will be requested with {@link NCDModule_func_die}.
  773. * The backend instance was in down state.
  774. *
  775. * @param o state pointer, as in {@link NCDModule_func_new2}
  776. */
  777. typedef void (*NCDModule_func_clean) (void *o);
  778. #define NCDMODULE_FLAG_CAN_RESOLVE_WHEN_DOWN (1 << 0)
  779. /**
  780. * Structure encapsulating the implementation of a module backend.
  781. */
  782. struct NCDModule {
  783. /**
  784. * If this implements a plain statement, the name of the statement.
  785. * If this implements a method, then "base_type::method_name".
  786. */
  787. const char *type;
  788. /**
  789. * The base type for methods operating on instances of this backend.
  790. * Any module with type of form "base_type::method_name" is considered
  791. * a method of instances of this backend.
  792. * If this is NULL, the base type will default to type.
  793. */
  794. const char *base_type;
  795. /**
  796. * Function called to create an new backend instance.
  797. */
  798. NCDModule_func_new2 func_new2;
  799. /**
  800. * Function called to request termination of a backend instance.
  801. * May be NULL, in which case the default is to call NCDModuleInst_Backend_Dead().
  802. */
  803. NCDModule_func_die func_die;
  804. /**
  805. * Function called to resolve a variable within the backend instance.
  806. * May be NULL.
  807. */
  808. NCDModule_func_getvar func_getvar;
  809. /**
  810. * Function called to resolve a variable within the backend instance.
  811. * May be NULL.
  812. */
  813. NCDModule_func_getvar2 func_getvar2;
  814. /**
  815. * Function called to resolve an object within the backend instance.
  816. * May be NULL.
  817. */
  818. NCDModule_func_getobj func_getobj;
  819. /**
  820. * Function called when the backend instance is in a clean state.
  821. * May be NULL.
  822. */
  823. NCDModule_func_clean func_clean;
  824. /**
  825. * Various flags.
  826. *
  827. * - NCDMODULE_FLAG_CAN_RESOLVE_WHEN_DOWN
  828. * Whether the interpreter is allowed to call func_getvar and func_getobj
  829. * even when the backend instance is in down state (as opposed to just
  830. * in up state.
  831. */
  832. int flags;
  833. /**
  834. * The amount of memory to preallocate for each module instance.
  835. * Preallocation can be used to avoid having to allocate memory from
  836. * module initialization. The memory can be accessed via the first
  837. * argument to {@link NCDModule_func_new2} and other calls.
  838. */
  839. int alloc_size;
  840. };
  841. /**
  842. * Structure encapsulating a group of module backend implementations,
  843. * with global init and free functions.
  844. */
  845. struct NCDModuleGroup {
  846. /**
  847. * Function called before any instance of any module backend in this
  848. * group is crated. May be NULL.
  849. */
  850. NCDModule_func_globalinit func_globalinit;
  851. /**
  852. * Function called to clean up after {@link NCDModule_func_globalinit}.
  853. * May be NULL.
  854. */
  855. NCDModule_func_globalfree func_globalfree;
  856. /**
  857. * Array of module backends. The array must be terminated with a
  858. * structure that has a NULL type member.
  859. */
  860. const struct NCDModule *modules;
  861. /**
  862. * A pointer to an array of strings which will be mapped to
  863. * {@link NCDStringIndex} string identifiers for the module to use.
  864. * The array must be terminated by NULL. The resulting string
  865. * identifiers will be available in the 'strings' member in
  866. * {@link NCDInterpModuleGroup}.
  867. */
  868. const char *const*strings;
  869. /**
  870. * A pointer to an array of global functions implemented by this module
  871. * group. The array must be terminated with a structure that has a NULL
  872. * func_name member. May be NULL.
  873. */
  874. struct NCDModuleFunction const *functions;
  875. };
  876. /**
  877. * Represents an {@link NCDModule} within an interpreter.
  878. * This structure is initialized by the interpreter when it loads a module group.
  879. */
  880. struct NCDInterpModule {
  881. /**
  882. * A copy of the original NCDModule structure,
  883. */
  884. struct NCDModule module;
  885. /**
  886. * The string identifier of this module's base_type (or type if base_type is
  887. * not specified) according to {@link NCDStringIndex}.
  888. */
  889. NCD_string_id_t base_type_id;
  890. /**
  891. * A pointer to the {@link NCDInterpModuleGroup} representing the group
  892. * this module belongs to.
  893. */
  894. struct NCDInterpModuleGroup *group;
  895. };
  896. /**
  897. * Represents an {@link NCDModuleGroup} within an interpreter.
  898. * This structure is initialized by the interpreter when it loads a module group.
  899. */
  900. struct NCDInterpModuleGroup {
  901. /**
  902. * A copy of the original NCDModuleGroup structure.
  903. */
  904. struct NCDModuleGroup group;
  905. /**
  906. * An array of string identifiers corresponding to the strings
  907. * in the 'strings' member of NCDModuleGroup. May be NULL if there
  908. * are no strings in the NCDModuleGroup.
  909. */
  910. NCD_string_id_t *strings;
  911. /**
  912. * Pointer which allows the module to keep private interpreter-wide state.
  913. * This can be freely modified by the module; the interpeter will not
  914. * read or write it.
  915. */
  916. void *group_state;
  917. };
  918. /**
  919. * An abstraction of function call evaluations, mutually decoupling the
  920. * interpreter and the function implementations.
  921. *
  922. * The function implementation is given an instance of this structure
  923. * in the evaluation callback (func_eval), and uses it to request
  924. * information and submit results. The function implementation does these
  925. * things by calling the various NCDCall functions with the NCDCall
  926. * instance. Note that function arguments are evaluated on demand from
  927. * the function implementation. This enables behavior such as
  928. * short-circuit evaluation of logical operators.
  929. *
  930. * The NCDCall struct has a value semantic - it can be copied
  931. * around freely by the function implementation during the
  932. * lifetime of the evaluation call.
  933. */
  934. typedef struct {
  935. struct NCDCall_interp_shared const *interp_shared;
  936. void *interp_user;
  937. struct NCDInterpFunction const *interp_function;
  938. size_t arg_count;
  939. NCDValMem *res_mem;
  940. NCDValRef *out_ref;
  941. } NCDCall;
  942. /**
  943. * Used by the intepreter to call a function.
  944. *
  945. * It calls the func_eval callback of the function implementation
  946. * with an appropriately initialized NCDCall value. This is the only
  947. * NCDCall related function used by the interpreter.
  948. *
  949. * As part of the call, callbacks to the interpreter (given in interp_shared)
  950. * may occur. All of these callbacks are passed interp_user as the first
  951. * argument. The callbacks are:
  952. * - logfunc (to log a message),
  953. * - func_eval_arg (to evaluate a particular function argument).
  954. *
  955. * @param interp_shared pointer to things expected to be the same for all
  956. * function calls by the interpreter. This includes interpreter callbacks.
  957. * @param interp_user pointer to be passed through to interpreter callbacks
  958. * @param interp_function the function to call. The evaluation function of
  959. * the function implementation that will be called is taken from here
  960. * (interp_function->function.func_eval), but this is also exposed to the
  961. * function implementation, so it should be initialized appropriately.
  962. * @param arg_count number of arguments passed to the function.
  963. * The function implementation is only permitted to attempt evaluation
  964. * of arguments with indices lesser than arg_count.
  965. * @param res_mem the (initialized) value memory object for the result to
  966. * be stored into. However this may also be used as storage for temporary
  967. * values computed as part of the call.
  968. * @param res_out on success, *res_out will be set to the result of the call
  969. * @return 1 on success, 0 on error
  970. */
  971. int NCDCall_DoIt (
  972. struct NCDCall_interp_shared const *interp_shared, void *interp_user,
  973. struct NCDInterpFunction const *interp_function,
  974. size_t arg_count, NCDValMem *res_mem, NCDValRef *res_out
  975. ) WARN_UNUSED;
  976. /**
  977. * Returns a pointer to the NCDInterpFunction object for the function,
  978. * initialized by the interpreter. This alows, among other things,
  979. * determining which function is being called, and getting the module
  980. * group's private data pointer.
  981. */
  982. struct NCDInterpFunction const * NCDCall_InterpFunction (NCDCall const *o);
  983. /**
  984. * Returns a pointer to an NCDModuleInst_iparams structure, exposing
  985. * services provided by the interpreter.
  986. */
  987. struct NCDModuleInst_iparams const * NCDCall_Iparams (NCDCall const *o);
  988. /**
  989. * Returns the number of arguments for the function call.
  990. */
  991. size_t NCDCall_ArgCount (NCDCall const *o);
  992. /**
  993. * Attempts to evaluate a function argument.
  994. *
  995. * @param index the index of the argument to be evaluated. Must be
  996. * in the range [0, ArgCount).
  997. * @param mem the value memory object for the value to be stored into.
  998. * However temporary value data may also be stored here.
  999. * @return on success, the value reference to the argument value;
  1000. * on failure, an invalid value reference
  1001. */
  1002. NCDValRef NCDCall_EvalArg (NCDCall const *o, size_t index, NCDValMem *mem);
  1003. /**
  1004. * Returns a pointer to the value memory object that the result
  1005. * of the call should be stored into. The memory object may also
  1006. * be used to store temporary value data.
  1007. */
  1008. NCDValMem * NCDCall_ResMem (NCDCall const *o);
  1009. /**
  1010. * Provides result value of the evaluation to the interpreter.
  1011. * Note that this only stores the result without any immediate
  1012. * action.
  1013. *
  1014. * Passing an invalid value reference indicates failure of the
  1015. * call, though failure is also assumed if this function is
  1016. * not called at all during the call. When a non-invalid
  1017. * value reference is passed (indicating success), it must point
  1018. * to a value stored within the memory object returned by
  1019. * NCDCall_ResMem.
  1020. *
  1021. * @param ref the result value for the call, or an invalid
  1022. * value reference to indicate failure of the call
  1023. */
  1024. void NCDCall_SetResult (NCDCall const *o, NCDValRef ref);
  1025. /**
  1026. * Returns a log context that can be used to log messages
  1027. * associated with the call.
  1028. */
  1029. BLogContext NCDCall_LogContext (NCDCall const *o);
  1030. /**
  1031. * A structure initialized by the interpreter and passed
  1032. * to NCDCall_DoIt for function evaluations.
  1033. * It contains a pointer to things expected to be the same for all
  1034. * function calls by the interpreter, so it can be initialized once
  1035. * and not for every call.
  1036. */
  1037. struct NCDCall_interp_shared {
  1038. /**
  1039. * A callack for log messages originating from the function call.
  1040. * The first argument is the interp_user argument to NCDCall_DoIt.
  1041. */
  1042. BLog_logfunc logfunc;
  1043. /**
  1044. * A callback for evaluating function arguments.
  1045. *
  1046. * @param user interpreter private data (the interp_user argument
  1047. * to NCDCall_DoIt)
  1048. * @param index the index of the argument to be evaluated.
  1049. * This will be in the range [0, arg_count).
  1050. * @param mem the value memory object where the result of the
  1051. * evaluation should be stored. Temporary value data may also
  1052. * be stored here.
  1053. * @param out on success, *out should be set to the value reference
  1054. * to the result of the evaluation. An invalid value reference is
  1055. * permitted, in which case failure is assumed.
  1056. * @return 1 on success (but see above), 0 on failure
  1057. */
  1058. int (*func_eval_arg) (void *user, size_t index, NCDValMem *mem, NCDValRef *out);
  1059. /**
  1060. * A pointer to an NCDModuleInst_iparams structure, exposing
  1061. * services provided by the interpreter.
  1062. */
  1063. struct NCDModuleInst_iparams const *iparams;
  1064. };
  1065. /**
  1066. * This structure is initialized statically by a function
  1067. * implementation to describe the function and provide
  1068. * the resources required for its evaluation by the interpreter.
  1069. *
  1070. * These structures always appear in arrays, pointed to by
  1071. * the functions pointer in the NCDModuleGroup structure.
  1072. */
  1073. struct NCDModuleFunction {
  1074. /**
  1075. * The name of the function.
  1076. * NULL to terminate the array of functions.
  1077. */
  1078. char const *func_name;
  1079. /**
  1080. * Callback for evaluating the function.
  1081. */
  1082. void (*func_eval) (NCDCall call);
  1083. };
  1084. /**
  1085. * Represents an {@link NCDModuleFunction} within an interpreter.
  1086. * This structure is initialized by the interpreter when it loads a module group.
  1087. */
  1088. struct NCDInterpFunction {
  1089. /**
  1090. * A copy of the original NCDModuleFunction structure.
  1091. * We could just use a pointer to the original statically defined structure,
  1092. * but then we wouldn't be annoying the premature-optimization hipsters.
  1093. */
  1094. struct NCDModuleFunction function;
  1095. /**
  1096. * The string identifier of this functions's name. according to
  1097. * {@link NCDStringIndex}.
  1098. */
  1099. NCD_string_id_t func_name_id;
  1100. /**
  1101. * A pointer to the {@link NCDInterpModuleGroup} representing the group
  1102. * this function belongs to.
  1103. */
  1104. struct NCDInterpModuleGroup *group;
  1105. };
  1106. #endif