3

I'm trying to register object on dbus using dbus-java from org.freedesktop. According to documentation such operation requires: creating DBusConnection, creating object and calling method exportObject on DBusConnection.

My Code:

DatabaseAccessImpl dbAccess = new DatabaseAccessImpl();

    System.out.println("Object created.");



    System.out.println("Trying to connect session bus");
    try {
        conn = DBusConnection.getConnection(DBusConnection.SESSION);
    } catch(DBusException ex) {
        ex.printStackTrace();
    }

    System.out.println("Connected to session bus.");

    System.out.println("Trying to register dbus object");

    try {
        conn.exportObject("/obj/path", new DatabaseAccessImpl());
    } catch (DBusException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }

where:

DatabaseAccessImpl is implementation of interface created automatically by CreateInterface (xml worked fine while using with c++ (qt)).

dbAccess will send on dbus some data (mostly ints) from database. It all work good in Qt but I have to reimplement it in java (not my language).

For using dbus-java you have to install libmatthew-debug and execute program with

-Djava.library.path=/usr/lib/jni

I'm working on Linux Mint.

1 Answer 1

5

Two things:

  1. You need to register a bus name first, i.e. conn.requestBustName("com.example")
  2. DatabaseAccessImpl needs to implement an interface which extends DBusInterface.

Here's a tutorial that I made a while ago with code that may help you understand what's going on.

Sign up to request clarification or add additional context in comments.

1 Comment

in this tutorial, where is the so located? and how can I add the ref to the project??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.