[libnet-dbus-perl] 234/335: Added support for opening private connections/buses
Intrigeri
intrigeri at moszumanska.debian.org
Sat Mar 21 01:08:04 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 53532c8c447a4e787113bb1d4ce9338b6be6b44b
Author: Daniel P. Berrange <berrange at redhat.com>
Date: Tue Nov 14 22:45:40 2006 -0500
Added support for opening private connections/buses
---
DBus.xs | 38 ++++++++++++++++++++++++++++++++++++++
lib/Net/DBus.pm | 10 ++++++++++
lib/Net/DBus/Binding/Bus.pm | 17 ++++++++++++++---
lib/Net/DBus/Binding/Connection.pm | 13 +++++++++++--
4 files changed, 73 insertions(+), 5 deletions(-)
diff --git a/DBus.xs b/DBus.xs
index 4194ae4..3fb6459 100644
--- a/DBus.xs
+++ b/DBus.xs
@@ -463,6 +463,7 @@ _open(address)
DBusConnection *con;
CODE:
dbus_error_init(&error);
+ DEBUG_MSG("Open connection shared %s\n", address);
con = dbus_connection_open(address, &error);
dbus_connection_ref(con);
if (!con) {
@@ -472,6 +473,24 @@ _open(address)
OUTPUT:
RETVAL
+DBusConnection *
+_open_private(address)
+ char *address;
+ PREINIT:
+ DBusError error;
+ DBusConnection *con;
+ CODE:
+ dbus_error_init(&error);
+ DEBUG_MSG("Open connection private %s\n", address);
+ con = dbus_connection_open_private(address, &error);
+ dbus_connection_ref(con);
+ if (!con) {
+ _croak_error (&error);
+ }
+ RETVAL = con;
+ OUTPUT:
+ RETVAL
+
MODULE = Net::DBus::Binding::C::Connection PACKAGE = Net::DBus::Binding::C::Connection
void
@@ -825,6 +844,7 @@ _open(type)
DBusConnection *con;
CODE:
dbus_error_init(&error);
+ DEBUG_MSG("Open bus shared %d\n", type);
con = dbus_bus_get(type, &error);
dbus_connection_ref(con);
if (!con) {
@@ -834,6 +854,24 @@ _open(type)
OUTPUT:
RETVAL
+DBusConnection *
+_open_private(type)
+ DBusBusType type;
+ PREINIT:
+ DBusError error;
+ DBusConnection *con;
+ CODE:
+ dbus_error_init(&error);
+ DEBUG_MSG("Open bus private %d\n", type);
+ con = dbus_bus_get_private(type, &error);
+ dbus_connection_ref(con);
+ if (!con) {
+ _croak_error(&error);
+ }
+ RETVAL = con;
+ OUTPUT:
+ RETVAL
+
MODULE = Net::DBus::Binding::Message PACKAGE = Net::DBus::Binding::Message
PROTOTYPES: ENABLE
diff --git a/lib/Net/DBus.pm b/lib/Net/DBus.pm
index 20120b4..d2f59de 100644
--- a/lib/Net/DBus.pm
+++ b/lib/Net/DBus.pm
@@ -169,6 +169,11 @@ attached to the main L<Net::DBus::Reactor> event loop.
sub system {
my $class = shift;
+ my %params = @_;
+ if ($params{private}) {
+ return $class->_new(Net::DBus::Binding::Bus->new(type => &Net::DBus::Binding::Bus::SYSTEM, private => 1), @_);
+ }
+
unless ($bus_system) {
$bus_system = $class->_new(Net::DBus::Binding::Bus->new(type => &Net::DBus::Binding::Bus::SYSTEM), @_);
}
@@ -187,6 +192,11 @@ attached to the main L<Net::DBus::Reactor> event loop.
sub session {
my $class = shift;
+ my %params = @_;
+ if ($params{private}) {
+ return $class->_new(Net::DBus::Binding::Bus->new(type => &Net::DBus::Binding::Bus::SESSION, private => 1), @_);
+ }
+
unless ($bus_session) {
$bus_session = $class->_new(Net::DBus::Binding::Bus->new(type => &Net::DBus::Binding::Bus::SESSION), @_);
}
diff --git a/lib/Net/DBus/Binding/Bus.pm b/lib/Net/DBus/Binding/Bus.pm
index 0dfa075..d9e34c2 100644
--- a/lib/Net/DBus/Binding/Bus.pm
+++ b/lib/Net/DBus/Binding/Bus.pm
@@ -59,7 +59,10 @@ use base qw(Net::DBus::Binding::Connection);
Open a connection to a message bus, either a well known bus type
specified using the C<type> parameter, or an arbitrary bus specified
-using the C<address> parameter.
+using the C<address> parameter. If the C<private> parameter is set
+to a true value, then a private connection to the bus is obtained.
+The caller must explicitly disconnect this bus instance before
+releasing the last instance of the object.
=cut
@@ -70,9 +73,17 @@ sub new {
my $connection;
if (defined $params{type}) {
- $connection = Net::DBus::Binding::Bus::_open($params{type});
+ if ($params{private}) {
+ $connection = Net::DBus::Binding::Bus::_open_private($params{type});
+ } else {
+ $connection = Net::DBus::Binding::Bus::_open($params{type});
+ }
} elsif (defined $params{address}) {
- $connection = Net::DBus::Binding::Connection::_open($params{address});
+ if ($params{private}) {
+ $connection = Net::DBus::Binding::Connection::_open_private($params{address});
+ } else {
+ $connection = Net::DBus::Binding::Connection::_open($params{address});
+ }
$connection->dbus_bus_register();
} else {
die "either type or address parameter is required";
diff --git a/lib/Net/DBus/Binding/Connection.pm b/lib/Net/DBus/Binding/Connection.pm
index 36b0ba0..ec9d6be 100644
--- a/lib/Net/DBus/Binding/Connection.pm
+++ b/lib/Net/DBus/Binding/Connection.pm
@@ -83,7 +83,12 @@ use Net::DBus::Binding::PendingCall;
=item my $con = Net::DBus::Binding::Connection->new(address => "unix:path=/path/to/socket");
Creates a new connection to the remove server specified by
-the parameter C<address>.
+the parameter C<address>. If the C<private> parameter is
+supplied, and set to a True value the connection opened is
+private; otherwise a shared connection is opened. A private
+connection must be explicitly shutdown with the C<disconnect>
+method before the last reference to the object is released.
+A shared connection must never be explicitly disconnected.
=cut
@@ -93,8 +98,12 @@ sub new {
my %params = @_;
my $self = {};
+ my $private = $params{private} ? $params{private} : 0;
$self->{address} = exists $params{address} ? $params{address} : (exists $params{connection} ? "" : die "address parameter is required");
- $self->{connection} = exists $params{connection} ? $params{connection} : Net::DBus::Binding::Connection::_open($self->{address});
+ $self->{connection} = exists $params{connection} ? $params{connection} :
+ ($private ?
+ Net::DBus::Binding::Connection::_open_private($self->{address}) :
+ Net::DBus::Binding::Connection::_open($self->{address}));
bless $self, $class;
--
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