Giter VIP home page Giter VIP logo

erlang-dbus's Introduction

A native erlang implementation of D-Bus

D-Bus is now largely used in a lot of applications for language-independant, object-oriented RPC system.

The erlang platform needs an erlang native implementation.

Flattr this git repo Build Status Hex.pm Hex.pm Project Stats

Usage as Client

This example is making a dbus call to the org.freedesktop.DBus system service (under linux) and a list of registered services.

  {ok, Bus} = dbus_bus_reg:get_bus(session),
  {ok, Service} = dbus_bus:get_service(Bus, 'org.freedesktop.DBus'),
  {ok, RemoteObject} = dbus_remote_service:get_object(Service, '/org/freedesktop/DBus'),
  {ok, Iface} = dbus_proxy:interface(RemoteObject, 'org.freedesktop.DBus'),
  {ok, Names} = dbus_proxy:call(Iface, 'ListNames', []),
  io:format("ListNames: ~p~n", [lists:sort(Reply1)]),
  ok = dbus_remote_service:release_object(Service, RemoteObject),
  ok = dbus_bus:release_service(Bus, Service),

Usage as Service

In the demo folder there is a bigger example, but is a minimal service callback module:

-module(my_service).
-include_lib("dbus/include/dbus.hrl").
-behaviour(gen_dbus).

-export([
%% api
  start_link/2,
  handle_info/2,

%% dbus object callbacks
  'HelloWorld'/1,
  'HelloWorld'/3,

%% gen_dbus callbacks
  init/1
]).

-record(state, {}).

start_link() ->
  gen_dbus:start_link({local, ?MODULE}, ?MODULE, [], []).

init([Service, Path]) ->
  State = #state{},
  Methods = ['HelloWorld'],
  {ok, {"com.example.MyService", '/SomeObject', [
    {interface, 'com.example.MyInterface'},
    {methods, Methods},
    {signals, []}
    ]}, State}.

'HelloWorld'(dbus_info) ->
  [{interface, 'com.example.MyInterface'},
    {signature, [string], [{array, string}]}].

'HelloWorld'([HelloMessage], From, State) ->
  {reply, ["Hello from Erlang"], State}.

handle_info(Info, State) ->
  error_logger:warning_msg("Unhandled info: ~p~n", [Info]),
  {noreply, State}.

When the dbus application is running you can start this service with my_module:start_link(). or add it to your supervision tree.

Caveat at the moment the service creation does not open a dbus connection and as a result the service will not be visible until you create the first dbus connection e.g. via dbus_bus_reg:get_bus(session).

Documentation

Current status

The status:

  • Consuming D-Bus services: ok
  • Providing D-Bus services: ok
  • Tests for both are working!
  • Connect through TCP and UNIX socket: ok

TODO

erlang-dbus's People

Contributors

dominicletz avatar jeanparpaillon avatar lauramcastro avatar leizhao5 avatar lemenkov avatar mkrentovskiy avatar mpotra avatar saa avatar slashmili avatar tonywallace64 avatar wrachwal avatar

Stargazers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.