5 * Copyright (C) 2008-2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include "services/kernel_state.h"
33 using namespace manes
;
35 p
<manec
> manec::instance
= (manec
*)0;
37 void manec::connect_manes(p
<root
> root_mgr
) {
39 types
= main
->get_component(component_name((type_name
)"factory",0))->get
<factory
>();
44 void manec::connect_manes() {
47 __asm__ ("int $0x32": "=a" (main
));
52 p
<manec
> manec::get() {
53 if (!instance
.valid())
59 p
<services::kernel_state
> manec::state() {
61 kstate
= get
<services::kernel_state
>("/kernel_state");
65 bool manec::far_calls() {
69 error
*manec::err_msg(const string x
) {
70 return state()->new_error(x
);
74 p
<component
> manec::new_component(const type_name
&name
) {
75 return main
->new_component(name
);
78 p
<component
> manec::get_component(const component_name
&obj
) {
79 return main
->get_component(obj
);
82 p
<component
> manec::get_component(const string cname
) {
83 return get_component(component_name((type_name
)cname
,0));
86 p
<component
> manec::get_by_path(const string
&tpath
) {
87 char *path
= new char[strlen(tpath
) + 1];
92 char *dep_res
= (char*)0;
94 char *specific_name
= (char*)0;
100 main_res
= &(path
[j
]);
103 if (path
[i
] == ',') {
106 if (string::is_digit(path
[i
]))
107 for (; path
[i
] && path
[i
] != '/'; i
++)
108 num
= num
* 10 + path
[i
] - '0';
110 specific_name
= &path
[i
];
111 } else if (path
[i
] == '/') {
113 dep_res
= &(path
[j
]);
117 for (; path
[i
] && path
[i
] != ',' && path
[i
] != '/'; i
++);
123 return get_component(component_name(type_name(main_res
), num
));
125 return get_component(component_name(type_name(main_res
), specific_name
));
128 void manec::register_type(const string me
, const string parent
, type::root_type tpe
, delegate
<p
<implementation
> > deleg
) {
129 type_name
bus_name(me
, true);
130 register_type(new type(tpe
, (type_name
)parent
, bus_name
, deleg
));
133 void manec::register_driver(const string me
,const string parent
,type::root_type tpe
, delegate
<p
<implementation
> > deleg
, delegate
<bool, p
<resources::did
> > check
) {
134 type_name
bus_name(me
, true);
135 register_type(new driver(tpe
, (type_name
)parent
, bus_name
, deleg
, check
));
136 main
->type_added(bus_name
);
139 void manec::register_abstract(const string me
, const string parent
) {
140 type_name
abstr_name(me
, true);
141 register_type(new abstract(type::device
, (type_name
)parent
, abstr_name
));
144 void manec::register_type(p
<type
> tpe
) {
145 assert("manager: incorrect type pointer", tpe
== 0);
147 types
->register_impl(tpe
);
150 p
<type
> manec::get_type(const type_name
&tpe
) {
151 return types
->get_component(component_name((type_name
)"type",tpe
.get_textname()))->get
<type
>();
154 p
<type
> manec::get_driver(p
<resources::did
> id
) {
155 for (int i
= 0; i
< types
->count(); i
++) {
156 p
<type
> drv
= types
->get_component(component_name((type_name
)"driver", i
))->get
<type
>();
157 if (drv
.cast
<driver
>().valid() && drv
.cast
<driver
>()->check_device(id
))
164 arch::irq_op
*manec::get_low() {
168 p
<root
> manec::get_root() {
173 p
<factory
> manec::get_factory() {