Conquering DBus

I haven't written in a while because I've been pretty heads down on a project I'm working on. Hopefully, it will be in a shape where it makes sense to share with everyone before too long.

In this project, I needed an RPC system that could have multiple transport and be fully asynchronous (with GAsyncResult, etc). So I took a little time and wrote a crappy little python program that generates the following peices in GObject/C from a simple input format.

  • Transport agnostic (currently has DBus backend).
  • A client library with lowlevel RPC calls and an object model built on top of the lowlevel calls. Consumer can choose which best fits their use case. (Object model not finished).
  • A server implementation (also transport agnostic).
  • Fully Asynchronous. Synchronous implementation is built on top of the asynchronous implementation.
  • Unit tests (for testing RPC round trips, etc).
  • Generated code should be clean to read and debug.
  • Tracing support for debugging. (Use -DDISABLE_TRACING to turn off).
  • Generate DBus Introspection XML.

Anyway, code is here[1]. There is a sample video below where I generate a mockup service for getting information on "Books" and "Authors". See the Makefile in the outdir directory for how to build things. Keep in mind I have absolutely NO INTENTION of maintaining this. But at minimum, I figured it might serve useful for someone.

So a quick example of the imput format would be like the following. I've removed the header lines for succinctness.

  1. object Book {
  2. # books are identified by a unique int (string also supported).
  3. id int
  4.  
  5. """
  6. Document your rpc's with python style docs. Comments persist into
  7. the generated code's gtkdoc.
  8. """
  9. rpc get_name (out string name)
  10.  
  11. """
  12. Retrieves the book's author.
  13. """
  14. rpc get_author (out Author author)
  15. }
  16.  
  17. object Author {
  18. id int
  19.  
  20. """
  21. Retrieves the books by this author.
  22. """
  23. rpc get_books (out Book[] books)
  24. }
  25.  
  26. object Manager {
  27. # only one of these per application (/org/blah/Project/Manager).
  28. # might consider this later to simply be the default servce such as
  29. # (/org/blah/Project).
  30. singleton
  31.  
  32. rpc get_books (out Book[] books)
  33. rpc get_authors (out Author[] authors)
  34. }

Thats pretty much it. The code is uglier than anything you've ever seen, but at least the generated C is pretty. The code parser/generator is not super resilient or anything. I pretty much hack it to have what I need as I go.

[1] http://github.com/chergert/yosemite

Comments (5)

  1. Luca Bruno wrote:

    You know if Vala having a great support for DBus right? You can mix both C and Vala.

    Thursday, May 13, 2010 at 2:05 am #
  2. chergert wrote:

    Quite aware. Not interested however. It doesn’t provide transport abstractions that I want and it is terribly painful to debug the generated code.

    Thursday, May 13, 2010 at 2:30 am #
  3. Ryan Phillips wrote:

    This looks very nice, and was looking at writing myself. Could you post a license in the source. I would prefer LGPLv2 or BSD.

    Very nice job!

    Thursday, May 13, 2010 at 11:06 am #
  4. chergert wrote:

    The source to my generator is MITX11. But the output is whatever you want it to be.

    Thursday, May 13, 2010 at 12:02 pm #
  5. Ryan Phillips wrote:

    Thanks!

    Thursday, May 13, 2010 at 4:32 pm #