summaryrefslogtreecommitdiff
path: root/Source/Library/Userland/App
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Library/Userland/App')
-rw-r--r--Source/Library/Userland/App/Application.proto.h41
-rw-r--r--Source/Library/Userland/App/ShellApp.proto.h18
2 files changed, 59 insertions, 0 deletions
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 <Binding/Process.class.h>
+#include <String.class.h>
+
+extern u32int start_dtors, end_dtors;
+
+#define APP(t) static t the_app; \
+ Application *app = &the_app;
+
+class Application {
+ public:
+ Process pr;
+ Vector<String> 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 <App/Application.proto.h>
+#include <Binding/VirtualTerminal.class.h>
+
+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
+