Coder Social home page Coder Social logo

Comments (9)

hypfvieh avatar hypfvieh commented on August 14, 2024

Why do you want to send your struct wrapped in a variant?
Structs should extend the Struct.class and can therefore be send without wrapping it in a variant.

A struct should be looking like the samples in test sources (e.g. org.freedesktop.dbus.test.helper.structs.SampleStruct).
The position-annotation is important and is zero based!

If you wrap your object in a variant, the result will look like 'v(byyyyyyyyyyyyssssssssuiqyiiiis)'.
So you have to expect a Variant on the other side as well.
You then have to get the value from the variant and so on.

from dbus-java.

LotekB avatar LotekB commented on August 14, 2024

from dbus-java.

hypfvieh avatar hypfvieh commented on August 14, 2024

How does your code for receiving look like?

Usually you have an java interface with some methods in it.
Then you get the remote object from DBus by using somthing like:

MyRemoteInterface foo = (MyRemoteInterface) dbusSession.getRemoteObject("what.ever", "/where/ever");

Variant<MyStructData> variantStruct = foo.getMyStructDataWrappedInVariant();
MyStructData struct = variantStruct.getValue();

// continue to work with struct

The interface would look like:

@DBusInterfaceName("what.ever")
public interface MyRemoteInterface extends DBusInterface {
    Variant<MyStructData> getMyStructDataWrappedInVariant();
}

So what are you doing?

from dbus-java.

LotekB avatar LotekB commented on August 14, 2024

from dbus-java.

hypfvieh avatar hypfvieh commented on August 14, 2024

Now I see what's going on.

Due to the fact that the struct is wrapped in a Variant object, the information on which class to use for this struct is getting lost.

When de-serializing the DBus message the resulting Variant will contain a struct of dummy type DBusStructType (you can see that when calling variant.getType() or see your ClassCastException).
When reading variant.getValue() you will receive all fields of the struct in order as Object[] instead of the struct class itself.

There is no way to 'teach' the library to do this automatically as the signature of a struct is not unique. There may be multiple structs with the same signature but resulting in different classes.

So to get a Struct out of a Variant, you have to know which kind of Struct it is and re-construct it manually.

To provide some more help, I added the class StructHelper to dbus-java.
This should be able to convert a Variant to a given Struct subclass, if Variant is compatible.

Please check my sandbox project to see how it works.

from dbus-java.

LotekB avatar LotekB commented on August 14, 2024

from dbus-java.

hypfvieh avatar hypfvieh commented on August 14, 2024

File attachments are not supported on github when answer tickets by mail, so I cannot see whatever you wanted to share.

Did you try my solution I posted before?

from dbus-java.

LotekB avatar LotekB commented on August 14, 2024

from dbus-java.

hypfvieh avatar hypfvieh commented on August 14, 2024

Your quoted part is in deed duplicated code in the sample. I've removed that part.
The conversion is already done in StructHelper.

As this solution is working for you, I'll close the ticket.

from dbus-java.

Related Issues (20)

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.