浏览代码

ncd: NCDModule: add interface for loading modules, currently a stub

ambrop7 13 年之前
父节点
当前提交
808bf4524e
共有 3 个文件被更改,包括 40 次插入0 次删除
  1. 7 0
      ncd/NCDInterpreter.c
  2. 9 0
      ncd/NCDModule.c
  3. 24 0
      ncd/NCDModule.h

+ 7 - 0
ncd/NCDInterpreter.c

@@ -117,6 +117,7 @@ static void statement_instance_logfunc (NCDModuleInst *inst);
 static void statement_instance_func_interp_exit (void *vinterp, int exit_code);
 static int statement_instance_func_interp_getargs (void *vinterp, NCDValMem *mem, NCDValRef *out_value);
 static btime_t statement_instance_func_interp_getretrytime (void *vinterp);
+static int statement_instance_func_interp_loadgroup (void *vinterp, const struct NCDModuleGroup *group);
 static void process_moduleprocess_func_event (struct process *p, int event);
 static int process_moduleprocess_func_getobj (struct process *p, NCD_string_id_t name, NCDObject *out_object);
 
@@ -211,6 +212,7 @@ int NCDInterpreter_Init (NCDInterpreter *o, NCDProgram program, struct NCDInterp
     o->module_iparams.func_interp_exit = statement_instance_func_interp_exit;
     o->module_iparams.func_interp_getargs = statement_instance_func_interp_getargs;
     o->module_iparams.func_interp_getretrytime = statement_instance_func_interp_getretrytime;
+    o->module_iparams.func_loadgroup = statement_instance_func_interp_loadgroup;
     
     // init processes list
     LinkedList1_Init(&o->processes);
@@ -1305,6 +1307,11 @@ btime_t statement_instance_func_interp_getretrytime (void *vinterp)
     return interp->params.retry_time;
 }
 
+int statement_instance_func_interp_loadgroup (void *vinterp, const struct NCDModuleGroup *group)
+{
+    return 0;
+}
+
 void process_moduleprocess_func_event (struct process *p, int event)
 {
     ASSERT(p->module_process)

+ 9 - 0
ncd/NCDModule.c

@@ -356,6 +356,15 @@ btime_t NCDModuleInst_Backend_InterpGetRetryTime (NCDModuleInst *n)
     return n->params->iparams->func_interp_getretrytime(n->params->iparams->user);
 }
 
+int NCDModuleInst_Backend_InterpLoadGroup (NCDModuleInst *n, const struct NCDModuleGroup *group)
+{
+    DebugObject_Access(&n->d_obj);
+    inst_assert_backend(n);
+    ASSERT(group)
+    
+    return n->params->iparams->func_loadgroup(n->params->iparams->user, group);
+}
+
 int NCDModuleProcess_InitId (NCDModuleProcess *o, NCDModuleInst *n, NCD_string_id_t template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event)
 {
     DebugObject_Access(&n->d_obj);

+ 24 - 0
ncd/NCDModule.h

@@ -56,6 +56,7 @@
 
 struct NCDModuleInst_s;
 struct NCDModuleProcess_s;
+struct NCDModuleGroup;
 struct NCDInterpModule;
 struct NCDInterpModuleGroup;
 
@@ -156,6 +157,16 @@ typedef int (*NCDModuleInst_func_interp_getargs) (void *user, NCDValMem *mem, NC
  */
 typedef btime_t (*NCDModuleInst_func_interp_getretrytime) (void *user);
 
+/**
+ * Function called when the module instance wants the interpreter to
+ * load a new module group.
+ * 
+ * @param user value of 'user' member of {@link NCDModuleInst_iparams}
+ * @param group module group to load
+ * @return 1 on success, 0 on failure
+ */
+typedef int (*NCDModuleInst_func_interp_loadgroup) (void *user, const struct NCDModuleGroup *group);
+
 #define NCDMODULEPROCESS_EVENT_UP 1
 #define NCDMODULEPROCESS_EVENT_DOWN 2
 #define NCDMODULEPROCESS_EVENT_TERMINATED 3
@@ -347,6 +358,10 @@ struct NCDModuleInst_iparams {
      * Callback to get retry time.
      */
     NCDModuleInst_func_interp_getretrytime func_interp_getretrytime;
+    /**
+     * Callback to load a module group.
+     */
+    NCDModuleInst_func_interp_loadgroup func_loadgroup;
 };
 
 /**
@@ -585,6 +600,15 @@ int NCDModuleInst_Backend_InterpGetArgs (NCDModuleInst *n, NCDValMem *mem, NCDVa
  */
 btime_t NCDModuleInst_Backend_InterpGetRetryTime (NCDModuleInst *n);
 
+/**
+ * Loads a module group into the interpreter.
+ * 
+ * @param n backend instance handle
+ * @param group module group to load
+ * @return 1 on success, 0 on failure
+ */
+int NCDModuleInst_Backend_InterpLoadGroup (NCDModuleInst *n, const struct NCDModuleGroup *group);
+
 /**
  * Initializes a process in the interpreter from a process template.
  * This must be called on behalf of a module backend instance.