Change wyebuntil to run on idle

This commit is contained in:
jun7 2018-05-22 14:24:54 +09:00
parent 257c0a893c
commit 49555db038

View File

@ -364,44 +364,53 @@ void wyebsend(char *exe, char *req)
{ {
request(exe, CSdata, NULL, req); request(exe, CSdata, NULL, req);
} }
void wyebuntil(char *exe, int sec) typedef struct {
char *exe;
int sec;
} wyebsst;
static void wsfree(wyebsst *ss)
{
g_free(ss->exe);
g_free(ss);
}
static gboolean untilcb(wyebsst *ss)
{ {
if (!lastsec) if (!lastsec)
lastsec = g_hash_table_new(g_str_hash, g_str_equal); lastsec = g_hash_table_new(g_str_hash, g_str_equal);
g_hash_table_replace(lastsec, exe, GINT_TO_POINTER(sec)); g_hash_table_replace(lastsec, ss->exe, GINT_TO_POINTER(ss->sec));
char *str = g_strdup_printf("%d", sec); char *str = g_strdup_printf("%d", ss->sec);
request(exe, CSuntil, NULL, str); request(ss->exe, CSuntil, NULL, str);
g_free(str); g_free(str);
return false;
}
void wyebuntil(char *exe, int sec)
{
wyebsst *ss = g_new(wyebsst, 1);
ss->exe = g_strdup(exe);
ss->sec = sec;
g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)untilcb,
ss, (GDestroyNotify)wsfree);
} }
typedef struct { static gboolean loopcb(wyebsst *ss)
char *exe;
int sec;
} wyebloopt;
static void wlfree(wyebloopt *wl)
{ {
g_free(wl->exe); untilcb(ss);
g_free(wl);
}
static gboolean loopcb(wyebloopt *wl)
{
wyebuntil(wl->exe, wl->sec);
return true; return true;
} }
guint wyebloop(char *exe, int sec, int loopsec) guint wyebloop(char *exe, int sec, int loopsec)
{ {
wyebloopt *wl = g_new(wyebloopt, 1); wyebsst *ss = g_new(wyebsst, 1);
wl->exe = g_strdup(exe); ss->exe = g_strdup(exe);
wl->sec = sec; ss->sec = sec;
loopcb(wl); loopcb(ss);
return g_timeout_add_full(G_PRIORITY_DEFAULT, return g_timeout_add_full(G_PRIORITY_DEFAULT,
loopsec * 1000, loopsec * 1000,
(GSourceFunc)loopcb, (GSourceFunc)loopcb,
wl, ss, (GDestroyNotify)wsfree);
(GDestroyNotify)wlfree);
} }
static gboolean tcinputcb(GIOChannel *ch, GIOCondition c, char *exe) static gboolean tcinputcb(GIOChannel *ch, GIOCondition c, char *exe)