Last active
February 9, 2016 21:00
-
-
Save arteymix/0f3acedc8d6e08d4cbf9 to your computer and use it in GitHub Desktop.
Controller using GObject Introspection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HandlerCallback controller (string namespace) { | |
return (req, res, next, ctx) => { | |
var controller_type = Type.from_name ("%s%s".printf (namespace, ctx["controller"])); | |
if (!controller_type.is_classed ()) | |
throw new ClientError.NOT_FOUND ("'%s' is not an existing controller", ctx["controller"]); | |
var controller = Object.new (controller_type); | |
var action_info = GI.Repository.get_default ().find_by_name (namespace, | |
"%s_action_%s".printf (ctx["controller"], | |
ctx["action"].get_string () ?? "index")); | |
if (action_info is UnresolvedInfo) | |
throw new ClientError ("no such action '%s'", ctx["action"].get_string () ?? "index"); | |
// assume you go through http://valadoc.org/#!wiki=gobject-introspection-1.0/index | |
// | |
// - obtain an CallableInfo for the action | |
// - obtain the function symbol | |
// - build the arguments (tricky part) | |
CallableInfo.invoke (action_info as CallableInfo, callable_symbol, arguments, 4, null, 0, true, true); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Valum; | |
using VSGI.HTTP; | |
var app = new Router (); | |
app.rule (Method.GET | Method.POST, "<controller>(/<action>)", controller); | |
new Server ("org.valum.example.Controller", app.handle).run (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment