From 9a7fd1655c3bedd5d7c43979fdef5f7f24d850f5 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Fri, 3 Jul 2009 00:13:30 +0200 Subject: [PATCH] component distribution system introduced TODO: * minor bugs remain in the system --- actors/actor.cpp | 14 +-- actors/actor.h | 9 +- actors/director.cpp | 4 +- actors/director.h | 6 +- actors/roundrobin.cpp | 2 +- arch/x86/console.cpp | 2 +- arch/x86/isa.cpp | 15 ++-- arch/x86/pci.cpp | 10 +-- hydra/quarn/uapi.cpp | 5 +- libs/pointer.h | 7 ++ libs/string.cpp | 2 +- libs/string.h | 6 +- manes/Makefile | 16 ++-- manes/access_control.cpp | 34 ------- manes/access_control.h | 43 --------- manes/{ => cds}/abstract.h | 22 +++-- services/server.cpp => manes/cds/component.cpp | 42 ++++----- manes/{type_name.h => cds/component.h} | 54 ++++++----- manes/{ => cds}/component_name.cpp | 80 +++++++++++------ manes/cds/component_name.h | 88 ++++++++++++++++++ manes/{ => cds}/creator.cpp | 19 ++-- manes/cds/creator.h | 109 +++++++++++++++++++++++ manes/{ => cds}/driver.h | 37 ++++---- manes/{ => cds}/factory.cpp | 51 ++++------- manes/cds/factory.h | 70 +++++++++++++++ manes/{ => cds}/root.cpp | 27 ++++-- manes/{ => cds}/root.h | 40 +++++---- manes/{ => cds}/type.cpp | 59 ++++--------- manes/cds/type.h | 78 ++++++++++++++++ manes/component.cpp | 72 --------------- manes/component.h | 85 ------------------ manes/component_name.h | 58 ------------ manes/creator.h | 103 --------------------- manes/factory.h | 65 -------------- manes/implementation.cpp | 34 ------- manes/implementation.h | 68 -------------- manes/manec.cpp | 47 +++++----- manes/manec.h | 64 ++++++-------- manes/manei.cpp | 45 ++++------ manes/manei.h | 10 +-- manes/mem_alloc.cpp | 2 +- manes/name.h | 33 ------- manes/start.cpp | 13 ++- manes/type.h | 118 ------------------------- manes/type_name.cpp | 54 ----------- modules/Makefile | 2 +- modules/elf.cpp | 2 +- modules/loader.cpp | 19 ++-- modules/loader.h | 9 +- modules/module.cpp | 2 +- modules/module.h | 2 +- modules/modules_start.cpp | 1 - resources/Makefile | 2 +- resources/bus.cpp | 17 ++-- resources/bus.h | 14 +-- resources/device.h | 4 +- resources/fat.cpp | 10 +-- resources/fat.h | 3 - resources/fdc.cpp | 3 +- resources/file.cpp | 2 +- resources/file.h | 4 +- resources/foma.cpp | 3 +- resources/foma.h | 2 - resources/fs.cpp | 9 +- resources/fs.h | 6 +- resources/isa.cpp | 3 +- resources/keybscr.cpp | 2 +- resources/memm.h | 5 +- resources/ne2k.cpp | 2 +- resources/pci.cpp | 6 +- resources/pci.h | 2 +- resources/physmem.cpp | 10 +-- resources/physmem.h | 3 - resources/pio.cpp | 2 +- resources/rs232.cpp | 3 +- resources/rtl8139.cpp | 2 +- resources/slob.cpp | 2 +- resources/speaker.cpp | 2 +- resources/spinlock.cpp | 53 ----------- resources/spinlock.h | 41 --------- resources/uhci.cpp | 5 +- resources/unknown.cpp | 2 +- resources/usb.cpp | 2 +- resources/virtual_bus.cpp | 7 +- resources/virtual_bus.h | 1 - services/asynch_tasks.cpp | 4 +- services/asynch_tasks.h | 4 +- services/early_logger.cpp | 9 +- services/early_logger.h | 2 +- services/interrupt_manager.cpp | 2 +- services/interrupt_manager.h | 4 +- services/kernel_state.cpp | 2 +- services/kernel_state.h | 4 +- services/logger.h | 6 +- services/server.cpp | 20 ++--- services/server.h | 10 +-- services/stats.cpp | 2 +- services/stats.h | 4 +- services/timer.cpp | 2 +- services/timer.h | 4 +- services/tty_logger.cpp | 4 +- services/tty_logger.h | 2 +- services/unmangler.cpp | 2 +- services/unmangler.h | 2 +- 104 files changed, 808 insertions(+), 1374 deletions(-) delete mode 100644 manes/access_control.cpp delete mode 100644 manes/access_control.h rename manes/{ => cds}/abstract.h (73%) copy services/server.cpp => manes/cds/component.cpp (56%) rename manes/{type_name.h => cds/component.h} (57%) rename manes/{ => cds}/component_name.cpp (57%) create mode 100644 manes/cds/component_name.h rename manes/{ => cds}/creator.cpp (79%) create mode 100644 manes/cds/creator.h rename manes/{ => cds}/driver.h (62%) rename manes/{ => cds}/factory.cpp (51%) create mode 100644 manes/cds/factory.h rename manes/{ => cds}/root.cpp (64%) rename manes/{ => cds}/root.h (56%) rename manes/{ => cds}/type.cpp (51%) create mode 100644 manes/cds/type.h delete mode 100644 manes/component.cpp delete mode 100644 manes/component.h delete mode 100644 manes/component_name.h delete mode 100644 manes/creator.h delete mode 100644 manes/factory.h delete mode 100644 manes/implementation.cpp delete mode 100644 manes/implementation.h delete mode 100644 manes/name.h delete mode 100644 manes/type.h delete mode 100644 manes/type_name.cpp delete mode 100644 resources/spinlock.cpp delete mode 100644 resources/spinlock.h diff --git a/actors/actor.cpp b/actors/actor.cpp index fca6558..d200452 100644 --- a/actors/actor.cpp +++ b/actors/actor.cpp @@ -23,7 +23,6 @@ #include "actor.h" #include "manes/error.h" #include "manes/manec.h" -#include "manes/access_control.h" #include "arch/low/memory.h" #include "arch/low/taskswitch.h" @@ -47,21 +46,10 @@ void actor::execute() { } void actor::register_type() { - manes::manec::get()->register_type("actor", "director", manes::type::actor); + manes::manec::get()->register_type("actor", "none"); } unsigned int actor::get_tss() { return tss_selector; } -void actor::locked(access_control *lock) { - locks.add(lock); -} - -void actor::unlocked(access_control *lock) { - for (int i = 0; i < locks.get_count(); i++) { - if (locks[i] == lock) { - locks.remove(i); - } - } -} diff --git a/actors/actor.h b/actors/actor.h index 1f74fa1..3fd4bc9 100644 --- a/actors/actor.h +++ b/actors/actor.h @@ -26,12 +26,12 @@ #include "libs/delegate.h" #include "libs/list.h" #include "libs/pointer.h" -#include "manes/implementation.h" +#include "manes/cds/component.h" class access_control; namespace actors { - class actor : public manes::implementation { + class actor : public manes::cds::component { private: p parent; @@ -40,8 +40,6 @@ namespace actors { //list > exec_files; - list locks; - // p env; public: actor(); @@ -51,9 +49,6 @@ namespace actors { virtual void execute(); virtual void set(delegate); - virtual void locked(access_control *); - virtual void unlocked(access_control *); - static void register_type(); }; } diff --git a/actors/director.cpp b/actors/director.cpp index a3476da..606e683 100644 --- a/actors/director.cpp +++ b/actors/director.cpp @@ -33,7 +33,7 @@ bool director::initialize() { return true; } -bool director::type_added(manes::type_name) { +bool director::type_added(manes::cds::component_name) { return true; } @@ -60,6 +60,6 @@ p director::get_current() const { } void director::register_type() { - manes::manec::get()->register_type("director", "manec", manes::type::director); + manes::manec::get()->register_type("director", "manec"); } diff --git a/actors/director.h b/actors/director.h index ba5e37f..9837690 100644 --- a/actors/director.h +++ b/actors/director.h @@ -23,7 +23,7 @@ #ifndef _DIRECTOR_H_ #define _DIRECTOR_H_ -#include "manes/creator.h" +#include "manes/cds/creator.h" #include "actor.h" #include "libs/fifo.h" @@ -31,7 +31,7 @@ #include "libs/delegate.h" namespace actors { - class director : public manes::creator { + class director : public manes::cds::creator { protected: fifo > execution_list; p current; @@ -40,7 +40,7 @@ namespace actors { public: bool initialize(); - bool type_added(manes::type_name); + bool type_added(manes::cds::component_name); virtual void start(p); virtual void launch(p); diff --git a/actors/roundrobin.cpp b/actors/roundrobin.cpp index bc9d8c5..311ce2e 100644 --- a/actors/roundrobin.cpp +++ b/actors/roundrobin.cpp @@ -50,6 +50,6 @@ void roundrobin::launch(p process) { } void roundrobin::register_type() { - manes::manec::get()->register_type("director", "manec", manes::type::director); + manes::manec::get()->register_type("director", "manec"); } diff --git a/arch/x86/console.cpp b/arch/x86/console.cpp index 814f373..b52bbb1 100644 --- a/arch/x86/console.cpp +++ b/arch/x86/console.cpp @@ -45,7 +45,7 @@ bool arch::keyboard_init(delegate kb_hndl) { shift = false; /* Set IRQ1 */ - manes::manec::get()->get("/interrupt_manager")->register_interrupt(0x21, delegate::function(keyboard_received)); + manes::manec::get()->get("/interrupt_manager");//->register_interrupt(0x21, delegate::function(keyboard_received)); return true; } diff --git a/arch/x86/isa.cpp b/arch/x86/isa.cpp index 98b683a..cad570b 100644 --- a/arch/x86/isa.cpp +++ b/arch/x86/isa.cpp @@ -35,6 +35,7 @@ using namespace arch; using namespace manes; +using namespace manes::cds; using namespace resources; int isa::scan_bus() { @@ -42,7 +43,7 @@ int isa::scan_bus() { /* Keyboard */ p tty0_addr = new isa_did(this); - p tty = new_component((type_name)"keybscr")->get(); + p tty = new_component(component_name::from_path("/type,keybscr")).cast(); if (tty->init_device(tty0_addr)) dev_count++; /* Get number of installed rs232 ports */ @@ -60,8 +61,8 @@ int isa::scan_bus() { component *c = new_component((manes::type_name)"rs232"); c->get()->init_device(com1_addr); } else {*/ - component *c = new_component((manes::type_name)"unknown"); - c->get()->init_device(com1_addr); + p c = new_component(component_name::from_path("/type,unknown")); + c.cast()->init_device(com1_addr); // } dev_count++; @@ -74,15 +75,15 @@ int isa::scan_bus() { com2_addr->irq = 0x23 ; com2_addr->set_ioport((int)*com2_base_port); - component *c = new_component((manes::type_name)"unknown"); - c->get()->init_device(com2_addr); + p c = new_component(component_name::from_path("/type,unknown")); + c.cast()->init_device(com2_addr); dev_count++; } /* Speaker */ p speak_addr = new isa_did(this); - p speak = new_component((type_name)"speaker")->get(); + p speak = new_component(component_name::from_path("/type,speaker")).cast(); speak->init_device(speak_addr); dev_count++; @@ -98,7 +99,7 @@ int isa::scan_bus() { fdc_addr->irq = 0x26; fdc_addr->set_ioport(0x3f0); fdc_addr->dma_channel = 2; - p ofdc = manec::get()->new_component((type_name)"fdc")->get(); + p ofdc = new_component(component_name::from_path("/type,fdc")).cast(); ofdc->init_device(fdc_addr); dev_count++; } diff --git a/arch/x86/pci.cpp b/arch/x86/pci.cpp index 7d862cb..41ff915 100644 --- a/arch/x86/pci.cpp +++ b/arch/x86/pci.cpp @@ -120,15 +120,15 @@ void pci::device_found(int _bus, int dev, int func) { id->device = dev; id->function = func; - p drv = manes::manec::get()->get_driver(id); + p drv = manes::manec::get()->get_driver(id); if (!drv.valid()) { - p c = new_component((manes::type_name)"unknown"); - c->get()->init_device(id.cast()); + p c = new_component(manes::cds::component_name::from_path("/type,unknown")); + c.cast()->init_device(id.cast()); } else { *id = alloc_resources(_bus, dev, func); - p c = new_component(drv->get_name()); - p cdev = c->get(); + p c = new_component(drv->get_name()); + p cdev = c.cast(); if (cdev.valid()) cdev->init_device(id); diff --git a/hydra/quarn/uapi.cpp b/hydra/quarn/uapi.cpp index 6898df3..0e31d61 100644 --- a/hydra/quarn/uapi.cpp +++ b/hydra/quarn/uapi.cpp @@ -22,6 +22,7 @@ #include "manes/manec.h" #include "services/logger.h" +#include "libs/stream.h" #include "resources/stream.h" #include "resources/fs.h" #include "resources/file.h" @@ -36,12 +37,12 @@ namespace hydra { } void _output::write(const char *x) { - resources::stream *tty = manes::manec::get()->get_component("keybscr")->get(); + resources::stream *tty = manes::manec::get()->get("/keybscr"); tty->write(buffer((void*)x, strlen(x))); } void _input::read(char *x, int size) { - resources::stream *tty = manes::manec::get()->get_component("keybscr")->get(); + resources::stream *tty = manes::manec::get()->get("/keybscr"); for (int i = 0; i < size; i++) { buffer buf = buffer::to_mem(x[i]); diff --git a/libs/pointer.h b/libs/pointer.h index d27ea01..db0bae4 100644 --- a/libs/pointer.h +++ b/libs/pointer.h @@ -97,6 +97,13 @@ public: return (pointer != (T*)0); } + template + bool is() { + if (dynamic_cast(pointer)) + return true; + return false; + } + void dispose() { if (!valid()) return; diff --git a/libs/string.cpp b/libs/string.cpp index 0765703..d7dc790 100644 --- a/libs/string.cpp +++ b/libs/string.cpp @@ -223,7 +223,7 @@ void string::operator=(const string &x) { strcpy(data, x.data); } -buffer string::to_mem() { +buffer string::to_mem() const { return buffer(data, strlen(data)); } diff --git a/libs/string.h b/libs/string.h index 3542072..e092ec6 100644 --- a/libs/string.h +++ b/libs/string.h @@ -55,6 +55,9 @@ public: bool operator==(const char*) const; bool operator==(const string&) const; + bool operator!=(const string&x) const { + return !operator==(x); + } operator const char*() const; @@ -66,10 +69,9 @@ public: void operator+=(const string&); void operator=(const string&); - static bool is_digit(char); - buffer to_mem(); + buffer to_mem() const; // void serialize(manes::ods::object_stream &ostr) { } //void deserialize(manes::ods::object_stream &ostr) { } diff --git a/manes/Makefile b/manes/Makefile index 3bce747..f86b75a 100644 --- a/manes/Makefile +++ b/manes/Makefile @@ -24,20 +24,17 @@ OBJS = error.o \ manec.o \ manei.o \ mem_alloc.o \ - component.o \ + cds/component.o \ runtime.o \ start.o \ - type.o \ - creator.o \ - type_name.o \ - implementation.o \ - component_name.o \ + cds/type.o \ + cds/creator.o \ + cds/component_name.o \ rtti.o \ - root.o \ + cds/root.o \ dyncast.o \ exception.o \ - factory.o \ - access_control.o + cds/factory.o manes: dep.d compile @@ -64,6 +61,7 @@ clean: @echo -e "\t\t[rm]\tmanes" @-rm -f dep.d @rm -f *.o + @rm -f cds/*.o ifeq ($(MAKECMDGOALS),) -include dep.d diff --git a/manes/access_control.cpp b/manes/access_control.cpp deleted file mode 100644 index 76a659e..0000000 --- a/manes/access_control.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Quarn OS - * - * Access control class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "access_control.h" -#include "manes/manec.h" -#include "actors/director.h" -#include "actors/actor.h" - -void access_control::register_lock() { - manes::manec::get()->get("/director")->get_current()->locked(this); -} - -void access_control::unregister_lock() { - manes::manec::get()->get("/driector")->get_current()->unlocked(this); -} diff --git a/manes/access_control.h b/manes/access_control.h deleted file mode 100644 index f1f67b6..0000000 --- a/manes/access_control.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Quarn OS - * - * Access control classes interface - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _ACCESS_CONTROL_H_ -#define _ACCESS_CONTROL_H_ - -class access_control { -protected: - void register_lock(); - void unregister_lock(); - -public: - typedef enum { - read_lock, - write_lock - } lock_type; - - virtual bool try_lock() = 0; - - virtual void lock(lock_type) = 0; - virtual void unlock() = 0; -}; - -#endif diff --git a/manes/abstract.h b/manes/cds/abstract.h similarity index 73% rename from manes/abstract.h rename to manes/cds/abstract.h index 24ca94a..da58040 100644 --- a/manes/abstract.h +++ b/manes/cds/abstract.h @@ -1,4 +1,4 @@ -/* Quarn OS / Manes +/* Quarn OS / Manes / CDS * * Abstract type class * @@ -26,16 +26,20 @@ #include "type.h" namespace manes { - class abstract : public type { - private: - delegate > pure_virtual; + namespace cds { + /** + * @brief Abstract type class + */ + class abstract : public type { + private: + delegate > pure_virtual; - public: - abstract(const root_type a, const type_name b, const type_name c) : - type(a, b, c, pure_virtual) { } + public: + abstract(const component_name &name, const component_name &base) : type(name, base, pure_virtual) { } - virtual ~abstract() { } - }; + virtual ~abstract() { } + }; + } } #endif diff --git a/services/server.cpp b/manes/cds/component.cpp similarity index 56% copy from services/server.cpp copy to manes/cds/component.cpp index 4a7dc82..216e9b6 100644 --- a/services/server.cpp +++ b/manes/cds/component.cpp @@ -1,6 +1,6 @@ -/* Quarn OS +/* Quarn OS / Manes * - * Server + * Component class * * Copyright (C) 2008-2009 Pawel Dziepak * @@ -20,32 +20,32 @@ * */ -#include "server.h" -#include "manes/creator.h" -#include "manes/type.h" +#include "component.h" #include "manes/manec.h" - -#include "libs/delegate.h" +#include "manes/typeinfo" +#include "manes/exception.h" using namespace manes; -using namespace services; +using namespace std; +using namespace manes::ods; +using namespace manes::cds; -bool server::initialize() { - return true; -} +component::component() : name(component_name::from_index("none",0)) {} -bool server::type_added(type_name) { - return true; -} +component::component(p _type) : + obj_type(_type), + name(component_name::from_index(_type->get_name().get_name(), 0)) {} -p server::get_component(const component_name &_name) { - p get = creator::get_component(_name); - if (!get.valid()) - get = new_component(_name.get_type_name()); +void component::set(p _type) { + obj_type = _type; + name = component_name::from_index(_type->get_name().get_name(), 0); +} - return get; +const component_name &component::get_name() const { + return name; } -void server::register_type() { - manec::get()->register_type("server", "manec", type::server); +p component::get_type() const { + return obj_type; } + diff --git a/manes/type_name.h b/manes/cds/component.h similarity index 57% rename from manes/type_name.h rename to manes/cds/component.h index d6d7a13..b199b71 100644 --- a/manes/type_name.h +++ b/manes/cds/component.h @@ -1,6 +1,6 @@ -/* Quarn OS / Manes +/* Quarn OS / Manes / CDS * - * Type name class + * Component class * * Copyright (C) 2008-2009 Pawel Dziepak * @@ -20,27 +20,41 @@ * */ -#ifndef _TYPE_NAME_H_ -#define _TYPE_NAME_H_ +#ifndef _COMPONENT_H_ +#define _COMPONENT_H_ -#include "libs/string.h" +#include "manes/ods/obj_ref.h" +#include "component_name.h" -namespace manes { - class type_name { - private: - string text_name; - - mutable unsigned int last_tcid; - - public: - type_name(const string); - type_name(const type_name &); +#include "libs/pointer.h" - unsigned int get_tcid() const; - string get_textname() const; - - bool operator==(const type_name&) const; - }; +namespace manes { + /** + * @brief Component Distribution System + */ + namespace cds { + class type; + + /** + * @brief Component + * + * @details Ths is a representation of component in CDS + */ + class component : public ods::obj_ref { + protected: + p obj_type; + + component_name name; + + public: + component(); + component(p); + void set(p); + + const component_name &get_name() const; + p get_type() const; + }; + } } #endif diff --git a/manes/component_name.cpp b/manes/cds/component_name.cpp similarity index 57% rename from manes/component_name.cpp rename to manes/cds/component_name.cpp index feda484..9cbe394 100644 --- a/manes/component_name.cpp +++ b/manes/cds/component_name.cpp @@ -21,37 +21,21 @@ */ #include "component_name.h" -#include "manec.h" -using namespace manes; - -component_name::component_name(const type_name _type, const string name, unsigned int index) : - type_n(_type), - type_index(index), - text_name(name) { } - -component_name::component_name(const type_name _type, unsigned int index) : - type_n(_type), - type_index(index) { } - -component_name::component_name(const type_name _type, const string name) : - type_n(_type), - text_name(name) { } +using namespace manes::cds; component_name::component_name(const component_name &x) : - type_n(x.type_n), type_index(x.type_index), - text_name(x.text_name) { } - -type_name component_name::get_type_name() const { - return type_n; + text_name(x.text_name) { + if (x.type_name) + type_name = new component_name(*x.type_name); } -p component_name::get_type() const { - return manec::get()->get_type(type_n); +const component_name &component_name::get_type() const { + return *type_name; } -unsigned int component_name::get_tindex() const { +unsigned int component_name::get_index() const { return type_index; } @@ -60,7 +44,14 @@ string component_name::get_name() const { } bool component_name::operator==(const component_name &x) const { - if (x.type_n == type_n && x.type_index == type_index) + if (!x.type_name && type_name) + return false; + if (x.type_name && !type_name) + return false; + + if (!x.type_name && !type_name && x.text_name == text_name) + return true; + if (*x.type_name == *type_name && x.text_name == text_name) return true; return false; } @@ -101,9 +92,44 @@ component_name component_name::from_path(const string &tpath) { break; } - return component_name(type_name(main_res), specific_name, num); + component_name cname; + + cname.type_name = new component_name; + cname.type_name->text_name = main_res; + if (strcmp(main_res, "type")) { + cname.type_name->type_name = new component_name; + cname.type_name->type_name->text_name = "type"; + } + if (specific_name) + cname.text_name = (string)specific_name; + else + cname.text_name = ""; + cname.type_index = num; + + return cname; +} + +component_name component_name::from_index(const string &tname, unsigned int i) { + component_name cname; + + cname.type_name = new component_name; + cname.type_name->text_name = tname; + cname.type_name->type_name = new component_name; + cname.type_name->type_name->text_name = "type"; + + cname.type_index = i; + + return cname; +} + +component_name::component_name() : text_name("") {} + +void component_name::serialize(ods::object_stream &ostr) { + } -component_name component_name::new_name(const type_name tname, const string &name) { - return component_name(tname, name, tname.get_tcid()); +void component_name::deserialize(ods::object_stream &ostr) { + } + +const component_name component_name::invalid; diff --git a/manes/cds/component_name.h b/manes/cds/component_name.h new file mode 100644 index 0000000..75b4787 --- /dev/null +++ b/manes/cds/component_name.h @@ -0,0 +1,88 @@ +/* Quarn OS / Manes / CDS + * + * Component name class + * + * Copyright (C) 2008-2009 Pawel Dziepak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef _COMPONENT_NAME_H_ +#define _COMPONENT_NAME_H_ + +#include "manes/ods/obj_val.h" + +#include "libs/string.h" + +namespace manes { + namespace cds { + /** + * @brief Component name + * + * @details Instances of this class are used to explicitly identify + * the component in the CDS network. + */ + class component_name : public ods::obj_val { + private: + component_name *type_name; + unsigned int type_index; + + string text_name; + + component_name(); + public: + component_name(const component_name &); + + virtual ~component_name() {} + + /** + * Get component_name of component's type + */ + const component_name &get_type() const; + + /** + * Get component's text name + */ + string get_name() const; + + /** + * Get component's index + */ + unsigned int get_index() const; + + bool operator==(const component_name&) const; + + /** + * Create component_name from path + * + * @code /type,name/type,index @endcode + */ + static component_name from_path(const string &); + + /** + * Create component_name from index + */ + static component_name from_index(const string &, unsigned int); + + static const component_name invalid; + + virtual void serialize(ods::object_stream &ostr); + virtual void deserialize(ods::object_stream &ostr); + }; + } +} + +#endif diff --git a/manes/creator.cpp b/manes/cds/creator.cpp similarity index 79% rename from manes/creator.cpp rename to manes/cds/creator.cpp index 7082bb4..88c066e 100644 --- a/manes/creator.cpp +++ b/manes/cds/creator.cpp @@ -21,15 +21,16 @@ */ #include "creator.h" -#include "manec.h" +#include "manes/manec.h" using namespace manes; +using namespace manes::cds; bool creator::initialize() { return true; } -bool creator::type_added(const type_name&) { +bool creator::type_added(const component_name&) { return true; } @@ -37,22 +38,22 @@ int creator::count() const { return components.get_count(); } -p creator::new_component(const type_name &obj_type) { - p comp = manec::get()->get_type(obj_type)->create_component((component*)this); +p creator::new_component(const component_name &obj_type) { + p comp = manec::get()->get_type(obj_type)->create_component(); components.add(comp); return comp; } void creator::delete_component(const component_name &obj) { for (int i = 0; i < components.get_count(); i++) - if (*components[i]->get_name() == obj) + if (components[i]->get_name() == obj) return components.remove(i); } p creator::get_component(const component_name &obj) { for (int i = 0, j = 0; i < components.get_count(); i++) { - if (*components[i]->get_name() == obj) { - if ((unsigned int)j == obj.get_tindex()) { + if (components[i]->get_name() == obj) { + if ((unsigned int)j == obj.get_index()) { return components[i]; } else { j++; @@ -62,3 +63,7 @@ p creator::get_component(const component_name &obj) { return p::invalid; } + +p creator::add_existing(p comp) { + return comp; +} diff --git a/manes/cds/creator.h b/manes/cds/creator.h new file mode 100644 index 0000000..9b8eb80 --- /dev/null +++ b/manes/cds/creator.h @@ -0,0 +1,109 @@ +/* Quarn OS / Manes + * + * Creator class + * + * Copyright (C) 2008-2009 Pawel Dziepak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef _CREATOR_H_ +#define _CREATOR_H_ + +#include "component.h" +#include "component_name.h" + +#include "libs/pointer.h" +#include "libs/list.h" + +namespace manes { + namespace cds { + /** + * @brief Components creator. + * @details This is an abstract base class for all component creators. + * It stores list of created components and provides interface needed + * to manage them. + */ + class creator : public component { + protected: + /** + * @brief List of components stored by creator. + */ + list > components; + + public: + creator() {} + creator(p tpe) : component(tpe) {} + + /** + * @brief Performs creator initialization. + * @details This method is called once creator is construced and + * ready to work since Manes does not allow some things to be + * performed in constructors. + * @return information if initialization was successful + */ + virtual bool initialize(); + + /** + * @brief New type was registered in the system. + * @details This method is called each time new type is registered, + * what allows creator to perform any actions that such event + * may require. It is commonly used by bus classes that support + * lazy drivers loading. + * @param newtype name of recently registered type + * @return ignored value + */ + virtual bool type_added(const component_name &newtype); + + /** + * @brief Create new component. + * @details Create new component of specified type. Instances of + * class type provides interface that allow to create an object + * of specific type. To get type from type_name manager is used. + * Notice that some subclasses may make more restricted or + * completely impossible creation of new components. + * @param name type of requested component + * @return created component + */ + virtual p new_component(const component_name &name); + + virtual p add_existing(p); + + /** + * @brief Returns number of components stored in this creator. + * @return components count + */ + virtual int count() const; + + /** + * @todo Implement this method. + */ + virtual void delete_component(const component_name&); + + /** + * @brief Get an exsiting component. + * @details Search in components list for a specifed component. + * In most cases this function should not be invoced directly, but + * client should use manager's method manager::get_component. + * @param name name of the requested component + * @return requested component + */ + virtual p get_component(const component_name &name); + }; + } +} + +#endif diff --git a/manes/driver.h b/manes/cds/driver.h similarity index 62% rename from manes/driver.h rename to manes/cds/driver.h index d41ca60..4b2097c 100644 --- a/manes/driver.h +++ b/manes/cds/driver.h @@ -31,21 +31,28 @@ namespace resources { } namespace manes { - class driver : public type { - protected: - delegate > recognize_device; - - public: - driver(const root_type a, const type_name b, const type_name c, - const delegate > d, const delegate > e) : - type(a, b, c, d), recognize_device(e) { } - - virtual ~driver() {} - - virtual bool check_device(p id) { - return recognize_device(id); - } - }; + namespace cds { + /** + * @brief Driver class + */ + class driver : public type { + protected: + delegate > recognize_device; + + public: + driver(const component_name &name, const component_name &base, delegate > create, delegate > recognize) : + type(name, base, create), recognize_device(recognize) { } + + virtual ~driver() {} + + /** + * Check if device is supported by the driver + */ + virtual bool check_device(p id) { + return recognize_device(id); + } + }; + } } #endif diff --git a/manes/factory.cpp b/manes/cds/factory.cpp similarity index 51% rename from manes/factory.cpp rename to manes/cds/factory.cpp index 87b222b..744b967 100644 --- a/manes/factory.cpp +++ b/manes/cds/factory.cpp @@ -1,4 +1,4 @@ -/* Quarn OS / Manes +/* Quarn OS / Manes / CDS * * Factory * @@ -22,50 +22,35 @@ #include "factory.h" -using namespace manes; +using namespace manes::cds; -bool factory::initialize() { - /* Create dummy type*/ - string str0("type"); - type_name mm_tname(str0); - - delegate > mm_create; - - string str("factory"); - type_name mm_bname(str); - - type *base_type = new type(type::ctype, mm_bname, mm_tname, mm_create); - register_impl(base_type); - - return true; -} - -p factory::new_component(const type_name &obj_type) { -/* p comp = root_type->create_component((component*)this); - - - components.add(comp); - return comp;*/ - return (component*)0; +p factory::new_component(const component_name &obj_type) { + throw new not_supported_exception; } p factory::get_component(const component_name &obj) { - if (obj.get_type_name().get_textname() == "type") { + if (obj.get_type().get_name() == "type") { /* Client looks for type with a certain name */ for (int i = 0; i < components.get_count(); i++) - if (components[i]->get_type()->get_name().get_textname() == obj.get_name()) + if (components[i]->get_name() == obj) return components[i]; - } else + + } else if (obj.get_type().get_name() == "driver") { /* Clients looks for appropiate driver and uses index to get type */ - return components[obj.get_tindex()]; + return components[obj.get_index()]; + } - throw new type_not_found_exception((const char*)((string)"Attempt to get not existing type: " + obj.get_name())); + return p::invalid; } -void factory::register_impl(p tpe) { - p comp = new component((component*)this, tpe, tpe.cast()); - components.add(comp); +p factory::add_existing(p tpe) { + if (tpe.is()) + components.add(tpe); + else + throw new argument_exception; + + return tpe; } diff --git a/manes/cds/factory.h b/manes/cds/factory.h new file mode 100644 index 0000000..9dda463 --- /dev/null +++ b/manes/cds/factory.h @@ -0,0 +1,70 @@ +/* Quarn OS / Manes + * + * Factory + * + * Copyright (C) 2009 Pawel Dziepak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef _FACTORY_H_ +#define _FACTORY_H_ + +#include "type.h" +#include "creator.h" + +namespace manes { + namespace cds { + /** + * @brief Types manager + * @details This is main type manager in Manes. At leas one insance + * of this class exists and is created by manei. In most cases + * construction of such class is performed manually, not using + * automatic Manes mechanisms. + * @see manei + */ + class factory : public creator { + public: + factory(){} + factory(p tpe) : creator(tpe) {} + + /** + * @brief Not supported + */ + virtual p new_component(const component_name &name); + + /** + * @brief Get the specified type + * + * @details This function overrides base behavior introducing mechanisms + * necessary to correctly store and retrieve types from database. + */ + virtual p get_component(const component_name &name); + + /** + * @brief Register type in system. + * @details This is a decorator that allows client to get rid + * off unecessary code required when any other class instances are + * created. In this case there is only need to provide factory + * with an existing instance of type class. + * @param newtype type to be registered + */ + virtual p add_existing(p); + }; + } +} + +#endif diff --git a/manes/root.cpp b/manes/cds/root.cpp similarity index 64% rename from manes/root.cpp rename to manes/cds/root.cpp index 24e5163..ee0b30f 100644 --- a/manes/root.cpp +++ b/manes/cds/root.cpp @@ -21,9 +21,11 @@ */ #include "root.h" -#include "error.h" +#include "services/server.h" +#include "modules/loader.h" +#include "factory.h" -using namespace manes; +using namespace manes::cds; bool root::initialize(p comp) { components.add(comp); @@ -31,10 +33,10 @@ bool root::initialize(p comp) { return true; } -bool root::type_added(type_name ntype) { +bool root::type_added(const component_name &ntype) { p creat; for (int i = 0; i < components.get_count(); i++) - if ((creat = components[i]->get()).valid()) + if ((creat = components[i].cast()).valid()) creat->type_added(ntype); return true; @@ -46,11 +48,18 @@ p root::get_component(const component_name &obj) { if (comp.valid()) return comp; - for (int i = 0; i < components.get_count(); i++) - if (components[i]->get_type()->get_child_type() == obj.get_type()->get_root_type() - && components[i]->get_type()->get_child_type() != type::zero) - if ((comp = components[i]->get()->get_component(obj)).valid()) + for (int i = 0; i < components.get_count(); i++) { + if (components[i].is()) { + if ((comp = components[i].cast()->get_component(obj)).valid()) { return comp; + } + } + } + + return p::invalid; +// throw new component_not_found_exception((const char*)((string)"Attempt to get not existing compontnt" + obj.get_name() + ", " + obj.get_type().get_name())); +} - throw new component_not_found_exception((const char*)((string)"Attempt to get not existing compontnt" + obj.get_name() + ", " + obj.get_type_name().get_textname())); +p root::add_existing(p comp) { + return comp; } diff --git a/manes/root.h b/manes/cds/root.h similarity index 56% rename from manes/root.h rename to manes/cds/root.h index dc4449c..506a280 100644 --- a/manes/root.h +++ b/manes/cds/root.h @@ -28,27 +28,31 @@ #include "libs/pointer.h" namespace manes { - /** - * @brief Main component creator. - * - * @details In most cases there is only one instance of this class. It stores - * pointers to all child-creators. - */ - class root : public creator { - public: - virtual bool initialize(p); - virtual bool type_added(type_name); - + namespace cds { /** - * @brief Get specific component. + * @brief Main component creator. * - * @details Search in compontens list for the specified one. If none is - * found then ask for it each known that is able to maintain such component. - * @param name The name of requested component. - * @return Requested component. + * @details In most cases there is only one instance of this class. It stores + * pointers to all child-creators. */ - virtual p get_component(const component_name &name); - }; + class root : public creator { + public: + virtual bool initialize(p); + virtual bool type_added(const component_name &ntype); + + /** + * @brief Get specific component. + * + * @details Search in compontens list for the specified one. If none is + * found then ask for it each known that is able to maintain such component. + * @param name The name of requested component. + * @return Requested component. + */ + virtual p get_component(const component_name &name); + + virtual p add_existing(p); + }; + } } #endif diff --git a/manes/type.cpp b/manes/cds/type.cpp similarity index 51% rename from manes/type.cpp rename to manes/cds/type.cpp index af04f21..b0e1b16 100644 --- a/manes/type.cpp +++ b/manes/cds/type.cpp @@ -21,59 +21,33 @@ */ #include "component.h" -#include "implementation.h" #include "type.h" -#include "error.h" +#include "manes/error.h" #include "factory.h" #include "abstract.h" #include "libs/string.h" -#include "manec.h" +#include "manes/manec.h" using namespace manes; +using namespace manes::cds; -type::type(const root_type rtype, const type_name _base, const type_name _me, /*unit_test _test,*/ const delegate > creat) : - main_type(rtype), +type::type(const component_name &_name, const component_name &_base, const delegate > creat) : base(_base), - me(_me), - create_impl(creat) {} - -type::type(const type &x) : - main_type(x.main_type), - base(x.base), - me(x.me), - create_impl(x.create_impl) {} - -type_name type::get_name() const { - return me; -} - -type::root_type type::get_root_type() const { - return main_type; + create_impl(creat) { + this->name = _name; } -type::root_type type::get_child_type() const { - switch (main_type) { - case server : return service; - case bus : return device; - case mem_alloc : return buffer; - case loader : return module; - case filesystem : return file; - case factory : return ctype; - default : return zero; - }; -} - -type_name type::get_base_type() const { +component_name type::get_base() const { return base; } -bool type::is(const type_name &x) const { - if (x == me) +bool type::is(const component_name &x) const { + if (x == name) return true; - p tpe = manec::get()->get_factory()->get_component(component_name((type_name)"type", base.get_textname()))->get(); + p tpe = manec::get()->get_factory()->get_component(component_name::from_path((string)"/type," + base.get_name())).cast(); if (!tpe.cast().valid()) return false; @@ -83,16 +57,17 @@ bool type::is(const type_name &x) const { return tpe->is(x); } -p type::create_component(p parent) { - assert("type: attempt to create implementation of abstract type", create_impl.null()); +p type::create_component() { + assert((string)"type: attempt to create implementation of abstract type: " + name.get_name(), create_impl.null()); + + p comp = create_impl(); + comp->set(this); - p this_type = p(this); - p impl = create_impl(); - return new component(parent, this_type, impl); + return comp; } bool type::operator==(const type &x) const { - return x.me == me; + return x.name == name; } bool type::operator!=(const type &x) const { diff --git a/manes/cds/type.h b/manes/cds/type.h new file mode 100644 index 0000000..8dce9b7 --- /dev/null +++ b/manes/cds/type.h @@ -0,0 +1,78 @@ +/* Quarn OS / Manes + * + * Type class + * + * Copyright (C) 2008-2009 Pawel Dziepak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef _TYPE_H_ +#define _TYPE_H_ + +#include "libs/pointer.h" +#include "libs/delegate.h" + +#include "component.h" + +namespace manes { + namespace cds { + + /** + * @brief Type class + * @details This class describes type of components. It provides + * inheritance information as well as possibility to create a new + * instance. As long as types are just special kind of components + * client code can inherit from them and introduce new functionality. + * @see driver + */ + class type : public component { + protected: + const component_name base; + + const delegate > create_impl; + + public: + + type(const component_name&, const component_name&, delegate >); + + component_name get_base() const; + + /** + * @brief Tell if type1 is-a type2. + * @details This function checks if this type is or inherits + * from type given in argument. + * @param x type to compare with + * @return true if cast would be successful + */ + bool is(const component_name &x) const; + + /** + * @brief Create new instance of the type. + * @details This method creates new instance of the type described + * by this class. It mainly uses create_impl delegate. + * @param parent component that wants to create new object + * @return pointer to newly created instance + */ + p create_component(); + + bool operator==(const type&) const; + bool operator!=(const type&) const; + }; + } +} + +#endif diff --git a/manes/component.cpp b/manes/component.cpp deleted file mode 100644 index 405fbbd..0000000 --- a/manes/component.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* Quarn OS / Manes - * - * Component class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "component.h" -#include "implementation.h" -#include "manec.h" -#include "typeinfo" -#include "exception.h" - -using namespace manes; -using namespace std; -using namespace manes::ods; - -extern "C" void inject_remote_efc(void*,void*); -extern "C" unsigned int get_symbol_size(void*); - -component::component(p _parent, p _type, p _impl) : - impl(_impl), - obj_type(_type), - parent(_parent), - me(new component_name(_type->get_name(), "(none)")) { - - if (!impl.valid()) - throw new argument_null_exception("Attempt to create component without implementation."); - if (!impl.valid()) - throw new argument_null_exception("Attempt to create component without type."); - - impl->set_owner(this); -} - -p component::get_name() const { - return me; -} - -p component::get_parent() const { - return parent; -} - -p component::get_type() const { - return obj_type; -} - -component::obj_location component::get_location() const { - return local_kernel; -} - -p component::get_stub() const { - return impl_stub; -} - -p component::get_implementation() const { - return impl; -} diff --git a/manes/component.h b/manes/component.h deleted file mode 100644 index 084adc2..0000000 --- a/manes/component.h +++ /dev/null @@ -1,85 +0,0 @@ -/* Quarn OS / Manes - * - * Component class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _COMPONENT_H_ -#define _COMPONENT_H_ - -#include "access_control.h" -#include "component_name.h" -#include "type.h" - -#include "libs/delegate.h" -#include "libs/list.h" -#include "libs/pointer.h" - -namespace manes { - class component { - public: - typedef enum { - all, - read, - write, - command - } access_type; - - typedef enum { - local_kernel, - local_user, - remote - } obj_location; - - protected: - /* Synchronization mechanism */ - access_control *locker; - - //obj_location locate; (distributed) - - mutable p impl; - p impl_stub; - - p obj_type; - p parent; - - p me; - - virtual p get_stub() const; - public: - typedef component_name name; - - component(p, p, p); - - p get_name() const; - p get_parent() const; - - p get_type() const; - - obj_location get_location() const; - - virtual p get_implementation() const; - - template - p get() const; - }; - -} - -#endif diff --git a/manes/component_name.h b/manes/component_name.h deleted file mode 100644 index 6b0e1aa..0000000 --- a/manes/component_name.h +++ /dev/null @@ -1,58 +0,0 @@ -/* Quarn OS / Manes - * - * Component name class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _COMPONENT_NAME_H_ -#define _COMPONENT_NAME_H_ - -#include "type_name.h" -#include "type.h" - -#include "libs/value.h" - -namespace manes { - class component_name { - private: - type_name type_n; - unsigned int type_index; - - string text_name; - - public: - component_name(const component_name &); - - component_name(const type_name, const string); - component_name(const type_name, unsigned int); - component_name(const type_name, const string, unsigned int); - - type_name get_type_name() const; - p get_type() const; - string get_name() const; - unsigned int get_tindex() const; - - bool operator==(const component_name&) const; - - static component_name from_path(const string &); - static component_name new_name(const type_name, const string &); - }; -} - -#endif diff --git a/manes/creator.h b/manes/creator.h deleted file mode 100644 index 2df2677..0000000 --- a/manes/creator.h +++ /dev/null @@ -1,103 +0,0 @@ -/* Quarn OS / Manes - * - * Creator class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _CREATOR_H_ -#define _CREATOR_H_ - -#include "component.h" -#include "component_name.h" -#include "type_name.h" - -#include "libs/pointer.h" -#include "libs/list.h" - -namespace manes { - /** - * @brief Components creator. - * @details This is an abstract base class for all component creators. - * It stores list of created components and provides interface needed - * to manage them. - */ - class creator : public implementation { - protected: - /** - * @brief List of components stored by creator. - */ - list > components; - - public: - /** - * @brief Performs creator initialization. - * @details This method is called once creator is construced and - * ready to work since Manes does not allow some things to be - * performed in constructors. - * @return information if initialization was successful - */ - virtual bool initialize(); - - /** - * @brief New type was registered in the system. - * @details This method is called each time new type is registered, - * what allows creator to perform any actions that such event - * may require. It is commonly used by bus classes that support - * lazy drivers loading. - * @param newtype name of recently registered type - * @return ignored value - */ - virtual bool type_added(const type_name &newtype); - - /** - * @brief Create new component. - * @details Create new component of specified type. Instances of - * class type provides interface that allow to create an object - * of specific type. To get type from type_name manager is used. - * Notice that some subclasses may make more restricted or - * completely impossible creation of new components. - * @param name type of requested component - * @return created component - */ - virtual p new_component(const type_name &name); - - /** - * @brief Returns number of components stored in this creator. - * @return components count - */ - virtual int count() const; - - /** - * @todo Implement this method. - */ - virtual void delete_component(const component_name&); - - /** - * @brief Get an exsiting component. - * @details Search in components list for a specifed component. - * In most cases this function should not be invoced directly, but - * client should use manager's method manager::get_component. - * @param name name of the requested component - * @return requested component - */ - virtual p get_component(const component_name &name); - }; -} - -#endif diff --git a/manes/factory.h b/manes/factory.h deleted file mode 100644 index c5671ce..0000000 --- a/manes/factory.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Quarn OS / Manes - * - * Factory - * - * Copyright (C) 2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _FACTORY_H_ -#define _FACTORY_H_ - -#include "type.h" -#include "creator.h" - -namespace manes { - /** - * @brief Types manager - * @details This is main type manager in Manes. At leas one insance - * of this class exists and is created by manei. In most cases - * construction of such class is performed manually, not using - * automatic Manes mechanisms. - * @see manei - */ - class factory : public creator { - private: - p base_type; - - public: - bool initialize(); - - /** - * @brief Method not implemented yet. - * @todo Implement this method. - */ - virtual p new_component(const type_name &name); - - virtual p get_component(const component_name &name); - - /** - * @brief Register type in system. - * @details This is a decorator that allows client to get rid - * off unecessary code required when any other class instances are - * created. In this case there is only need to provide factory - * with an existing instance of type class. - * @param newtype type to be registered - */ - virtual void register_impl(p newtype); - }; -} - -#endif diff --git a/manes/implementation.cpp b/manes/implementation.cpp deleted file mode 100644 index 9ae958b..0000000 --- a/manes/implementation.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Quarn OS / Manes - * - * Implementation class implementation - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "implementation.h" -#include "manec.h" - -using namespace manes; - -void implementation::set_owner(p own) { - owner = own; -} -p implementation::get_parent() { - p comp = owner->get_parent(); - return comp; -} diff --git a/manes/implementation.h b/manes/implementation.h deleted file mode 100644 index 6737f15..0000000 --- a/manes/implementation.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Quarn OS / Manes - * - * Implementation class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _IMPLEMENTATION_H_ -#define _IMPLEMENTATION_H_ - -#include "ods/obj_ref.h" - -#include "libs/pointer.h" - -namespace manes { - class component; - - /** - * @brief Component implementation base class. - * @details This is the base class for all components and objects - * implementations managed, stored or distributed by - * Managed Execution System. - */ - class implementation : public ods::obj_ref { - protected: - /** - * @brief Pointer to component object that this class implements. - * @todo This field has to be made read-only. - */ - p owner; - - public: - /** - * @details This method is used only by internal Manes code, while - * creating instance of this class. - * @param owner implementation owner - * @deprecated Client should not have any possibility to - * change implemetnation owner. - */ - virtual void set_owner(p owner); - - /** - * @brief Get component parent. - * @details This method returns parent of the component that this - * class implement. - * @return component parent - */ - virtual p get_parent(); - }; -} - -#endif - diff --git a/manes/manec.cpp b/manes/manec.cpp index f67fec6..2c3b88d 100644 --- a/manes/manec.cpp +++ b/manes/manec.cpp @@ -20,17 +20,18 @@ * */ -#include "creator.h" +#include "cds/creator.h" #include "manec.h" -#include "type.h" +#include "cds/type.h" #include "error.h" -#include "root.h" -#include "driver.h" -#include "factory.h" -#include "abstract.h" +#include "cds/root.h" +#include "cds/driver.h" +#include "cds/factory.h" +#include "cds/abstract.h" #include "services/kernel_state.h" using namespace manes; +using namespace manes::cds; p manec::comp = (component*)0; p manec::instance = (manec*)0; @@ -39,7 +40,7 @@ manec::manec() : usermode(false) {} void manec::connect_manes(p root_mgr) { main = root_mgr; - types = main->get_component(component_name((type_name)"factory",0))->get(); + types = main->get_component(component_name::from_path("/factory")); } void manec::connect_manes() { @@ -75,53 +76,45 @@ p manec::err_msg(const string &x) { return state()->new_error(x); } - -p manec::new_component(const type_name &name) { - return main->new_component(name); -} - p manec::get_component(const component_name &obj) { return main->get_component(obj); } p manec::get_component(const string cname) { - return get_component(component_name((type_name)cname,0)); + return get_component(component_name::from_index(cname,0)); } p manec::get_by_path(const string &tpath) { return get_component(component_name::from_path(tpath)); } -void manec::register_type(const string me, const string parent, type::root_type tpe, delegate > deleg) { - type_name bus_name(me); - register_type(new type(tpe, (type_name)parent, bus_name, deleg)); +void manec::register_type(const string &me, const string &parent, delegate > deleg) { + register_type(new type(component_name::from_path((string)"/type," + me), component_name::from_path((string)"/type," + parent), deleg)); } -void manec::register_driver(const string me,const string parent,type::root_type tpe, delegate > deleg, delegate > check) { - type_name bus_name(me); - register_type(new driver(tpe, (type_name)parent, bus_name, deleg, check)); - main->type_added(bus_name); +void manec::register_driver(const string &me,const string &parent, delegate > deleg, delegate > check) { + register_type(new driver(component_name::from_path((string)"/type," + me), component_name::from_path((string)"/type," + parent), deleg, check)); + main->type_added(component_name::from_path((string)"/type," + me)); } -void manec::register_abstract(const string me, const string parent) { - type_name abstr_name(me); - register_type(new abstract(type::device, (type_name)parent, abstr_name)); +void manec::register_abstract(const string &me, const string &parent) { + register_type(new abstract(component_name::from_path((string)"/type," + me), component_name::from_path((string)"/type," + parent))); } void manec::register_type(p tpe) { if (!tpe.valid()) throw new argument_null_exception(); - types->register_impl(tpe); + types->add_existing(tpe); } -p manec::get_type(const type_name &tpe) { - return types->get_component(component_name((type_name)"type",tpe.get_textname()))->get(); +p manec::get_type(const component_name &tpe) { + return types->get_component(tpe).cast(); } p manec::get_driver(p id) { for (int i = 0; i < types->count(); i++) { - p drv = types->get_component(component_name((type_name)"driver", i))->get(); + p drv = types->get_component(component_name::from_index("driver", i)).cast(); if (drv.cast().valid() && drv.cast()->check_device(id)) return drv; } diff --git a/manes/manec.h b/manes/manec.h index ea64a33..696b878 100644 --- a/manes/manec.h +++ b/manes/manec.h @@ -23,7 +23,8 @@ #ifndef _MANEC_H_ #define _MANEC_H_ -#include "component.h" +#include "cds/component.h" +#include "cds/type.h" #include "libs/pointer.h" #include "arch/low/irq.h" #include "arch/low/general.h" @@ -38,28 +39,29 @@ namespace services { namespace manes { class error; - class root; - class factory; + namespace cds { + class root; + class factory; + } /* Managed Execution Controller */ - class manec : public implementation { + class manec : public cds::component { private: - p main; - p types; + p main; + p types; p kstate; arch::irq_op irqs; public: bool usermode; - static p comp; + static p comp; static p instance; manec(); public: - virtual p new_component(const type_name &name); - virtual p get_component(const component_name &name); - virtual p get_component(const string cname); + virtual p get_component(const cds::component_name &name); + virtual p get_component(const string cname); /** * @brief Get component specified by path. @@ -73,7 +75,7 @@ public: * @param path Path to the requested component. * @return Requested component. */ - virtual p get_by_path(const string &path); + virtual p get_by_path(const string &path); /** * @brief Get certain interface of the specific component. @@ -87,8 +89,8 @@ public: template p get(const string &path); - virtual void register_type(const string, const string, type::root_type, delegate >); - virtual void register_driver(const string, const string, type::root_type, delegate >, delegate >); + virtual void register_type(const string&, const string&, delegate >); + virtual void register_driver(const string&, const string&, delegate >, delegate >); /** * @brief Register new type in Manes. @@ -98,7 +100,7 @@ public: * for all clients and operations on components of that type are possible. * @param newtype Pointer to newly created type. */ - virtual void register_type(p newtype); + virtual void register_type(p newtype); /** * @brief Get type from Manes. @@ -108,20 +110,20 @@ public: * @param name Name of the requested type. * @return Requested type. */ - virtual p get_type(const type_name &name); + virtual p get_type(const cds::component_name &name); - virtual p get_driver(p); + virtual p get_driver(p); virtual arch::irq_op *get_low(); - virtual void connect_manes(p root_mgr); + virtual void connect_manes(p root_mgr); static void connect_manes(); static p get(); - virtual p get_root(); - virtual p get_factory(); + virtual p get_root(); + virtual p get_factory(); virtual p state(); @@ -132,12 +134,12 @@ public: } template - void register_type(const string, const string, type::root_type); + void register_type(const string&, const string&); template - void register_driver(const string, const string, type::root_type, delegate >); + void register_driver(const string&, const string&, delegate >); - virtual void register_abstract(const string, const string); + virtual void register_abstract(const string&, const string&); }; template @@ -146,26 +148,18 @@ public: } template -void manec::register_type(const string me, const string parent, type::root_type tpe) { - register_type(me, parent, tpe, delegate >::function(create_object)); +void manec::register_type(const string &me, const string &parent) { + register_type(me, parent, delegate >::function(create_object)); } template -void manec::register_driver(const string me, const string parent, type::root_type tpe, delegate > check) { - register_driver(me, parent, tpe, delegate >::function(create_object), check); +void manec::register_driver(const string &me, const string &parent, delegate > check) { + register_driver(me, parent, delegate >::function(create_object), check); } template p manec::get(const string &path) { - return get_by_path(path)->get(); -} - -template -p component::get() const { -// if (!manec::get()->far_calls()) - return get_implementation().cast(); -/* else - return get_stub().cast();*/ + return get_by_path(path).cast(); } } diff --git a/manes/manei.cpp b/manes/manei.cpp index 21beb45..4e350b3 100644 --- a/manes/manei.cpp +++ b/manes/manei.cpp @@ -20,10 +20,10 @@ * */ -#include "creator.h" +#include "cds/creator.h" #include "manec.h" #include "manei.h" -#include "type.h" +#include "cds/type.h" #include "services/server.h" #include "services/tty_logger.h" @@ -61,6 +61,7 @@ #include "actors/actor.h" using namespace manes; +using namespace manes::cds; extern p allocator; @@ -74,24 +75,8 @@ p manei::get() { void manei::launch_manes() { main = new root(); - types = new factory(); - - string str_factory("factory"); - type_name factory_tname(str_factory); - - delegate > create_deleg; - - string str("none"); - type_name bname(str); - - p factory_type = new type(type::factory, bname, factory_tname, create_deleg); - - p comp = new component((component*)this, factory_type, types.cast()); - - comp->get()->initialize(); - comp->get()->register_impl(factory_type); - - main->initialize(comp); + types = new factory(new type(component_name::from_path("/type,factory"), component_name::invalid, delegate >())); + main->initialize(types); } @@ -198,32 +183,32 @@ void manei::register_builtin_types() { void manei::animate_creators() { /* animate server */ - main->new_component((type_name)"server")->get()->initialize(); + main->new_component(component_name::from_path("/type,server")).cast()->initialize(); - kstate = main->new_component((type_name)"kernel_state")->get(); + kstate = main->new_component(component_name::from_path("/type,kernel_state")).cast(); - main->new_component((type_name)"physmem")->get()->initialize(); + main->new_component(component_name::from_path("/type,physmem"));//.cast()->initialize(); /* animate slob */ - allocator = main->new_component((type_name)"foma")->get(); + allocator = main->new_component(component_name::from_path("/type,foma")).cast(); /* animate loader */ - main->new_component((type_name)"loader")->get()->initialize(); + main->new_component(component_name::from_path("/type,loader")).cast()->initialize(); /* animate isa - main bus */ - main->new_component((type_name)"isa")->get()->initialize(); + main->new_component(component_name::from_path("/type,isa")).cast()->initialize(); /* animate pci */ - main->new_component((type_name)"pci")->get()->initialize(); + main->new_component(component_name::from_path("/type,pci")).cast()->initialize(); /* animate virtual_bus */ - main->new_component((type_name)"virtual_bus")->get()->initialize(); + main->new_component(component_name::from_path("/type,virtual_bus")).cast()->initialize(); /* animate fat - main fs (temp) */ - main->new_component((type_name)"fat")->get()->initialize(); + main->new_component(component_name::from_path("/type,fat")).cast()->initialize(); /* animate director */ - main->new_component((type_name)"director")->get()->initialize(); + main->new_component(component_name::from_path("/type,director")).cast()->initialize(); } p manei::get_root() { diff --git a/manes/manei.h b/manes/manei.h index 7494f94..a1df000 100644 --- a/manes/manei.h +++ b/manes/manei.h @@ -24,16 +24,16 @@ #define _MANEI_H_ #include "manec.h" -#include "root.h" -#include "factory.h" +#include "cds/root.h" +#include "cds/factory.h" #include "services/kernel_state.h" namespace manes { /* Managed Execution Initializer */ class manei { private: - p main; - p types; + p main; + p types; p kstate; @@ -48,7 +48,7 @@ namespace manes { void register_builtin_types(); void animate_creators(); - p get_root(); + p get_root(); p state(); }; diff --git a/manes/mem_alloc.cpp b/manes/mem_alloc.cpp index c9f5576..bc60000 100644 --- a/manes/mem_alloc.cpp +++ b/manes/mem_alloc.cpp @@ -28,7 +28,7 @@ #include "services/kernel_state.h" #include "manec.h" #include "error.h" -#include "manes/component.h" +#include "manes/cds/component.h" #include "resources/memm.h" using namespace manes; diff --git a/manes/name.h b/manes/name.h deleted file mode 100644 index 5fe81d3..0000000 --- a/manes/name.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Quarn OS / Manes - * - * Name class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _NAME_H_ -#define _NAME_H_ - -namespace manes { - class name { - public: - virtual int get_id() const = 0; - }; -} - -#endif diff --git a/manes/start.cpp b/manes/start.cpp index 137f458..bfb4e8f 100644 --- a/manes/start.cpp +++ b/manes/start.cpp @@ -105,11 +105,15 @@ extern "C" void _start() { p main = manec::get(); /* Abstract types */ - main->register_abstract("storage", "none"); - main->register_abstract("console", "none"); - main->register_abstract("nic", "none"); + main->register_abstract("device", "none"); + main->register_abstract("storage", "device"); + main->register_abstract("console", "device"); + main->register_abstract("nic", "device"); + main->register_abstract("allocator", "none"); + main->register_abstract("service", "none"); + /* Run low-level procedures */ arch::launch(); @@ -182,6 +186,7 @@ extern "C" void _start() { fs_floppy->mount(floppy); p temp = main->get("/file,authors"); + tlog->print((string)(const char*)((const string)*temp), services::logger::log_warning); p mod = main->get("/module,rs232.ko"); @@ -199,7 +204,7 @@ extern "C" void _start() { //jump_v86(); p sched = main->get("/director"); - p proc = sched->new_component((type_name)"actor")->get(); + p proc = sched->new_component(cds::component_name::from_path("/type,actor")).cast(); proc->set(delegate::function(next)); /* Benchmark diff --git a/manes/type.h b/manes/type.h deleted file mode 100644 index fdc787a..0000000 --- a/manes/type.h +++ /dev/null @@ -1,118 +0,0 @@ -/* Quarn OS / Manes - * - * Type class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _TYPE_H_ -#define _TYPE_H_ - -#include "implementation.h" -//#include "test.h" -#include "type_name.h" - -#include "libs/pointer.h" -#include "libs/delegate.h" - -namespace manes { - class component; - - class unit_test {}; - - /** - * @brief Type class - * @details This class describes type of components. It provides - * inheritance information as well as possibility to create a new - * instance. As long as types are just special kind of components - * client code can inherit from them and introduce new functionality. - * @see driver - */ - class type : public implementation { - public: - typedef enum { - /* invalid */ - zero, - - /* factories */ - server, - bus, - mem_alloc, - loader, - director, - filesystem, - factory, - - /* components */ - service, - device, - buffer, - file, - module, - ctype, - actor - } root_type; - - private: - const root_type main_type; - const type_name base; - const type_name me; - - //unit_test *utest; - - const delegate > create_impl; - - public: - typedef type_name name; - - type(const root_type, const type_name, const type_name, //unit_test, - const delegate >); - - type(const type&); - - virtual type_name get_name() const; - - /** - * @brief Tell if type1 is-a type2. - * @details This function checks if this type is or inherits - * from type given in argument. - * @param x type to compare with - * @return true if cast would be successful - */ - bool is(const type_name &x) const; - - root_type get_root_type() const; - root_type get_child_type() const; - - type_name get_base_type() const; - - /** - * @brief Create new instance of the type. - * @details This method creates new instance of the type described - * by this class. It mainly uses create_impl delegate. - * @param parent component that wants to create new object - * @return pointer to newly created instance - */ - p create_component(p parent); - - bool operator==(const type&) const; - bool operator!=(const type&) const; - }; -} - -#endif diff --git a/manes/type_name.cpp b/manes/type_name.cpp deleted file mode 100644 index c84b76e..0000000 --- a/manes/type_name.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* Quarn OS / Manes - * - * Type name class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "type_name.h" -#include "manec.h" - -using namespace manes; - - -type_name::type_name(const string _name) : text_name(_name), last_tcid(0) { -} - -type_name::type_name(const type_name &x) : - text_name(x.text_name), - last_tcid(x.last_tcid) { - -} - -unsigned int type_name::get_tcid() const { - unsigned int tcid = last_tcid++; - - assert("type_name: last_tcid overflow!", last_tcid == 0); - - return tcid; -} - -string type_name::get_textname() const { - return text_name; -} - -bool type_name::operator==(const type_name &x) const { - if (x.text_name == text_name) - return true; - return false; -} diff --git a/modules/Makefile b/modules/Makefile index b5d1de2..108bbac 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -30,7 +30,7 @@ MODULE = rs232.ko MODULE_LIBS = ../libs/string.o #../manes/rtti.o -OBJS = modules_start.o ../resources/rs232.o ../arch/low/rs232.o ../arch/low/lowlevel.o ../manes/implementation.o ../resources/device.o $(MODULE_LIBS) +OBJS = modules_start.o ../manes/cds/component.o ../resources/rs232.o ../arch/low/rs232.o ../arch/low/lowlevel.o ../resources/device.o $(MODULE_LIBS) modules: dep.d compile diff --git a/modules/elf.cpp b/modules/elf.cpp index a832f61..d517706 100644 --- a/modules/elf.cpp +++ b/modules/elf.cpp @@ -348,6 +348,6 @@ void modules::elf::load(const string &prog) { void modules::elf::register_type() { - manes::manec::get()->register_type("elf", "module", manes::type::module); + manes::manec::get()->register_type("elf", "module"); } diff --git a/modules/loader.cpp b/modules/loader.cpp index c19dce1..f65cd37 100644 --- a/modules/loader.cpp +++ b/modules/loader.cpp @@ -26,19 +26,14 @@ using namespace modules; -bool loader::initialize() { - return true; -} - -bool loader::type_added(manes::type_name) { - return true; -} - /* Load module */ -p loader::get_component(const manes::component_name &mname) { - p module_comp = new_component(manes::type_name("elf")); - p mp = module_comp->get(); +p loader::get_component(const manes::cds::component_name &mname) { + if (mname.get_type().get_name() != string("module")) + return p::invalid; + + p module_comp = new_component(manes::cds::component_name::from_path("/type,elf")); + p mp = module_comp.cast(); mp->load(mname.get_name()); @@ -46,6 +41,6 @@ p loader::get_component(const manes::component_name &mname) { } void loader::register_type() { - manes::manec::get()->register_type("loader", "manec", manes::type::loader); + manes::manec::get()->register_type("loader", "manec"); } diff --git a/modules/loader.h b/modules/loader.h index 25cf4a7..cb7e17e 100644 --- a/modules/loader.h +++ b/modules/loader.h @@ -23,7 +23,7 @@ #ifndef _LOADER_H_ #define _LOADER_H_ -#include "manes/creator.h" +#include "manes/cds/creator.h" #include "manes/manec.h" #include "libs/list.h" @@ -31,14 +31,11 @@ #include "libs/pointer.h" namespace modules { - class loader : public manes::creator { + class loader : public manes::cds::creator { public: typedef void (*module_entry)(/*manes::component**/); - virtual bool initialize(); - virtual bool type_added(manes::type_name); - - virtual p get_component(const manes::component_name&); + virtual p get_component(const manes::cds::component_name&); static void register_type(); }; diff --git a/modules/module.cpp b/modules/module.cpp index 0821b12..b148dde 100644 --- a/modules/module.cpp +++ b/modules/module.cpp @@ -46,6 +46,6 @@ delegate module::get_delegate() { } void module::register_type() { - manes::manec::get()->register_type("module", "none", manes::type::module); + manes::manec::get()->register_type("module", "none"); } diff --git a/modules/module.h b/modules/module.h index fb2a4d2..6a30eab 100644 --- a/modules/module.h +++ b/modules/module.h @@ -26,7 +26,7 @@ #include "manes/manec.h" namespace modules { - class module : public manes::implementation { + class module : public manes::cds::component { public: typedef enum { module_kernel_space, diff --git a/modules/modules_start.cpp b/modules/modules_start.cpp index be876a4..3af46fb 100644 --- a/modules/modules_start.cpp +++ b/modules/modules_start.cpp @@ -22,7 +22,6 @@ #include "manes/manec.h" #include "services/logger.h" -#include "manes/component.h" #include "resources/memm.h" #include "services/kernel_state.h" diff --git a/resources/Makefile b/resources/Makefile index 5a70904..e4dc4dc 100644 --- a/resources/Makefile +++ b/resources/Makefile @@ -19,7 +19,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -RESOURCE = isa.o pci.o device.o keybscr.o fdc.o speaker.o prvl.o spinlock.o foma.o fat.o fs.o file.o virtual_bus.o pio.o physmem.o unknown.o ne2k.o usb.o uhci.o bus.o arp.o mac_addr.o arp_table.o ethernet.o link_layer.o ipv4.o icmp.o rtl8139.o slob.o # rs232.o +RESOURCE = isa.o pci.o device.o keybscr.o fdc.o speaker.o prvl.o foma.o fat.o fs.o file.o virtual_bus.o pio.o physmem.o unknown.o ne2k.o usb.o uhci.o bus.o arp.o mac_addr.o arp_table.o ethernet.o link_layer.o ipv4.o icmp.o rtl8139.o slob.o # rs232.o OBJS = $(MANES) $(RESOURCE) diff --git a/resources/bus.cpp b/resources/bus.cpp index 0b381a0..3a728e1 100644 --- a/resources/bus.cpp +++ b/resources/bus.cpp @@ -21,26 +21,27 @@ */ #include "bus.h" -#include "manes/driver.h" +#include "manes/cds/driver.h" #include "manes/manec.h" #include "unknown.h" using namespace resources; using namespace manes; +using namespace manes::cds; -bool bus::type_added(const type_name &tname) { +bool bus::type_added(const component_name &tname) { if (get_count() == 0) return false; p drv; p ukn; - if ((drv = manec::get()->get((string)"/type," + tname.get_textname()).cast()).valid()) { + if ((drv = manec::get()->get((string)"/type," + tname.get_name()).cast()).valid()) { for (int i = 0; i < components.get_count(); i++) { - if ((ukn = components[i]->get()).valid()) { + if ((ukn = components[i].cast()).valid()) { if (drv->check_device(ukn->get_did())) { components.remove(i); p c = new_component(tname); - c->get()->init_device(ukn->get_did()); + c.cast()->init_device(ukn->get_did()); // delete ukn; } } @@ -52,8 +53,8 @@ bool bus::type_added(const type_name &tname) { p bus::get_component(const component_name &obj) { for (unsigned int i = 0, j = 0; (int)i < components.get_count(); i++) { - if (components[i]->get_type()->is(obj.get_type_name())) { - if (j == obj.get_tindex()) { + if (components[i]->get_type()->is(obj.get_type())) { + if (j == obj.get_index()) { return components[i]; } else { j++; @@ -61,5 +62,5 @@ p bus::get_component(const component_name &obj) { } } - return (component*)0; + return p::invalid; } diff --git a/resources/bus.h b/resources/bus.h index 8d4c073..396f1bd 100644 --- a/resources/bus.h +++ b/resources/bus.h @@ -23,26 +23,26 @@ #ifndef _BUS_H_ #define _BUS_H_ -#include "manes/creator.h" -#include "manes/type_name.h" +#include "manes/cds/creator.h" +#include "manes/cds/component_name.h" namespace resources { class did; class device; - class bus : public manes::creator { + class bus : public manes::cds::creator { public: - p get_component(const manes::component_name &obj); + p get_component(const manes::cds::component_name &obj); //virtual bool initialize() = 0; - virtual bool type_added(const manes::type_name&); + virtual bool type_added(const manes::cds::component_name&); virtual int get_count() = 0; - virtual bool init_device(did *id) { + virtual bool init_device(p id) { return false; } - virtual bool init_bus(device *dev) { + virtual bool init_bus(p dev) { return false; } }; diff --git a/resources/device.h b/resources/device.h index 3961dae..4878ee0 100644 --- a/resources/device.h +++ b/resources/device.h @@ -23,11 +23,11 @@ #ifndef _DEVICE_H_ #define _DEVICE_H_ -#include "manes/implementation.h" +#include "manes/cds/component.h" #include "did.h" namespace resources { - class device : public manes::implementation { + class device : public manes::cds::component { protected: bool inited; diff --git a/resources/fat.cpp b/resources/fat.cpp index cb0f8f6..13136d4 100644 --- a/resources/fat.cpp +++ b/resources/fat.cpp @@ -29,14 +29,6 @@ using namespace resources; fat::fat() : mounted(false) {} -bool fat::initialize() { - return true; -} - -bool fat::type_added(type_name) { - return true; -} - bool fat::mount(p _dep) { dep = _dep; @@ -274,6 +266,6 @@ int fat::find_file(const char *filename) { } void fat::register_type() { - manec::get()->register_type("fat", "manec", type::filesystem); + manec::get()->register_type("fat", "manec"); } diff --git a/resources/fat.h b/resources/fat.h index ff0fe60..b480821 100644 --- a/resources/fat.h +++ b/resources/fat.h @@ -70,9 +70,6 @@ namespace resources { public: fat(); - bool initialize(); - bool type_added(manes::type_name); - void load_file(const string &filename, buffer &addr); file::file_meta load_meta(const string &filename); diff --git a/resources/fdc.cpp b/resources/fdc.cpp index 81f1f9a..0fe44e9 100644 --- a/resources/fdc.cpp +++ b/resources/fdc.cpp @@ -22,7 +22,6 @@ #include "fdc.h" #include "manes/manec.h" -#include "spinlock.h" using namespace manes; using namespace resources; @@ -68,5 +67,5 @@ bool fdc::init_device(p iadr) { } void fdc::register_type() { - manec::get()->register_type("fdc", "isa", type::device); + manec::get()->register_type("fdc", "isa"); } diff --git a/resources/file.cpp b/resources/file.cpp index 6b05104..c2fb633 100644 --- a/resources/file.cpp +++ b/resources/file.cpp @@ -49,5 +49,5 @@ buffer file::get_buffer() { } void file::register_type() { - manes::manec::get()->register_type("file", "fat", manes::type::file); + manes::manec::get()->register_type("file", "fat"); } diff --git a/resources/file.h b/resources/file.h index ed3368a..7c8a5a7 100644 --- a/resources/file.h +++ b/resources/file.h @@ -28,13 +28,13 @@ #include "libs/pointer.h" #include "libs/list.h" #include "libs/buffer.h" -#include "manes/implementation.h" +#include "manes/cds/component.h" #include "prvl.h" namespace resources { class fs; - class file : public manes::implementation { + class file : public manes::cds::component { public: typedef enum { attr_hidden = 1, diff --git a/resources/foma.cpp b/resources/foma.cpp index 54f93d7..dfbb8bd 100644 --- a/resources/foma.cpp +++ b/resources/foma.cpp @@ -40,6 +40,7 @@ bool foma::initialize() { foma::foma() { physical = manec::get()->get("/physmem"); memory_size = manec::get()->state()->get_memory_size(); + start_heap = (void*)0x300000; for (int i = 0; i < 20; i++) first_block[i] = 0; @@ -145,6 +146,6 @@ unsigned int foma::get_size(void *ptr) const { } void foma::register_type() { - manec::get()->register_type("foma", "allocator", type::mem_alloc); + manec::get()->register_type("foma", "allocator"); } diff --git a/resources/foma.h b/resources/foma.h index 66dfb97..30b28bd 100644 --- a/resources/foma.h +++ b/resources/foma.h @@ -24,7 +24,6 @@ #define _FOMA_H_ #include "memm.h" -#include "manes/type_name.h" #include "libs/list.h" #include "arch/low/general.h" #include "physmem.h" @@ -51,7 +50,6 @@ namespace resources { foma(); bool initialize(); - bool type_added(manes::type_name); virtual void *allocate_space(unsigned int size); virtual void deallocate_space(void *ptr); diff --git a/resources/fs.cpp b/resources/fs.cpp index 9fee46f..c779bc4 100644 --- a/resources/fs.cpp +++ b/resources/fs.cpp @@ -27,10 +27,13 @@ using namespace manes; using namespace resources; /* Only for testing */ -p fs::get_component(const manes::component_name &fname) { +p fs::get_component(const manes::cds::component_name &fname) { + if (fname.get_type().get_name() != string("file")) + return p::invalid; + /* TODO: check if file's object already exist before create new one */ - p file_comp = new_component(type_name("file")); - p fp = file_comp->get(); + p file_comp = new_component(manes::cds::component_name::from_path("/type,file")); + p fp = file_comp.cast(); /* Till constructor's arguments are supported by manes */ fp->set(fname.get_name(), this); diff --git a/resources/fs.h b/resources/fs.h index 27dab8f..1eba0c8 100644 --- a/resources/fs.h +++ b/resources/fs.h @@ -23,7 +23,7 @@ #ifndef _FS_H_ #define _FS_H_ -#include "manes/creator.h" +#include "manes/cds/creator.h" #include "manes/manec.h" #include "block.h" #include "file.h" @@ -31,7 +31,7 @@ #include "libs/pointer.h" namespace resources { - class fs : public manes::creator { + class fs : public manes::cds::creator { protected: p dep; p main_dir; @@ -42,7 +42,7 @@ namespace resources { virtual list > list_directory(const string &dirname) = 0; - virtual p get_component(const manes::component_name&); + virtual p get_component(const manes::cds::component_name&); virtual bool mount(p) = 0; diff --git a/resources/isa.cpp b/resources/isa.cpp index efd766a..968ae42 100644 --- a/resources/isa.cpp +++ b/resources/isa.cpp @@ -23,7 +23,6 @@ #include "isa.h" #include "unknown.h" #include "manes/manec.h" -#include "manes/driver.h" using namespace manes; using namespace resources; @@ -39,6 +38,6 @@ int isa::get_count() { } void isa::register_type() { - manec::get()->register_type("isa", "manec", type::bus); + manec::get()->register_type("isa", "manec"); } diff --git a/resources/keybscr.cpp b/resources/keybscr.cpp index c17fe71..74ff854 100644 --- a/resources/keybscr.cpp +++ b/resources/keybscr.cpp @@ -85,5 +85,5 @@ bool keybscr::init_device(p iadr) { } void keybscr::register_type() { - manec::get()->register_type("keybscr", "console", type::device); + manec::get()->register_type("keybscr", "console"); } diff --git a/resources/memm.h b/resources/memm.h index 3cc1eb5..73bda7e 100644 --- a/resources/memm.h +++ b/resources/memm.h @@ -23,11 +23,10 @@ #ifndef _MEMM_H_ #define _MEMM_H_ -#include "manes/implementation.h" -#include "manes/creator.h" +#include "manes/cds/creator.h" namespace resources { - class memm : public manes::creator { + class memm : public manes::cds::component { public: virtual void *allocate_space(unsigned int size) = 0; virtual void deallocate_space(void *ptr) = 0; diff --git a/resources/ne2k.cpp b/resources/ne2k.cpp index 245bf54..f197522 100644 --- a/resources/ne2k.cpp +++ b/resources/ne2k.cpp @@ -73,5 +73,5 @@ mac_addr ne2k::get_haddr() const { void ne2k::register_type() { delegate > chk; chk.function(&ne2k::check_device); - manes::manec::get()->register_driver("ne2k", "nic", manes::type::device, chk); + manes::manec::get()->register_driver("ne2k", "nic", chk); } diff --git a/resources/pci.cpp b/resources/pci.cpp index b1d0ad2..0e866b3 100644 --- a/resources/pci.cpp +++ b/resources/pci.cpp @@ -33,15 +33,11 @@ bool pci::initialize() { return false; } -bool pci::type_added(type_name) { - return true; -} - int pci::get_count() { return dev_count; } void pci::register_type() { - manec::get()->register_type("pci", "manec", type::bus); + manec::get()->register_type("pci", "manec"); } diff --git a/resources/pci.h b/resources/pci.h index cfe2e8b..70a8823 100644 --- a/resources/pci.h +++ b/resources/pci.h @@ -70,7 +70,7 @@ namespace resources { pci_did alloc_resources(int bus, int dev, int func); bool initialize(); - bool type_added(manes::type_name); + bool type_added(manes::cds::component_name); int get_count(); diff --git a/resources/physmem.cpp b/resources/physmem.cpp index 650ab42..e6fc154 100644 --- a/resources/physmem.cpp +++ b/resources/physmem.cpp @@ -27,14 +27,6 @@ using namespace resources; -bool physmem::initialize() { - return true; -} - -bool physmem::type_added(manes::type_name) { - return true; -} - physmem::physmem() : last_p((paddr)0x300000), available_memory(arch::get_memory_size()), default_region(0) { region kern = { (paddr)0, 0x80000000, (paddr)0x300000, region::kernel }; regions.add(kern); @@ -87,6 +79,6 @@ void physmem::deallocate_space(void *page) { } void physmem::register_type() { - manes::manec::get()->register_type("physmem", "manec", manes::type::mem_alloc); + manes::manec::get()->register_type("physmem", "manec"); } diff --git a/resources/physmem.h b/resources/physmem.h index aec0053..fb3c2d7 100644 --- a/resources/physmem.h +++ b/resources/physmem.h @@ -61,9 +61,6 @@ namespace resources { public: physmem(); - bool initialize(); - bool type_added(manes::type_name); - void *allocate_space(unsigned int); vaddr get_page(region::type); diff --git a/resources/pio.cpp b/resources/pio.cpp index 44632e6..36c7f38 100644 --- a/resources/pio.cpp +++ b/resources/pio.cpp @@ -79,6 +79,6 @@ bool pio::start(bool wait, delegate notice) { } void pio::register_type() { - manes::manec::get()->register_type("pio", "virtual_bus", manes::type::device); + manes::manec::get()->register_type("pio", "virtual_bus"); } diff --git a/resources/rs232.cpp b/resources/rs232.cpp index 53658ac..33424c6 100644 --- a/resources/rs232.cpp +++ b/resources/rs232.cpp @@ -23,7 +23,6 @@ #include "rs232.h" #include "arch/low/rs232.h" #include "libs/delegate.h" -#include "spinlock.h" #include "isa.h" #include "manes/manec.h" @@ -80,7 +79,7 @@ bool rs232::check_device(p id) { } void rs232::register_type() { - manes::manec::get()->register_driver("rs232", "console", manes::type::device, delegate >::function(rs232::check_device)); + manes::manec::get()->register_driver("rs232", "console", delegate >::function(rs232::check_device)); } extern "C" void module_init() { diff --git a/resources/rtl8139.cpp b/resources/rtl8139.cpp index 6d67eeb..ebb4799 100644 --- a/resources/rtl8139.cpp +++ b/resources/rtl8139.cpp @@ -71,5 +71,5 @@ mac_addr rtl8139::get_haddr() const { void rtl8139::register_type() { delegate > chk; chk.function(&rtl8139::check_device); - manes::manec::get()->register_driver("rtl8139", "nic", manes::type::device, chk); + manes::manec::get()->register_driver("rtl8139", "nic", chk); } diff --git a/resources/slob.cpp b/resources/slob.cpp index d5a7a34..79b66d1 100644 --- a/resources/slob.cpp +++ b/resources/slob.cpp @@ -119,5 +119,5 @@ bool slob::merge(unit *ptr) { void slob::register_type() { - manes::manec::get()->register_type("slob", "allocator", manes::type::mem_alloc); + manes::manec::get()->register_type("slob", "allocator"); } diff --git a/resources/speaker.cpp b/resources/speaker.cpp index 63583eb..68f2da7 100644 --- a/resources/speaker.cpp +++ b/resources/speaker.cpp @@ -52,5 +52,5 @@ bool speaker::init_device(p iadr) { } void speaker::register_type() { - manec::get()->register_type("speaker", "isa", type::device); + manec::get()->register_type("speaker", "isa"); } diff --git a/resources/spinlock.cpp b/resources/spinlock.cpp deleted file mode 100644 index f93d422..0000000 --- a/resources/spinlock.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* Quarn OS - * - * Spinlock class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "spinlock.h" - -#include "manes/error.h" - -spinlock::spinlock() { - locked = false; -} - -spinlock::~spinlock() { - if (locked) - debug("spinlock: destroying locked object"); -} - -bool spinlock::try_lock() { - if (!locked) { - locked = true; - return true; - } else - return false; -} - -void spinlock::lock(lock_type) { - while (locked); - locked = true; -} - -void spinlock::unlock() { - if (!locked) - debug("spinlock: attempt to unlock unlocked object"); - locked = false; -} diff --git a/resources/spinlock.h b/resources/spinlock.h deleted file mode 100644 index 565a98f..0000000 --- a/resources/spinlock.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Quarn OS - * - * Spinlock class - * - * Copyright (C) 2008-2009 Pawel Dziepak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _SPINLOCK_H_ -#define _SPINLOCK_H_ - -#include "manes/access_control.h" - -class spinlock : public access_control { -private: - volatile bool locked; -public: - spinlock(); - ~spinlock(); - - bool try_lock(); - - void lock(lock_type); - void unlock(); -}; - -#endif diff --git a/resources/uhci.cpp b/resources/uhci.cpp index 4af66c3..52718ab 100644 --- a/resources/uhci.cpp +++ b/resources/uhci.cpp @@ -24,6 +24,7 @@ #include "usb.h" #include "manes/manec.h" +#include "manes/cds/root.h" using namespace resources; @@ -43,7 +44,7 @@ bool uhci::init_device(p id) { uhci_count++; init(); - manes::manec::get()->new_component((manes::type_name)"usb")->get()->init_bus(this); + manes::manec::get()->get_root()->new_component(manes::cds::component_name::from_path("/type,usb")).cast()->init_bus(this); return true; } @@ -65,5 +66,5 @@ bool uhci::check_device(p id) { void uhci::register_type() { delegate > chk; chk.function(&uhci::check_device); - manes::manec::get()->register_driver("uhci", "pci", manes::type::bus, chk); + manes::manec::get()->register_driver("uhci", "pci", chk); } diff --git a/resources/unknown.cpp b/resources/unknown.cpp index 60de2ec..fd7790b 100644 --- a/resources/unknown.cpp +++ b/resources/unknown.cpp @@ -35,5 +35,5 @@ p unknown::get_did() const { } void unknown::register_type() { - manes::manec::get()->register_type("unknown", "isa", manes::type::device); + manes::manec::get()->register_type("unknown", "isa"); } diff --git a/resources/usb.cpp b/resources/usb.cpp index 2563c49..c618151 100644 --- a/resources/usb.cpp +++ b/resources/usb.cpp @@ -45,5 +45,5 @@ int usb::get_count() { } void usb::register_type() { - manes::manec::get()->register_type("usb", "pci", manes::type::bus); + manes::manec::get()->register_type("usb", "pci"); } diff --git a/resources/virtual_bus.cpp b/resources/virtual_bus.cpp index 4a0ab01..c86c228 100644 --- a/resources/virtual_bus.cpp +++ b/resources/virtual_bus.cpp @@ -29,12 +29,7 @@ int virtual_bus::get_count() { return 0; } -p virtual_bus::get_component(const manes::component_name &obj) { - /* We DO need garbage collector! */ - return new_component(obj.get_type_name()); -} - void virtual_bus::register_type() { - manes::manec::get()->register_type("virtual_bus", "manec", manes::type::bus); + manes::manec::get()->register_type("virtual_bus", "manec"); } diff --git a/resources/virtual_bus.h b/resources/virtual_bus.h index 2fa642e..bd01ca6 100644 --- a/resources/virtual_bus.h +++ b/resources/virtual_bus.h @@ -27,7 +27,6 @@ namespace resources { public: int get_count(); - p get_component(const manes::component_name&); static void register_type(); }; diff --git a/services/asynch_tasks.cpp b/services/asynch_tasks.cpp index 733c928..331af48 100644 --- a/services/asynch_tasks.cpp +++ b/services/asynch_tasks.cpp @@ -45,7 +45,7 @@ void asynch_tasks::add_task(asynch_task task) { if (!working) { p sched = manes::manec::get()->get("/director"); - p loop = sched->new_component((manes::type_name)"actor")->get(); + p loop = sched->new_component(manes::cds::component_name::from_path("/type,actor")).cast(); loop->set(delegate::method(this, &asynch_tasks::main_loop)); working = true; @@ -55,5 +55,5 @@ void asynch_tasks::add_task(asynch_task task) { } void asynch_tasks::register_type() { - manes::manec::get()->register_type("asynch_tasks", "server", manes::type::service); + manes::manec::get()->register_type("asynch_tasks", "service"); } diff --git a/services/asynch_tasks.h b/services/asynch_tasks.h index b06590e..791338d 100644 --- a/services/asynch_tasks.h +++ b/services/asynch_tasks.h @@ -23,13 +23,13 @@ #ifndef _ASYNCH_TASK_H_ #define _ASYNCH_TASK_H_ -#include "manes/implementation.h" +#include "manes/cds/component.h" #include "libs/fifo.h" #include "libs/delegate.h" namespace services { - class asynch_tasks : public manes::implementation { + class asynch_tasks : public manes::cds::component { public: typedef delegate asynch_task; diff --git a/services/early_logger.cpp b/services/early_logger.cpp index 22ceab9..c617829 100644 --- a/services/early_logger.cpp +++ b/services/early_logger.cpp @@ -29,13 +29,14 @@ #include "early_logger.h" #include "server.h" -#include "manes/creator.h" -#include "manes/type.h" +#include "manes/cds/creator.h" +#include "manes/cds/type.h" #include "manes/manec.h" #include "arch/low/console.h" using namespace manes; +using namespace manes::cds; using namespace services; @@ -44,7 +45,7 @@ early_logger::early_logger() : x(17), y(0) { } /* Print a log message. This logger prints everything on the screen regardless * of its level. At the stage when it is used, all information is imported. */ -void early_logger::print(string message, log_level) { +void early_logger::print(const string &message, log_level) { assert("early_logger: empty message provided", message.null()); for (int i = 0; message[i] != 0; i++) { @@ -63,6 +64,6 @@ void early_logger::print(string message, log_level) { } void early_logger::register_type() { - manec::get()->register_type("early_logger", "server", type::service); + manec::get()->register_type("early_logger", "service"); } diff --git a/services/early_logger.h b/services/early_logger.h index 9741aa4..d3232d9 100644 --- a/services/early_logger.h +++ b/services/early_logger.h @@ -38,7 +38,7 @@ namespace services { int x, y; public: early_logger(); - void print(string, log_level); + void print(const string&, log_level); static void register_type(); }; diff --git a/services/interrupt_manager.cpp b/services/interrupt_manager.cpp index 90d47a1..e234b82 100644 --- a/services/interrupt_manager.cpp +++ b/services/interrupt_manager.cpp @@ -60,5 +60,5 @@ void interrupt_manager::interrupt_called(unsigned int i) { } void interrupt_manager::register_type() { - manes::manec::get()->register_type("interrupt_manager", "server", manes::type::service); + manes::manec::get()->register_type("interrupt_manager", "service"); } diff --git a/services/interrupt_manager.h b/services/interrupt_manager.h index 7299b6c..2fdaf83 100644 --- a/services/interrupt_manager.h +++ b/services/interrupt_manager.h @@ -23,12 +23,12 @@ #ifndef _INTERRUPT_MANAGER_H_ #define _INTERRUPT_MANAGER_H_ -#include "manes/implementation.h" +#include "manes/cds/component.h" #include "libs/delegate.h" #include "libs/array.h" namespace services { - class interrupt_manager : public manes::implementation { + class interrupt_manager : public manes::cds::component { private: array_stack, 256> handlers; diff --git a/services/kernel_state.cpp b/services/kernel_state.cpp index 83a8fd6..13f98fc 100644 --- a/services/kernel_state.cpp +++ b/services/kernel_state.cpp @@ -94,5 +94,5 @@ unsigned int kernel_state::get_memory_size() const { } void kernel_state::register_type() { - manec::get()->register_type("kernel_state", "server", type::service); + manec::get()->register_type("kernel_state", "service"); } diff --git a/services/kernel_state.h b/services/kernel_state.h index 65710ca..f0b6149 100644 --- a/services/kernel_state.h +++ b/services/kernel_state.h @@ -28,7 +28,7 @@ #ifndef _KERNEL_STATE_H_ #define _KERNEL_STATE_H_ -#include "manes/implementation.h" +#include "manes/cds/component.h" #include "libs/list.h" #include "libs/delegate.h" @@ -46,7 +46,7 @@ namespace services { * should be transported by Manes. This class does not support * multiprocessors machines. */ - class kernel_state : public manes::implementation { + class kernel_state : public manes::cds::component { public: /** Types of execution environment */ typedef enum { diff --git a/services/logger.h b/services/logger.h index f1d23c5..e8bd644 100644 --- a/services/logger.h +++ b/services/logger.h @@ -31,10 +31,10 @@ #include "libs/string.h" -#include "manes/implementation.h" +#include "manes/cds/component.h" namespace services { - class logger : public manes::implementation { + class logger : public manes::cds::component { public: typedef enum { log_critical, @@ -46,7 +46,7 @@ namespace services { log_debug } log_level; - virtual void print(string, log_level) = 0; + virtual void print(const string&, log_level) = 0; }; } diff --git a/services/server.cpp b/services/server.cpp index 4a7dc82..004463a 100644 --- a/services/server.cpp +++ b/services/server.cpp @@ -21,31 +21,27 @@ */ #include "server.h" -#include "manes/creator.h" -#include "manes/type.h" +#include "manes/cds/creator.h" +#include "manes/cds/type.h" #include "manes/manec.h" #include "libs/delegate.h" using namespace manes; +using namespace manes::cds; using namespace services; -bool server::initialize() { - return true; -} - -bool server::type_added(type_name) { - return true; -} - p server::get_component(const component_name &_name) { + if (!manec::get()->get_type(_name.get_type())->is(component_name::from_path("/type,service"))) + return p::invalid; + p get = creator::get_component(_name); if (!get.valid()) - get = new_component(_name.get_type_name()); + get = new_component(_name.get_type()); return get; } void server::register_type() { - manec::get()->register_type("server", "manec", type::server); + manec::get()->register_type("server", "manec"); } diff --git a/services/server.h b/services/server.h index 747251a..3360343 100644 --- a/services/server.h +++ b/services/server.h @@ -20,18 +20,14 @@ * */ -#include "manes/creator.h" -#include "manes/type_name.h" +#include "manes/cds/creator.h" #include "libs/pointer.h" namespace services { - class server : public manes::creator { + class server : public manes::cds::creator { public: - virtual bool initialize(); - virtual bool type_added(manes::type_name); - - virtual p get_component(const manes::component_name&); + virtual p get_component(const manes::cds::component_name&); static void register_type(); }; diff --git a/services/stats.cpp b/services/stats.cpp index 9243315..418b3e5 100644 --- a/services/stats.cpp +++ b/services/stats.cpp @@ -69,5 +69,5 @@ string stats::full_stats() const { } void stats::register_type() { - manec::get()->register_type("stats", "server", type::service); + manec::get()->register_type("stats", "service"); } diff --git a/services/stats.h b/services/stats.h index 90ad720..497a9d7 100644 --- a/services/stats.h +++ b/services/stats.h @@ -20,11 +20,11 @@ * */ -#include "manes/implementation.h" +#include "manes/cds/component.h" #include "libs/string.h" namespace services { - class stats : public manes::implementation { + class stats : public manes::cds::component { public: typedef enum { efc_remotecalls, diff --git a/services/timer.cpp b/services/timer.cpp index 3be44af..16f351f 100644 --- a/services/timer.cpp +++ b/services/timer.cpp @@ -50,5 +50,5 @@ void timer::time_tick() { } void timer::register_type() { - manec::get()->register_type("timer", "server", type::service); + manec::get()->register_type("timer", "service"); } diff --git a/services/timer.h b/services/timer.h index d897e14..d77cbd8 100644 --- a/services/timer.h +++ b/services/timer.h @@ -23,12 +23,12 @@ #ifndef _TIMER_H_ #define _TIMER_H_ -#include "manes/implementation.h" +#include "manes/cds/component.h" #include "kernel_state.h" #include "libs/delegate.h" namespace services { - class timer : public manes::implementation { + class timer : public manes::cds::component { public: typedef delegate timer_tick; diff --git a/services/tty_logger.cpp b/services/tty_logger.cpp index 4da097d..c69f6be 100644 --- a/services/tty_logger.cpp +++ b/services/tty_logger.cpp @@ -34,7 +34,7 @@ tty_logger::tty_logger() { slave_tty = main->get("/keybscr"); } -void tty_logger::print(string message, log_level level) { +void tty_logger::print(const string &message, log_level level) { assert("tty_logger: empty log message", message.null()); if (level <= log_warning) @@ -44,6 +44,6 @@ void tty_logger::print(string message, log_level level) { } void tty_logger::register_type() { - manec::get()->register_type("tty_logger", "server", type::service); + manec::get()->register_type("tty_logger", "service"); } diff --git a/services/tty_logger.h b/services/tty_logger.h index f9638d9..76394c4 100644 --- a/services/tty_logger.h +++ b/services/tty_logger.h @@ -33,7 +33,7 @@ namespace services { public: tty_logger(); - void print(string, log_level); + void print(const string&, log_level); static void register_type(); }; diff --git a/services/unmangler.cpp b/services/unmangler.cpp index 3148863..e60ef6a 100644 --- a/services/unmangler.cpp +++ b/services/unmangler.cpp @@ -155,5 +155,5 @@ string unmangler::get_argument(const string &name, int &index) const { } void unmangler::register_type() { - manes::manec::get()->register_type("unmangler", "server", manes::type::service); + manes::manec::get()->register_type("unmangler", "server"); } diff --git a/services/unmangler.h b/services/unmangler.h index d369570..7b899dc 100644 --- a/services/unmangler.h +++ b/services/unmangler.h @@ -26,7 +26,7 @@ #include "libs/string.h" namespace services { - class unmangler : public manes::implementation { + class unmangler : public manes::cds::component { protected: string decode_name(const string&, int&) const; string get_argument(const string&, int&) const; -- 2.11.4.GIT