summaryrefslogtreecommitdiff
path: root/Source/Library/Userland/Binding
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Library/Userland/Binding')
-rw-r--r--Source/Library/Userland/Binding/FSNode.class.h1
-rw-r--r--Source/Library/Userland/Binding/File.class.h68
-rw-r--r--Source/Library/Userland/Binding/Process.class.h7
-rw-r--r--Source/Library/Userland/Binding/Sys.ns.cpp15
-rw-r--r--Source/Library/Userland/Binding/Sys.ns.h26
5 files changed, 98 insertions, 19 deletions
diff --git a/Source/Library/Userland/Binding/FSNode.class.h b/Source/Library/Userland/Binding/FSNode.class.h
index 6a860ea..a7adbc0 100644
--- a/Source/Library/Userland/Binding/FSNode.class.h
+++ b/Source/Library/Userland/Binding/FSNode.class.h
@@ -2,6 +2,7 @@
#define DEF_FSNODE_CLASS_H
#include <Syscall/RessourceCaller.class.h>
+#include <String.class.h>
#include <FSNode.iface.h>
class FSNode : public RessourceCaller {
diff --git a/Source/Library/Userland/Binding/File.class.h b/Source/Library/Userland/Binding/File.class.h
new file mode 100644
index 0000000..4d1ac16
--- /dev/null
+++ b/Source/Library/Userland/Binding/File.class.h
@@ -0,0 +1,68 @@
+#ifndef DEF_FILE_CLASS_H
+#define DEF_FILE_CLASS_H
+
+#include <File.iface.h>
+#include <Binding/FSNode.class.h>
+#include <Syscall/RessourceCaller.class.h>
+#include <Binding/VirtualTerminal.class.h>
+#include <ByteArray.class.h>
+
+class File : public RessourceCaller {
+ public:
+ File(String name, u8int mode, FSNode start = FSNode(0)) :
+ RessourceCaller(sCall(FLIF_OBJTYPE, FLIF_SOPEN, (u32int)&name, mode, start.resId()), FLIF_OBJTYPE) {
+ }
+ File(u32int id) : RessourceCaller(id, FLIF_OBJTYPE) {}
+
+ void close() {
+ doCall(FLIF_CLOSE);
+ }
+ bool validOpened() {
+ return (doCall(FLIF_VALID) != 0);
+ }
+ u32int read(u32int max_length, u8int *ptr) {
+ return (doCall(FLIF_READ, max_length, (u32int)ptr));
+ }
+ bool write(u32int length, u8int* ptr) {
+ return (doCall(FLIF_WRITE, length, (u32int)ptr) != 0);
+ }
+ u32int read(ByteArray &data) {
+ if (!valid()) {
+ data.clear();
+ return 0;
+ }
+ u32int l = read(data.size(), (u8int*)data);
+ if (l != data.size()) data.resize(l);
+ return l;
+ }
+ bool write(ByteArray &data) {
+ if (!valid()) return false;
+ return write(data.size(), (u8int*)data);
+ }
+
+ template <typename T> bool read(T* elem) {
+ return (read(sizeof(T), (u8int*)elem) == sizeof(T));
+ }
+ template <typename T> bool write(T* elem) {
+ return write(sizeof(T), (u8int*)elem);
+ }
+
+ bool seek(u64int count, u8int mode) {
+ union {
+ u64int x;
+ u32int a[2];
+ } wat = {count};
+ return (doCall(FLIF_SEEK, wat.a[0], wat.a[1], mode) != 0);
+ }
+ u64int position() {
+ return *((u64int*)doCall(FLIF_POSITION));
+ }
+ u64int length() {
+ return *((u64int*)doCall(FLIF_LENGTH));
+ }
+ bool eof() {
+ return (doCall(FLIF_EOF) != 0);
+ }
+};
+
+#endif
diff --git a/Source/Library/Userland/Binding/Process.class.h b/Source/Library/Userland/Binding/Process.class.h
index ddca6be..9687ea9 100644
--- a/Source/Library/Userland/Binding/Process.class.h
+++ b/Source/Library/Userland/Binding/Process.class.h
@@ -29,8 +29,11 @@ class Process : public RessourceCaller {
u32int getPpid() {
return doCall(PRIF_GETPPID);
}
- String getCmdline() {
- return String::unserialize(doCall(PRIF_GETCMDLINE));
+ u32int argc() {
+ return doCall(PRIF_ARGC);
+ }
+ String argv(u32int idx) {
+ return String::unserialize(doCall(PRIF_ARGV, idx));
}
};
diff --git a/Source/Library/Userland/Binding/Sys.ns.cpp b/Source/Library/Userland/Binding/Sys.ns.cpp
deleted file mode 100644
index 7083e56..0000000
--- a/Source/Library/Userland/Binding/Sys.ns.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <Sys.iface.h>
-#include "Sys.ns.h"
-#include <Syscall/RessourceCaller.class.h>
-
-namespace Sys {
-
-void halt() {
- RessourceCaller::sCall(SYIF_IFID, SYIF_HALT);
-}
-
-void reboot() {
- RessourceCaller::sCall(SYIF_IFID, SYIF_REBOOT);
-}
-
-}
diff --git a/Source/Library/Userland/Binding/Sys.ns.h b/Source/Library/Userland/Binding/Sys.ns.h
index 3a8426b..eb09504 100644
--- a/Source/Library/Userland/Binding/Sys.ns.h
+++ b/Source/Library/Userland/Binding/Sys.ns.h
@@ -1,9 +1,31 @@
#ifndef DEF_SYS_NS_H
#define DEF_SYS_NS_H
+#include <Sys.iface.h>
+#include <Syscall/RessourceCaller.class.h>
+
namespace Sys {
- void halt();
- void reboot();
+
+inline void halt() {
+ RessourceCaller::sCall(SYIF_IFID, SYIF_HALT);
+}
+
+inline void reboot() {
+ RessourceCaller::sCall(SYIF_IFID, SYIF_REBOOT);
+}
+
+inline u32int uptime() { //Returns uptime in seconds
+ return RessourceCaller::sCall(SYIF_IFID, SYIF_UPTIME);
+}
+
+inline u32int totalRam() { //Returns total amount of RAM in Ko
+ return RessourceCaller::sCall(SYIF_IFID, SYIF_TOTALRAM);
+}
+
+inline u32int freeRam() { //Returns free amount of RAM in Ko
+ return RessourceCaller::sCall(SYIF_IFID, SYIF_FREERAM);
+}
+
}
#endif