The easiest thing to do for the moment is to create a replacement for
mDNS.pm:
>
> % mv mDNS.pm mDNS.pm.orig
> % ln -s avahiDNS.pm mDNS.pm
>
One of the great things about the Avahi replacement is that when
SlimServer stops, the service is removed from the Avahi publication
list. Previously, mDNSResponderPosix would continue to run, even when
SlimServer had been stopped.
This code implements a suitable replacement:
Code:
--------------------
package Slim::Networking::mDNS;
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2.
use strict;
use Slim::Utils::Misc;
use Slim::Utils::Prefs;
use Net::Rendezvous::Publish;
my $init = 0;
my $publisher;
my @advertisement = ();
my %services = ();
sub init {
my $class = shift;
$::d_mdns && msg("mDNS: Initializing..\n");
$publisher = Net::Rendezvous::Publish->new(
backend => 'Net::Rendezvous::Publish::Backend::Avahi');
if ($publisher) {
$init = 1;
} else {
$::d_mdns && msg("mDNS: Failed to create responder.\n");
}
}
sub addService {
my ($class, $service, $port) = @_;
unless ($init) {
return unless $class->init;
}
my $name = Slim::Utils::Prefs::get('mDNSname');
if (!defined $name || $name eq '') {
$::d_mdns && msg("mDNS: Blank name, skipping service: $service - TXT -
$port\n");
} else {
$::d_mdns && msg("mDNS: Adding service: $name - $service - TXT - $port\n");
$services{$service} = [ $name, $port ];
}
}
sub removeService {
my ($class, $service) = @_;
unless ($init) {
return unless $class->init;
}
$::d_mdns && msg("mDNS: Removing service: $service\n");
delete $services{$service};
}
sub startAdvertising {
my $class = shift;
unless ($init) {
return unless $class->init;
}
# Remove any existing services
$class->stopAdvertising;
# Publish each specified service
$::d_mdns && msg("mDNS: startAdvertising()\n");
while (my ($service, $data) = each %services) {
my ($name, $port) = @$data;
push @advertisement, $publisher->publish(
name => $name,
type => $service,
port => $port,
txt => "TXT",
);
}
}
sub stopAdvertising {
my $class = shift;
$::d_mdns && msg("mDNS: stopAdvertising()\n");
while (@advertisement) {
shift(@advertisement)->stop;
}
}
1;
__END__
# Local Variables:
# tab-width:4
# indent-tabs-mode:t
# End:
--------------------
--
quietdragon
------------------------------------------------------------------------
quietdragon's Profile: http://forums.slimdevices.com/member.php?userid=10412
View this thread: http://forums.slimdevices.com/showthread.php?t=33915
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/unix