Skip to content
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

Troubles with multi subscription to d-bus data #226

Open
v-sadovsky opened this issue Feb 20, 2021 · 2 comments
Open

Troubles with multi subscription to d-bus data #226

v-sadovsky opened this issue Feb 20, 2021 · 2 comments

Comments

@v-sadovsky
Copy link

Hello.

I'm trying to subscribe to a d-bus event and a d-bus property.
When I implement only one type of subscription all woks fine - I receive corresponding data via d-bus (a signal or a property data).

But when I try to use both (subscribe to a signal and to a property) I have the following troubles:
When the d-bus signal comes to the corresponding channel the same data also appears on the channel that is linked to the d-bus property. And vice versa.

This is my implementation of multi subscription:
`func TestSubs() {
// connect to the DBus
bus, err := dbus.SystemBus()
if err != nil {
log.Fatalf("error: dbus not connected. %s", err)
}

defer func() {
	bus.Close()
}()

// subscribe to property
prop_ch := make(chan *dbus.Signal)
err = bus.AddMatchSignal(dbus.WithMatchObjectPath(dbusPath), dbus.WithMatchInterface(propIface), dbus.WithMatchMember(propMember))
if err != nil {
	log.Fatalf("error: failed to subscribe to dbus property. %s", err)
}
bus.Signal(prop_ch)

// subscribe to event
event_ch := make(chan *dbus.Signal)
err = bus.AddMatchSignal(dbus.WithMatchObjectPath(dbusPath), dbus.WithMatchInterface(sigIface), dbus.WithMatchMember(sigMember))
if err != nil {
	log.Fatalf("error: failed to subscribe to dbus event. %s", err)
}
bus.Signal(event_ch)

// poll received via d-bus data
for {
	select {
	case <-prop_ch:
		fmt.Println("Property has been received via d-bus")

	case <-event_ch:
		fmt.Println("Signal has been received via d-bus")

	default:
		time.Sleep(50 * time.Millisecond)
	}
}

}`

And there is the result that I get when a signal comes to the event_ch:
Signal has been received via d-bus Property has been received via d-bus

Am I doing something wrong?

Kind regards,
Viacheslau

@jhenstridge
Copy link
Contributor

That is the current expected behaviour of the library: the AddSignalMatch calls tell dbus-daemon what types of signal messages we're interested in, and the Signal calls set up channels that will receive all signals received from the bus.

We don't currently have a way to create a channel that will only receive signals matching a particular rule. I agree that it would be useful to add such a feature, but it is non-trivial to implement. In particular, WithMatchSender rules that use a well known bus name require that we track the ownership of that bus name, since matching signals will instead list the unique name as the sender (i.e. something like :1.42).

@v-sadovsky
Copy link
Author

Thanks.
Currently, I am using the "Name" property of a received dbus.Signal to check what kind of signal is coming to a channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants