minor: is_device no longer needed, using dynamic_cast
[quarnos.git] / manes / manager.h
blob8f4a5d497165c65be6cc2a2f09d3bbe695391255
1 /* Quarn OS / Manes
3 * Manager class
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 #ifndef _MANAGER_H_
24 #define _MANAGER_H_
26 #include "creator.h"
27 #include "type.h"
28 #include "arch/low/irq.h"
29 #include "implementation.h"
30 #include "factory.h"
31 #include "root.h"
32 #include "libs/pointer.h"
34 namespace services {
35 class kernel_state;
38 namespace resources {
39 class did;
42 namespace manes {
43 class type;
45 /**
46 * @brief Main component manager.
48 * @details In most cases there is only one instance of this class. It stores
49 * pointers to all creators and information about all registered types.
50 * Additionally it provides simplified Manes interface to the client. This is
51 * the main class that clients are using in case of performing a Manes request.
53 class manager : public implementation {
54 private:
55 root *main;
56 factory *types;
58 arch::irq_op irqs;
60 public:
61 virtual bool initialize();
62 virtual bool type_added(type_name);
64 manager();
66 /**
67 * @brief Get specific component.
69 * @details Search in compontens list for the specified one. If none is
70 * found then ask for it each known that is able to maintain such component.
71 * @param name The name of requested component.
72 * @return Requested component.
74 virtual p<component> new_component(const type_name &name);
75 virtual p<component> get_component(const component_name &name);
77 virtual p<component> get_component(const char *cname);
79 /**
80 * @brief Get component specified by path.
82 * @details This method parses given path and then uses multiple invocations
83 * of get_component method to get specified component. This is the syntax
84 * of component path:
85 * @code
86 * /type,id/type,id/type,id
87 * @endcode
88 * @param path Path to the requested component.
89 * @return Requested component.
91 virtual p<component> get_by_path(const string &path);
93 /**
94 * @brief Get certain interface of the specific component.
96 * @details This is a part of simplified interface of Manes manager.
97 * It gets specified component using method get_by_path, then narrows
98 * it to the needed interface T.
99 * @param path Path to the requested component.
100 * @return Requested interface of the component.
102 template<typename T>
103 p<T> get(const string &path);
105 virtual void register_type(const char*,const char*,type::root_type, delegate<implementation*>*);
106 virtual void register_driver(const char*, const char*, type::root_type, delegate<implementation*>*, delegate<bool, resources::did*>);
109 * @brief Register new type in Manes.
111 * @details When given a pointer to a completely initialized type this function
112 * inserts that type into internal Manes database, so that it is available
113 * for all clients and operations on components of that type are possible.
114 * @param newtype Pointer to newly created type.
116 virtual void register_type(type *newtype);
119 * @brief Get type from Manes.
121 * @details This method looks for requested type in internal Manes database.
122 * An error will occur if type wasn't previously registered.
123 * @param name Name of the requested type.
124 * @return Requested type.
126 virtual type *get_type(type_name name);
128 virtual type *get_driver(resources::did *);
130 virtual services::kernel_state *get_state() const;
132 virtual arch::irq_op *get_low();
136 template<typename T>
137 p<T> manager::get(const string &path) {
138 return get_by_path(path)->get<T>();
143 #endif