(*prepare) and (*check) need user_data



hi owen,

i discovered that for most applications of GSource in conjunction
with a poll fd, you'd want to add the pollfd right away with the source
and remove it again, like:

static void
destroy_poll_fd (gpointer data)
{
  GPollFD *pfd = data;

  g_main_remove_poll (pfd);
  g_free (pfd);
}


  pfd = g_new0 (GPollFD, 1);
  pfd->fd = some_fd;
  pfd->events |= G_IO_IN | G_IO_OUT | G_IO_PRI;
  g_main_add_poll (pfd, X_PRIORITY);
  g_source_add (X_PRIORITY, TRUE, &x_funcs, x, pfd, destroy_poll_fd);

to properly make use of the pollfd in prepare and check, the user_data pointer
needs to be provided though, this can be achived while keeping binary
compatibility with 1.2.0.
so we got:
struct _GSourceFuncs
{
  gboolean (*prepare)  (gpointer  source_data,
                        GTimeVal *current_time,
                        gint     *timeout,
                        gpointer  user_data);
  gboolean (*check)    (gpointer  source_data,
                        GTimeVal *current_time,
                        gpointer  user_data);
  gboolean (*dispatch) (gpointer  source_data,
                        GTimeVal *current_time,
                        gpointer  user_data);
  GDestroyNotify destroy;
};

e.g. in my above example, "x" is some
object that serves as source data, and i wouldn't want to add the pfd
structure to it through some data_by_id functions since i had to "undo"
that somehow in the destroy_poll_fd() function that doesn't give me access
to source_data (thus "x"). 

i consider this fairly important for dynamic GSources with different fds (not
as in gdk where you just have one constant and static fd).

[sorry, meant to Cc: this to gtk-devel on the first incarnation already ;)]

---
ciaoTJ




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]