From a8da6dba7ddc5e3d31a1914597e7b38fbc2d197c Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 10 Sep 2010 19:35:31 +0200 Subject: Removed all old object/request/... stuff (that was crap) --- src/modules/manager/Makefile | 9 ---- src/modules/manager/main.c | 109 ------------------------------------------- src/modules/test/main.c | 61 +++++++++--------------- 3 files changed, 21 insertions(+), 158 deletions(-) delete mode 100644 src/modules/manager/Makefile delete mode 100644 src/modules/manager/main.c (limited to 'src/modules') 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 -#include -#include -#include -#include -#include - -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 #include -#include -#include -#include -#include #include -#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; } -- cgit v1.2.3