component distribution system introduced
[quarnos.git] / manes / cds / creator.h
blob9b8eb806c87ea4bcb6e12366a7683974a9ebe2c9
1 /* Quarn OS / Manes
3 * Creator 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 _CREATOR_H_
24 #define _CREATOR_H_
26 #include "component.h"
27 #include "component_name.h"
29 #include "libs/pointer.h"
30 #include "libs/list.h"
32 namespace manes {
33 namespace cds {
34 /**
35 * @brief Components creator.
36 * @details This is an abstract base class for all component creators.
37 * It stores list of created components and provides interface needed
38 * to manage them.
40 class creator : public component {
41 protected:
42 /**
43 * @brief List of components stored by creator.
45 list<p<component> > components;
47 public:
48 creator() {}
49 creator(p<type> tpe) : component(tpe) {}
51 /**
52 * @brief Performs creator initialization.
53 * @details This method is called once creator is construced and
54 * ready to work since Manes does not allow some things to be
55 * performed in constructors.
56 * @return information if initialization was successful
58 virtual bool initialize();
60 /**
61 * @brief New type was registered in the system.
62 * @details This method is called each time new type is registered,
63 * what allows creator to perform any actions that such event
64 * may require. It is commonly used by bus classes that support
65 * lazy drivers loading.
66 * @param newtype name of recently registered type
67 * @return ignored value
69 virtual bool type_added(const component_name &newtype);
71 /**
72 * @brief Create new component.
73 * @details Create new component of specified type. Instances of
74 * class type provides interface that allow to create an object
75 * of specific type. To get type from type_name manager is used.
76 * Notice that some subclasses may make more restricted or
77 * completely impossible creation of new components.
78 * @param name type of requested component
79 * @return created component
81 virtual p<component> new_component(const component_name &name);
83 virtual p<component> add_existing(p<component>);
85 /**
86 * @brief Returns number of components stored in this creator.
87 * @return components count
89 virtual int count() const;
91 /**
92 * @todo Implement this method.
94 virtual void delete_component(const component_name&);
96 /**
97 * @brief Get an exsiting component.
98 * @details Search in components list for a specifed component.
99 * In most cases this function should not be invoced directly, but
100 * client should use manager's method manager::get_component.
101 * @param name name of the requested component
102 * @return requested component
104 virtual p<component> get_component(const component_name &name);
109 #endif