added %time vane

This commit is contained in:
Ubuntu 2014-10-15 02:25:23 +00:00
parent 502abc8667
commit 383ab05977
7 changed files with 128 additions and 1 deletions

View File

@ -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 \

View File

@ -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')

View File

@ -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.

View File

@ -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";

View File

@ -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

View File

@ -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);
}

93
v/temp.c Normal file
View File

@ -0,0 +1,93 @@
/* v/temp.c
**
** This file is in the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <setjmp.h>
#include <gmp.h>
#include <dirent.h>
#include <stdint.h>
#include <uv.h>
#include <curses.h>
#include <termios.h>
#include <term.h>
#include <errno.h>
#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);
}