[libnet-dbus-perl] 24/335: Fixed many problems with signals
Intrigeri
intrigeri at moszumanska.debian.org
Sat Mar 21 01:07:13 UTC 2015
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to branch experimental
in repository libnet-dbus-perl.
commit a30cd09b83195d427398715ed4d5c62b40591a9b
Author: Daniel P. Berrange <dan at berrange.com>
Date: Tue Nov 23 23:24:47 2004 +0000
Fixed many problems with signals
---
lib/Net/DBus.pm | 80 +++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 55 insertions(+), 25 deletions(-)
diff --git a/lib/Net/DBus.pm b/lib/Net/DBus.pm
index a14a357..51e71fb 100644
--- a/lib/Net/DBus.pm
+++ b/lib/Net/DBus.pm
@@ -24,17 +24,21 @@ use vars qw(@EXPORT);
require XSLoader;
XSLoader::load('Net::DBus', $VERSION);
-use vars qw($TYPE_SESSION $TYPE_SYSTEM);
+sub system {
+ my $class = shift;
+ return $class->_new(&Net::DBus::Binding::Bus::SYSTEM);
+}
-$TYPE_SESSION = &Net::DBus::Binding::Bus::SESSION;
-$TYPE_SYSTEM = &Net::DBus::Binding::Bus::SYSTEM;
+sub session {
+ my $class = shift;
+ return $class->_new(&Net::DBus::Binding::Bus::SESSION);
+}
-sub new {
+sub _new {
my $class = shift;
my $self = {};
- my $type = shift;
-
- $self->{connection} = Net::DBus::Binding::Bus->new(type => $type);
+
+ $self->{connection} = Net::DBus::Binding::Bus->new(type => shift);
$self->{signals} = {};
bless $self, $class;
@@ -44,25 +48,30 @@ sub new {
return $self;
}
+sub get_connection {
+ my $self = shift;
+ return $self->{connection};
+}
sub get_service {
my $self = shift;
my $name = @_ ? shift : "org.freedesktop.Broadcast";
- return Net::DBus::RemoteService->new($self->{connection}, $name);
+ return Net::DBus::RemoteService->new($self, $name);
}
sub add_signal_receiver {
my $self = shift;
my $receiver = shift;
- my $interface = @_ ? shift : "None";
- my $service = @_ ? shift : "None";
- my $path = @_ ? shift : "None";
+ my $signal_name = shift;
+ my $interface = shift;
+ my $service = shift;
+ my $path = shift;
- my $rule = $self->_match_rule($interface, $service, $path);
+ my $rule = $self->_match_rule($signal_name, $interface, $service, $path);
$self->{receivers}->{$rule} = [] unless $self->{receivers}->{$rule};
- push @{$self->{receivers}}, $receiver;
+ push @{$self->{receivers}->{$rule}}, $receiver;
$self->{connection}->add_match($rule);
}
@@ -70,12 +79,13 @@ sub add_signal_receiver {
sub remove_signal_receiver {
my $self = shift;
my $receiver = shift;
- my $interface = @_ ? shift : "None";
- my $service = @_ ? shift : "None";
- my $path = @_ ? shift : "None";
-
- my $rule = $self->_match_rule($interface, $service, $path);
+ my $signal_name = shift;
+ my $interface = shift;
+ my $service = shift;
+ my $path = shift;
+ my $rule = $self->_match_rule($signal_name, $interface, $service, $path);
+
my @receivers;
foreach (@{$self->{receivers}->{$rule}}) {
if ($_ eq $receiver) {
@@ -90,12 +100,32 @@ sub remove_signal_receiver {
sub _match_rule {
my $self = shift;
+ my $signal_name = shift;
my $interface = shift;
my $service = shift;
my $path = shift;
- # FIXME: use the service here too!!!
- return "type='signal',interface='$interface',path='$path'";
+ my $rule = "type='signal'";
+ if ($interface) {
+ $rule .= ",interface='$interface'";
+ }
+ if ($service) {
+ if ($service !~ /^:/ &&
+ $service ne "org.freedesktop.DBus") {
+ my $bus_service = $self->get_service("org.freedesktop.DBus");
+ my $bus_object = $bus_service->get_object('/org/freedesktop/DBus',
+ 'org.freedesktop.DBus');
+ $service = $bus_object->GetServiceOwner($service);
+ }
+ $rule .= ",sender='$service'";
+ }
+ if ($path) {
+ $rule .= ",path='$path'";
+ }
+ if ($signal_name) {
+ $rule .= ",member='$signal_name'";
+ }
+ return $rule;
}
@@ -104,19 +134,19 @@ sub _signal_func {
my $connection = shift;
my $message = shift;
- return 0 unless $message->isa("Net::DBus::Message::Signal");
+ return 0 unless $message->isa("Net::DBus::Binding::Message::Signal");
my $interface = $message->get_interface;
my $service = $message->get_sender;
my $path = $message->get_path;
my $member = $message->get_member;
- my $rule = $self->_match_rule($interface, $service, $path);
-
+ my $rule = $self->_match_rule($member, $interface, $service, $path);
+
my $handled = 0;
if (exists $self->{receivers}->{$rule}) {
- foreach (@{$self->{receivers}->{$rule}}) {
- &$_($interface, $member, $service, $path, $message);
+ foreach my $callback (@{$self->{receivers}->{$rule}}) {
+ &$callback($interface, $member, $service, $path, $message);
$handled = 1;
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libnet-dbus-perl.git
More information about the Pkg-perl-cvs-commits
mailing list