--- loncom/lonnet/perl/lonnet.pm 2011/07/28 18:22:44 1.1120 +++ loncom/lonnet/perl/lonnet.pm 2011/07/31 22:55:53 1.1121 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1120 2011/07/28 18:22:44 raeburn Exp $ +# $Id: lonnet.pm,v 1.1121 2011/07/31 22:55:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -306,6 +306,44 @@ sub get_server_homeID { return &do_cache_new('serverhomeID',$hostname,$serverhomeID,$cachetime); } +sub get_remote_globals { + my ($lonhost,$whathash,$ignore_cache) = @_; + my (%returnhash,%whatneeded); + if (ref($whathash) eq 'ARRAY') { + foreach my $what (sort(keys(%{$whathash}))) { + my $type = $whathash->{$what}; + my $hashid = $lonhost.'-'.$what; + my ($result,$cached); + unless ($ignore_cache) { + ($result,$cached)=&is_cached_new('lonnetglobal',$hashid); + $returnhash{$what} = $result; + } + if (defined($cached)) { + $returnhash{$what} = $result; + } else { + $whatneeded{$what} = $type; + } + } + if (keys(%whatneeded) > 0) { + my $requested = &freeze_escape(\%whatneeded); + my $rep=&reply('readlonnetglobal:'.$requested,$lonhost); + unless (($rep=~/^refused/) || ($rep=~/^rejected/) || $rep eq 'con_lost')) { + my @pairs=split(/\&/,$rep); + if ($rep !~ /^error/) { + foreach my $item (@pairs) { + my ($key,$value)=split(/=/,$item,2); + my $what = &unescape($key); + my $hashid = $lonhost.'-'.$what; + $returnhash{$what}=&thaw_unescape($value); + &do_cache_new('lonnetglobal',$hashid,$returnhash{$what},600); + } + } + } + } + } + return %returnhash; +} + # -------------------------------------------------- Non-critical communication sub subreply { my ($cmd,$server)=@_;