New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only a single listener allowed per name using dbus.connect_signal #1071
Comments
Awesome's dbus bindings are quite... basic. Also, writing awesome-specific dbus Lua bindings limits their use to awesome. The long-term goal is that someone comes up with generic dbus Lua bindings (based on lgi) that also work in awesome. When this happens, all of the dbus-based code in awesome('s C code) would be dropped. Thus, I'm not really enthusiastic for improving the existing bindings. Anyway:
diff --git a/dbus.c b/dbus.c
index dc5bcaf..5eb30a8 100644
--- a/dbus.c
+++ b/dbus.c
@@ -761,6 +761,8 @@ luaA_dbus_remove_match(lua_State *L)
*
* @param interface A string with the interface name.
* @param func The function to call.
+ * @treturn boolean true on success, false if the signal could not be connected
+ * because another function is already connected.
* @function connect_signal
*/
static int
@@ -771,10 +773,14 @@ luaA_dbus_connect_signal(lua_State *L)
signal_t *sig = signal_array_getbyid(&dbus_signals,
a_strhash((const unsigned char *) name));
if(sig)
+ {
luaA_warn(L, "cannot add signal %s on D-Bus, already existing", name);
- else
+ lua_pushboolean(L, false);
+ } else {
signal_connect(&dbus_signals, name, luaA_object_ref(L, 2));
- return 0;
+ lua_pushboolean(L, true);
+ }
+ return 1;
}
/** Remove a signal receiver on the D-Bus. Unrelated(?) issue: local function f() end
dbus.connect_signal("foo", f)
dbus.disconnect_signal("foo", f)
dbus.connect_signal("foo", function() end) -- This does not work, but prints a warning Untested patch for this would be (if anyone wants, this can also be turned into a PR (after having been tested; perhaps even adding a new test to diff --git a/common/signal.h b/common/signal.h
index d9d5e45..46bad94 100644
--- a/common/signal.h
+++ b/common/signal.h
@@ -92,6 +92,8 @@ signal_disconnect(signal_array_t *arr, const char *name, const void *ref)
if(ref == *func)
{
cptr_array_remove(&sigfound->sigfuncs, func);
+ if(sigfound->sigfuncs.len == 0)
+ signal_array_remove(arr, sigfound);
return true;
}
} Edit: The above patch also fixes a crash. If a dbus function call fo "foo" comes in after the above connect-disconnect-dance, we crash. |
@psychon Thanks for the quick and thorough feedback; it seems that my problems stem from my false assumption that As all I want is for two decoupled parts of my configuration to listen for the same DBus signal, what would be the recommended approach? AFAICT, awesome could add a separate function in the Alternatively, I could use a library like ldbus to connect to dbus for this purpose, but then I would have to poll at an interval to receive signals, as awesome doesn't expose its event loop to Lua, right? As far as that change above goes, I just submitted at PR for it: #1078 |
I'm not sure. Via https://github.com/daurnimator/ldbus I got to the docs for
Since awesome's C code sets up the session bus ( Scratch that. After looking at our code, awesome will actively(?) break things. Its dbus-integration "steals" all dbus messages that come in.
Awesome's event loop as a glib Edit:
I didn't even know that we handle dbus signals correctly and hand them to Lua. Hm... this is all quite a horrible API (both dbus signals and dbus function calls look the same to Lua, I think; a lot of information seems to be missing). In that case, perhaps we should just drop the restriction on only one connection to a signal? Only the first one will be called for function calls, but dbus signals should be handled correctly. I don't know... |
@psychon Ok, thanks for the info! I think since my primary concern has been addressed, I'm going to close this issue. |
Output of
awesome --version
:How to reproduce the issue:
Call this twice:
dbus.connect_signal('org.freedesktop.DBus.Properties', function() end)
Actual result:
dbus.connect_signal
returnsnil
both times, a warning is emitted to Awesome's output, and the second callback function is not invoked fororg.freedesktop.DBus.Properties
DBus events.Expected result:
Ideally, I would like for multiple functions to be able to listen for the same DBus event.
Barring that, it would be nice if
dbus.connect_signal
returnedtrue
upon success andnil, string
upon failure, like many other Lua functions, so that scripters could know from their script whether or not they were able to register the callback. In addition, it would be nice if there were a way to get the callback currently associated with the name so that the user could manually chain callbacks, like so:The text was updated successfully, but these errors were encountered: