2 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
16 #include <l4/cxx/string>
17 #include <l4/mag/server/session>
18 #include <l4/re/error_helper>
24 namespace Mag_server {
26 Plugin *Plugin::_first;
28 Core_api::Core_api(lua_State *lua, User_state *u,
29 L4::Cap<void> rcvc, L4::Cap<L4Re::Video::Goos> fb,
30 Mag_gfx::Font const *label_font)
31 : _ust(u), _rcv_cap(rcvc), _fb(fb), _lua(lua), _label_font(label_font)
33 lua_pushlightuserdata(_lua, this);
35 lua_rawset(_lua, LUA_REGISTRYINDEX);
39 Core_api::get_refs_table() const
41 lua_pushlightuserdata(_lua, const_cast<Core_api*>(this));
42 lua_rawget(_lua, LUA_REGISTRYINDEX);
46 Session::Property_handler const _default_session_props[] =
47 { { "l", true, &Session::set_label_prop },
48 { "label", true, &Session::set_label_prop },
49 { "col", true, &Session::set_color_prop },
53 static bool handle_option(Session *s, Session::Property_handler const *p, cxx::String const &a)
55 for (; p && p->tag; ++p)
57 cxx::String::Index v = a.starts_with(p->tag);
58 if (v && (!p->value_property || a[v] == '='))
60 p->handler(s, p, a.substr(v + 1));
69 Core_api::set_session_options(Session *s, L4::Ipc::Istream &ios,
70 Session::Property_handler const *extra) const
75 if (!opt.is_of<char const *>())
77 printf("skipping non string argument for session!\n");
81 cxx::String a(opt.value<char const *>(), opt.length());
83 if (!handle_option(s, _default_session_props, a)
84 && !handle_option(s, extra, a))
86 printf("unknown session option '%.*s'\n", a.len(), a.start());
87 L4Re::chksys(-L4_EINVAL, "parsing session options");
92 s->set_label_prop(s, 0, "<empty>");