usb: getting string descriptors, minor improvements
[quarnos.git] / manes / manec.cpp
blob2c3b88d1b2d01a4cae6612f403b184b0db73a2ed
1 /* Quarn OS / Manes
3 * Manes Controller
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.
23 #include "cds/creator.h"
24 #include "manec.h"
25 #include "cds/type.h"
26 #include "error.h"
27 #include "cds/root.h"
28 #include "cds/driver.h"
29 #include "cds/factory.h"
30 #include "cds/abstract.h"
31 #include "services/kernel_state.h"
33 using namespace manes;
34 using namespace manes::cds;
36 p<component> manec::comp = (component*)0;
37 p<manec> manec::instance = (manec*)0;
39 manec::manec() : usermode(false) {}
41 void manec::connect_manes(p<root> root_mgr) {
42 main = root_mgr;
43 types = main->get_component(component_name::from_path("/factory"));
46 void manec::connect_manes() {
47 manec *main;
49 __asm__ ("int $0x32": "=a" (main));
51 instance = main;
52 main->usermode = true;
55 p<manec> manec::get() {
56 if (!instance.valid()) {
57 instance = new manec;
58 // p<type> tpe = new abstract(type::zero, type_name("nme",true), type_name("nme",true));
59 // comp = new component((component*)0, tpe, instance.cast<implementation>());
62 return instance; //comp->get<manec>();
65 p<services::kernel_state> manec::state() {
66 if (!kstate.valid())
67 kstate = get<services::kernel_state>("/kernel_state");
68 return kstate;
71 bool manec::far_calls() {
72 return usermode;
73 }*/
75 p<error> manec::err_msg(const string &x) {
76 return state()->new_error(x);
79 p<component> manec::get_component(const component_name &obj) {
80 return main->get_component(obj);
83 p<component> manec::get_component(const string cname) {
84 return get_component(component_name::from_index(cname,0));
87 p<component> manec::get_by_path(const string &tpath) {
88 return get_component(component_name::from_path(tpath));
91 void manec::register_type(const string &me, const string &parent, delegate<p<component> > deleg) {
92 register_type(new type(component_name::from_path((string)"/type," + me), component_name::from_path((string)"/type," + parent), deleg));
95 void manec::register_driver(const string &me,const string &parent, delegate<p<component> > deleg, delegate<bool, p<resources::did> > check) {
96 register_type(new driver(component_name::from_path((string)"/type," + me), component_name::from_path((string)"/type," + parent), deleg, check));
97 main->type_added(component_name::from_path((string)"/type," + me));
100 void manec::register_abstract(const string &me, const string &parent) {
101 register_type(new abstract(component_name::from_path((string)"/type," + me), component_name::from_path((string)"/type," + parent)));
104 void manec::register_type(p<type> tpe) {
105 if (!tpe.valid())
106 throw new argument_null_exception();
108 types->add_existing(tpe);
111 p<type> manec::get_type(const component_name &tpe) {
112 return types->get_component(tpe).cast<type>();
115 p<type> manec::get_driver(p<resources::did> id) {
116 for (int i = 0; i < types->count(); i++) {
117 p<type> drv = types->get_component(component_name::from_index("driver", i)).cast<type>();
118 if (drv.cast<driver>().valid() && drv.cast<driver>()->check_device(id))
119 return drv;
122 // throw new driver_not_found_exception();
123 return p<type>::invalid;
126 arch::irq_op *manec::get_low() {
127 return &irqs;
130 p<root> manec::get_root() {
131 return main;
135 p<factory> manec::get_factory() {
136 return types;