Quellcode durchsuchen

ncd: modules: rimp_call: allow access to caller's variables/objects

ambrop7 vor 14 Jahren
Ursprung
Commit
bc8f577df6
1 geänderte Dateien mit 30 neuen und 0 gelöschten Zeilen
  1. 30 0
      ncd/modules/rimp_call.c

+ 30 - 0
ncd/modules/rimp_call.c

@@ -44,6 +44,7 @@
 #include <stdlib.h>
 
 #include <misc/parse_number.h>
+#include <misc/string_begins_with.h>
 #include <ncd/NCDModule.h>
 
 #include <generated/blog_channel_ncd_rimp_call.h>
@@ -99,6 +100,30 @@ static void process_handler_event (struct instance *o, int event)
     }
 }
 
+static int process_func_getspecialvar (struct instance *o, const char *name, NCDValue *out)
+{
+    ASSERT(o->state == STATE_WORKING || o->state == STATE_CLEANING)
+    
+    size_t p;
+    if (p = string_begins_with(name, "_caller.")) {
+        return NCDModuleInst_Backend_GetVar(o->i, name + p, out);
+    }
+    
+    return 0;
+}
+
+static NCDModuleInst * process_func_getspecialobj (struct instance *o, const char *name)
+{
+    ASSERT(o->state == STATE_WORKING || o->state == STATE_CLEANING)
+    
+    size_t p;
+    if (p = string_begins_with(name, "_caller.")) {
+        return NCDModuleInst_Backend_GetObj(o->i, name + p);
+    }
+    
+    return NULL;
+}
+
 static void timer_handler (struct instance *o)
 {
     ASSERT(o->have_timeout)
@@ -238,6 +263,11 @@ static void func_die (void *vo)
         goto fail;
     }
     
+    // set special functions
+    NCDModuleProcess_SetSpecialFuncs(&o->process,
+                                    (NCDModuleProcess_func_getspecialvar)process_func_getspecialvar,
+                                    (NCDModuleProcess_func_getspecialobj)process_func_getspecialobj);
+    
     // start timer if used
     if (o->have_timeout) {
         BReactor_SetTimer(o->i->reactor, &o->timer);