Esempio n. 1
0
static void ack ( int signalNumber )
// Mode d'emploi :
// Acknowledge the death of a children GarerParking tasks.
// Update the shared state and display accordingly.
{
	// Retrieve the pid of the terminated child
	int status;
	pid_t pid;
	// For each child task that has died
	while ( (pid = waitpid ( -1, &status, WNOHANG )) > 0 )
	{
		if ( WIFEXITED ( status ) )
		{
			// Retrieve the spot number (encoded into the return value)
			int spotNumber = WEXITSTATUS ( status );
			Car car = currentValets[pid];
			car.entranceTime = time ( NULL );

			// Remove this pid from the list of running tasks
			currentValets.erase ( pid );

			// Update the state of the parking lot
			placeCar ( spotNumber, car );
			// Display the newly parked car
			AfficherPlace ( spotNumber, car.priority, 
							car.licensePlate, car.entranceTime );
		}
	}
} // Fin de ack
Esempio n. 2
0
// ------ Handler SIGCHLD --------
static void HandlerCHLD(int noSig)
{
	int numPlace;
	pid_t pidDestruct = waitpid(-1 ,&numPlace,0);
	numPlace = WEXITSTATUS(numPlace);

	Voiture voitureGarer;
	std::vector<pidVoiture>::iterator ite; 
	for(ite = listeFils.begin(); ite != listeFils.end(); ite++)
	{
		if((*ite).pid == pidDestruct)
		{
			voitureGarer = (*ite).voiture;
			listeFils.erase(ite);
			break;
		}
	}

	while(semop(semId, decrSemParking, 1) == -1 && errno == EINTR);
	
	// Mise a jour memoire partagee
	ParkingMPPtr->parking[numPlace - 1] = voitureGarer;

	semop(semId, incrSemParking, 1);
	
	AfficherPlace(numPlace, voitureGarer.usager, voitureGarer.immatriculation, voitureGarer.dateArrive);
}
Esempio n. 3
0
static void faireAMortFils(int noSignal)
// Algorithme :
//	Handler pour le signal SIGCHLD
//  Met à jour l'écran par l'affichage de la place occupée
//  Fait les gestions adéquates de fin du fils
{
	if(noSignal == SIGCHLD){
		struct sembuf reserver = {MUTEX_MEMPARTAGEE, -1,0};	//p Operation --> Reservation
		struct sembuf liberer = {MUTEX_MEMPARTAGEE, 1, 0};	//v Operation --> liberation

		int status;
		//Recupere dont provient SIGCHLD
		pid_t filsFini = wait(&status);

		//Retrouver la voiture associée
		msgClavier* voiture;
		for(vector<Voiturier>::iterator it=mouvementPark.begin(); it!= mouvementPark.end() ; it++){
			if(it->mouvementGarer == filsFini)
			{
				voiture = (*it).voiture;
				voiture -> tArrivee = time(NULL);
				break;
			}
		}

		AfficherPlace(WEXITSTATUS(status),voiture->typeVehicule,voiture->id,voiture->tArrivee);
		//Met à jour l'écran avec la nouvelle place

		while(semop(semId,&reserver,1)==-1 && errno==EINTR); //Reservation de la memoire

		//Ecrire la voiture sur la mémoire partagée
		structMemoire *park = (structMemoire *) shmat(idMemPart, NULL, 0) ; //attachment
		park->places[WEXITSTATUS(status)-1] = (*voiture) ;
		shmdt(park); //detachement

		semop(semId,&liberer,1); //Liberation de la memoire

		//Supprimer la bonne voiture de la map des voitures en train de se garer

		for(vector<Voiturier>::iterator it=mouvementPark.begin(); it!= mouvementPark.end() ; it++){
			if(it->mouvementGarer == filsFini)
			{
				mouvementPark.erase(it);
				break;
			}
		}

	}
}
Esempio n. 4
0
static void sigChldHandler(int noSig, siginfo_t *siginfo, void *context)
{
	std::map<pid_t, Voiture>::iterator voiturierIt = mapVoiturier.find(siginfo->si_pid);
	if(voiturierIt == mapVoiturier.end())
    {
    	return; //si le signal n'a pas ete envoye par un voiturier
    }
    else
    {
        //affiche sur l'IHM
        AfficherPlace(siginfo->si_status,voiturierIt->second.typeUsager,voiturierIt->second.immatriculation,
                      voiturierIt->second.heureArrivee);
        //ajoute la voiture au parking
    	semP(SEMELM_MP_PARKING);
    	mpParking[siginfo->si_status] = voiturierIt->second;
    	semV(SEMELM_MP_PARKING);
    	mapVoiturier.erase(voiturierIt);
    }
}