I am able to use the dbus commands like dbus-send
and etc. But i am not getting how to use the api's of dbus efficiently to write sample applications.
Can any one please tell me how to receive the data from the dbus. I am not getting how to use the existing services in dbus like org.freedesktop.NetworkManager
Please tell me the proper way to access and use the services of dbus. Please post some sample examples and also suggest me what are the rules we have to follow while using a service.
i am looking for 1)How to add our own service to the system / session Bus.At the same time,how to receive that service. 2) How to use the existing services just like org.freedesktop.NetworkManager.GetDevices .I want implementation code
Your question is quite open as you do not state any requirements on e.g. what language and binding (if any) you plan use in the sample application.
When you ask about the APIs of D-Bus, that might mean different things depending on what level of abstraction you intend to write your code. I will make the assumption that you intend to use a binding that integrates with the low level API of D-Bus, i.e. the API you will use is at a higher level of abstraction than the low level D-Bus C API.
In python, using one of the available bindings
dbus-python
, a very simple service might look like this:The
Echo
method could then be called withdbus-send
like this:Continuing the python example, a client to the above service might look like this:
For more information about the specifics of
dbus-python
you can check out this tutorial.Extending the client example, one way of calling
org.freedesktop.NetworkManager.GetDevices
is:So in general you need to find out what bindings exist for your language of choice, then find out about the API of any specific services you want to interact with. Any particular rules about how to interact with services should be documented as part of the API or design documents and so on.
On the client side you will often have the option to do synchronous or asynchronous calls (if supported by the binding and language) and that will have an impact on your design.