3 * Managed Execution 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.
26 #include "component.h"
27 #include "libs/pointer.h"
28 #include "arch/low/irq.h"
43 /* Managed Execution Controller */
49 services::kernel_state
*kstate
;
55 static manec
*instance
;
59 virtual p
<component
> new_component(const type_name
&name
);
60 virtual p
<component
> get_component(const component_name
&name
);
61 virtual p
<component
> get_component(const char *cname
);
64 * @brief Get component specified by path.
66 * @details This method parses given path and then uses multiple invocations
67 * of get_component method to get specified component. This is the syntax
70 * /type,id/type,id/type,id
72 * @param path Path to the requested component.
73 * @return Requested component.
75 virtual p
<component
> get_by_path(const string
&path
);
79 * @brief Get certain interface of the specific component.
81 * @details This is a part of simplified interface of Manes manager.
82 * It gets specified component using method get_by_path, then narrows
83 * it to the needed interface T.
84 * @param path Path to the requested component.
85 * @return Requested interface of the component.
88 p
<T
> get(const string
&path
);
90 virtual void register_type(const char*,const char*,type::root_type
, delegate
<implementation
*>*);
91 virtual void register_driver(const char*, const char*, type::root_type
, delegate
<implementation
*>*, delegate
<bool, resources::did
*>);
94 * @brief Register new type in Manes.
96 * @details When given a pointer to a completely initialized type this function
97 * inserts that type into internal Manes database, so that it is available
98 * for all clients and operations on components of that type are possible.
99 * @param newtype Pointer to newly created type.
101 virtual void register_type(type
*newtype
);
104 * @brief Get type from Manes.
106 * @details This method looks for requested type in internal Manes database.
107 * An error will occur if type wasn't previously registered.
108 * @param name Name of the requested type.
109 * @return Requested type.
111 virtual type
*get_type(type_name name
);
113 virtual type
*get_driver(resources::did
*);
115 virtual arch::irq_op
*get_low();
118 virtual void connect_manes(root
*root_mgr
);
119 static void connect_manes();
123 virtual root
*get_root();
124 virtual factory
*get_factory();
126 virtual services::kernel_state
*state();
128 virtual error
*err_msg(const char *x
);
133 void register_type(const char*, const char*, type::root_type
);
136 void register_driver(const char*, const char*, type::root_type
, delegate
<bool, resources::did
*>);
138 virtual void register_abstract(const char*, const char*);
141 template<typename T
, typename U
>
147 void manec::register_type(const char *me
, const char *parent
, type::root_type tpe
) {
148 delegate
<implementation
*> *bus_create
= new delegate
<implementation
*>;
149 bus_create
->function(create_object
<implementation
, T
>);
150 register_type(me
, parent
, tpe
, bus_create
);
152 /* type_name bus_name(me, true);
153 delegate<implementation *> *bus_create = new delegate<implementation *>;
154 bus_create->function(create_object<implementation, T>);
155 manec::get()->register_type(new type(tpe, (type_name)parent, bus_name, *bus_create));*/
159 void manec::register_driver(const char *me
, const char *parent
, type::root_type tpe
, delegate
<bool, resources::did
*> check
) {
160 delegate
<implementation
*> *bus_create
= new delegate
<implementation
*>;
161 bus_create
->function(create_object
<implementation
, T
>);
162 register_driver(me
, parent
, tpe
, bus_create
, check
);
166 p
<T
> manec::get(const string
&path
) {
167 return get_by_path(path
)->get
<T
>();
171 T
*component::get() const {
172 if (!manec::get()->far_calls())
173 return dynamic_cast<T
*>(get_implementation());
175 return (T
*)get_stub();