From 3d5aca66b9712758aecb2e80bc5b2fb3df6256a4 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Wed, 16 Dec 2009 18:22:58 +0100 Subject: New model, object-oriented, for applications --- Source/Library/Userland/App/Application.proto.h | 41 ++++++++++++++++++++++ Source/Library/Userland/App/ShellApp.proto.h | 18 ++++++++++ .../Userland/Binding/VirtualTerminal.class.h | 2 -- Source/Library/Userland/Start.cpp | 37 ++++++++----------- 4 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 Source/Library/Userland/App/Application.proto.h create mode 100644 Source/Library/Userland/App/ShellApp.proto.h (limited to 'Source/Library') diff --git a/Source/Library/Userland/App/Application.proto.h b/Source/Library/Userland/App/Application.proto.h new file mode 100644 index 0000000..1f3a963 --- /dev/null +++ b/Source/Library/Userland/App/Application.proto.h @@ -0,0 +1,41 @@ +#ifndef DEF_APPLICATION_PROTO_H +#define DEF_APPLICATION_PROTO_H + +#include +#include + +extern u32int start_dtors, end_dtors; + +#define APP(t) static t the_app; \ + Application *app = &the_app; + +class Application { + public: + Process pr; + Vector args; + + Application() : pr(Process::get()), args(pr.argc()) { + for (u32int i = 0; i < args.size(); i++) args[i] = pr.argv(i); + //TODO : add default signal handlers + } + virtual ~Application() {} + + virtual int run() = 0; //Application's main loop + + virtual void doEvents() { + //TODO : handle signals (IPC featurs to come) + } + + void exit(u32int ret) { + //Call static destructors + for(u32int * call = &start_dtors; call < &end_dtors; call++) { + ((void (*)(void))*call)(); + } + threadFinishedSyscall(ret); + } +}; + +extern Application *app; + +#endif + diff --git a/Source/Library/Userland/App/ShellApp.proto.h b/Source/Library/Userland/App/ShellApp.proto.h new file mode 100644 index 0000000..846f2b1 --- /dev/null +++ b/Source/Library/Userland/App/ShellApp.proto.h @@ -0,0 +1,18 @@ +#ifndef DEF_SHELLAPP_CLASS_H +#define DEF_SHELLAPP_CLASS_H + +#include +#include + +class ShellApp : public Application { + public: + VirtualTerminal invt, outvt; + + ShellApp() : Application(), invt(VirtualTerminal::getIn()), outvt(VirtualTerminal::getOut()) { + if (!invt.valid()) exit(1); + if (!outvt.valid()) exit(2); + } +}; + +#endif + diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h index c8a4123..70c6b23 100644 --- a/Source/Library/Userland/Binding/VirtualTerminal.class.h +++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h @@ -71,6 +71,4 @@ class VirtualTerminal : public RessourceCaller { inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; } }; -extern VirtualTerminal invt, outvt; - #endif diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp index f1d1771..cb9faf9 100644 --- a/Source/Library/Userland/Start.cpp +++ b/Source/Library/Userland/Start.cpp @@ -1,46 +1,37 @@ #include #include -#include + +#include #include -extern u32int start_ctors, end_ctors, start_dtors, end_dtors; +extern u32int start_ctors, end_ctors; -Heap heap; +Heap *heap; VirtualTerminal invt(0), outvt(0); int main(const Vector& args); extern "C" void start() { - heap.create(0x40000000, 0x00040000, 0x00004000); //Initially create a 256ko heap with 16ko index + Heap h; + h.create(0x40000000, 0x00040000, 0x00004000); //Initially create a 256ko heap with 16ko index + heap = &h; - //Call static constructors + //Call static constructors (this will construct the Application object and get some stuff (arguments, ...)) u32int i = 0; for(u32int * call = &start_ctors; call < &end_ctors; call++) { ((void (*)(void))*call)(); } - invt = VirtualTerminal::getIn(); outvt = VirtualTerminal::getOut(); - if (!invt.valid()) threadFinishedSyscall(1); - if (!outvt.valid()) threadFinishedSyscall(2); - - u32int argc = Process::get().argc(); - Vector args(argc); - for (u32int i = 0; i < argc; i++) args[i] = Process::get().argv(i); - - u32int r = main(args); - - //Call static destructors - for(u32int * call = &start_dtors; call < &end_dtors; call++) { - ((void (*)(void))*call)(); - } - - threadFinishedSyscall(r); + app->doEvents(); + u32int r = app->run(); + app->doEvents(); + app->exit(r); //Will call static destructors } namespace Mem { - void* alloc (size_t sz) { return heap.alloc(sz); } - void free(void* ptr) { heap.free(ptr); } + void* alloc (size_t sz) { return heap->alloc(sz); } + void free(void* ptr) { heap->free(ptr); } void* mkXchgSpace (size_t sz) { return alloc(sz); } } -- cgit v1.2.3