Re: glib main loop without gtk



Thomas Stover wrote:
So if one wants to use g_io_channels with out gtk (console / server app), what exactly is the idea? Does glib need an initialization function called first? I see the g_main_loop_new() and friends functions, and that part make sense. The thing is g_io_add_watch_full() type functions don't have a main loop parameter. In other words were does this "default" main loop come from?
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

From giochannel.c:

guint
g_io_add_watch_full (
  GIOChannel *channel,
  gint priority,
  GIOCondition condition,
  GIOFunc func,
  gpointer user_data,
  GDestroyNotify notify)
{
  GSource *source;
  guint id;

  g_return_val_if_fail (channel != NULL, 0);

  source = g_io_create_watch (channel, condition);

  if (priority != G_PRIORITY_DEFAULT)
    g_source_set_priority (source, priority);
  g_source_set_callback (source, (GSourceFunc)func, user_data, notify);

  id = g_source_attach (source, NULL);
  g_source_unref (source);

  return id;
}

g_source_attach docs say:

Adds a GSource <cid:part1.08000109.07070102@gmail.com> to a /|context|/ so that it will be executed within that context.

/|source|/ :

        a GSource <cid:part1.08000109.07070102@gmail.com>

/|context|/ :

a GMainContext <cid:part3.06080301.01060802@gmail.com> (if |NULL| <cid:part4.06010104.01000906@gmail.com>, the default context will be used)

/Returns/ :

the ID (greater than 0) for the source within the GMainContext <cid:part3.06080301.01060802@gmail.com>.


From gmain.c (g_source_attach func):

if (!context)
  context = g_main_context_default ();

So, main loop is found throw GMainContext.

Regards.



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