Skip to content

Start refactoring into marshalers and translators

If you want to do some code reading over the weekend... 😄

I want to move from the old libdbus, and the dbind/droute utilities, to automatically-generated code and all the amenities of gdbus.

However, a lot of the code looks like this:

  static void
  handle_some_method (DBusMessage *message)
  {
    foo = demarshal_a_bit ();
    bar = find_the_accessible ();
    bar_set_foo (bar, foo);

    baz = demarshal_a_bit ();
    bar_set_baz (bar, baz);

    while (some_logic_here)
    {
      qux = demarshal_something ();
      blah_blah (qux, bar);
    }

    /* etc */
  }

My plan is to first split that code into a part that marshals/demarshals everything to "easy" structs, and then a part that plugs those structs to the actual logic:

  typedef struct {
    Accessible accessible;
    Foo foo;
    Baz baz;
    Qux quxes[];
  } SomeMethodArgs;

  handle_some_method (DBusMessage *message)
  {
    SomeMethodArgs args;

    if (demarshal_some_method_args (message, &args) != SUCCESS)
    {
      return ERROR;
    }

    do_the_thing (args.accessible, args.foo, args.baz, args.quxes);
  }

Once everything is split apart, it should be easier to just rewrite the marshaling code with gdbus stuff or even auto-generated code. Hopefully the logic can remain mostly unchanged.

This branch starts with a sample refactoring of that kind, and then with finer-grained ones to clean up various things.

It also documents the Socket interface, now that I understand it, and am right in the registry code.

Edited by Federico Mena Quintero

Merge request reports