/* -*-C-*-
-$Id: $
-
-Copyright (C) 2008, 2009 Matthew Birkholz
+Copyright (C) 2008, 2009, 2010 Matthew Birkholz
This file is part of MIT/GNU Scheme.
GSource source;
/* This is in GSource, but is private(?). */
- GMainContext* main_context;
+ GMainContext * main_context;
/* The main loop running in main_context (if any). */
- GMainLoop* main_loop;
+ GMainLoop * main_loop;
/* The list of GPollFDs that have been added to the main_context. */
- GSList* gpollfds;
+ GSList * gpollfds;
/* When to give up waiting. */
double time_limit;
};
typedef struct _SchemeSource SchemeSource;
-static gboolean scheme_source_prepare (GSource* source, gint* timeout);
-static gboolean scheme_source_check (GSource* source);
-static int pending_io (SchemeSource* source);
-static gboolean scheme_source_dispatch (GSource* source, GSourceFunc callback, gpointer user_data);
-SchemeSource* scheme_source_new (void);
-void scheme_source_destroy (SchemeSource* source);
-static void clear_registry (SchemeSource* source);
-static void set_registry (SchemeSource* source, GSList* new, double time);
+static gboolean scheme_source_prepare (GSource * source, gint * timeout);
+static gboolean scheme_source_check (GSource * source);
+static int pending_io (SchemeSource * source);
+static gboolean scheme_source_dispatch (GSource * source, GSourceFunc callback, gpointer user_data);
+SchemeSource * scheme_source_new (void);
+void scheme_source_destroy (SchemeSource * source);
+static void clear_registry (SchemeSource * source);
+static void set_registry (SchemeSource * source, GSList * new, double time);
-static SchemeSource* scheme_source;
+static SchemeSource * scheme_source;
extern int cstack_depth; /* in pruxffi.c */
static SCHEME_OBJECT tracing_gtk_select;
-static GSList* gtk_registry (select_registry_t registry);
+static GSList * gtk_registry (select_registry_t registry);
static int slice_counter = 0;
-static GtkWidget* slice_window;
-static GtkWidget* slice_label;
-static GtkWidget* status_label;
+static GtkWidget * slice_window;
+static GtkWidget * slice_label;
+static GtkWidget * status_label;
static void open_slice_window (void);
static void close_slice_window (void);
-static gchar* gpollfds_string (GSList* gpollfds);
+static gchar * gpollfds_string (GSList * gpollfds);
static gboolean
-scheme_source_prepare (GSource* source, gint* timeout)
+scheme_source_prepare (GSource * source, gint * timeout)
{
/* Return TRUE when ready to dispatch (without a poll).
Return FALSE and set `timeout' to do a poll/check before
dispatching. */
- SchemeSource* src = (SchemeSource*)source;
+ SchemeSource * src = (SchemeSource *)source;
double dtime = OS_real_time_clock ();
int timeo = src->time_limit - dtime;
if (timeo <= 0
}
static gboolean
-scheme_source_check (GSource* source)
+scheme_source_check (GSource * source)
{
/* Return TRUE when ready to dispatch (after the poll). */
- SchemeSource* src = (SchemeSource*)source;
+ SchemeSource * src = (SchemeSource *)source;
double time = OS_real_time_clock ();
if (time > src->time_limit
|| pending_io (src)
}
static int
-pending_io (SchemeSource* src)
+pending_io (SchemeSource * src)
{
- GSList* scan;
+ GSList * scan;
if (tracing_gtk_select == SHARP_T)
{
scan = src->gpollfds;
while (scan != NULL)
{
- GPollFD* gfd = scan->data;
+ GPollFD * gfd = scan->data;
if (gfd->revents != 0)
{
outf_console (";scheme_source_check: i/o ready on %d\n",
scan = src->gpollfds;
while (scan != NULL)
{
- GPollFD* gfd = scan->data;
+ GPollFD * gfd = scan->data;
if (gfd->revents != 0)
return (TRUE);
scan = scan->next;
}
static gboolean
-scheme_source_dispatch (GSource* source,
+scheme_source_dispatch (GSource * source,
GSourceFunc callback, gpointer user_data)
{
/* Executes our "idle" task. Ignore the callback and user_data
arguments. Must return TRUE to stay on the list of mainloop
event sources. */
- SchemeSource* src = (SchemeSource*)source;
+ SchemeSource * src = (SchemeSource *)source;
slice_counter += 1;
if (slice_window != NULL)
{
- gchar* fdstr, * text;
+ gchar * fdstr, * text;
text = g_strdup_printf ("Scheme time-slice: %d\n", slice_counter);
- gtk_label_set_text(GTK_LABEL(slice_label), text);
+ gtk_label_set_text (GTK_LABEL (slice_label), text);
g_free (text);
fdstr = gpollfds_string (src->gpollfds);
text = g_strdup_printf ("Channels:%s", fdstr);
- if (fdstr[0] != '\0') g_free (fdstr);
- gtk_label_set_text(GTK_LABEL(status_label), text);
+ if (fdstr[0] != '\0')
+ g_free (fdstr);
+ gtk_label_set_text (GTK_LABEL (status_label), text);
g_free (text);
}
if (tracing_gtk_select == SHARP_T)
NULL
};
-SchemeSource*
+SchemeSource *
scheme_source_new (void)
{
- GSource* source = g_source_new (&scheme_source_funcs, sizeof (SchemeSource));
- SchemeSource* src = (SchemeSource*)source;
- GMainContext* context = g_main_context_default ();
+ GSource * source = g_source_new (&scheme_source_funcs, sizeof (SchemeSource));
+ SchemeSource * src = (SchemeSource *)source;
+ GMainContext * context = g_main_context_default ();
src->main_context = context;
src->main_loop = g_main_loop_new (context, FALSE);
src->gpollfds = NULL;
}
void
-scheme_source_destroy (SchemeSource* source)
+scheme_source_destroy (SchemeSource * source)
{
clear_registry (source);
if (source->main_loop != NULL)
g_main_loop_unref (source->main_loop);
source->main_loop = NULL;
}
- g_source_destroy ((GSource*) source);
+ g_source_destroy ((GSource *) source);
}
static void
-clear_registry (SchemeSource* source)
+clear_registry (SchemeSource * source)
{
- GSList* gpollfds = source->gpollfds;
+ GSList * gpollfds = source->gpollfds;
if (gpollfds != NULL)
{
- GMainContext* context = source->main_context;
- GSList* scan = gpollfds;
+ GMainContext * context = source->main_context;
+ GSList * scan = gpollfds;
while (scan != NULL)
{
- GPollFD* gfd = scan->data;
+ GPollFD * gfd = scan->data;
g_main_context_remove_poll (context, gfd);
g_free (gfd);
scan->data = NULL;
}
static void
-set_registry (SchemeSource* source, GSList* new, double time)
+set_registry (SchemeSource * source, GSList * new, double time)
{
/* Set the source's current gpollfds to match NEW. Warns if the
registry is already set. */
source->time_limit = time;
source->gpollfds = new;
{
- GMainContext* context = source->main_context;
+ GMainContext * context = source->main_context;
while (new != NULL)
{
- GPollFD* gfd = new->data;
+ GPollFD * gfd = new->data;
g_main_context_add_poll (context, gfd, G_PRIORITY_DEFAULT);
new = new->next;
}
set_registry (scheme_source, gtk_registry (r), time);
if (tracing_gtk_select == SHARP_T)
{
- GSList* gpollfds = scheme_source->gpollfds;
- gchar* fdstr = gpollfds_string (gpollfds);
+ GSList * gpollfds = scheme_source->gpollfds;
+ gchar * fdstr = gpollfds_string (gpollfds);
outf_console (";run_gtk%s%s until %.1f\n",
gpollfds == NULL ? "" : " waiting on", fdstr, time);
outf_flush_console ();
- if (fdstr[0] != '\0') g_free (fdstr);
+ if (fdstr[0] != '\0')
+ g_free (fdstr);
}
POP_PRIMITIVE_FRAME (2);
SET_EXP (SHARP_F);
| ((((revents) & G_IO_ERR) != 0) ? SELECT_MODE_ERROR : 0) \
| ((((revents) & G_IO_HUP) != 0) ? SELECT_MODE_HUP : 0))
-static GSList*
+static GSList *
gtk_registry (select_registry_t registry)
{
/* Construct Gtk's version of a select_registry_t. */
int len = OS_select_registry_length (registry);
int i = 0;
- GSList* list = NULL;
+ GSList * list = NULL;
while (i < len)
{
int fd;
unsigned int mode;
- GPollFD* item = g_malloc (sizeof (GPollFD));
+ GPollFD * item = g_malloc (sizeof (GPollFD));
OS_select_registry_entry (registry, i, (&fd), (&mode));
item->fd = fd;
item->events = DECODE_MODE (mode) | G_IO_ERR | G_IO_HUP;
return (list);
}
-static gchar*
-gpollfds_string (GSList* gpollfds)
+static gchar *
+gpollfds_string (GSList * gpollfds)
{
/* Construct a string describing the fds and r/w flags in GPOLLFDS,
e.g. " 0(r)" */
- gchar* string = "";
- GSList* scan = gpollfds;
+ gchar * string = "";
+ GSList * scan = gpollfds;
while (scan != NULL)
{
- GPollFD* gfd = scan->data;
+ GPollFD * gfd = scan->data;
int mode = (gfd->events) & (~(G_IO_HUP|G_IO_ERR));
- gchar* next = g_strdup_printf ("%s %d(%s)", string, gfd->fd,
+ gchar * next = g_strdup_printf ("%s %d(%s)", string, gfd->fd,
(mode == (G_IO_IN|G_IO_OUT) ? "rw"
: mode == G_IO_IN ? "r"
: mode == G_IO_OUT ? "w" : "?"));
static void
open_slice_window (void)
{
- slice_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- GtkWidget* vbox = gtk_vbox_new(FALSE, 5);
- status_label = gtk_label_new("Channels:");
- slice_label = gtk_label_new("Scheme time-slice: 0");
- gtk_container_add(GTK_CONTAINER(slice_window), vbox);
+ slice_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ GtkWidget * vbox = gtk_vbox_new (FALSE, 5);
+ status_label = gtk_label_new ("Channels:");
+ slice_label = gtk_label_new ("Scheme time-slice: 0");
+ gtk_container_add (GTK_CONTAINER (slice_window), vbox);
gtk_box_pack_start (GTK_BOX (vbox), status_label, FALSE, FALSE, 2);
gtk_box_pack_end (GTK_BOX (vbox), slice_label, FALSE, FALSE, 2);
- gtk_window_set_title(GTK_WINDOW(slice_window), "Scheme Time-Slice Counter");
- gtk_window_set_type_hint (GTK_WINDOW(slice_window),
+ gtk_window_set_title (GTK_WINDOW (slice_window), "Scheme Time-Slice Counter");
+ gtk_window_set_type_hint (GTK_WINDOW (slice_window),
GDK_WINDOW_TYPE_HINT_UTILITY);
gtk_widget_show_all (slice_window);
gtk_window_parse_geometry (GTK_WINDOW (slice_window), "250x50+0-40");
{
PRIMITIVE_HEADER (1);
{
- SCHEME_OBJECT arg = ARG_REF(1);
+ SCHEME_OBJECT arg = (ARG_REF (1));
if (arg == SHARP_F)
{
if (slice_window != NULL)
- close_slice_window();
+ close_slice_window ();
}
else
{
if (slice_window == NULL)
- open_slice_window();
+ open_slice_window ();
}
PRIMITIVE_RETURN (arg);
}
{
PRIMITIVE_HEADER (1);
{
- SCHEME_OBJECT arg = ARG_REF(1);
+ SCHEME_OBJECT arg = (ARG_REF (1));
tracing_gtk_select = (arg == SHARP_F ? SHARP_F : SHARP_T);
PRIMITIVE_RETURN (arg);
}
#ifdef COMPILE_AS_MODULE
-char*
+char *
dload_initialize_file (void)
{
scheme_source = NULL;