<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:html="http://www.w3.org/1999/html" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Ross Burton</title><link>http://www.burtonini.com/blog</link><description>A potted account of Ross' life</description><language>en</language><ttl>60</ttl><dc:creator>Ross Burton</dc:creator><admin:generatorAgent rdf:resource="http://pyblosxom.sourceforge.net/"/><admin:errorReportsTo rdf:resource="mailto:ross@burtonini.com"/><item><title>Public Perception of Immigration</title><guid isPermaLink="false">life/immigration-2005-05-12-13-15</guid><link>http://www.burtonini.com/blog/life/immigration-2005-05-12-13-15</link><description>The excellent Observer Blog has an interesting post about a recent MORI survey: Regular readers of different papers were asked ...</description><content:encoded><![CDATA[    <p>
      The excellent <a href="http://blogs.guardian.co.uk/observer/">Observer
      Blog</a> has an <a
      href="http://blogs.guardian.co.uk/observer/archives/2005/05/12/what_came_first_the_antichicken_headlines_or_public_hostility_to_the_egg_.html">interesting
      post</a> about a recent MORI survey:
    </p>
    <blockquote>
      <p>
        Regular readers of different papers were asked 'what percentage of the
        British population do you think are immigrants to this country?'
      </p>
      <p>
        The highest bid came from Daily Star and Sun readers - 26 per cent. Next
        up, Daily Mirror on 25 per cent, then in order, The Express - 21 per
        cent; Mail - 19 per cent; Telegraph - 13 per cent; Guardian - 11 per
        cent; Times 10 - per cent; The Indie - 9 per cent; FT - 6 per cent.
      </p>
      <p>
        The UK average guess is 21 per cent. And the actual figure? That would
        be 7 per cent. So as a nation we're only 3 times out of proportion on
        this one.
      </p>
    </blockquote>
    <p>
      <cite>Daily Star</cite>, <cite>Mirror</cite>, and <cite>Sun</cite> readers
      think that more than <em>1 in 4</em> of the country are immigrants?  It's
      interesting both how the more right-wing papers give the impression of
      more immigration, and how almost everyone over-estimates to some degree.
    </p>
    <p>
      <small>NP: <cite>Entroducing.....</cite>, DJ Shadow</small>
    </p>
]]></content:encoded><category domain="http://www.burtonini.com">/life</category><dc:date>2005-05-12T12:15:00Z</dc:date></item><item><title>Asynchronous DBus Calls</title><guid isPermaLink="false">computers/dbus-2005-05-12-11-50</guid><link>http://www.burtonini.com/blog/computers/dbus-2005-05-12-11-50</link><description>This week I have been mostly playing with asynchronous calls in the DBus GLib bindings. DBus is inherently an asynchronous ...</description><content:encoded><![CDATA[    <p>
      This week I have been mostly playing with asynchronous calls in the DBus GLib bindings.  DBus
      is inherently an asynchronous system, but the present GLib bindings wrap that with the
      <tt>GProxy</tt> object into a quite simple asynchronous interface, a simple synchronous
      interface, and a tool to <a
      href="http://www.burtonini.com/blog/computers/dbus-2005-04-04-14-14">generate incredibly
      simple bindings</a>.
    </p>
    <p>
      The synchronous interface is trivial: <tt>dbus_g_proxy_invoke</tt>. This will make a call with
      arguments, specified as addresses for arguments to send and locations to put return values in.
      It blocks until a reply is returned, and works well.
    </p>
    <blockquote><pre>
char **names;
dbus_g_proxy_invoke (proxy, "ListNames", error, G_TYPE_INVALID, G_TYPE_STRV, &amp;names, G_TYPE_INVALID);
</pre></blockquote>
    <p>
      The asynchronous interface is pretty simple. First call <tt>dbus_g_proxy_begin_call()</tt> to
      send the message.  This returns a <tt>DBusGPendingCall</tt> object, on which you call
      <tt>dbus_g_pending_call_set_notify</tt> to set a function which is called when a reply is
      received.  Inside the callback, <tt>dbus_g_proxy_end_call</tt> will get the return arguments.
    </p>
<blockquote><pre>
static void callback(DBusGPendingCall *call, DBusGProxy *proxy) {
  GError *error = NULL;
  char **name_list;
  int name_list_len, i;

  if (!dbus_g_proxy_end_call (proxy, call, &amp;error,
                              DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
                              &amp;name_list, &amp;name_list_len,
                              DBUS_TYPE_INVALID)) {
      g_printerr ("Failed to complete ListNames call: %s\n", error->message);
      g_error_free (error);
      g_main_loop_quit (loop);
  }

  g_print ("Names on the message bus:\n");
  for (i = 0; i < name_list_len; ++i) {
      g_print ("  %s\n", name_list[i]);
  }
  g_strfreev (name_list);

  dbus_g_pending_call_unref (call);
  g_main_loop_quit (loop);
}

int main (int argc, char **argv) {
  DBusGConnection *connection;
  GError *error = NULL;
  DBusGProxy *proxy;
  DBusGPendingCall *call;
  
  g_type_init ();
  loop = g_main_loop_new (NULL, TRUE);

  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &amp;error);
  proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

  call = dbus_g_proxy_begin_call (proxy, "ListNames", DBUS_TYPE_INVALID);
  dbus_g_pending_call_set_notify(call, (DBusGPendingCallNotify)callback, proxy, g_object_unref);
  g_main_loop_run (loop);
  return 0;
}
</pre></blockquote>
    <p>
      Asynchronous method calls are possible in the GLib bindings, but are not wrapped by the
      bindings generator at the moment.  As an example, this is the prototype for the generated
      binding of the <tt>ListNames</tt> call:
    </p>
    <blockquote><pre>
gboolean org_freedesktop_DBus_list_names (DBusGProxy *proxy, char *** OUT_names, GError **error);
</pre></blockquote>
    <p>
      Where <tt>OUT_names</tt> is a pointer to a string array.  Now, wouldn't it be nice if the
      bindings could generate asynchronous wrappers too:
    </p>
    <blockquote><pre>
static void callback (char **names, GError *error, gpointer userdata) {
  char **i;
  g_print ("Names on the message bus:\n");
  for (i = names; *i; i++) {
    g_print ("  %s\n", *i);
  }
}
...
org_freedesktop_DBus_list_names_async (proxy, callback, NULL);
</pre></blockquote>
    <p>
      That was copied from working code by the way.  Hopefully it will pass the Havoc test and get
      into CVS!
    </p>
    <p>
      <small>NP: <cite>Means of Production</cite>, Aim</small>
    </p>
]]></content:encoded><category domain="http://www.burtonini.com">/computers</category><dc:date>2005-05-12T10:50:00Z</dc:date></item></channel></rss>