]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/mag/plugins/client_fb/service.cc
update
[l4.git] / l4 / pkg / mag / plugins / client_fb / service.cc
1 /*
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)
5  *
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.
9  */
10 #include <l4/cxx/ipc_server>
11 #include <l4/re/util/object_registry>
12 #include <l4/re/env>
13 #include <l4/re/protocols>
14 #include <l4/re/console>
15 #include <l4/re/util/cap_alloc>
16 #include <l4/re/error_helper>
17 #include <l4/re/rm>
18 #include <l4/re/dataspace>
19 #include <l4/re/mem_alloc>
20 #include <l4/re/util/meta>
21
22 #include <cstdio>
23 #include <cstring>
24 #include <algorithm>
25
26 #include "client_fb.h"
27 #include <l4/mag-gfx/canvas>
28 #include <l4/mag/server/user_state>
29 #include <l4/mag/server/factory>
30
31 #include "service.h"
32 #include <l4/sys/kdebug.h>
33
34 namespace Mag_server {
35
36 using L4Re::Util::Auto_cap;
37
38 void Service::start(Core_api *core)
39 {
40   _core = core;
41   if (!reg()->register_obj(cxx::Ref_ptr<Service>(this), "svc").is_valid())
42     printf("Service registration failed.\n");
43   else
44     printf("Plugin: Frame-buffer service started\n");
45 }
46
47
48 namespace {
49   Session::Property_handler const _client_fb_opts[] =
50     { { "g",         true,  &Client_fb::set_geometry_prop },
51       { "geometry",  true,  &Client_fb::set_geometry_prop },
52       { "focus",     false, &Client_fb::set_flags_prop },
53       { "shaded",    false, &Client_fb::set_flags_prop },
54       { "fixed",     false, &Client_fb::set_flags_prop },
55       { "barheight", true,  &Client_fb::set_bar_height_prop },
56       { 0, 0, 0 }
57     };
58 };
59
60 int
61 Service::dispatch(l4_umword_t, L4::Ipc_iostream &ios)
62 {
63   l4_msgtag_t tag;
64   ios >> tag;
65
66   switch (tag.label())
67     {
68     case L4::Meta::Protocol:
69       return L4Re::Util::handle_meta_request<L4::Factory>(ios);
70     case L4::Factory::Protocol:
71       if (L4::kobject_typeid<L4Re::Console>()->
72             has_proto(L4::Ipc::read<L4::Factory::Proto>(ios)))
73         {
74           L4::Ipc::Istream_copy cp_is = ios;
75           cxx::Ref_ptr<Client_fb> x(new Client_fb(_core));
76           _core->set_session_options(x.get(), cp_is, _client_fb_opts);
77           x->setup();
78
79           _core->register_session(x.get());
80           reg()->register_obj(x);
81           x->obj_cap()->dec_refcnt(1);
82           ust()->vstack()->push_top(x.ptr());
83           ios << x->obj_cap();
84           return 0;
85         }
86       return -L4_ENODEV;
87     default:
88       return -L4_EBADPROTO;
89     }
90 }
91
92 void
93 Service::destroy()
94 {
95   printf("MAG: destroying the fb_client_service, holla\n");
96 }
97
98 Service::~Service()
99 {
100   printf("MAG: destroy FB svc\n");
101 }
102
103 static Service _fb_service("frame-buffer");
104
105 }