diff --git a/Makefile b/Makefile index 62b28ded2..2bdcee4fe 100644 --- a/Makefile +++ b/Makefile @@ -283,6 +283,7 @@ V_OFILES=\ v/reck.o \ v/save.o \ v/sist.o \ + v/temp.o \ v/term.o \ v/time.o \ v/unix.o \ diff --git a/include/c/motes.h b/include/c/motes.h index 4bb4e88f6..82427b694 100644 --- a/include/c/motes.h +++ b/include/c/motes.h @@ -994,6 +994,7 @@ # define c3__teal c3_s4('t','e','a','l') # define c3__teck c3_s4('t','e','c','k') # define c3__tell c3_s4('t','e','l','l') +# define c3__temp c3_s4('t','e','m','p') # define c3__terg c3_s4('t','e','r','g') # define c3__term c3_s4('t','e','r','m') # define c3__test c3_s4('t','e','s','t') @@ -1001,6 +1002,7 @@ # define c3__this c3_s4('t','h','i','s') # define c3__thin c3_s4('t','h','i','n') # define c3__thud c3_s4('t','h','u','d') +# define c3__time c3_s4('t','i','m','e') # define c3__tgbn c3_s4('t','g','b','n') # define c3__tgbr c3_s4('t','g','b','r') # define c3__tgdg c3_s4('t','g','d','g') diff --git a/include/v/vere.h b/include/v/vere.h index 6159c2d10..70a8b9679 100644 --- a/include/v/vere.h +++ b/include/v/vere.h @@ -373,6 +373,14 @@ u2_bean alm; // alarm } u2_batz; + /* u2_temp: just a timer for ever + */ + typedef struct _u2_temp { + uv_timer_t tim_u; // clay timer + c3_w run_w; // run of consecutive alarms + u2_bean alm; // alarm + } u2_temp; + /* u2_utfo: unix terminfo strings. */ typedef struct { @@ -553,6 +561,7 @@ u2_opts ops_u; // commandline options u2_unix unx_u; // sync and clay u2_batz beh_u; // batz timer + u2_temp teh_u; // temp timer u2_bean liv; // if u2_no, shut down c3_i xit_i; // exit code for shutdown void* ssl_u; // struct SSL_CTX* @@ -1097,6 +1106,24 @@ u2_batz_io_poll(void); + /** Temp, just a timer. + **/ + /* u2_temp_io_init(): initialize temp timer. + */ + void + u2_temp_io_init(void); + + /* u2_temp_io_exit(): terminate timer. + */ + void + u2_temp_io_exit(void); + + /* u2_temp_io_poll(): update temp IO state. + */ + void + u2_temp_io_poll(void); + + /** HTTP server. **/ /* u2_http_ef_thou(): send %thou effect to http. diff --git a/v/loop.c b/v/loop.c index 6d1979438..8a344dd8b 100644 --- a/v/loop.c +++ b/v/loop.c @@ -168,6 +168,7 @@ _lo_init() u2_cttp_io_init(); u2_save_io_init(); u2_batz_io_init(); + u2_temp_io_init(); } /* _lo_talk(): bring up listeners across the process. @@ -193,6 +194,7 @@ u2_lo_exit(void) u2_cttp_io_exit(); u2_save_io_exit(); u2_batz_io_exit(); + u2_temp_io_exit(); } /* _lo_poll(): reset event flags across the process. @@ -206,6 +208,7 @@ _lo_poll(void) u2_save_io_poll(); u2_unix_io_poll(); u2_batz_io_poll(); + u2_temp_io_poll(); } #if 0 @@ -219,6 +222,7 @@ _lo_how(u2_noun how) case c3__ames: return "ames"; case c3__batz: return "batz"; + case c3__temp: return "temp"; case c3__term: return "cons"; case c3__htcn: return "http-conn"; case c3__htls: return "http-lisn"; diff --git a/v/raft.c b/v/raft.c index f0c071609..99023f6e0 100644 --- a/v/raft.c +++ b/v/raft.c @@ -1562,6 +1562,7 @@ _raft_punk(u2_reck* rec_u, u2_noun ovo) // if ( c3__wake != u2h(u2t(ovo)) ) { u2_Host.beh_u.run_w = 0; + u2_Host.teh_u.run_w = 0; } #ifdef GHETTO diff --git a/v/reck.c b/v/reck.c index 19b194282..311d8c425 100644 --- a/v/reck.c +++ b/v/reck.c @@ -169,7 +169,6 @@ _reck_nock_keep(u2_reck* rec_u, u2_noun hap) { u2_noun fun = u2_cn_nock(u2k(rec_u->roc), u2k(u2_cx_at(4, rec_u->roc))); u2_noun sam = u2nc(u2k(rec_u->now), hap); - return u2_cn_mung(fun, sam); } diff --git a/v/temp.c b/v/temp.c new file mode 100644 index 000000000..a13ee153d --- /dev/null +++ b/v/temp.c @@ -0,0 +1,93 @@ +/* v/temp.c +** +** This file is in the public domain. +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "all.h" +#include "f/coal.h" +#include "v/vere.h" + +/* u2_temp(): initialize time timer. +*/ +void +u2_temp_io_init(void) +{ + u2_temp* teh_u = &u2_Host.teh_u; + + uv_timer_init(u2L, &teh_u->tim_u); + teh_u->alm = u2_no; +} + +/* u2_temp_io_exit(): terminate timer. +*/ +void +u2_temp_io_exit(void) +{ +} + +/* _temp_time_cb(): timer callback. +*/ +static void +_temp_time_cb(uv_timer_t* tim_u) +{ + u2_temp* teh_u = &u2_Host.teh_u; + if(teh_u->run_w < 1024) { + teh_u->run_w++; + } + + u2_lo_open(); + { + u2_reck_plan + (u2A, + u2nt(u2_blip, c3__temp, u2_nul), + u2nc(c3__wake, u2_nul)); + } + u2_lo_shut(u2_no); +} + +/* u2_temp_io_poll(): update temp IO state. +*/ +void +u2_temp_io_poll(void) +{ + u2_temp* teh_u = &u2_Host.teh_u; + u2_noun wen = u2_reck_keep(u2A, u2nt(u2_blip, c3__temp, u2_nul)); + + if ( (u2_nul != wen) && + (u2_yes == u2du(wen)) && + (u2_yes == u2ud(u2t(wen))) ) + { + c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen))); + + gap_d += teh_u->run_w; + + if ( u2_yes == teh_u->alm ) { + uv_timer_stop(&teh_u->tim_u); + } + else teh_u->alm = u2_yes; + + uv_timer_start(&teh_u->tim_u, _temp_time_cb, gap_d, 0); + } + else { + if ( u2_yes == teh_u->alm ) { + uv_timer_stop(&teh_u->tim_u); + } + teh_u->alm = u2_no; + } + u2z(wen); +}