Kaydet (Commit) 444985ae authored tarafından Gürer Özen's avatar Gürer Özen

job.c'yi db yi kullanacak şekle getirdim.

az biraz dökümantasyon.
üst 42841152
COMARd
======
Modüller:
* model.c Sistem modelini yükleme/indeksleme
* data.c Veritabanı (acl, script, apps, model, config)
* job.c İş yapan süreçler (Register, Execute, Remove script)
* process.c Süreç yönetimi ve süreçler arası iletişim
* cfg.c Komut satırı parametreleri
* rpc_unix.c Unix soket üzerinden comar çağrısı modülü
* main.c Ana süreç
Kod stili:
* K&R
* Fonksiyon isimleri (module)_(görev) şeklinde
* Ana süreçte hazırlık işlemleri (module)_init
* Yeni bir süreç başlatan fonksiyonlar (module)_start [ _(opsiyonel isim)]
/*
** Copyright (c) 2005, TUBITAK/UEKAE
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 2 of the License, or (at your
** option) any later version. Please read the COPYING file.
*/
#ifndef JOB_H
#define JOB_H 1
int job_start_register(int node_no, const char *app, const char *csl_file);
int job_start_execute(int node_no, const char *app);
#endif /*JOB_H */
......@@ -13,6 +13,7 @@
int model_init(void);
int model_lookup_object(const char *path);
int model_lookup_method(const char *path);
int model_parent(int node_no);
const char *model_get_method(int node_no);
......
......@@ -14,6 +14,17 @@
#include "csl.h"
#include "process.h"
#include "data.h"
struct reg_cmd {
int node_no;
size_t app_len;
char data[2];
};
struct exec_cmd {
int node_no;
};
static unsigned char *
load_file(const char *fname, int *sizeptr)
......@@ -52,43 +63,112 @@ load_file(const char *fname, int *sizeptr)
return data;
}
void
job_start(void)
static void
register_proc(void)
{
struct reg_cmd *cmd;
struct ProcChild *sender;
char *buf;
char *code;
char *func;
char *res;
int reslen;
size_t codelen;
int e;
while (1) {
if (1 == proc_listen(&sender, 1)) break;
}
proc_get_data(sender, &func);
proc_get_data(sender, &cmd);
csl_setup();
buf = load_file("test.py", NULL);
e = csl_compile(buf, "test", &code, &codelen);
if (e) {
buf = load_file(&cmd->data[0] + cmd->app_len + 1, NULL);
if (!buf) {
proc_send_cmd(TO_PARENT, CMD_FAIL, 0);
exit(1);
}
e = csl_execute(code, codelen, func, &res, &reslen);
e = csl_compile(buf, "test", &code, &codelen);
if (e) {
proc_send_cmd(TO_PARENT, CMD_FAIL, 0);
exit(4);
exit(1);
}
db_put_script(cmd->node_no, &cmd->data[0], code, codelen);
proc_send_cmd(TO_PARENT, CMD_RESULT, 0);
csl_cleanup();
}
int
job_start_register(int node_no, const char *app, const char *csl_file)
{
struct ProcChild *p;
struct reg_cmd *cmd;
size_t sz;
sz = sizeof(struct reg_cmd) + strlen(app) + strlen(csl_file);
cmd = malloc(sz);
if (!cmd) return -1;
cmd->node_no = node_no;
cmd->app_len = strlen(app);
strcpy(&cmd->data[0], app);
strcpy(&cmd->data[0] + strlen(app) + 1, csl_file);
p = proc_fork(register_proc);
if (!p) {
free(cmd);
return -1;
}
proc_send_cmd(p, CMD_CALL, sz);
proc_send_data(p, cmd, sz);
free(cmd);
return 0;
}
static void
exec_proc(void)
{
struct ProcChild *sender;
struct exec_cmd *cmd;
char *apps;
char *code;
char *res;
size_t reslen;
size_t size;
int e;
while (1) {
if (1 == proc_listen(&sender, 1)) break;
}
proc_get_data(sender, &cmd);
proc_send_cmd(TO_PARENT, CMD_RESULT, reslen);
if (reslen)
proc_send_data(TO_PARENT, res, reslen);
csl_setup();
if (db_open_node(model_parent(cmd->node_no), &apps) != 0) {
proc_send_cmd(TO_PARENT, CMD_FAIL, 0);
exit(1);
}
// FIXME: multiple apps & value return
db_get_code(apps, &code, &size);
e = csl_execute(code, size, model_get_method(cmd->node_no), &res, &reslen);
free(res);
db_close_node();
csl_cleanup();
}
int
job_start_execute(int node_no, const char *app) // FIXME: args
{
struct ProcChild *p;
struct exec_cmd cmd;
cmd.node_no = node_no;
p = proc_fork(exec_proc);
if (!p) return -1;
proc_send_cmd(p, CMD_CALL, sizeof(struct exec_cmd));
proc_send_data(p, &cmd, sizeof(struct exec_cmd));
return 0;
}
......@@ -15,8 +15,8 @@
#include "process.h"
#include "model.h"
#include "data.h"
#include "job.h"
void job_start(void);
void rpc_unix_start(void);
int
......@@ -32,12 +32,18 @@ main(int argc, char *argv[])
proc_init();
model_init();
job_start_register(model_lookup_object("Net.NIC"), "eth", "test.py");
rpc = proc_fork(rpc_unix_start);
while (1) {
if (1 == proc_listen(&p, 1)) {
printf("Child %d said %d, %d.\n", p->pid, p->cmd.cmd, p->cmd.data_size);
if (p == rpc) {
if (p->cmd.cmd == CMD_RESULT) {
puts("hede");
job_start_execute(model_lookup_method("Net.NIC.up"), NULL);
}
/* if (p == rpc) {
size = p->cmd.data_size - 4;
proc_get_data(p, &data);
p = proc_fork(job_start);
......@@ -69,7 +75,7 @@ main(int argc, char *argv[])
}
break;
}
}
} */
}
// puts("tick");
}
......
......@@ -22,7 +22,7 @@ struct node {
const char *path;
const char *method;
struct node *next;
struct node *parent; // FIXME: for acl stuff, not used yet
int parent_no;
int type;
int no;
};
......@@ -55,8 +55,8 @@ prepare_tables(int max_nodes, size_t str_size)
return 0;
}
static void
add_node(const char *path, int type)
static int
add_node(int parent_no, const char *path, int type)
{
struct node *n;
int val;
......@@ -71,24 +71,28 @@ add_node(const char *path, int type)
} else {
n->method = NULL;
}
n->parent_no = parent_no;
n->type = type;
n->no = nr_nodes++;
val = hash_string(path, len) % TABLE_SIZE;
n->next = node_table[val];
node_table[val] = n;
return n->no;
}
int
model_init(void)
{
int no;
// FIXME: silly test case, replace with real loader
if (prepare_tables(4, 128)) return -1;
add_node("Net", N_MODULE);
add_node("Net.NIC", N_OBJECT);
add_node("Net.NIC.up", N_METHOD);
add_node("Net.NIC.down", N_METHOD);
no = add_node(-1, "Net", N_MODULE);
no = add_node(no, "Net.NIC", N_OBJECT);
add_node(no, "Net.NIC.up", N_METHOD);
add_node(no, "Net.NIC.down", N_METHOD);
return 0;
}
......@@ -123,6 +127,15 @@ model_lookup_method(const char *path)
return -1;
}
int
model_parent(int node_no)
{
struct node *n;
n = &nodes[node_no];
return n->parent_no;
}
const char *
model_get_method(int node_no)
{
......
......@@ -2,9 +2,8 @@
import comar
def funcA():
comar.call("funcB")
return "Ahmet"
def up():
print "Ahmet"
def funcB():
return "Baran"
def down():
print "Baran"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment