Coder Social home page Coder Social logo

Comments (10)

charleseidsness avatar charleseidsness commented on July 1, 2024 1

That is a legitimate way to define multiple output arguments, but it isn't supported by the proxy. It only supports a single return type.

adbus/adbus/client/proxy.py

Lines 172 to 182 in f976d50

self.arg_signatures = []
self.return_signature = ''
for x in etree.iter():
if x.tag == 'method':
self.name = x.attrib['name']
if x.tag == 'arg':
if x.attrib['direction'] == 'out':
self.return_signature = x.attrib['type']
elif x.attrib['direction'] == 'in':
self.arg_signatures.append(x.attrib['type'])

In your mocked test that worked what did the signature look like?

There is a chance that if you change line 180 of proxy.py:

self.return_signature = x.attrib['type']

To:

self.return_signature += x.attrib['type']

it may work.

It'll be easier for you to test since you have all of your tooling setup.

from adbus.

charleseidsness avatar charleseidsness commented on July 1, 2024 1

D-Bus supports multiple in and out values for method calls. The multiple ins map nicely to multiple arguments in Python, but there isn't a straight-forward equivalent to multiple outs.

We could convert it to a tuple if there are multiple outs, it may make sense with the Python unpacking syntax.

I don't have an easy way to test it, but it may be as simple as fudging the return signature into a struct. You'd have to count how many out definitions there are if you have more than 1 out enclose it in "()".

Something like this:

 self.arg_signatures = [] 
 self.return_signature = '' 
 num_outs = 0

 for x in etree.iter(): 
     if x.tag == 'method': 
         self.name = x.attrib['name'] 
     if x.tag == 'arg': 
         if x.attrib['direction'] == 'out': 
             self.return_signature += x.attrib['type']
             num_outs += 1
         elif x.attrib['direction'] == 'in': 
             self.arg_signatures.append(x.attrib['type']) 

  if num_outs > 1:
    self.return_signature = "(" + self.return_signature + ")"

from adbus.

charleseidsness avatar charleseidsness commented on July 1, 2024 1

Thanks for trying.

I'll have to add this as a new feature, it may be a few days before I have some time to look at it.

from adbus.

charleseidsness avatar charleseidsness commented on July 1, 2024 1

I created a branch with a few updates for this new feature. I don't have time to test it (or even build it right now) but it should get things started. If you get a chance to test it that would be a big help.

feature-multi-return-proxy-call

from adbus.

charleseidsness avatar charleseidsness commented on July 1, 2024

This is strange, the output signature looks like it can be either 'i' or 's'?

  <method name="New">
   <arg type="s" direction="in"/>
   <arg type="i" direction="out"/>
   <arg type="s" direction="out"/>
  </method>

It's been a while since I worked with D-Bus introspect xml, I'm not sure what that means. Looking it up now.

from adbus.

hamid-rostami avatar hamid-rostami commented on July 1, 2024

Hi @charleseidsness, thanks for your response.

You're right, output signature of mock-up is different from main program.
Return type of mock-up:

‣ Type=method_return  Endian=l  Flags=1  Version=1  Priority=0 Cookie=4  ReplyCookie=3
  Sender=:1.169  Destination=:1.172
  UniqueName=:1.169                                   
  MESSAGE "(is)" {
          STRUCT "is" { 
                  INT32 10;                            
                  STRING "success";
          };                                  
  }; 

Return type of main program:

‣ Type=method_return  Endian=l  Flags=1  Version=1  Priority=0 Cookie=47  ReplyCookie=3
  Sender=:1.111  Destination=:1.147
  UniqueName=:1.111
  MESSAGE "is" {
          INT32 6;
          STRING "";
  };

About changing in proxy.py source line 180. The result is no exception occurs anymore, but still just int part returned from proxy.
If I should test something else, I'll be appreciate if you tell me.

from adbus.

hamid-rostami avatar hamid-rostami commented on July 1, 2024

Nice idea, but unfortunately didn't work.
The reason of failure, I guess, is that the program is asking for (is), and there's no such a thing.

Here is occurred exception:

  File "client.py", line 18, in <module>
    asyncio.run(main())
  File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "client.py", line 15, in main
    ret = await proxy.New("body")
  File "/usr/local/lib/python3.7/site-packages/adbus/client/proxy.py", line 202, in __call__
    timeout_ms=self.timeout_ms
  File "/usr/local/lib/python3.7/site-packages/adbus/client/call.py", line 48, in call
    raise call.response
  File "adbus/sdbus/call.pyx", line 13, in adbus.sdbus.call_callback
  File "adbus/sdbus/message.pyx", line 221, in adbus.sdbus.Message.read
  File "adbus/sdbus/message.pyx", line 170, in adbus.sdbus.Message._read_struct
adbus.sdbus.SdbusError: Failed to enter structure b'is'

from adbus.

hamid-rostami avatar hamid-rostami commented on July 1, 2024

I hope you get free time soon, feel free to ask me if I can help.

from adbus.

hamid-rostami avatar hamid-rostami commented on July 1, 2024

Great work @charleseidsness,
Problem fixed, now it's working for both services (mock-up and my C program)
Do I need to provide log or something ?

from adbus.

charleseidsness avatar charleseidsness commented on July 1, 2024

That's great, I'll issue a PR.

from adbus.

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.