{"id":107,"date":"2011-03-19T01:42:52","date_gmt":"2011-03-19T00:42:52","guid":{"rendered":"http:\/\/blogs.free-social.net\/elima\/?p=107"},"modified":"2016-10-20T13:13:32","modified_gmt":"2016-10-20T11:13:32","slug":"the-web-jumps-into-d-bus","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/elima\/2011\/03\/19\/the-web-jumps-into-d-bus\/","title":{"rendered":"The Web jumps into D-Bus"},"content":{"rendered":"<p>Lets start with the fun. The following demos show the EventDance&#8217;s D-Bus bridge in action:<\/p>\n<p><strong>Proxying org.freedesktop.Notifications<\/strong><\/p>\n<p>Directly from a Web page, we create a proxy to the standard <a href=\"https:\/\/www.freedesktop.org\/wiki\/\">freedesktop.org<\/a> object <a href=\"http:\/\/www.galago-project.org\/specs\/notification\/0.9\/x408.html\"><em>\/org\/freedesktop\/Notifications<\/em><\/a> which is exported to the session bus running in my normal desktop environment. Then, we call the remote method <em>Notify<\/em> using  a simple web form. This method opens a notification dialog showing a quick note to the desktop user. The proxy also watches the remote signal <em>NotificationClosed<\/em> telling that a notification dialog was closed.<br \/>\nDuring the demo we open different browsers to show the cross-browser nature of EventDance&#8217;s Web transport.<\/p>\n<p>Your browser doesn\u2019t seem to support HTML5 video tag but you can <a href=\"https:\/\/people.igalia.com\/elima\/evd-dbus-bridge-proxy-example.ogv\">download the video<\/a> directly.<\/p>\n<p><a href=\"https:\/\/people.igalia.com\/elima\/evd-dbus-bridge-proxy-example.ogv\">Screencast 1: D-Bus proxy example<\/a><br \/>\n<strong>Acquiring a bus name and exporting an object<\/strong><\/p>\n<p>In the next screencast we acquire\/release a name on the session bus, and export a simple object onto it. The object has one method <em>Ask<\/em> that receives a string as input argument, shows a confirmation dialog on the Web page, and return a boolean value depending on whether the user pressed &#8220;Ok&#8221; or &#8220;Cancel&#8221; to close the dialog. We use <a href=\"https:\/\/live.gnome.org\/DFeet\/\">D-Feet<\/a> to call the remote method on the browser that owns the name at the moment of the call.<\/p>\n<p>Your browser doesn\u2019t seem to support HTML5 video tag but you can <a href=\"https:\/\/people.igalia.com\/elima\/evd-dbus-bridge-own-name-example.ogv\">download the video<\/a> directly.<\/p>\n<p><a href=\"https:\/\/people.igalia.com\/elima\/evd-dbus-bridge-own-name-example.ogv\">Screencast 2: D-Bus name owning example<\/a><br \/>\nThe client-side source code of both demos is available at <a href=\"https:\/\/gitorious.org\/eventdance\/eventdance\/blobs\/master\/examples\/common\/dbus-bridge-proxy.html\">examples\/common\/dbus-bridge-proxy.html<\/a> and <a href=\"https:\/\/gitorious.org\/eventdance\/eventdance\/blobs\/master\/examples\/common\/dbus-bridge-own-name.html\">examples\/common\/dbus-bridge-own-name.html<\/a> respectively, inside <a href=\"https:\/\/gitorious.org\/eventdance\/eventdance\">EventDance repository<\/a>. You can check them to realize how simple is the API to connect to and use the D-Bus connection.<\/p>\n<p>The server-side code for both demos is the same, and is public at <a href=\"https:\/\/gitorious.org\/eventdance\/eventdance\/blobs\/master\/examples\/dbus-bridge.c\">examples\/dbus-bridge.c<\/a>. There is also a JavaScript version at <a href=\"https:\/\/gitorious.org\/eventdance\/eventdance\/blobs\/master\/examples\/js\/dbusBridge.js\">examples\/js\/dbusBridge.js<\/a> and a python version at <a href=\"https:\/\/gitorious.org\/eventdance\/eventdance\/blobs\/master\/examples\/python\/dbus-bridge.py\">examples\/python\/dbus-bridge.py<\/a>. To run JavaScript and python examples you need EventDance compiled with <em>&#8211;enable-introspection<\/em> configure flag active (the default), and <a href=\"https:\/\/live.gnome.org\/Gjs\/\">GJS<\/a> or <a href=\"https:\/\/live.gnome.org\/PyGObject\">pygobject<\/a> respectively available in your system.<\/p>\n<h2>The D-Bus bridge<\/h2>\n<p>At the highest level, <a href=\"https:\/\/blogs.igalia.com\/elima\/2010\/10\/14\/eventdance-a-peer-to-peer-inter-process-communication-library\/\">EventDance library<\/a> provides a set of transports and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Inter-process_communication\">IPC<\/a> mechanisms. The D-Bus bridge is just one of these mechanisms, written specifically to work over the Web transport. Its purpose is to connect a Web page with a remote D-Bus daemon running on the Web server, using the EventDance&#8217;s Web transport (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Push_technology#Long_polling\">long-polling<\/a> or <a href=\"https:\/\/en.wikipedia.org\/wiki\/WebSockets\">websocket<\/a> if available).<\/p>\n<p>D-Bus uses a binary protocol, and the browser&#8217;s JavaScript context doesn&#8217;t (yet) support binary data. Thus, it was sensible to translate D-Bus messages to a browser-friendly protocol, in this case JSON. Using the <a href=\"https:\/\/blogs.igalia.com\/elima\/2011\/01\/31\/json-and-gvariant\/\">API recently added<\/a> into <a href=\"http:\/\/folks.o-hand.com\/~ebassi\/docs\/json-glib\/\">json-glib<\/a> to integrate <a href=\"https:\/\/library.gnome.org\/devel\/glib\/unstable\/glib-GVariant.html\">GVariant<\/a> and <a href=\"http:\/\/json.org\">JSON<\/a>, the bridge translates messages back and forth from <a href=\"https:\/\/library.gnome.org\/devel\/gio\/2.25\/ch27.html\">GDBus<\/a> to JSON and vice-versa. Also, it tries to reduce message payload as much as possible, by caching the GDBus objects server-side, and sending only their references over the wire. This makes the protocol very simple and lightweight.<\/p>\n<h2>Cool, now what?<\/h2>\n<p>Hopefully you are already wondering about the many purposes this feature can serve.<\/p>\n<p>While many people envision that the next desktop will be the browser, many more do use Web applications almost exclusively, already today. The traditional separation between Web and Desktop app development is blurring. Browsers have become powerful platforms for running complex applications, and this situation is speeding up with the broad and increasing adoption of <a href=\"https:\/\/en.wikipedia.org\/wiki\/HTML5\">HTML5<\/a> standards by major browsers.<\/p>\n<p>On the other hand, we have D-Bus, a freedesktop.org standard that is at the core of almost every GNU\/Linux system out there. It is the de-facto IPC mechanism on which your applications talk and share. D-Bus allows us to write a program in any language, and export its usefulness over a standard channel. Also allows us to write differentiated UIs (e.g, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Qt_(framework)\">Qt<\/a> vs. <a href=\"https:\/\/gtk.org\">GTK+<\/a> vs. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ncurses\">NCurses<\/a>) to interface a common functionality. Yes, one bus to bind them all!<\/p>\n<p>Joining these two pieces together is just the next logical step. A step towards bringing together the best of two contexts: the ubiquity of the Web and the inter-process collaborative nature of the Desktop.<\/p>\n<p>We need to write applications that you can host and use securely and reliably not only in your computer, but anywhere in the Planet where you happen to have a browser plugged into the Net; whether it is your laptop, mobile phone, tablet or your neighbors&#8217; PS3. We also need to encourage application developers to export the logic of their programs over D-Bus, to allow other platforms (like the Web!) to reuse it. <a href=\"https:\/\/telepathy.freedesktop.org\/wiki\/\">Telepathy<\/a> is a good example of such program.<\/p>\n<p>Almost identical applications in terms of functionality are written for many FOSS environments like <a href=\"https:\/\/www.gnome.org\/\">GNOME<\/a>, <a href=\"https:\/\/www.kde.org\/\">KDE<\/a>, <a href=\"http:\/\/meego.com\/\">MeeGo<\/a>, <a href=\"https:\/\/www.android.com\/\">Android<\/a>, etc; yet many times only the user experience and the technologies used to build it are different. Although not always possible, there is room for a wider code-reusing culture if we come back to the original <a href=\"https:\/\/en.wikipedia.org\/wiki\/Unix_philosophy\">Unix philosophy<\/a>:<\/p>\n<p><em><br \/>\nWrite programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.<br \/>\n<\/em><\/p>\n<p>That universal interface has just been upgraded.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lets start with the fun. The following demos show the EventDance&#8217;s D-Bus bridge in action: Proxying org.freedesktop.Notifications Directly from a Web page, we create a proxy to the standard freedesktop.org object \/org\/freedesktop\/Notifications which is exported to the session bus running in my normal desktop environment. Then, we call the remote method Notify using a simple &hellip; <a href=\"https:\/\/blogs.igalia.com\/elima\/2011\/03\/19\/the-web-jumps-into-d-bus\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;The Web jumps into D-Bus&#8221;<\/span><\/a><\/p>\n","protected":false},"author":34,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,5,6,7],"tags":[16,17,73,26,35,36,42,44,45],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-eventdance","category-gnome","category-hacking","category-igalia","tag-d-bus","tag-dbus","tag-eventdance","tag-html5","tag-long-polling","tag-longpolling","tag-transport","tag-web","tag-websocket"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/comments?post=107"}],"version-history":[{"count":4,"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":455,"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/posts\/107\/revisions\/455"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/media?parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/categories?post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/elima\/wp-json\/wp\/v2\/tags?post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}