Browse Source

ncd: NCDModule: pass some parameters to NCDModuleInst_Init() indirectly via a struct pointer. These are always the
same, so this can reduce memory usage.

ambrop7 14 years ago
parent
commit
f007867b5f

+ 17 - 25
ncd/NCDModule.c

@@ -66,7 +66,7 @@ static int process_arg_object_func_getvar2 (NCDModuleProcess *o, NCDValue *arg,
 
 static void frontend_event (NCDModuleInst *n, int event)
 {
-    n->func_event(n->user, event);
+    n->params->func_event(n->user, event);
 }
 
 static void init_job_handler (NCDModuleInst *n)
@@ -151,37 +151,29 @@ static void process_event_job_handler (NCDModuleProcess *o)
     }
 }
 
-void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValue *args, BReactor *reactor, BProcessManager *manager, NCDUdevManager *umanager, void *user,
-                         NCDModuleInst_func_event func_event,
-                         NCDModuleInst_func_getobj func_getobj,
-                         NCDModuleInst_func_initprocess func_initprocess,
-                         BLog_logfunc logfunc)
+void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValue *args, void *user, const struct NCDModuleInst_params *params)
 {
+    ASSERT(m)
     ASSERT(args)
     ASSERT(NCDValue_Type(args) == NCDVALUE_LIST)
-    ASSERT(func_event)
-    ASSERT(func_getobj)
-    ASSERT(func_initprocess)
-    ASSERT(logfunc)
+    ASSERT(params)
+    ASSERT(params->func_event)
+    ASSERT(params->func_getobj)
+    ASSERT(params->func_initprocess)
+    ASSERT(params->logfunc)
     
     // init arguments
     n->m = m;
     n->method_user = (method_object ? method_object->user : NULL);
     n->args = args;
-    n->reactor = reactor;
-    n->manager = manager;
-    n->umanager = umanager;
     n->user = user;
-    n->func_event = func_event;
-    n->func_getobj = func_getobj;
-    n->func_initprocess = func_initprocess;
-    n->logfunc = logfunc;
+    n->params = params;
     
     // init jobs
-    BPending_Init(&n->init_job, BReactor_PendingGroup(n->reactor), (BPending_handler)init_job_handler, n);
-    BPending_Init(&n->uninit_job, BReactor_PendingGroup(n->reactor), (BPending_handler)uninit_job_handler, n);
-    BPending_Init(&n->die_job, BReactor_PendingGroup(n->reactor), (BPending_handler)die_job_handler, n);
-    BPending_Init(&n->clean_job, BReactor_PendingGroup(n->reactor), (BPending_handler)clean_job_handler, n);
+    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);
     
     // set initial state
     n->state = STATE_INIT;
@@ -412,7 +404,7 @@ int NCDModuleInst_Backend_GetObj (NCDModuleInst *n, const char *name, NCDObject
     ASSERT(name)
     ASSERT(out_object)
     
-    int res = n->func_getobj(n->user, name, out_object);
+    int res = n->params->func_getobj(n->user, name, out_object);
     ASSERT(res == 0 || res == 1)
     
     return res;
@@ -424,7 +416,7 @@ void NCDModuleInst_Backend_Log (NCDModuleInst *n, int channel, int level, const
     
     va_list vl;
     va_start(vl, fmt);
-    BLog_LogViaFuncVarArg(n->logfunc, n->user, channel, level, fmt, vl);
+    BLog_LogViaFuncVarArg(n->params->logfunc, n->user, channel, level, fmt, vl);
     va_end(vl);
 }
 
@@ -459,7 +451,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->reactor), (BPending_handler)process_event_job_handler, o);
+    BPending_Init(&o->event_job, BReactor_PendingGroup(n->params->reactor), (BPending_handler)process_event_job_handler, o);
     
     // set state
     o->state = PROCESS_STATE_INIT;
@@ -469,7 +461,7 @@ int NCDModuleProcess_Init (NCDModuleProcess *o, NCDModuleInst *n, const char *te
     o->interp_func_getobj = NULL;
     
     // init interpreter part
-    if (!(n->func_initprocess(n->user, o, template_name))) {
+    if (!(n->params->func_initprocess(n->user, o, template_name))) {
         goto fail1;
     }
     

+ 40 - 19
ncd/NCDModule.h

@@ -196,6 +196,40 @@ struct NCDModuleInitParams {
     NCDUdevManager *umanager;
 };
 
+/**
+ * Contains parameters to {@link NCDModuleInst_Init} that are passed indirectly.
+ */
+struct NCDModuleInst_params {
+    /**
+     * Reactor we live in.
+     */
+    BReactor *reactor;
+    /**
+     * Process manager.
+     */
+    BProcessManager *manager;
+    /**
+     * 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;
+};
+
 /**
  * Module instance.
  * The module instance is initialized by the interpreter by calling
@@ -206,14 +240,8 @@ typedef struct NCDModuleInst_s {
     const struct NCDModule *m;
     void *method_user;
     NCDValue *args;
-    BReactor *reactor;
-    BProcessManager *manager;
-    NCDUdevManager *umanager;
     void *user;
-    NCDModuleInst_func_event func_event;
-    NCDModuleInst_func_getobj func_getobj;
-    NCDModuleInst_func_initprocess func_initprocess;
-    BLog_logfunc logfunc;
+    const struct NCDModuleInst_params *params;
     BPending init_job;
     BPending uninit_job;
     BPending die_job;
@@ -257,19 +285,12 @@ typedef struct NCDModuleProcess_s {
  *                      being initialized.
  * @param args arguments to the module. Must be a NCDVALUE_LIST value. Must be available as long as
  *             the instance is freed.
- * @param reactor reactor we live in
- * @param manager process manager
- * @param umanager udev manager
  * @param user argument to callback functions
- * @param func_event callback to report state changes
- * @param func_getobj callback to resolve objects from the viewpoint of the instance
- * @param logfunc log function which appends a log prefix with {@link BLog_Append}
- */
-void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValue *args, BReactor *reactor, BProcessManager *manager, NCDUdevManager *umanager, void *user,
-                         NCDModuleInst_func_event func_event,
-                         NCDModuleInst_func_getobj func_getobj,
-                         NCDModuleInst_func_initprocess func_initprocess,
-                         BLog_logfunc logfunc);
+ * @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.
+ */
+void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValue *args, void *user, const struct NCDModuleInst_params *params);
 
 /**
  * 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->manager, (BProcess_handler)process_handler, o, o->do_exec, CmdLine_Get(&o->do_cmdline), NULL)) {
+        if (!BProcess_Init(&o->process, o->i->params->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->manager, (BProcess_handler)process_handler, o, o->undo_exec, CmdLine_Get(&o->undo_cmdline), NULL)) {
+        if (!BProcess_Init(&o->process, o->i->params->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->manager, (BProcess_handler)process_handler, o, exec, CmdLine_Get(&cl), NULL);
+    int res = BProcess_Init(&o->process, o->i->params->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->reactor, &o->timer);
+    BReactor_SetTimer(o->i->params->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->reactor, &o->timer);
+    BReactor_SetTimer(o->i->params->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->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->params->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->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->params->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->reactor, &o->timer);
+    BReactor_SetTimer(o->i->params->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->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->params->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->reactor, &o->deinit_timer);
+    BReactor_SetTimer(o->i->params->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->reactor, &o->deinit_timer);
+            BReactor_RemoveTimer(o->i->params->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->manager, (BProcess_handler)process_handler, o, ((char **)c.arr.v)[0], (char **)c.arr.v, o->user)) {
+    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)) {
         ModuleLog(o->i, BLOG_ERROR, "BProcess_Init failed");
         goto fail1;
     }
@@ -113,7 +113,7 @@ fail1:
 fail0:
     // retry
     o->started = 0;
-    BReactor_SetTimer(o->i->reactor, &o->timer);
+    BReactor_SetTimer(o->i->params->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->reactor, &o->timer);
+    BReactor_SetTimer(o->i->params->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->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->params->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->reactor, (NCDRfkillMonitor_handler)monitor_handler, o)) {
+    if (!NCDRfkillMonitor_Init(&o->monitor, o->i->params->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->umanager, o->devpath)) {
+    if (o->devpath && !strcmp(devpath, o->devpath) && !NCDUdevManager_Query(o->i->params->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->umanager, devpath);
+        const BStringMap *cache_map = NCDUdevManager_Query(o->i->params->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->umanager, o, (NCDUdevClient_handler)client_handler);
+    NCDUdevClient_Init(&o->client, o->i->params->umanager, o, (NCDUdevClient_handler)client_handler);
     
     // compile regex
     if (regcomp(&o->reg, DEVPATH_REGEX, REG_EXTENDED)) {

+ 1 - 1
ncd/modules/net_backend_waitlink.c

@@ -94,7 +94,7 @@ static void func_new (NCDModuleInst *i)
     o->ifname = NCDValue_StringValue(arg);
     
     // init monitor
-    if (!NCDInterfaceMonitor_Init(&o->monitor, o->i->reactor, (NCDInterfaceMonitor_handler)monitor_handler, o)) {
+    if (!NCDInterfaceMonitor_Init(&o->monitor, o->i->params->reactor, (NCDInterfaceMonitor_handler)monitor_handler, o)) {
         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->reactor, o->i->manager, o,
+    if (!BInputProcess_Init(&o->process, o->i->params->reactor, o->i->params->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->reactor));
+    PacketPassInterface_Init(&o->pipe_input, MAX_LINE_LEN, (PacketPassInterface_handler_send)process_pipe_handler_send, o, BReactor_PendingGroup(o->i->params->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->reactor, o, (BArpProbe_handler)arpprobe_handler)) {
+    if (!BArpProbe_Init(&o->arpprobe, ifname, addr, i->params->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->reactor, (BDHCPClient_handler)dhcp_handler, o)) {
+    if (!BDHCPClient_Init(&o->dhcp, ifname, opts, o->i->params->reactor, (BDHCPClient_handler)dhcp_handler, o)) {
         ModuleLog(o->i, BLOG_ERROR, "BDHCPClient_Init failed");
         goto fail1;
     }

+ 2 - 2
ncd/modules/net_watch_interfaces.c

@@ -303,7 +303,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->umanager, devpath);
+    const BStringMap *cache_map = NCDUdevManager_Query(o->i->params->umanager, devpath);
     
     if (!cache_map) {
         if (ex_device) {
@@ -368,7 +368,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init client
-    NCDUdevClient_Init(&o->client, o->i->umanager, o, (NCDUdevClient_handler)client_handler);
+    NCDUdevClient_Init(&o->client, o->i->params->umanager, o, (NCDUdevClient_handler)client_handler);
     
     // init devices list
     LinkedList1_Init(&o->devices_list);

+ 2 - 2
ncd/modules/process_manager.c

@@ -187,7 +187,7 @@ void process_free (struct process *p)
     LinkedList2_Remove(&o->processes_list, &p->processes_list_node);
     
     // free timer
-    BReactor_RemoveTimer(o->i->reactor, &p->retry_timer);
+    BReactor_RemoveTimer(o->i->params->reactor, &p->retry_timer);
     
     // free name
     free(p->name);
@@ -334,7 +334,7 @@ void process_try (struct process *p)
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         
         // set timer
-        BReactor_SetTimer(o->i->reactor, &p->retry_timer);
+        BReactor_SetTimer(o->i->params->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->reactor));
+    BEventLock_Init(&o->lock, BReactor_PendingGroup(i->params->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

@@ -234,7 +234,7 @@ static void func_new (NCDModuleInst *i)
     fds[nfds] = -1;
     
     // start process
-    if (!BProcess_InitWithFds(&o->process, o->i->manager, (BProcess_handler)process_handler, o, exec, CmdLine_Get(&cl), NULL, fds, fds_map)) {
+    if (!BProcess_InitWithFds(&o->process, o->i->params->manager, (BProcess_handler)process_handler, o, exec, CmdLine_Get(&cl), NULL, fds, fds_map)) {
         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->reactor, &o->timer, o->ms_start);
+    BReactor_SetTimerAfter(o->i->params->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->reactor, &o->timer);
+    BReactor_RemoveTimer(o->i->params->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->reactor, &o->timer, o->ms_stop);
+    BReactor_SetTimerAfter(o->i->params->reactor, &o->timer, o->ms_stop);
 }
 
 static const struct NCDModule modules[] = {

+ 5 - 5
ncd/modules/sys_evdev.c

@@ -118,7 +118,7 @@ static void device_handler (struct instance *o, int events)
     }
     
     // stop reading
-    BReactor_SetFileDescriptorEvents(o->i->reactor, &o->bfd, 0);
+    BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, 0);
     
     // set processing
     o->processing = 1;
@@ -132,7 +132,7 @@ static void device_nextevent (struct instance *o)
     ASSERT(o->processing)
     
     // start reading
-    BReactor_SetFileDescriptorEvents(o->i->reactor, &o->bfd, BREACTOR_READ);
+    BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, BREACTOR_READ);
     
     // set not processing
     o->processing = 0;
@@ -179,11 +179,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->reactor, &o->bfd)) {
+    if (!BReactor_AddFileDescriptor(o->i->params->reactor, &o->bfd)) {
         ModuleLog(o->i, BLOG_ERROR, "BReactor_AddFileDescriptor failed");
         goto fail2;
     }
-    BReactor_SetFileDescriptorEvents(o->i->reactor, &o->bfd, BREACTOR_READ);
+    BReactor_SetFileDescriptorEvents(o->i->params->reactor, &o->bfd, BREACTOR_READ);
     
     // set not processing
     o->processing = 0;
@@ -204,7 +204,7 @@ void instance_free (struct instance *o, int is_error)
     NCDModuleInst *i = o->i;
     
     // free BFileDescriptor
-    BReactor_RemoveFileDescriptor(o->i->reactor, &o->bfd);
+    BReactor_RemoveFileDescriptor(o->i->params->reactor, &o->bfd);
     
     // close device.
     // Ignore close error which happens if the device is removed.

+ 6 - 6
ncd/modules/sys_watch_directory.c

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

+ 2 - 2
ncd/modules/sys_watch_input.c

@@ -282,7 +282,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->umanager, devpath);
+    const BStringMap *cache_map = NCDUdevManager_Query(o->i->params->umanager, devpath);
     
     if (!cache_map) {
         if (ex_device) {
@@ -372,7 +372,7 @@ static void func_new (NCDModuleInst *i)
     o->devnode_type = NCDValue_StringValue(devnode_type_arg);
     
     // init client
-    NCDUdevClient_Init(&o->client, o->i->umanager, o, (NCDUdevClient_handler)client_handler);
+    NCDUdevClient_Init(&o->client, o->i->params->umanager, o, (NCDUdevClient_handler)client_handler);
     
     // init devices list
     LinkedList1_Init(&o->devices_list);

+ 2 - 2
ncd/modules/sys_watch_usb.c

@@ -267,7 +267,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->umanager, devpath);
+    const BStringMap *cache_map = NCDUdevManager_Query(o->i->params->umanager, devpath);
     
     if (!cache_map) {
         if (ex_device) {
@@ -341,7 +341,7 @@ static void func_new (NCDModuleInst *i)
     }
     
     // init client
-    NCDUdevClient_Init(&o->client, o->i->umanager, o, (NCDUdevClient_handler)client_handler);
+    NCDUdevClient_Init(&o->client, o->i->params->umanager, o, (NCDUdevClient_handler)client_handler);
     
     // init devices list
     LinkedList1_Init(&o->devices_list);

+ 13 - 7
ncd/ncd.c

@@ -162,6 +162,9 @@ NCDModuleIndex mindex;
 // config AST
 struct NCDConfig_processes *config_ast;
 
+// common module parameters
+struct NCDModuleInst_params module_params;
+
 // processes
 LinkedList2 processes;
 
@@ -341,6 +344,15 @@ int main (int argc, char **argv)
         num_inited_modules++;
     }
     
+    // 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;
+    
     // init processes list
     LinkedList2_Init(&processes);
     
@@ -1255,13 +1267,7 @@ void process_advance_job_handler (struct process *p)
     }
     
     // initialize module instance
-    NCDModuleInst_Init(
-        &ps->inst, ps->module, object_ptr, &ps->inst_args, &ss, &manager, &umanager, ps,
-        (NCDModuleInst_func_event)process_statement_instance_func_event,
-        (NCDModuleInst_func_getobj)process_statement_instance_func_getobj,
-        (NCDModuleInst_func_initprocess)process_statement_instance_func_initprocess,
-        (BLog_logfunc)process_statement_instance_logfunc
-    );
+    NCDModuleInst_Init(&ps->inst, ps->module, object_ptr, &ps->inst_args, ps, &module_params);
     
     // set statement state CHILD
     ps->state = SSTATE_CHILD;