summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2010-04-07 11:37:21 +0200
committerAlexis211 <alexis211@gmail.com>2010-04-07 11:37:21 +0200
commitee348973b0cb0f6481e4fd6e7494c63167c9759c (patch)
treea9f1cd82703aaeeefbf4cf449203881cfcafc0a5 /src/modules
parentca4f5906f284e60a7a59ca7450e3e09c4f9356e5 (diff)
downloadTCE-ee348973b0cb0f6481e4fd6e7494c63167c9759c.tar.gz
TCE-ee348973b0cb0f6481e4fd6e7494c63167c9759c.zip
More work on manager
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/manager/main.c97
-rw-r--r--src/modules/test/main.c60
2 files changed, 115 insertions, 42 deletions
diff --git a/src/modules/manager/main.c b/src/modules/manager/main.c
index 9e23097..d211831 100644
--- a/src/modules/manager/main.c
+++ b/src/modules/manager/main.c
@@ -2,20 +2,107 @@
#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) printk("[manager] Received a {nothing} request.\n");
- else printk("[manager] Received a {nothing} message.\n");
+ 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;
+ printk("open: "); printk(svc); printk("\n");
+ 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() {
- printk("[manager] Manager module configuring...\n");
- Server *mgr = srv_get(0);
+ logsvc(1, "Manager module configuring...", LL_NOTICE);
+ registersvc(1, "manager", 0);
+ Server *mgr = srv_get(0);
srv_addHandler(mgr, M_NOTHING_VVVV, handle_nothing);
- printk("[manager] Manager module configured : starting request handling.\n");
+ 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");
diff --git a/src/modules/test/main.c b/src/modules/test/main.c
index 148490b..88242e5 100644
--- a/src/modules/test/main.c
+++ b/src/modules/test/main.c
@@ -2,60 +2,46 @@
#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
-int obj = -1;
-
struct method_ret nulhandle(struct method_data *d) {
- if (d->blocking) printk("[test:2?] Handling a request.\n");
- else printk("[test:2?] Handling a message.\n");
+ 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) {
- printk("[test:2] Creating new object...\n");
- Server *s = srv_create();
+ Server *s = srv_get(0);
srv_addHandler(s, M_NOTHING_VVVV, nulhandle);
- obj = s->id;
+ srv_addHandler(s, M_OPEN_OMVV, openhandle);
while (1) {
- printk("[test:2] Waiting for a request...\n");
+ c_logSvc("{2} Waiting for a request on main object...", LL_STATUS);
srv_handle(s, HA_WAIT);
}
}
int main() {
- int i;
-
- printk("[test:1] Hi world !\n");
- printk("[test:1] Creating new thread...\n");
+ c_logSvc("Hi world from unregistered test module !", LL_NOTICE);
+ c_registerSvc("test");
+ c_logSvc("Creating new thread...", LL_STATUS);
thread_new(thread2, 0);
- while (obj == -1);
- printk("[test:1] Object was created. Sending request...\n");
- struct user_sendrequest sr;
- sr.func = M_NOTHING_VVVV;
- request(obj, &sr);
- printk("[test:1] Got answer. Now sending request to manager...\n");
- request(1, &sr);
- printk("[test:1] And now a message to manager...\n");
- send_msg(1, &sr);
+ c_logSvc("{1} Sending a test message to manager", LL_STATUS);
+ c_nothing(1, 0);
- printk("[test:1] testing malloc and free...");
- int* v = malloc(10 * sizeof(int));
- if (v == 0) printk("zero");
- int* vv = malloc(10 * sizeof(int));
- for (i = 0; i < 10; i++) { v[i] = i * 1243; }
- for (i = 0; i < 10; i++) { vv[i] = i * 2; }
- for (i = 0; i < 10; i++) {
- if (v[i] != i * 1243) printk("FAIL");
- }
- for (i = 0; i < 10; i++) {
- if (vv[i] != i * 2) printk("fail");
- }
- free(v); free(vv);
- printk("nothing bad happened :)\n");
+ Object t = open("test");
+ printk("Open 'test' : "); printk_int(t); printk("\n");
- printk("[test:1] HAHA !!! Death of [test] in 1 seconds!\n");
- thread_sleep(1000);
+ c_logSvc("{1} Thread now sleeping...", LL_WARNING);
+ while (1) thread_sleep(1000);
return 0;
}