1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| sub genXmlInfoHotel{
my @listeHotel = @_;
#my $pipeFils_Pere = new IO::Pipe;
my $isPere=0;
my $nbHotels = scalar(@listeHotel);
@tableauxPipe=qw();
@fils=qw();
#Creation des "nbProcessus" Processus
for (my $indice=0;$indice<$nbProcessus;$indice++){
push @tableauxPipe, new IO::Pipe;
$isPere = fork ();
#Les process fils recup les infos de l'hotel
if (! ($isPere)){
#$pipeFils_Pere->writer();
$tableauxPipe[$indice]->writer();
#Pour chaques hotels attribués a ce process
for(my $j=$nbHotels*(($indice/$nbProcessus)-(1/$nbProcessus));$j<$nbHotels*($indice/$nbProcessus);$j++){
$hotelId = $listeHotel[$j][0];
$hotelNom = $listeHotel[$j][1];
$dispo = "";
$enLigne = "";
my $dateOuv = "";
if ($hotelId > 0){
isOnLine();
print "fils $indice :: hotel : $hotelId :++: online : $enLigne \n";
getDateOuverture();
getDispo();
$str = "<hotel id=\"".$hotelId."\" nom=\"".$hotelNom."\"><nbChDispo>".$dispo."</nbChDispo><ouverture>".$dateOuv."</ouverture><enLigne>".$enLigne."</enLigne></hotel> \n";
print {$tableauxPipe[$indice]} $str;
#print $pipeFils_Pere $str;
}
}
print "fin fils $indice : $isPere \n";
exit(0);
}
#Construction du tableaux de fils
push @fils,$isPere;
print "je viens de cree les process : $isPere\n";
}
# Le process pere attend la mort des fils
foreach $pid (@fils) {
print "attends mort fils $pid \n";
print "-->" . waitpid($pid, 0);
print "mort du fils $pid \n";
}
# Le process pere cré le fichier xml et recup par pipe les infos des fils
my $fh = new FileHandle "> $locationXmlFile";
if (!defined $fh){
print "Erreur : PB de creation du fichier XML";
}
print $fh "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n";
print $fh "<listesHotels> \n";
print "papa\n";
# Lecture des pipes
for (my $indice=0;$indice<$nbProcessus;$indice++){
$tableauxPipe[$indice]->reader();
while( defined( my $line = $tableauxPipe[1]->getline )) {
print $fh "$line";
print "tot\n";
}
}
print $fh "</listesHotels> \n";
$fh->close;
print "fin pere\n";
} |
Partager