Bläddra i källkod

ncd: NCDModule: move some parameters into NCDModuleInst_iparams

ambrop7 14 år sedan
förälder
incheckning
d900614b60

+ 14 - 10
ncd/NCDModule.c

@@ -163,7 +163,7 @@ static void inst_assert_backend (NCDModuleInst *n)
            n->state == STATE_DYING)
 }
 
-void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValue *args, void *user, const struct NCDModuleInst_params *params)
+void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValue *args, void *user, const struct NCDModuleInst_params *params, const struct NCDModuleInst_iparams *iparams)
 {
     ASSERT(m)
     ASSERT(args)
@@ -171,8 +171,11 @@ void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDO
     ASSERT(params)
     ASSERT(params->func_event)
     ASSERT(params->func_getobj)
-    ASSERT(params->func_initprocess)
     ASSERT(params->logfunc)
+    ASSERT(iparams)
+    ASSERT(iparams->func_initprocess)
+    ASSERT(iparams->func_interp_exit)
+    ASSERT(iparams->func_interp_getargs)
     
     // init arguments
     n->m = m;
@@ -180,12 +183,13 @@ void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDO
     n->args = args;
     n->user = user;
     n->params = params;
+    n->iparams = iparams;
     
     // init jobs
-    BPending_Init(&n->init_job, BReactor_PendingGroup(params->reactor), (BPending_handler)init_job_handler, n);
-    BPending_Init(&n->uninit_job, BReactor_PendingGroup(params->reactor), (BPending_handler)uninit_job_handler, n);
-    BPending_Init(&n->die_job, BReactor_PendingGroup(params->reactor), (BPending_handler)die_job_handler, n);
-    BPending_Init(&n->clean_job, BReactor_PendingGroup(params->reactor), (BPending_handler)clean_job_handler, n);
+    BPending_Init(&n->init_job, BReactor_PendingGroup(iparams->reactor), (BPending_handler)init_job_handler, n);
+    BPending_Init(&n->uninit_job, BReactor_PendingGroup(iparams->reactor), (BPending_handler)uninit_job_handler, n);
+    BPending_Init(&n->die_job, BReactor_PendingGroup(iparams->reactor), (BPending_handler)die_job_handler, n);
+    BPending_Init(&n->clean_job, BReactor_PendingGroup(iparams->reactor), (BPending_handler)clean_job_handler, n);
     
     // set initial state
     n->state = STATE_INIT;
@@ -458,7 +462,7 @@ void NCDModuleInst_Backend_InterpExit (NCDModuleInst *n, int exit_code)
     DebugObject_Access(&n->d_obj);
     inst_assert_backend(n);
     
-    n->params->func_interp_exit(n->user, exit_code);
+    n->iparams->func_interp_exit(n->user, exit_code);
 }
 
 int NCDModuleInst_Backend_InterpGetArgs (NCDModuleInst *n, NCDValue *out_value)
@@ -467,7 +471,7 @@ int NCDModuleInst_Backend_InterpGetArgs (NCDModuleInst *n, NCDValue *out_value)
     inst_assert_backend(n);
     ASSERT(out_value)
     
-    int res = n->params->func_interp_getargs(n->user, out_value);
+    int res = n->iparams->func_interp_getargs(n->user, out_value);
     ASSERT(res == 0 || res == 1)
     ASSERT(!res || (NCDValue_Type(out_value), 1))
     
@@ -493,7 +497,7 @@ int NCDModuleProcess_Init (NCDModuleProcess *o, NCDModuleInst *n, const char *te
     o->func_getspecialobj = NULL;
     
     // init event job
-    BPending_Init(&o->event_job, BReactor_PendingGroup(n->params->reactor), (BPending_handler)process_event_job_handler, o);
+    BPending_Init(&o->event_job, BReactor_PendingGroup(n->iparams->reactor), (BPending_handler)process_event_job_handler, o);
     
     // set state
     o->state = PROCESS_STATE_INIT;
@@ -503,7 +507,7 @@ int NCDModuleProcess_Init (NCDModuleProcess *o, NCDModuleInst *n, const char *te
     o->interp_func_getobj = NULL;
     
     // init interpreter part
-    if (!(n->params->func_initprocess(n->user, o, template_name))) {
+    if (!(n->iparams->func_initprocess(n->user, o, template_name))) {
         goto fail1;
     }
     

+ 25 - 16
ncd/NCDModule.h

@@ -221,8 +221,29 @@ struct NCDModuleInitParams {
 
 /**
  * Contains parameters to {@link NCDModuleInst_Init} that are passed indirectly.
+ * This only contains parameters related to communication between the backend
+ * and the creator of the module instance.
  */
 struct NCDModuleInst_params {
+    /**
+     * Callback to report state changes.
+     */
+    NCDModuleInst_func_event func_event;
+    /**
+     * Callback to resolve objects from the viewpoint of the instance.
+     */
+    NCDModuleInst_func_getobj func_getobj;
+    /**
+     * Log function which appends a log prefix with {@link BLog_Append}.
+     */
+    BLog_logfunc logfunc;
+};
+
+/**
+ * Contains parameters to {@link NCDModuleInst_Init} that are passed indirectly.
+ * This only contains parameters related to services provided by the interpreter.
+ */
+struct NCDModuleInst_iparams {
     /**
      * Reactor we live in.
      */
@@ -235,22 +256,10 @@ struct NCDModuleInst_params {
      * Udev manager.
      */
     NCDUdevManager *umanager;
-    /**
-     * Callback to report state changes.
-     */
-    NCDModuleInst_func_event func_event;
-    /**
-     * Callback to resolve objects from the viewpoint of the instance.
-     */
-    NCDModuleInst_func_getobj func_getobj;
     /**
      * Callback to create a new template process.
      */
     NCDModuleInst_func_initprocess func_initprocess;
-    /**
-     * Log function which appends a log prefix with {@link BLog_Append}.
-     */
-    BLog_logfunc logfunc;
     /**
      * Callback to request interpreter termination.
      */
@@ -273,6 +282,7 @@ typedef struct NCDModuleInst_s {
     NCDValue *args;
     void *user;
     const struct NCDModuleInst_params *params;
+    const struct NCDModuleInst_iparams *iparams;
     BPending init_job;
     BPending uninit_job;
     BPending die_job;
@@ -316,11 +326,10 @@ typedef struct NCDModuleProcess_s {
  * @param args arguments to the module. Must be a NCDVALUE_LIST value. Must be available as long as
  *             the instance is freed.
  * @param user argument to callback functions
- * @param params remaining parameters, see {@link NCDModuleInst_params}. These are passed indirectly
- *               because they are usually always the same, to reduce memory usage, and the number of
- *               arguments to this function.
+ * @param params more parameters, see {@link NCDModuleInst_params}
+ * @param iparams more parameters, see {@link NCDModuleInst_iparams}
  */
-void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValue *args, void *user, const struct NCDModuleInst_params *params);
+void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValue *args, void *user, const struct NCDModuleInst_params *params, const struct NCDModuleInst_iparams *iparams);
 
 /**
  * Frees the instance.

+ 2 - 2
ncd/modules/command_template.c

@@ -51,7 +51,7 @@ static void lock_handler (command_template_instance *o)
     
     if (o->state == STATE_ADDING_LOCK) {
         // start process
-        if (!BProcess_Init(&o->process, o->i->params->manager, (BProcess_handler)process_handler, o, o->do_exec, CmdLine_Get(&o->do_cmdline), NULL)) {
+        if (!BProcess_Init(&o->process, o->i->iparams->manager, (BProcess_handler)process_handler, o, o->do_exec, CmdLine_Get(&o->do_cmdline), NULL)) {
             NCDModuleInst_Backend_Log(o->i, o->blog_channel, BLOG_ERROR, "BProcess_Init failed");
             free_template(o, 1);
             return;
@@ -64,7 +64,7 @@ static void lock_handler (command_template_instance *o)
         o->state = STATE_ADDING;
     } else {
         // start process
-        if (!BProcess_Init(&o->process, o->i->params->manager, (BProcess_handler)process_handler, o, o->undo_exec, CmdLine_Get(&o->undo_cmdline), NULL)) {
+        if (!BProcess_Init(&o->process, o->i->iparams->manager, (BProcess_handler)process_handler, o, o->undo_exec, CmdLine_Get(&o->undo_cmdline), NULL)) {
             NCDModuleInst_Backend_Log(o->i, o->blog_channel, BLOG_ERROR, "BProcess_Init failed");
             free_template(o, 1);
             return;

+ 4 - 4
ncd/modules/daemon.c

@@ -147,7 +147,7 @@ static void start_process (struct instance *o)
     }
     
     // start process
-    int res = BProcess_Init(&o->process, o->i->params->manager, (BProcess_handler)process_handler, o, exec, CmdLine_Get(&cl), NULL);
+    int res = BProcess_Init(&o->process, o->i->iparams->manager, (BProcess_handler)process_handler, o, exec, CmdLine_Get(&cl), NULL);
     CmdLine_Free(&cl);
     free(exec);
     
@@ -162,7 +162,7 @@ static void start_process (struct instance *o)
     
 fail:
     // start timer
-    BReactor_SetTimer(o->i->params->reactor, &o->timer);
+    BReactor_SetTimer(o->i->iparams->reactor, &o->timer);
     
     // set state retrying
     o->state = STATE_RETRYING;
@@ -193,7 +193,7 @@ static void process_handler (struct instance *o, int normally, uint8_t normally_
     BLog(BLOG_ERROR, "daemon crashed");
     
     // start timer
-    BReactor_SetTimer(o->i->params->reactor, &o->timer);
+    BReactor_SetTimer(o->i->iparams->reactor, &o->timer);
     
     // set state retrying
     o->state = STATE_RETRYING;
@@ -240,7 +240,7 @@ static void instance_free (struct instance *o)
     NCDModuleInst *i = o->i;
     
     // free timer
-    BReactor_RemoveTimer(o->i->params->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->iparams->reactor, &o->timer);
     
     // free instance
     free(o);

+ 3 - 3
ncd/modules/foreach.c

@@ -147,7 +147,7 @@ static void work (struct instance *o)
     assert_state(o);
     
     // stop timer
-    BReactor_RemoveTimer(o->i->params->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->iparams->reactor, &o->timer);
     
     if (o->state == ISTATE_WAITING) {
         return;
@@ -257,7 +257,7 @@ static void advance (struct instance *o)
     
 fail:
     // set timer
-    BReactor_SetTimer(o->i->params->reactor, &o->timer);
+    BReactor_SetTimer(o->i->iparams->reactor, &o->timer);
 }
 
 static void timer_handler (struct instance *o)
@@ -480,7 +480,7 @@ static void instance_free (struct instance *o)
     BFree(o->elems);
     
     // free timer
-    BReactor_RemoveTimer(o->i->params->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->iparams->reactor, &o->timer);
     
     // free instance
     free(o);

+ 2 - 2
ncd/modules/imperative.c

@@ -126,7 +126,7 @@ static void go_deinit (struct instance *o)
     }
     
     // start timer
-    BReactor_SetTimer(o->i->params->reactor, &o->deinit_timer);
+    BReactor_SetTimer(o->i->iparams->reactor, &o->deinit_timer);
     
     // set state deinit working
     o->state = STATE_DEINIT_WORKING;
@@ -177,7 +177,7 @@ static void deinit_process_handler_event (struct instance *o, int event)
             ASSERT(o->state == STATE_DEINIT_WORKING)
             
             // stop timer
-            BReactor_RemoveTimer(o->i->params->reactor, &o->deinit_timer);
+            BReactor_RemoveTimer(o->i->iparams->reactor, &o->deinit_timer);
             
             // start terminating
             NCDModuleProcess_Terminate(&o->process);

+ 4 - 4
ncd/modules/net_backend_badvpn.c

@@ -96,7 +96,7 @@ void try_process (struct instance *o)
     }
     
     // start process
-    if (!BProcess_Init(&o->process, o->i->params->manager, (BProcess_handler)process_handler, o, ((char **)c.arr.v)[0], (char **)c.arr.v, o->user)) {
+    if (!BProcess_Init(&o->process, o->i->iparams->manager, (BProcess_handler)process_handler, o, ((char **)c.arr.v)[0], (char **)c.arr.v, o->user)) {
         ModuleLog(o->i, BLOG_ERROR, "BProcess_Init failed");
         goto fail1;
     }
@@ -113,7 +113,7 @@ fail1:
 fail0:
     // retry
     o->started = 0;
-    BReactor_SetTimer(o->i->params->reactor, &o->timer);
+    BReactor_SetTimer(o->i->iparams->reactor, &o->timer);
 }
 
 void process_handler (struct instance *o, int normally, uint8_t normally_exit_status)
@@ -134,7 +134,7 @@ void process_handler (struct instance *o, int normally, uint8_t normally_exit_st
     }
     
     // set timer
-    BReactor_SetTimer(o->i->params->reactor, &o->timer);
+    BReactor_SetTimer(o->i->iparams->reactor, &o->timer);
 }
 
 void timer_handler (struct instance *o)
@@ -232,7 +232,7 @@ void instance_free (struct instance *o)
     NCDModuleInst *i = o->i;
     
     // free timer
-    BReactor_RemoveTimer(o->i->params->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->iparams->reactor, &o->timer);
     
     // set device down
     if (!NCDIfConfig_set_down(o->ifname)) {

+ 1 - 1
ncd/modules/net_backend_rfkill.c

@@ -175,7 +175,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init monitor
-    if (!NCDRfkillMonitor_Init(&o->monitor, o->i->params->reactor, (NCDRfkillMonitor_handler)monitor_handler, o)) {
+    if (!NCDRfkillMonitor_Init(&o->monitor, o->i->iparams->reactor, (NCDRfkillMonitor_handler)monitor_handler, o)) {
         ModuleLog(o->i, BLOG_ERROR, "monitor failed");
         goto fail1;
     }

+ 3 - 3
ncd/modules/net_backend_waitdevice.c

@@ -60,7 +60,7 @@ struct instance {
 
 static void client_handler (struct instance *o, char *devpath, int have_map, BStringMap map)
 {
-    if (o->devpath && !strcmp(devpath, o->devpath) && !NCDUdevManager_Query(o->i->params->umanager, o->devpath)) {
+    if (o->devpath && !strcmp(devpath, o->devpath) && !NCDUdevManager_Query(o->i->iparams->umanager, o->devpath)) {
         // free devpath
         free(o->devpath);
         
@@ -70,7 +70,7 @@ static void client_handler (struct instance *o, char *devpath, int have_map, BSt
         // signal down
         NCDModuleInst_Backend_Down(o->i);
     } else {
-        const BStringMap *cache_map = NCDUdevManager_Query(o->i->params->umanager, devpath);
+        const BStringMap *cache_map = NCDUdevManager_Query(o->i->iparams->umanager, devpath);
         if (!cache_map) {
             goto out;
         }
@@ -141,7 +141,7 @@ static void func_new (NCDModuleInst *i)
     o->ifname = NCDValue_StringValue(arg);
     
     // init client
-    NCDUdevClient_Init(&o->client, o->i->params->umanager, o, (NCDUdevClient_handler)client_handler);
+    NCDUdevClient_Init(&o->client, o->i->iparams->umanager, o, (NCDUdevClient_handler)client_handler);
     
     // compile regex
     if (regcomp(&o->reg, DEVPATH_REGEX, REG_EXTENDED)) {

+ 1 - 1
ncd/modules/net_backend_waitlink.c

@@ -107,7 +107,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init monitor
-    if (!NCDInterfaceMonitor_Init(&o->monitor, ifindex, NCDIFMONITOR_WATCH_LINK, i->params->reactor, o, (NCDInterfaceMonitor_handler)monitor_handler, (NCDInterfaceMonitor_handler_error)monitor_handler_error)) {
+    if (!NCDInterfaceMonitor_Init(&o->monitor, ifindex, NCDIFMONITOR_WATCH_LINK, i->iparams->reactor, o, (NCDInterfaceMonitor_handler)monitor_handler, (NCDInterfaceMonitor_handler_error)monitor_handler_error)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDInterfaceMonitor_Init failed");
         goto fail1;
     }

+ 2 - 2
ncd/modules/net_backend_wpa_supplicant.c

@@ -434,7 +434,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init process
-    if (!BInputProcess_Init(&o->process, o->i->params->reactor, o->i->params->manager, o,
+    if (!BInputProcess_Init(&o->process, o->i->iparams->reactor, o->i->iparams->manager, o,
                             (BInputProcess_handler_terminated)process_handler_terminated,
                             (BInputProcess_handler_closed)process_handler_closed
     )) {
@@ -443,7 +443,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init input interface
-    PacketPassInterface_Init(&o->pipe_input, MAX_LINE_LEN, (PacketPassInterface_handler_send)process_pipe_handler_send, o, BReactor_PendingGroup(o->i->params->reactor));
+    PacketPassInterface_Init(&o->pipe_input, MAX_LINE_LEN, (PacketPassInterface_handler_send)process_pipe_handler_send, o, BReactor_PendingGroup(o->i->iparams->reactor));
     
     // init buffer
     if (!LineBuffer_Init(&o->pipe_buffer, BInputProcess_GetInput(&o->process), &o->pipe_input, MAX_LINE_LEN, '\n')) {

+ 1 - 1
ncd/modules/net_ipv4_arp_probe.c

@@ -153,7 +153,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init arpprobe
-    if (!BArpProbe_Init(&o->arpprobe, ifname, addr, i->params->reactor, o, (BArpProbe_handler)arpprobe_handler)) {
+    if (!BArpProbe_Init(&o->arpprobe, ifname, addr, i->iparams->reactor, o, (BArpProbe_handler)arpprobe_handler)) {
         ModuleLog(o->i, BLOG_ERROR, "BArpProbe_Init failed");
         goto fail1;
     }

+ 1 - 1
ncd/modules/net_ipv4_dhcp.c

@@ -163,7 +163,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init DHCP
-    if (!BDHCPClient_Init(&o->dhcp, ifname, opts, o->i->params->reactor, (BDHCPClient_handler)dhcp_handler, o)) {
+    if (!BDHCPClient_Init(&o->dhcp, ifname, opts, o->i->iparams->reactor, (BDHCPClient_handler)dhcp_handler, o)) {
         ModuleLog(o->i, BLOG_ERROR, "BDHCPClient_Init failed");
         goto fail1;
     }

+ 1 - 1
ncd/modules/net_ipv6_wait_dynamic_addr.c

@@ -123,7 +123,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init monitor
-    if (!NCDInterfaceMonitor_Init(&o->monitor, ifindex, NCDIFMONITOR_WATCH_IPV6_ADDR, i->params->reactor, o, (NCDInterfaceMonitor_handler)monitor_handler, (NCDInterfaceMonitor_handler_error)monitor_handler_error)) {
+    if (!NCDInterfaceMonitor_Init(&o->monitor, ifindex, NCDIFMONITOR_WATCH_IPV6_ADDR, i->iparams->reactor, o, (NCDInterfaceMonitor_handler)monitor_handler, (NCDInterfaceMonitor_handler_error)monitor_handler_error)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDInterfaceMonitor_Init failed");
         goto fail1;
     }

+ 2 - 2
ncd/modules/net_watch_interfaces.c

@@ -299,7 +299,7 @@ static void client_handler (struct instance *o, char *devpath, int have_map, BSt
     // lookup existing device with this devpath
     struct device *ex_device = find_device_by_devpath(o, devpath);
     // lookup cache entry
-    const BStringMap *cache_map = NCDUdevManager_Query(o->i->params->umanager, devpath);
+    const BStringMap *cache_map = NCDUdevManager_Query(o->i->iparams->umanager, devpath);
     
     if (!cache_map) {
         if (ex_device) {
@@ -364,7 +364,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init client
-    NCDUdevClient_Init(&o->client, o->i->params->umanager, o, (NCDUdevClient_handler)client_handler);
+    NCDUdevClient_Init(&o->client, o->i->iparams->umanager, o, (NCDUdevClient_handler)client_handler);
     
     // init devices list
     LinkedList1_Init(&o->devices_list);

+ 2 - 2
ncd/modules/process_manager.c

@@ -186,7 +186,7 @@ void process_free (struct process *p)
     LinkedList2_Remove(&o->processes_list, &p->processes_list_node);
     
     // free timer
-    BReactor_RemoveTimer(o->i->params->reactor, &p->retry_timer);
+    BReactor_RemoveTimer(o->i->iparams->reactor, &p->retry_timer);
     
     // free name
     free(p->name);
@@ -353,7 +353,7 @@ void process_try (struct process *p)
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         
         // set timer
-        BReactor_SetTimer(o->i->params->reactor, &p->retry_timer);
+        BReactor_SetTimer(o->i->iparams->reactor, &p->retry_timer);
         
         // set state
         p->state = PROCESS_STATE_RETRYING;

+ 1 - 1
ncd/modules/run.c

@@ -146,7 +146,7 @@ static void func_new (NCDModuleInst *i)
     o->i = i;
     
     // init dummy event lock
-    BEventLock_Init(&o->lock, BReactor_PendingGroup(i->params->reactor));
+    BEventLock_Init(&o->lock, BReactor_PendingGroup(i->iparams->reactor));
     
     command_template_new(&o->cti, i, build_cmdline, template_free_func, o, BLOG_CURRENT_CHANNEL, &o->lock);
     return;

+ 1 - 1
ncd/modules/runonce.c

@@ -245,7 +245,7 @@ static void func_new (NCDModuleInst *i)
     params.do_setsid = do_setsid;
     
     // start process
-    if (!BProcess_Init2(&o->process, o->i->params->manager, (BProcess_handler)process_handler, o, exec, CmdLine_Get(&cl), params)) {
+    if (!BProcess_Init2(&o->process, o->i->iparams->manager, (BProcess_handler)process_handler, o, exec, CmdLine_Get(&cl), params)) {
         ModuleLog(i, BLOG_ERROR, "BProcess_Init failed");
         CmdLine_Free(&cl);
         free(exec);

+ 3 - 3
ncd/modules/sleep.c

@@ -108,7 +108,7 @@ static void func_new (NCDModuleInst *i)
     o->dying = 0;
     
     // set timer
-    BReactor_SetTimerAfter(o->i->params->reactor, &o->timer, o->ms_start);
+    BReactor_SetTimerAfter(o->i->iparams->reactor, &o->timer, o->ms_start);
     
     return;
     
@@ -124,7 +124,7 @@ void instance_free (struct instance *o)
     NCDModuleInst *i = o->i;
     
     // free timer
-    BReactor_RemoveTimer(o->i->params->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->iparams->reactor, &o->timer);
     
     // free instance
     free(o);
@@ -140,7 +140,7 @@ static void func_die (void *vo)
     o->dying = 1;
     
     // set timer
-    BReactor_SetTimerAfter(o->i->params->reactor, &o->timer, o->ms_stop);
+    BReactor_SetTimerAfter(o->i->iparams->reactor, &o->timer, o->ms_stop);
 }
 
 static const struct NCDModule modules[] = {

+ 5 - 5
ncd/modules/sys_evdev.c

@@ -114,7 +114,7 @@ static void device_handler (struct instance *o, int events)
     }
     
     // stop reading
-    BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, 0);
+    BReactor_SetFileDescriptorEvents(o->i->iparams->reactor, &o->bfd, 0);
     
     // set processing
     o->processing = 1;
@@ -128,7 +128,7 @@ static void device_nextevent (struct instance *o)
     ASSERT(o->processing)
     
     // start reading
-    BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, BREACTOR_READ);
+    BReactor_SetFileDescriptorEvents(o->i->iparams->reactor, &o->bfd, BREACTOR_READ);
     
     // set not processing
     o->processing = 0;
@@ -175,11 +175,11 @@ static void func_new (NCDModuleInst *i)
     
     // init BFileDescriptor
     BFileDescriptor_Init(&o->bfd, o->evdev_fd, (BFileDescriptor_handler)device_handler, o);
-    if (!BReactor_AddFileDescriptor(o->i->params->reactor, &o->bfd)) {
+    if (!BReactor_AddFileDescriptor(o->i->iparams->reactor, &o->bfd)) {
         ModuleLog(o->i, BLOG_ERROR, "BReactor_AddFileDescriptor failed");
         goto fail2;
     }
-    BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, BREACTOR_READ);
+    BReactor_SetFileDescriptorEvents(o->i->iparams->reactor, &o->bfd, BREACTOR_READ);
     
     // set not processing
     o->processing = 0;
@@ -200,7 +200,7 @@ void instance_free (struct instance *o, int is_error)
     NCDModuleInst *i = o->i;
     
     // free BFileDescriptor
-    BReactor_RemoveFileDescriptor(o->i->params->reactor, &o->bfd);
+    BReactor_RemoveFileDescriptor(o->i->iparams->reactor, &o->bfd);
     
     // close device.
     // Ignore close error which happens if the device is removed.

+ 1 - 1
ncd/modules/sys_request_client.c

@@ -566,7 +566,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init client
-    if (!NCDRequestClient_Init(&o->client, addr, i->params->reactor, o,
+    if (!NCDRequestClient_Init(&o->client, addr, i->iparams->reactor, o,
         (NCDRequestClient_handler_error)client_handler_error,
         (NCDRequestClient_handler_connected)client_handler_connected)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDRequestClient_Init failed");

+ 3 - 3
ncd/modules/sys_request_server.c

@@ -174,7 +174,7 @@ static void listener_handler (struct instance *o)
 {
     ASSERT(!o->dying)
     
-    BReactor *reactor = o->i->params->reactor;
+    BReactor *reactor = o->i->iparams->reactor;
     BPendingGroup *pg = BReactor_PendingGroup(reactor);
     
     struct connection *c = malloc(sizeof(*c));
@@ -684,7 +684,7 @@ static int init_listen (struct instance *o, NCDValue *listen_addr_arg)
         }
         
         // init listener
-        if (!BListener_InitUnix(&o->listener, o->unix_socket_path, o->i->params->reactor, o, (BListener_handler)listener_handler)) {
+        if (!BListener_InitUnix(&o->listener, o->unix_socket_path, o->i->iparams->reactor, o, (BListener_handler)listener_handler)) {
             ModuleLog(o->i, BLOG_ERROR, "BListener_InitUnix failed");
             return 0;
         }
@@ -714,7 +714,7 @@ static int init_listen (struct instance *o, NCDValue *listen_addr_arg)
         BAddr_InitFromIpaddrAndPort(&addr, ipaddr, hton16(port));
         
         // init listener
-        if (!BListener_Init(&o->listener, addr, o->i->params->reactor, o, (BListener_handler)listener_handler)) {
+        if (!BListener_Init(&o->listener, addr, o->i->iparams->reactor, o, (BListener_handler)listener_handler)) {
             ModuleLog(o->i, BLOG_ERROR, "BListener_InitUnix failed");
             return 0;
         }

+ 6 - 6
ncd/modules/sys_watch_directory.c

@@ -107,7 +107,7 @@ static void next_dir_event (struct instance *o)
             o->dir_handle = NULL;
             
             // start receiving inotify events
-            BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, BREACTOR_READ);
+            BReactor_SetFileDescriptorEvents(o->i->iparams->reactor, &o->bfd, BREACTOR_READ);
             return;
         }
     } while (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."));
@@ -169,7 +169,7 @@ static void next_inotify_event (struct instance *o)
     
     if (o->events_index == o->events_count) {
         // wait for more events
-        BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, BREACTOR_READ);
+        BReactor_SetFileDescriptorEvents(o->i->iparams->reactor, &o->bfd, BREACTOR_READ);
         return;
     }
     
@@ -198,7 +198,7 @@ static void inotify_fd_handler (struct instance *o, int events)
     }
     
     // stop waiting for inotify events
-    BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, 0);
+    BReactor_SetFileDescriptorEvents(o->i->iparams->reactor, &o->bfd, 0);
     
     ASSERT(res <= sizeof(o->events))
     ASSERT(res % sizeof(o->events[0]) == 0)
@@ -275,7 +275,7 @@ static void func_new (NCDModuleInst *i)
     
     // init BFileDescriptor
     BFileDescriptor_Init(&o->bfd, o->inotify_fd, (BFileDescriptor_handler)inotify_fd_handler, o);
-    if (!BReactor_AddFileDescriptor(o->i->params->reactor, &o->bfd)) {
+    if (!BReactor_AddFileDescriptor(o->i->iparams->reactor, &o->bfd)) {
         ModuleLog(o->i, BLOG_ERROR, "BReactor_AddFileDescriptor failed");
         goto fail2;
     }
@@ -295,7 +295,7 @@ static void func_new (NCDModuleInst *i)
     
 fail3:
     // free BFileDescriptor
-    BReactor_RemoveFileDescriptor(o->i->params->reactor, &o->bfd);
+    BReactor_RemoveFileDescriptor(o->i->iparams->reactor, &o->bfd);
 fail2:
     ASSERT_FORCE(close(o->inotify_fd) == 0)
 fail1:
@@ -317,7 +317,7 @@ void instance_free (struct instance *o, int is_error)
     }
     
     // free BFileDescriptor
-    BReactor_RemoveFileDescriptor(o->i->params->reactor, &o->bfd);
+    BReactor_RemoveFileDescriptor(o->i->iparams->reactor, &o->bfd);
     
     // close inotify
     ASSERT_FORCE(close(o->inotify_fd) == 0)

+ 2 - 2
ncd/modules/sys_watch_input.c

@@ -278,7 +278,7 @@ static void client_handler (struct instance *o, char *devpath, int have_map, BSt
     // lookup existing device with this devpath
     struct device *ex_device = find_device_by_devpath(o, devpath);
     // lookup cache entry
-    const BStringMap *cache_map = NCDUdevManager_Query(o->i->params->umanager, devpath);
+    const BStringMap *cache_map = NCDUdevManager_Query(o->i->iparams->umanager, devpath);
     
     if (!cache_map) {
         if (ex_device) {
@@ -368,7 +368,7 @@ static void func_new (NCDModuleInst *i)
     o->devnode_type = NCDValue_StringValue(devnode_type_arg);
     
     // init client
-    NCDUdevClient_Init(&o->client, o->i->params->umanager, o, (NCDUdevClient_handler)client_handler);
+    NCDUdevClient_Init(&o->client, o->i->iparams->umanager, o, (NCDUdevClient_handler)client_handler);
     
     // init devices list
     LinkedList1_Init(&o->devices_list);

+ 2 - 2
ncd/modules/sys_watch_usb.c

@@ -263,7 +263,7 @@ static void client_handler (struct instance *o, char *devpath, int have_map, BSt
     // lookup existing device with this devpath
     struct device *ex_device = find_device_by_devpath(o, devpath);
     // lookup cache entry
-    const BStringMap *cache_map = NCDUdevManager_Query(o->i->params->umanager, devpath);
+    const BStringMap *cache_map = NCDUdevManager_Query(o->i->iparams->umanager, devpath);
     
     if (!cache_map) {
         if (ex_device) {
@@ -337,7 +337,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init client
-    NCDUdevClient_Init(&o->client, o->i->params->umanager, o, (NCDUdevClient_handler)client_handler);
+    NCDUdevClient_Init(&o->client, o->i->iparams->umanager, o, (NCDUdevClient_handler)client_handler);
     
     // init devices list
     LinkedList1_Init(&o->devices_list);

+ 8 - 7
ncd/ncd.c

@@ -171,6 +171,7 @@ struct NCDConfig_processes *config_ast;
 
 // common module parameters
 struct NCDModuleInst_params module_params;
+struct NCDModuleInst_iparams module_iparams;
 
 // processes
 LinkedList1 processes;
@@ -363,15 +364,15 @@ int main (int argc, char **argv)
     }
     
     // init common module params
-    module_params.reactor = &ss;
-    module_params.manager = &manager;
-    module_params.umanager = &umanager;
     module_params.func_event = (NCDModuleInst_func_event)process_statement_instance_func_event;
     module_params.func_getobj = (NCDModuleInst_func_getobj)process_statement_instance_func_getobj;
-    module_params.func_initprocess = (NCDModuleInst_func_initprocess)process_statement_instance_func_initprocess;
     module_params.logfunc = (BLog_logfunc)process_statement_instance_logfunc;
-    module_params.func_interp_exit = (NCDModuleInst_func_interp_exit)process_statement_instance_func_interp_exit;
-    module_params.func_interp_getargs = (NCDModuleInst_func_interp_getargs)process_statement_instance_func_interp_getargs;
+    module_iparams.reactor = &ss;
+    module_iparams.manager = &manager;
+    module_iparams.umanager = &umanager;
+    module_iparams.func_initprocess = (NCDModuleInst_func_initprocess)process_statement_instance_func_initprocess;
+    module_iparams.func_interp_exit = (NCDModuleInst_func_interp_exit)process_statement_instance_func_interp_exit;
+    module_iparams.func_interp_getargs = (NCDModuleInst_func_interp_getargs)process_statement_instance_func_interp_getargs;
     
     // init processes list
     LinkedList1_Init(&processes);
@@ -1379,7 +1380,7 @@ void process_advance_job_handler (struct process *p)
     }
     
     // initialize module instance
-    NCDModuleInst_Init(&ps->inst, module, object_ptr, &ps->inst_args, ps, &module_params);
+    NCDModuleInst_Init(&ps->inst, module, object_ptr, &ps->inst_args, ps, &module_params, &module_iparams);
     
     // set statement state CHILD
     ps->state = SSTATE_CHILD;