suzhe / google-gadgets-for-linux

Automatically exported from code.google.com/p/google-gadgets-for-linux
Apache License 2.0
0 stars 0 forks source link

dbus: equal signal and method names #326

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
So I just wanted to write a gadget that uses some DBus controls
of my application and i had the following issue:

1. provide a dbus interface with a method called "foo" and a signal called
"foo"
2. use a gadget to connect to the interface
3. try to assign a function to dbusobj.foo

you get: "ReferenceError: Failed to set native property message (may be
readonly)."

After a little tracing, it seems to me, that I've figured out what goes wrong.
As I understood the code, the dynamic getter of the DBus scriptable
determines the prototype of the property (if it's a signal, use a slot, if
it's a method, it's a scriptable). But to assign signals, the DynamicSetter
is used, which handles signals first (instead of the getter which handles
methods first). I built some checkpoints in the code:

T 22:45.559: main.js:89: ScriptableDBusObject::DynamicGetter(message)
T 22:45.559: main.js:89: well, trying to get method message.
T 22:45.559: main.js:89: Oh hey, here in native_js_wrapper,
SetPropertyByName (message).
T 22:45.559: main.js:89: ScriptableDBusObject::DynamicGetter(message)
T 22:45.559: main.js:89: well, trying to get method message.
T 22:45.559: main.js:89: prototype of message is 7.
T 22:45.560: main.js:89: ScriptableDBusObject::DynamicSetter(message)
T 22:45.560: main.js:89: searching for message.
T 22:45.560: main.js:89: got SCRIPTABLE:0xfb3be0(CLASS_ID=65f4d888b7b749ed)
in first place.
T 22:45.560: main.js:89: Signal property expects a slot not 7.
E 22:45.560: main.js:89: ReferenceError: Failed to set native property
message (may be readonly).

To summarize the log:
DynamicSetter is called to assign the function to the signal "message"
DynamicSetter finds the signal "message"
DynamicGetter is called to get the prototype.
DynamicGetter finds the method "message", prototype Variant::TYPE_SCRIPTABLE
DynamicSetter fails at value.type() == Variant::TYPE_SLOT
Assignment (false) = function() {} fails.

Original issue reported on code.google.com by pro...@gmail.com on 7 Aug 2009 at 7:45

GoogleCodeExporter commented 9 years ago
Your remote dbus object must support Introspectable interface, otherwise signal 
won't
work correctly.

Original comment by james...@gmail.com on 8 Aug 2009 at 2:23

GoogleCodeExporter commented 9 years ago
Well, i think it does. See the attached dbus-monitor log, captured while 
connecting
the widget to the bus.

Original comment by pro...@gmail.com on 8 Aug 2009 at 1:19

Attachments:

GoogleCodeExporter commented 9 years ago
Then, which signal did you try to connect?

Original comment by james...@gmail.com on 8 Aug 2009 at 1:30

GoogleCodeExporter commented 9 years ago
message. There's a signal message and a method message which leads to type 
mismatch,
i think.

Original comment by pro...@gmail.com on 8 Aug 2009 at 1:32

GoogleCodeExporter commented 9 years ago
You can uncomment line 38 of ggadget/dbus/dbus_proxy.cc to get more verbose log 
message.

Original comment by james...@gmail.com on 8 Aug 2009 at 1:33

GoogleCodeExporter commented 9 years ago
That's the problem. they shouldn't use the same name, otherwise there is no way 
to
distinguish which you want when accessing the name from JavaScript.

Original comment by james...@gmail.com on 8 Aug 2009 at 1:59

GoogleCodeExporter commented 9 years ago
Did so. 

Original comment by pro...@gmail.com on 8 Aug 2009 at 2:00

Attachments:

GoogleCodeExporter commented 9 years ago
You're right. With this architecture you use (prototype determination by dynamic
getter) it's not possible. Maybe you could implement a method to return a 
signal slot
for cases like this. It's not that unlikely that there's a signal and a method 
with
the same name, i think.

Original comment by pro...@gmail.com on 8 Aug 2009 at 2:02

GoogleCodeExporter commented 9 years ago
You can try to modify ScriptableDBusObject::DynamicGetter() to try signal before
method. Then you can access the signal. You may still call the method with
$callMethod method.

If it works for you, I can modify the trunk code as it.

Original comment by james...@gmail.com on 8 Aug 2009 at 2:20

GoogleCodeExporter commented 9 years ago
I did so before. Yes it works.

Original comment by pro...@gmail.com on 8 Aug 2009 at 2:27

GoogleCodeExporter commented 9 years ago
Ok, I'll modify trunk.

Original comment by james...@gmail.com on 8 Aug 2009 at 2:29

GoogleCodeExporter commented 9 years ago
Ok. Thank you.

Original comment by pro...@gmail.com on 8 Aug 2009 at 3:08

GoogleCodeExporter commented 9 years ago

Original comment by james...@gmail.com on 10 Aug 2009 at 9:53