2001-07-30 09:59:37 -07:00
|
|
|
#include "fs.h"
|
|
|
|
#include "exec.h"
|
2001-02-09 00:13:16 -08:00
|
|
|
|
|
|
|
static EfsdConnection *ec = NULL;
|
|
|
|
static Evas_List fs_handlers = NULL;
|
2001-04-26 13:41:23 -07:00
|
|
|
static Evas_List fs_restart_handlers = NULL;
|
|
|
|
static pid_t efsd_pid = 0;
|
2001-02-09 00:13:16 -08:00
|
|
|
|
2001-04-26 13:41:23 -07:00
|
|
|
static void e_fs_child_handle(Eevent *ev);
|
2001-02-09 00:13:16 -08:00
|
|
|
static void _e_fs_fd_handle(int fd);
|
2001-04-26 13:41:23 -07:00
|
|
|
static void _e_fs_restarter(int val, void *data);
|
|
|
|
|
|
|
|
static void
|
|
|
|
e_fs_child_handle(Eevent *ev)
|
|
|
|
{
|
|
|
|
Ev_Child *e;
|
|
|
|
|
|
|
|
e = ev->event;
|
2001-08-09 16:48:40 -07:00
|
|
|
printf("pid went splat! (%i)\n", e->pid);
|
2001-04-26 13:41:23 -07:00
|
|
|
if (e->pid == efsd_pid)
|
|
|
|
{
|
2001-08-09 16:48:40 -07:00
|
|
|
printf("it was efsd!\n");
|
|
|
|
if (ec) efsd_close(ec);
|
2001-04-26 13:41:23 -07:00
|
|
|
ec = NULL;
|
2001-08-09 16:48:40 -07:00
|
|
|
efsd_pid = 0;
|
|
|
|
_e_fs_restarter(1, NULL);
|
2001-04-26 13:41:23 -07:00
|
|
|
}
|
|
|
|
}
|
2001-02-09 00:13:16 -08:00
|
|
|
|
2001-02-12 16:18:42 -08:00
|
|
|
static void
|
2001-03-15 17:14:42 -08:00
|
|
|
_e_fs_fd_handle(int fd)
|
2001-02-12 16:18:42 -08:00
|
|
|
{
|
2001-03-15 17:14:42 -08:00
|
|
|
double start, current;
|
2001-02-15 15:10:30 -08:00
|
|
|
|
2001-03-15 17:14:42 -08:00
|
|
|
start = e_get_time();
|
2001-02-15 15:10:30 -08:00
|
|
|
while ((ec) && efsd_events_pending(ec))
|
2001-03-15 17:14:42 -08:00
|
|
|
{
|
2001-03-23 19:18:17 -08:00
|
|
|
EfsdEvent ev;
|
2001-03-15 17:14:42 -08:00
|
|
|
|
2001-03-23 19:18:17 -08:00
|
|
|
if (efsd_next_event(ec, &ev) >= 0)
|
2001-02-15 15:10:30 -08:00
|
|
|
{
|
2001-03-23 19:18:17 -08:00
|
|
|
Evas_List l;
|
|
|
|
|
|
|
|
for (l = fs_handlers; l; l = l->next)
|
|
|
|
{
|
|
|
|
void (*func) (EfsdEvent *ev);
|
|
|
|
|
|
|
|
func = l->data;
|
|
|
|
func(&ev);
|
|
|
|
}
|
|
|
|
efsd_event_cleanup(&ev);
|
2001-02-15 15:10:30 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
efsd_close(ec);
|
|
|
|
e_del_event_fd(fd);
|
|
|
|
ec = NULL;
|
2001-08-09 16:48:40 -07:00
|
|
|
_e_fs_restarter(0, NULL);
|
2001-02-15 15:10:30 -08:00
|
|
|
/* FIXME: need to queue a popup dialog here saying */
|
|
|
|
/* efsd went wonky */
|
2001-07-29 23:21:28 -07:00
|
|
|
printf("EEEEEEEEEEK efsd went wonky. Bye bye efsd.\n");
|
2001-02-15 15:10:30 -08:00
|
|
|
}
|
|
|
|
|
2001-03-15 17:14:42 -08:00
|
|
|
/* spent more thna 1/20th of a second here.. get out */
|
|
|
|
current = e_get_time();
|
|
|
|
if ((current - start) > 0.05)
|
|
|
|
{
|
|
|
|
printf("fs... too much time spent..\n");
|
|
|
|
break;
|
|
|
|
}
|
2001-08-09 16:48:40 -07:00
|
|
|
}
|
2001-02-09 00:13:16 -08:00
|
|
|
}
|
|
|
|
|
2001-04-26 13:41:23 -07:00
|
|
|
static void
|
|
|
|
_e_fs_restarter(int val, void *data)
|
|
|
|
{
|
|
|
|
if (ec) return;
|
2001-07-31 22:22:39 -07:00
|
|
|
ec = efsd_open();
|
2001-08-09 16:48:40 -07:00
|
|
|
printf("restart efsd...\n");
|
2001-07-31 22:22:39 -07:00
|
|
|
if ((!ec) && (val > 0))
|
2001-04-26 13:41:23 -07:00
|
|
|
{
|
2001-08-09 16:48:40 -07:00
|
|
|
if (efsd_pid <= 0)
|
|
|
|
{
|
|
|
|
efsd_pid = e_exec_run("efsd -f");
|
|
|
|
printf("launch efsd... %i\n", efsd_pid);
|
|
|
|
}
|
2001-07-29 23:21:28 -07:00
|
|
|
if (efsd_pid > 0) ec = efsd_open();
|
2001-04-26 13:41:23 -07:00
|
|
|
}
|
|
|
|
if (ec)
|
|
|
|
{
|
|
|
|
Evas_List l;
|
|
|
|
|
2001-07-12 09:40:13 -07:00
|
|
|
e_add_event_fd(efsd_get_connection_fd(ec), _e_fs_fd_handle);
|
2001-04-26 13:41:23 -07:00
|
|
|
for (l = fs_restart_handlers; l; l = l->next)
|
|
|
|
{
|
|
|
|
E_FS_Restarter *rs;
|
|
|
|
|
|
|
|
rs = l->data;
|
|
|
|
rs->func(rs->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double gap;
|
|
|
|
|
|
|
|
gap = (double)val / 10;
|
|
|
|
if (gap > 10.0) gap = 10.0;
|
|
|
|
e_add_event_timer("e_fs_restarter", gap, _e_fs_restarter, val + 1, NULL);
|
|
|
|
}
|
2001-07-30 18:12:02 -07:00
|
|
|
UN(data);
|
2001-04-26 13:41:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
E_FS_Restarter *
|
|
|
|
e_fs_add_restart_handler(void (*func) (void *data), void *data)
|
|
|
|
{
|
|
|
|
E_FS_Restarter *rs;
|
|
|
|
|
|
|
|
rs = NEW(E_FS_Restarter, 1);
|
|
|
|
ZERO(rs, E_FS_Restarter, 1);
|
|
|
|
rs->func = func;
|
|
|
|
rs->data = data;
|
|
|
|
fs_restart_handlers = evas_list_append(fs_restart_handlers, rs);
|
2001-07-30 09:59:37 -07:00
|
|
|
|
|
|
|
return rs;
|
2001-04-26 13:41:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
e_fs_del_restart_handler(E_FS_Restarter *rs)
|
|
|
|
{
|
|
|
|
if (evas_list_find(fs_restart_handlers, rs))
|
|
|
|
{
|
|
|
|
fs_restart_handlers = evas_list_remove(fs_restart_handlers, rs);
|
|
|
|
FREE(rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-09 00:13:16 -08:00
|
|
|
void
|
|
|
|
e_fs_add_event_handler(void (*func) (EfsdEvent *ev))
|
|
|
|
{
|
|
|
|
if (!func) return;
|
|
|
|
fs_handlers = evas_list_append(fs_handlers, func);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
e_fs_init(void)
|
|
|
|
{
|
2001-04-26 13:41:23 -07:00
|
|
|
e_event_filter_handler_add(EV_CHILD, e_fs_child_handle);
|
2001-07-29 23:21:28 -07:00
|
|
|
_e_fs_restarter(0, NULL);
|
2001-02-12 10:58:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EfsdConnection *
|
|
|
|
e_fs_get_connection(void)
|
|
|
|
{
|
|
|
|
return ec;
|
2001-02-09 00:13:16 -08:00
|
|
|
}
|