diff options
author | carlosg <carlosg> | 2005-04-19 23:32:57 +0000 |
---|---|---|
committer | carlosg <carlosg> | 2005-04-19 23:32:57 +0000 |
commit | e87c416ec13c73fca63ed43440a988a28bd04b21 (patch) | |
tree | 4265dafe35422c3ada4842a49ddf814b9356f2df | |
parent | c656b5ce6ca7c20caf06551dafd1183e64279660 (diff) |
2005-04-20 Carlos Garnacho Parro <carlosg@gnome.org>
* Utils/Monitor.pm: New file for monitoring file changes and emitting
DBus signals according to this
* Loader.pl.in: added function for monitoring files in a timeout
* SharesList.pm: monitor SMB and NFS files and emit "changed" signal
* Shares/Exports.pm: misc changes
-rw-r--r-- | ChangeLog | 8 | ||||
-rwxr-xr-x | Loader.pl.in | 3 | ||||
-rw-r--r-- | Shares/Exports.pm | 17 | ||||
-rw-r--r-- | SharesList.pm | 3 | ||||
-rw-r--r-- | Utils/Monitor.pm | 71 |
5 files changed, 92 insertions, 10 deletions
@@ -1,5 +1,13 @@ 2005-04-20 Carlos Garnacho Parro <carlosg@gnome.org> + * Utils/Monitor.pm: New file for monitoring file changes and emitting + DBus signals according to this + * Loader.pl.in: added function for monitoring files in a timeout + * SharesList.pm: monitor SMB and NFS files and emit "changed" signal + * Shares/Exports.pm: misc changes + +2005-04-20 Carlos Garnacho Parro <carlosg@gnome.org> + * Loader.pl.in: Added, this will be the application that will load all the backend objects, instead of being each backend an executable * SharesList.pm: Added, this is the DBus object for the shared folders diff --git a/Loader.pl.in b/Loader.pl.in index dc0b7c5..c23d09e 100755 --- a/Loader.pl.in +++ b/Loader.pl.in @@ -25,6 +25,7 @@ use Net::DBus; use Net::DBus::Service; use Net::DBus::Reactor; use Utils::Backend; +use Utils::Monitor; use SharesList; @@ -40,5 +41,5 @@ my $reactor = Net::DBus::Reactor->new(); my $shares_list = SharesList->new ($service); $reactor->manage($bus->{connection}); -#$reactor->add_timeout (50, Net::DBus::Callback->new(method => \&files_monitor::do_monitor_files)); +$reactor->add_timeout (50, Net::DBus::Callback->new(method => \&Utils::Monitor::do_monitor_files)); $reactor->run(); diff --git a/Shares/Exports.pm b/Shares/Exports.pm index bc5c072..a26c77b 100644 --- a/Shares/Exports.pm +++ b/Shares/Exports.pm @@ -756,28 +756,29 @@ sub gst_share_replace_nfs_exports # filename, table } } -sub get_distro_files +sub get_files { my ($smb_comb, $exports); + my (@arr); %dist_attrib = &gst_network_get_parse_table (); - $smb_conf = $dist_attrib{"fn"}{"SMB_CONF"}; + push @arr, $dist_attrib{"fn"}{"SMB_CONF"}; # This is pretty standard - $exports = "/etc/exports"; + push @arr, "/etc/exports"; - return ($smb_conf, $exports); + return \@arr; } sub get_list { my ($smb_exports, $nfs_exports); - my (%dist_attrib, $smb_conf, $exports); + my ($arr); - ($smb_conf, $exports) = &get_distro_files (); + $arr = &get_files (); - $smb_exports = &gst_share_parse_smb_conf ($smb_conf); - $nfs_exports = &gst_share_parse_nfs_exports ($exports); + $smb_exports = &gst_share_parse_smb_conf ($$arr[0]); + $nfs_exports = &gst_share_parse_nfs_exports ($$arr[1]); return ($smb_exports, $nfs_exports); } diff --git a/SharesList.pm b/SharesList.pm index 73d60d1..37b9420 100644 --- a/SharesList.pm +++ b/SharesList.pm @@ -36,7 +36,8 @@ sub new ["get"], @_); bless $self, $class; -# share::monitor_share_files ($self, $OBJECT_NAME, "changed"); + Utils::Monitor::monitor_files (&Shares::Exports::get_files (), + $self, $OBJECT_NAME, "changed"); return $self; } diff --git a/Utils/Monitor.pm b/Utils/Monitor.pm new file mode 100644 index 0000000..8ecc90e --- /dev/null +++ b/Utils/Monitor.pm @@ -0,0 +1,71 @@ +#!/usr/bin/env perl +#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + +# Common functions for exporting network shares (NFS or SMB). +# +# Copyright (C) 2000-2001 Ximian, Inc. +# +# Authors: Carlos Garnacho Parro <carlosg@gnome.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library General Public License as published +# by the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +package Utils::Monitor; + +use SGI::FAM; +use Cwd; +use strict; +use base qw(Net::DBus::Object); +use Utils::Backend; + +my $fam = new SGI::FAM; +my %objects; + +sub do_monitor_files +{ + my ($event, $data, $func, $path); + + while ($fam->pending) + { + $event = $fam->next_event; + + if ($event->type eq "change") + { + $data = $objects {$event->filename}; + $path = $Utils::Backend::DBUS_PREFIX . "." . $$data{"name"}; + + &Net::DBus::Object::emit_signal ($$data {"object"}, + $path, + $$data {"signal"}); + } + } +} + +sub monitor_files +{ + my ($files, $object, $name, $signal) = @_; + my ($path, $f); + + foreach $f (@$files) + { + $path = &Cwd::abs_path ($f); + + $objects {$path} = { "object" => $object, + "name" => $name, + "signal" => $signal}; + $fam->monitor ($path); + } +} + +1; |