summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/manager/Makefile9
-rw-r--r--src/modules/manager/main.c109
-rw-r--r--src/modules/test/main.c61
3 files changed, 21 insertions, 158 deletions
diff --git a/src/modules/manager/Makefile b/src/modules/manager/Makefile
deleted file mode 100644
index abce5cb..0000000
--- a/src/modules/manager/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-Obj = main.o
-Out = manager.elf
-
-include ../../common.make
-
-CFLAGS += -I ../../include
-
-LDFLAGS += -T ../../library/link.ld -L ../../library -Map manager.map
-
diff --git a/src/modules/manager/main.c b/src/modules/manager/main.c
deleted file mode 100644
index 58d9232..0000000
--- a/src/modules/manager/main.c
+++ /dev/null
@@ -1,109 +0,0 @@
-#include <gc/syscall.h>
-#include <gc/mem.h>
-#include <gc/server.h>
-#include <gm/method.h>
-#include <gm/call/manager.h>
-#include <string.h>
-
-char *loglevels[] = {"Critical", "Error", "Warning", "Notice", "Status", "Debug"};
-int loglevel = LL_DEBUG;
-
-struct service {
- char* name;
- int pid;
- Object obj;
- struct service *next;
-};
-
-struct service *services = 0;
-
-//************************ FUNCTIONS THAT DO STUFF ********************
-void logsvc(int pid, char* log, int level) {
- if (level > loglevel || level < 0) return;
- struct service *svc = services;
- while (svc) {
- if (svc->pid == pid) break;
- svc = svc->next;
- }
- if (svc == 0) {
- printk("[log:??] ");
- } else {
- printk("[log:"); printk(svc->name); printk("] ");
- }
- printk(loglevels[level]); printk(": ");
- printk(log); printk("\n");
-}
-
-void registersvc(int pid, char* name, Object descriptor) {
- struct service *svc = malloc(sizeof(struct service));
- svc->name = strdup(name);
- svc->pid = pid;
- svc->obj = descriptor;
- svc->next = services;
- services = svc;
- char msg[100] = "Service registered: ";
- strcat(msg, svc->name);
- logsvc(1, msg, LL_NOTICE);
-}
-
-//****************************** HANDLING METHODS ON MAIN OBJECT *****************
-struct method_ret handle_nothing(struct method_data *d) {
- if (d->blocking) logsvc(1, "Received a {nothing} request.", LL_DEBUG);
- else logsvc(1, "Received a {nothing} message.", LL_DEBUG);
- return mr_void();
-}
-
-struct method_ret handle_open(struct method_data *d) {
- CHKSSTR(d, 0);
- char *svc = d->parameters[0].p;
- char *sep, *res;
- sep = strchr(svc, ':');
- if (sep != 0) *sep = '0';
- struct service *s = services;
- while (s) {
- if (strcmp(s->name, svc) == 0) break;
- s = s->next;
- }
- if (s == 0) return mr_err(-2);
- if (sep == 0) {
- return mr_obj(s->obj);
- } else {
- *sep = ':';
- res = sep + 1;
- // open service svc, ressource res
- Object r = c_open(s->obj, 1, res);
- if (r == -1) return mr_err(-3);
- return mr_obj(r);
- }
-}
-
-struct method_ret handle_registersvc(struct method_data *d) {
- CHKSSTR(d, 0);
- if (d->parameters[1].i == 0) return mr_err(-1);
- registersvc(d->pid, d->parameters[0].p, d->parameters[1].i);
- return mr_void();
-}
-
-struct method_ret handle_logsvc(struct method_data *d) {
- CHKSSTR(d, 0);
- logsvc(d->pid, d->parameters[0].p, d->parameters[1].i);
- return mr_void();
-}
-
-int main() {
- logsvc(1, "Manager module configuring...", LL_NOTICE);
- registersvc(1, "manager", 0);
-
- Server *mgr = srv_get(0);
- srv_addHandler(mgr, M_NOTHING_VVVV, handle_nothing);
-
- srv_addHandler(mgr, M_OPEN_OMVV, handle_open);
- srv_addHandler(mgr, M_REGISTERSVC_VMOV, handle_registersvc);
- srv_addHandler(mgr, M_LOGSVC_VMIV, handle_logsvc);
-
- logsvc(1, "Manager module configured : starting request handling.", LL_STATUS);
- srv_handle(mgr, HA_LOOP);
-
- printk("[manager] Manager EPIC FAIL.\n");
- return 0;
-}
diff --git a/src/modules/test/main.c b/src/modules/test/main.c
index 493867e..8085007 100644
--- a/src/modules/test/main.c
+++ b/src/modules/test/main.c
@@ -1,53 +1,34 @@
#include <gc/syscall.h>
#include <gc/mem.h>
-#include <gc/server.h>
-#include <gm/method.h>
-#include <gm/call.h>
-#include <gm/call/manager.h>
#include <stdlib.h>
-#define FACTOR 4
-
-struct method_ret nulhandle(struct method_data *d) {
- if (d->blocking) c_logSvc("Handling a nothing request.", LL_STATUS);
- else c_logSvc("Handling a nothing message.", LL_STATUS);
- return mr_void();
-}
-
-struct method_ret openhandle(struct method_data *d) {
- CHKSSTR(d, 0);
- printk("test.open: "); printk(d->parameters[0].p); printk("\n");
- return mr_err(-1);
-}
-
-void thread2(void* d) {
- Server *s = srv_get(0);
- srv_addHandler(s, M_NOTHING_VVVV, nulhandle);
- srv_addHandler(s, M_OPEN_OMVV, openhandle);
- while (1) {
- c_logSvc("{2} Waiting for a request on main object...", LL_STATUS);
- srv_handle(s, HA_WAIT);
- }
-}
-
void thread_cascade(void* d) {
- c_logSvc("{#} Thread cascade element started. Continuing.", LL_STATUS);
- thread_new(thread_cascade, (void*)((int)d - 1));
- c_logSvc("{#} Thread cascade element finished.", LL_STATUS);
+ int n = (int)d;
+
+ if (d == 0) {
+ printk("{#} 0 cascade element started => end\n");
+ } else {
+ if (n < 0) {
+ printk("{#} - cascade element started\n");
+ n = 0 - n;
+ } else {
+ printk("{#} + cascade element started\n");
+ }
+ printk("{#} FORK + ...\n");
+ thread_new(thread_cascade, (void*)(n - 1));
+ printk("{#} FORK - ...\n");
+ thread_new(thread_cascade, (void*)(1 - n));
+ printk("{#} Thread cascade element finished.\n");
+ }
}
int main() {
- c_logSvc("Hi world from unregistered test module !", LL_NOTICE);
- c_registerSvc("test");
- c_logSvc("Creating new thread...", LL_STATUS);
- thread_new(thread2, 0);
- c_logSvc("{1} Sending a test message to manager", LL_STATUS);
- c_nothing(1, 0);
+ printk("Hi world from unregistered test module !\n");
- c_logSvc("{1} Creating thread cascade len:3", LL_STATUS);
- thread_new(thread_cascade, (void*)3);
+ printk("{1} Creating thread cascade len:1\n");
+ thread_new(thread_cascade, (void*)1);
- c_logSvc("{1} Thread now sleeping...", LL_WARNING);
+ printk("{1} Thread now sleeping...\n");
while (1) thread_sleep(1000);
return 0;
}