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
| sub genXmlInfoHotel{
my @listeHotel = @_;
my $pipeFils_Pere = new IO::Pipe;
my $isPere=0;
my $nbHotels = scalar(@listeHotel);
#Creation des "nbProcessus" Processus
for (my $indice=0;$indice<$nbProcessus;$indice++){
$isPere = fork ();
#Les process fils recup les infos de l'hotel
if (! ($isPere)){
$pipeFils_Pere->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 $pipeFils_Pere $str;
}
}
print "fin fils $indice \n";
}
}
# Le process pere cré le fichier xml et recup par pipe les infos des fils
if ($isPere){
my $nbFilsMorts = 0;
$pipeFils_Pere->reader();
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";
while(<$pipeFils_Pere>) {
$fluxXml = "$_";
print $fh "$fluxXml";
}
print $fh "</listesHotels> \n";
$fh->close;
print "fin pere\n";
}
} |
Partager