* Optimized dispatching model
authorSteven Barth <steven@midlink.org>
Tue, 27 May 2008 20:39:48 +0000 (20:39 +0000)
committerSteven Barth <steven@midlink.org>
Tue, 27 May 2008 20:39:48 +0000 (20:39 +0000)
applications/luci-ffwizard-leipzig/luasrc/controller/luci_ffwizard_leipzig/wizard.lua
applications/luci-splash/luasrc/controller/splash/splash.lua
libs/web/luasrc/dispatcher.lua
modules/admin-core/luasrc/controller/admin/status.lua
modules/admin-core/luasrc/controller/admin/system.lua
modules/admin-core/luasrc/controller/admin/uci.lua
modules/freifunk/luasrc/controller/freifunk/freifunk.lua
modules/freifunk/luasrc/controller/freifunk/luciinfo.lua
modules/freifunk/luasrc/controller/freifunk/olsr.lua

index 4f2390b374a4c6156500a7ca50c5e03e33e17239..2fabfb11df8a8f0dbf78043b2b1182e1b5fc6c3b 100644 (file)
@@ -1,7 +1,7 @@
 module("luci.controller.luci_ffwizard_leipzig.wizard", package.seeall)
 
 function index()
-       entry({"admin", "index", "wizard"}, action_wizard, "Freifunkassistent", 20)
+       entry({"admin", "index", "wizard"}, call("action_wizard"), "Freifunkassistent", 20)
 end
 
 
index 544f1e89ea2fe76819d34f2765b5740c006835c2..e7448d7fbf6b6ec242c49a45c0a2343993e47c35 100644 (file)
@@ -5,9 +5,9 @@ function index()
        page.target = cbi("splash/splash")
        page.title  = "Client-Splash"
 
-       node("splash", "splash", "activate").target = action_activate
-       node("splash", "splash", "allowed").target  = action_allowed
-       node("splash", "splash", "unknown").target  = action_unknown
+       node("splash", "splash", "activate").target = call("action_activate")
+       node("splash", "splash", "allowed").target  = call("action_allowed")
+       node("splash", "splash", "unknown").target  = call("action_unknown")
        node("splash", "splash", "splash").target   = template("splash_splash/splash")
 end
 
index 6a6bceb29b5a9e4e125d009317953e0b78ee5a17..202e073321ab01137e57c9df830544ab44649081 100644 (file)
@@ -137,7 +137,11 @@ function dispatch()
 
        if c and type(c.target) == "function" then
                dispatched = c
-
+               stat, mod = pcall(require, c.module)
+               if stat then
+                       luci.util.updfenv(c.target, mod)
+               end
+               
                stat, err = pcall(c.target)
                if not stat then
                        error500(err)
@@ -222,12 +226,7 @@ function createtree()
 
        for k, v in pairs(index) do
                luci.util.updfenv(v, _M)
-               
-               local stat, mod = pcall(require, k)
-               if stat then            
-                       luci.util.updfenv(v, mod)
-               end
-               
+               luci.util.extfenv(v, "_NAME", k)
                pcall(v)
        end
        
@@ -242,6 +241,7 @@ function entry(path, target, title, order, add)
        c.target = target
        c.title  = title
        c.order  = order
+       c.module = getfenv(2)._NAME
 
        for k,v in pairs(add) do
                c[k] = v
@@ -260,7 +260,7 @@ function node(...)
 
        for k,v in ipairs(arg) do
                if not c.nodes[v] then
-                       c.nodes[v] = {nodes={}}
+                       c.nodes[v] = {nodes={}, module=getfenv(2)._NAME}
                end
 
                c = c.nodes[v]
@@ -278,6 +278,10 @@ function alias(...)
        end
 end
 
+function call(name)
+       return function() getfenv()[name]() end
+end
+
 function template(name)
        require("luci.template")
        return function() luci.template.render(name) end
index 34c210ca6b7ad24e9da3da97e82ce69ae8e250dc..79f728b99dd3887efbdafc17853d15a8c0d48a79 100644 (file)
@@ -2,7 +2,7 @@ module("luci.controller.admin.status", package.seeall)
 
 function index()
        entry({"admin", "status"}, template("admin_status/index"), "Status", 20)
-       entry({"admin", "status", "syslog"}, action_syslog, "Systemprotokoll")
+       entry({"admin", "status", "syslog"}, call("action_syslog"), "Systemprotokoll")
 end
 
 function action_syslog()
index e44e787fd6b84d5a220a9ebc399003320e140eee..304f1eee8380a573f5b6bc1c8bdcacb362d795a4 100644 (file)
@@ -14,21 +14,21 @@ function index()
        page.order  = 30
        
        local page  = node("admin", "system", "packages")
-       page.target = action_packages
+       page.target = call("action_packages")
        page.title  = "Paketverwaltung"
        page.order  = 10
        
        local page  = node("admin", "system", "packages", "ipkg")
-       page.target = action_ipkg
+       page.target = call("action_ipkg")
        page.title  = "IPKG-Konfiguration"
        
        local page  = node("admin", "system", "passwd")
-       page.target = action_passwd
+       page.target = call("action_passwd")
        page.title  = "Passwort ändern"
        page.order  = 20
        
        local page  = node("admin", "system", "sshkeys")
-       page.target = action_sshkeys
+       page.target = call("action_sshkeys")
        page.title  = "SSH-Schlüssel"
        page.order  = 30
        
@@ -43,12 +43,12 @@ function index()
        page.order  = 50
        
        local page  = node("admin", "system", "upgrade")
-       page.target = action_upgrade
+       page.target = call("action_upgrade")
        page.title  = "Firmwareupgrade"
        page.order  = 60
        
        local page  = node("admin", "system", "reboot")
-       page.target = action_reboot
+       page.target = call("action_reboot")
        page.title  = "Neu starten"
        page.order  = 70
 end
index ca1440bdeee645b5e51be3611604b68e0dd6ed58..9c0e1beb5be7c5db8a5c1d128f7490f8a438d2ce 100644 (file)
@@ -4,8 +4,8 @@ require("luci.sys")
 
 function index()
        node("admin", "uci", "changes").target = template("admin_uci/changes")
-       node("admin", "uci", "revert").target  = action_revert
-       node("admin", "uci", "apply").target   = action_apply
+       node("admin", "uci", "revert").target  = call("action_revert")
+       node("admin", "uci", "apply").target   = call("action_apply")
 end
 
 -- This function has a higher priority than the admin_uci/apply template
index 104f6cdfc3f6cb0a215c0b7c53d82c2288944238..89813b3d8ddfe03913c433c2efa3c4db9b5d3e47 100644 (file)
@@ -22,7 +22,7 @@ function index()
        
        
        local page  = node("freifunk", "status")
-       page.target = action_status
+       page.target = call("action_status")
        page.title  = "Status"
        page.order  = 20
        page.setuser  = false
index aabab19a125bc62898c525c122b55e38f67a74b6..c4c627601846c8be2213b3027cf9f3f58c9afe62 100644 (file)
@@ -1,7 +1,7 @@
 module("luci.controller.freifunk.luciinfo", package.seeall)
 
 function index()
-       node("freifunk", "luciinfo").target = action_index
+       node("freifunk", "luciinfo").target = call("action_index")
 end
 
 function action_index()
index 29858fc0e09b572b513630f501278fee3e63efc4..ac143277dbbab896f31bd13d2071e36ba891e9bd 100644 (file)
@@ -3,27 +3,27 @@ require("luci.sys")
 
 function index()
        local page  = node("freifunk", "olsr")
-       page.target = action_index
+       page.target = call("action_index")
        page.title  = "OLSR"
        page.order  = 30
        
        local page  = node("freifunk", "olsr", "routes")
-       page.target = action_routes
+       page.target = call("action_routes")
        page.title  = "Routen"
        page.order  = 10
        
        local page  = node("freifunk", "olsr", "topology")
-       page.target = action_topology
+       page.target = call("action_topology")
        page.title  = "Topologie"
        page.order  = 20
        
        local page  = node("freifunk", "olsr", "hna")
-       page.target = action_hna
+       page.target = call("action_hna")
        page.title  = "HNA"
        page.order  = 30
        
        local page  = node("freifunk", "olsr", "mid")
-       page.target = action_mid
+       page.target = call("action_mid")
        page.title  = "MID"
        page.order  = 50
 end