Skip to content

Commit

Permalink
add (initialising ...) and (initialised ...), as well as (get-schedul…
Browse files Browse the repository at this point in the history
…er-data) and a minor optimisation to the system update stage
  • Loading branch information
EffinMaggie committed Nov 16, 2009
1 parent 2ae6449 commit ef82311
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 8 deletions.
48 changes: 40 additions & 8 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
#include <kyuba/ipc.h>
#include <kyuba/types.h>

define_symbol (sym_update, "update");
define_symbol (sym_update, "update");
define_symbol (sym_initialising, "initialising");
define_symbol (sym_initialised, "initialised");
define_symbol (sym_get_scheduler_data, "get-scheduler-data");

static sexpr system_data;
static int currently_initialising = 0;

/* the module list is taken as the primary listing, so this function is
supposed to update the list of services using the dependency information
Expand Down Expand Up @@ -152,7 +156,20 @@ static void update_services ( void )

c = cdr (c);
}
/* TODO: update services here */
}

static void print_scheduler_data ()
{
sexpr sys = lx_environment_alist (system_data);

while (consp (sys))
{
sexpr sc = car (sys), sd = cdr (sc);

kyu_command (cons (sym_update, cons (sd, sx_end_of_list)));

sys = cdr (sys);
}
}

static void on_event (sexpr sx, void *aux)
Expand Down Expand Up @@ -227,12 +244,6 @@ static void on_event (sexpr sx, void *aux)

system_data = lx_environment_bind
(system_data, target_system, ts);

update_services();

ts = lx_environment_lookup (system_data, target_system);

kyu_command (cons (sym_update, cons (ts, sx_end_of_list)));
}
}
else if (ksystemp (a))
Expand All @@ -243,6 +254,27 @@ static void on_event (sexpr sx, void *aux)
system_data = lx_environment_bind (system_data, name, a);
}
}
else if (truep (equalp (a, sym_initialising)))
{
currently_initialising++;
}
else if (truep (equalp (a, sym_initialised)))
{
if (currently_initialising > 0)
{
currently_initialising--;
}

if (currently_initialising == 0)
{
update_services();
print_scheduler_data ();
}
}
else if (truep (equalp (a, sym_get_scheduler_data)))
{
print_scheduler_data ();
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/server-job.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ define_symbol (sym_kyuba_ipc, "kyuba-ipc");
define_symbol (sym_none, "none");
define_symbol (sym_active, "active");
define_symbol (sym_inactive, "inactive");
define_symbol (sym_initialising, "initialising");
define_symbol (sym_initialised, "initialised");

static sexpr global_environment;
static sexpr binaries;
static int open_config_files = 0;

static void on_job_file_read (sexpr sx, struct sexpr_io *io, void *p)
{
Expand Down Expand Up @@ -144,6 +147,15 @@ static void on_job_file_read (sexpr sx, struct sexpr_io *io, void *p)
}
}
}
else if (eofp (sx))
{
open_config_files--;
if (open_config_files == 0)
{
kyu_command (cons (sym_initialised,
cons (sym_server_job, sx_end_of_list)));
}
}
}

static void on_event (sexpr sx, void *aux)
Expand All @@ -164,6 +176,9 @@ static void on_event (sexpr sx, void *aux)

if (truep (equalp (a, sym_server_job)))
{
kyu_command (cons (sym_initialising,
cons (sym_server_job, sx_end_of_list)));

sx = lx_environment_lookup (car (cdr (sx)), sym_source);

while (consp (sx))
Expand All @@ -174,6 +189,8 @@ static void on_event (sexpr sx, void *aux)
{
sexpr t = car (files);

open_config_files++;

multiplex_add_sexpr
(sx_open_i (io_open_read (sx_string (t))),
on_job_file_read, (void *)0);
Expand All @@ -183,6 +200,12 @@ static void on_event (sexpr sx, void *aux)

sx = cdr (sx);
}

if (open_config_files == 0)
{
kyu_command (cons (sym_initialised,
cons (sym_server_job, sx_end_of_list)));
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/server-seteh.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ define_symbol (sym_functions, "functions");
define_symbol (sym_start, "start");
define_symbol (sym_stop, "stop");

define_symbol (sym_initialising, "initialising");
define_symbol (sym_initialised, "initialised");

static sexpr global_environment;
static int open_config_files = 0;

static void on_script_file_read (sexpr sx, struct sexpr_io *io, void *p)
{
Expand Down Expand Up @@ -134,6 +138,15 @@ static void on_script_file_read (sexpr sx, struct sexpr_io *io, void *p)
cons (module, sx_end_of_list))));
}
}
else if (eofp (sx))
{
open_config_files--;
if (open_config_files == 0)
{
kyu_command (cons (sym_initialised,
cons (sym_server_seteh, sx_end_of_list)));
}
}
}

static void on_event (sexpr sx, void *aux)
Expand All @@ -154,6 +167,9 @@ static void on_event (sexpr sx, void *aux)

if (truep (equalp (a, sym_server_seteh)))
{
kyu_command (cons (sym_initialising,
cons (sym_server_seteh, sx_end_of_list)));

sx = lx_environment_lookup (car (cdr (sx)), sym_source);

while (consp (sx))
Expand All @@ -164,6 +180,8 @@ static void on_event (sexpr sx, void *aux)
{
sexpr t = car (files);

open_config_files++;

multiplex_add_sexpr
(sx_open_i (io_open_read (sx_string (t))),
on_script_file_read, (void *)0);
Expand All @@ -173,6 +191,12 @@ static void on_event (sexpr sx, void *aux)

sx = cdr (sx);
}

if (open_config_files == 0)
{
kyu_command (cons (sym_initialised,
cons (sym_server_seteh, sx_end_of_list)));
}
}
}
}
Expand Down

0 comments on commit ef82311

Please sign in to comment.