affederaffe / Tmds.DBus.SourceGenerator

A roslyn source generator for creating proxies targeting the Tmds.DBus.Protocol API
MIT License
7 stars 5 forks source link

Method handlers with ObjectPath arguments need destination #25

Closed uhrm closed 1 day ago

uhrm commented 2 weeks ago

I have the problem to implement a DBus interface handler with a 'register' method that receives an ObjectPath as an argument. The object sitting at that ObjectPath implements a well-known interface (e.g. org.example.Callback). My goal is to create a proxy of that interface at ObjectPath inside the 'register' method. I.e. somethinkg like

protected override async ValueTask OnRegister(ObjectPath path)
{
    var obj = new Tmds.DBus.SourceGenerator.OrgExampleCallback(Connection, destination, path);
    ...
}

However, the constructor of proxy objects also requires a destination. How can I get the destination from inside the 'register' method?

In principle, this information would be available in the MethodContext.Request.DestinationAsString property. But I have found not way to get to this information.

affederaffe commented 1 week ago

The destination is the service you want to speak to that resides at the given path (think of it like a file system structure). If I understand you correctly, Register is called by an external service. When this method is called, you want to call some other method (defined by the well-known interface org.example.Callback) on an object that resides at the path that is provided as a parameter of the aforementioned Register method. Is this correct? In that case, simply set your destination to the interface name of the service you want to call, i.e. org.example.Callback.

uhrm commented 1 week ago

Ok, here is a diagram of what I'm trying to do.

diagram drawio

Some external process makes a DBus call to register of my interface. As a parameter, I receive an ObjectPath to where the org.example.Callback lives in the external process. I have to invoke a method on that interface from inside my OnRegister handler.

What I got wrong in my original submission is that I need the sender (MethodContext.Request.SenderAsString) to be able to construct a proxy for the callback interface. But it is still essentially the same problem.

affederaffe commented 1 week ago

Yeah that looks like a legit use-case. We could probably just expose the Message object as the first argument, would this work for you?

uhrm commented 1 week ago

Yes, that would solve my problem. (In fact, this is what I did as a work-around.)

It may be a little tricky to do this in a backwards-compatible way, though.

affederaffe commented 2 days ago

https://github.com/affederaffe/Tmds.DBus.SourceGenerator/commit/7aa0e0c91d580516ce57b589b2c4952bea40117b should address this use-case. Do you mind testing it out and report if this solution works for you?

uhrm commented 1 day ago

Yes, this solves my problem.

Thanks a lot.