Changeset 7

User picture

Author: macoma84

(2009/11/19 15:12) Over 2 years ago

FIN!!!!!!

Affected files

Updated Barberia.cpp Download diff

67
11
11
12
	InitializeCriticalSection(&cs);
12
	InitializeCriticalSection(&cs);
13
13
14
	asiento = NULL;
14
	asiento = 0x00000000;
15
15
16
	barberoEnPataleta = 0 ;
16
	barberoEnPataleta = 0 ;
17
17
...
...
20
	p = printer;
20
	p = printer;
21
21
22
	for (int i = 0; i < MAX_CLIENTES_ESPERANDO; i++) {
22
	for (int i = 0; i < MAX_CLIENTES_ESPERANDO; i++) {
23
		clientes_wait[i] = NULL;
23
		clientes_wait[i] = 0x00000000;
24
	}
24
	}
25
}
25
}
26
int Barberia::entrarPelu(int id){
26
int Barberia::entrarPelu(int id){
...
...
42
42
43
		WaitForSingleObject(l->semPaciencia,PACIENCIA*1000); // ES LA PACIENCIA DEL CLIENTE PARA ESPERAR SER ATENDIDO
43
		WaitForSingleObject(l->semPaciencia,PACIENCIA*1000); // ES LA PACIENCIA DEL CLIENTE PARA ESPERAR SER ATENDIDO
44
44
45
		if(l->comenzoCorte==0){
45
		if((l->comenzoCorte==0 && l->requierePeluquero == 1) || (l->requiereManicura == 1 && l->comenzoManicura==0)){
46
			
46
			
47
			if(barberoEnPataleta == 1){
47
			if(barberoEnPataleta == 1){
48
48
49
				l->enEspera = 0;
49
				l->enEspera = 0;
50
50
51
				sacarCliente(l);
51
				sacarCliente(l);
52
		
52
53
				ReleaseSemaphore(l->semAtendidoM,1,0x00000000);
54
				ReleaseSemaphore(l->semAtendidoP,1,0x00000000);
55
			
56
					
53
				return CLIENTE_PATALETA;
57
				return CLIENTE_PATALETA;
54
58
55
			}else{
59
			}else{
...
...
58
	 
62
	 
59
					l->enEspera = 0;
63
					l->enEspera = 0;
60
64
65
			
61
					sacarCliente(l);
66
					sacarCliente(l);
62
		
67
68
					ReleaseSemaphore(l->semAtendidoM,1,0x00000000);
69
					ReleaseSemaphore(l->semAtendidoP,1,0x00000000);
70
			
63
					return CLIENTE_ENOJADISIMO;
71
					return CLIENTE_ENOJADISIMO;
64
				
72
				
65
				}else{
73
				}else{
74
75
					if(l->rajadoPorManicura == 1){
76
					
77
						l->enEspera = 0;
78
79
						sacarCliente(l);
80
		
81
						ReleaseSemaphore(l->semAtendidoM,1,0x00000000);
82
						ReleaseSemaphore(l->semAtendidoP,1,0x00000000);
66
			
83
			
67
					l->enEspera = 0;
84
						return CLIENTE_ENOJADISIMO;
68
85
69
					sacarCliente(l);
86
					}else{
87
						l->enEspera = 0;
88
89
						sacarCliente(l);
70
		
90
		
71
					return CLIENTE_CANSADO_ESPERA;
91
						ReleaseSemaphore(l->semAtendidoM,1,0x00000000);
92
						ReleaseSemaphore(l->semAtendidoP,1,0x00000000);
93
						
94
						return CLIENTE_CANSADO_ESPERA;
95
					}
96
			
97
					
72
				
98
				
73
				}
99
				}
74
			
100
			
...
...
82
108
83
		sacarCliente(l);//saca cliente de espera
109
		sacarCliente(l);//saca cliente de espera
84
110
111
		ReleaseSemaphore(l->semAtendidoM,1,0x00000000);
112
		ReleaseSemaphore(l->semAtendidoP,1,0x00000000);
113
			
85
		return CLIENTE_ABANDONA_FELIZ; 
114
		return CLIENTE_ABANDONA_FELIZ; 
86
115
87
	}else{
116
	}else{
...
...
90
119
91
		sacarCliente(l);
120
		sacarCliente(l);
92
		
121
		
122
		ReleaseSemaphore(l->semAtendidoM,1,0x00000000);
123
		ReleaseSemaphore(l->semAtendidoP,1,0x00000000);
124
			
93
		return CLIENTE_CANSADO_ESPERA;	
125
		return CLIENTE_CANSADO_ESPERA;	
94
	}
126
	}
95
127
96
97
98
99
}
128
}
100
129
101
void Barberia::pataletaAlAzar(){
130
void Barberia::pataletaAlAzar(){
...
...
120
149
121
	asiento = l;
150
	asiento = l;
122
151
123
	if(l!=0x00000000){//hay clientes para atender
152
	if(asiento!=0x00000000){//hay clientes para atender
124
153
125
		if(l->requierePeluquero){
154
		if(asiento->requierePeluquero){
126
		
155
		
156
			asiento->comenzoCorte  = 1;
127
		
157
		
128
			l->comenzoCorte  = 1;
158
			if(asiento->amigo == 1){
129
		
130
			if(l->amigo == 1){
131
				atiendeAmigo=1;
159
				atiendeAmigo=1;
132
				p->cliente(l->id,CHARLANDO_DE_LA_VIDA);	
160
				p->cliente(asiento->id,CHARLANDO_DE_LA_VIDA);	
133
				p->peluquero( CHARLANDO_DE_LA_VIDA);
161
				p->peluquero( CHARLANDO_DE_LA_VIDA);
134
				Sleep(TIEMPO_DE_CHARLA*1000);
162
				Sleep(TIEMPO_DE_CHARLA*1000);
135
			}
163
			}
...
...
144
172
145
			Sleep(DEMORA_CORTE*1000);
173
			Sleep(DEMORA_CORTE*1000);
146
174
147
			l->atendido = 1;
175
			asiento->atendido = 1;
148
176
149
			atiendeAmigo=0;
177
			atiendeAmigo=0;
150
178
...
...
152
		
180
		
153
181
154
		}else{//no requiere peluqueria
182
		}else{//no requiere peluqueria
155
				
183
			
156
			WaitForSingleObject(l->semAtendidoM,INFINITE);//que espere a la manicura
184
			if(asiento->requiereManicura==1)
185
				WaitForSingleObject(l->semAtendidoM,INFINITE);//que espere a la manicura
157
186
158
			
187
			
159
188
160
		}
189
		}
161
		ReleaseSemaphore(l->semAtendidoP,1,NULL);
190
162
		ReleaseSemaphore(l->semSilla,1,NULL);
191
		ReleaseSemaphore(asiento->semAtendidoP,1,0x00000000);
192
		ReleaseSemaphore(asiento->semSilla,1,0x00000000);
193
194
		asiento->requierePeluquero = 0;
163
		
195
		
164
		return l->id;
196
		
197
		return asiento->id;
165
	}else{
198
	}else{
166
	
199
	
167
	
200
	
...
...
182
215
183
	}
216
	}
184
217
218
	asiento = 0x00000000;
219
185
	p->peluquero(PELUQUERO_ABRE_PUERTA);	
220
	p->peluquero(PELUQUERO_ABRE_PUERTA);	
186
221
187
}
222
}
...
...
198
233
199
		//el peluquero no discrimina entre niveles de amistad
234
		//el peluquero no discrimina entre niveles de amistad
200
235
201
		Lobby *cli = NULL;
236
		Lobby *cli = 0x00000000;
202
237
203
		//1) buscamos amigos sin atender (FCFS)
238
		//1) buscamos amigos sin atender (FCFS)
204
239
...
...
209
		
244
		
210
			if(cli!=0x00000000){
245
			if(cli!=0x00000000){
211
		
246
		
212
				if(cli->amigo==1 && cli->atendido == 0 && cli->enEspera == 1){
247
				if(cli->amigo==1 && cli->atendido == 0 && cli->enEspera == 1&& cli->esCliente == 1){
213
			
248
			
214
					clientes_wait[i] =NULL;
249
					clientes_wait[i] =0x00000000;
215
250
216
					p->peluquero(ENCONTRO_AMIGUITO);
251
					p->peluquero(ENCONTRO_AMIGUITO);
217
252
...
...
234
		
269
		
235
			if(cli!=0x00000000){
270
			if(cli!=0x00000000){
236
		
271
		
237
				if(cli->atendido == 0 && cli->enEspera == 1){
272
				if(cli->atendido == 0 && cli->enEspera == 1 && cli->esCliente == 1){
238
			
273
			
239
					clientes_wait[i] =NULL;
274
					clientes_wait[i] =0x00000000;
240
275
241
					LeaveCriticalSection(&cs);
276
					LeaveCriticalSection(&cs);
242
277
...
...
259
294
260
295
261
296
262
263
264
265
266
267
bool Barberia::peluqueria_full(){
297
bool Barberia::peluqueria_full(){
268
	bool full = true;
298
	bool full = true;
269
	int i = 0 ;
299
	int i = 0 ;
270
	while(clientes_wait[i]!=NULL && i < MAX_CLIENTES_ESPERANDO){
300
	while(clientes_wait[i]!=0x00000000 && i < MAX_CLIENTES_ESPERANDO){
271
		i++;
301
		i++;
272
	}
302
	}
273
303
...
...
285
bool Barberia::hay_gente(){
315
bool Barberia::hay_gente(){
286
	bool hayGente = false;
316
	bool hayGente = false;
287
	int i = 0 ;
317
	int i = 0 ;
288
	while(clientes_wait[i]==NULL && i < MAX_CLIENTES_ESPERANDO){
318
	while((clientes_wait[i]==0x00000000 || clientes_wait[i]->esCliente == 0 )&& i < MAX_CLIENTES_ESPERANDO){
289
		i++;
319
		i++;
290
	}
320
	}
291
321
292
	if(i < MAX_CLIENTES_ESPERANDO || clientes_wait[i]!=NULL){
322
	if(i < MAX_CLIENTES_ESPERANDO || (clientes_wait[i]!=0x00000000 && clientes_wait[i]->esCliente == 1)){
293
		hayGente = true;
323
		hayGente = true;
294
	}
324
	}
295
	return hayGente;
325
	return hayGente;
...
...
305
	}
335
	}
306
336
307
	if(clientes_wait[i]==cli && i < MAX_CLIENTES_ESPERANDO){
337
	if(clientes_wait[i]==cli && i < MAX_CLIENTES_ESPERANDO){
308
		clientes_wait[i] = NULL;
338
		clientes_wait[i] = 0x00000000;
309
	}
339
	}
310
340
311
	LeaveCriticalSection(&cs);
341
	LeaveCriticalSection(&cs);
...
...
319
	
349
	
320
	
350
	
321
	if(cli->id == -1){
351
	if(cli->id == -1){
322
		printf("Ingreso cliente -1, saca a cliente en pos 0");
352
		printf("\nIngreso cliente -1, saca a cliente en pos 0");
323
		cli->enEspera  = 1;
353
		cli->enEspera  = 1;
324
		clientes_wait[0] = cli;// LO METEMOS DE PREPO
354
		clientes_wait[0] = cli;// LO METEMOS DE PREPO
325
	}else{
355
	}else{
326
356
327
		int i = 0 ;
357
		int i = 0 ;
328
		while(clientes_wait[i]!=NULL && i < MAX_CLIENTES_ESPERANDO){
358
		while(clientes_wait[i]!=0x00000000 && i < MAX_CLIENTES_ESPERANDO){
329
			i++;
359
			i++;
330
		}
360
		}
331
		if(clientes_wait[i]==NULL && i < MAX_CLIENTES_ESPERANDO){
361
		if(clientes_wait[i]==0x00000000 && i < MAX_CLIENTES_ESPERANDO){
332
			cli->enEspera  = 1;
362
			cli->enEspera  = 1;
333
			clientes_wait[i]= cli;
363
			clientes_wait[i]= cli;
334
		}
364
		}
...
...
340
}
370
}
341
void Barberia::observarAsientos() {
371
void Barberia::observarAsientos() {
342
	printf("\n-Listado de clientes esperando: ");
372
	printf("\n-Listado de clientes esperando: ");
343
	Lobby* cli = NULL;
373
	Lobby* cli = 0x00000000;
344
	for (int i = 0; i < MAX_CLIENTES_ESPERANDO; i++) {
374
	for (int i = 0; i < MAX_CLIENTES_ESPERANDO; i++) {
345
			cli = clientes_wait[i];
375
			cli = clientes_wait[i];
346
			if(cli!=0x00000000){
376
			if(cli!=0x00000000){
...
...
364
	if(asiento!=0x00000000){
394
	if(asiento!=0x00000000){
365
	
395
	
366
		if(asiento->requiereManicura){
396
		if(asiento->requiereManicura){
397
398
			asiento->comenzoManicura = 1;
367
			
399
			
368
			p->cliente(asiento->id,MANICURA_ATIENDE);
400
			p->cliente(asiento->id,MANICURA_ATIENDE);
369
401
370
			Sleep(DEMORA_MANICURA*1000);
402
			Sleep(DEMORA_MANICURA*1000);
371
403
372
			ReleaseSemaphore(asiento->semAtendidoM,1,NULL);
404
			ReleaseSemaphore(asiento->semAtendidoM,1,0x00000000);
373
405
406
		
407
			asiento->requiereManicura = 0;
408
409
			ReleaseSemaphore(asiento->semAtendidoM,1,0x00000000);
410
			ReleaseSemaphore(asiento->semSilla,1,0x00000000);
411
		
374
			return asiento->id;
412
			return asiento->id;
375
		
413
		
376
		}else{
414
		}else{
377
		
415
		
378
			//RAJA A 1 CLIENTE Y OCUPA ESE LUGAR
416
			if(asiento!=0x00000000)
417
			ReleaseSemaphore(asiento->semAtendidoM,1,0x00000000);
418
			if(asiento!=0x00000000)
419
			ReleaseSemaphore(asiento->semSilla,1,0x00000000);
420
		
421
			manicuraEspera();
379
422
423
380
			p->manicura(MANICURA_VE_TV);
424
			p->manicura(MANICURA_VE_TV);
381
425
426
			if(asiento!=0x00000000)
382
			WaitForSingleObject(asiento->semAtendidoP,INFINITE);//que espere al peluquero
427
			WaitForSingleObject(asiento->semAtendidoP,INFINITE);//que espere al peluquero
428
						
429
			manicuraVuelve();
383
430
384
			//LIBERA EL LUGAR OCUPADO
431
			
385
386
387
			ReleaseSemaphore(asiento->semAtendidoM,1,NULL);
388
389
390
			return comenzarManicuria();//vuelve a llamar a la funcion
432
			return comenzarManicuria();//vuelve a llamar a la funcion
391
433
392
		}
434
		}
393
	}else{
435
	}else{
394
		
436
		
395
		
437
		
396
			//RAJA A 1 CLIENTE Y OCUPA ESE LUGAR
438
			manicuraEspera();
397
439
398
			p->manicura(MANICURA_VE_TV);
440
			p->manicura(MANICURA_VE_TV);
441
			
442
			while(asiento==0x00000000){}
399
443
400
			while(asiento==0x00000000 || !asiento->requiereManicura){}
444
			manicuraVuelve();
401
445
402
			//LIBERA EL LUGAR OCUPADO
403
404
			return comenzarManicuria();//vuelve a llamar a la funcion
446
			return comenzarManicuria();//vuelve a llamar a la funcion
405
447
406
	
448
	
407
	}
449
	}
408
450
409
}
451
}
452
453
void Barberia::manicuraEspera(){
454
	
455
		EnterCriticalSection(&cs);
456
457
		Lobby *l = new Lobby(ID_MANICURA);//objeto del lobby q no representa un cliente
458
459
		l->enEspera = 1;
460
		l->requiereManicura = 0;
461
		l->requierePeluquero  =0;
462
		l->amigo = 0;
463
		l->atendido = 0;
464
		l->comenzoCorte = 0;
465
		l->esCliente = 0;
466
467
		int i = 0 ;
468
		int lugarVacio = 0;
469
		while(clientes_wait[i]!=0x00000000 && i < MAX_CLIENTES_ESPERANDO){
470
			i++;
471
		}
472
		if(clientes_wait[i]==0x00000000 && i < MAX_CLIENTES_ESPERANDO){
473
			clientes_wait[i]= l;
474
			lugarVacio = 1;
475
		}
476
477
		if(lugarVacio == 0){//no encontro lugar para sentarse!
478
479
			printf("\nmanicura ocupa lugar %i", POS_FAVORITA_MANICURA);
480
481
			Lobby *cliente = clientes_wait[POS_FAVORITA_MANICURA];
482
			cliente->rajadoPorManicura = 1;
483
			clientes_wait[POS_FAVORITA_MANICURA] = l;
484
		
485
			//SACA AL CLIENTE, Y EL CLIENTE SE TIENE QUE IR ENOJADISIMO!!!!
486
		}
487
488
489
		
490
491
492
		LeaveCriticalSection(&cs);
493
494
495
}
496
497
void Barberia::manicuraVuelve(){
498
		EnterCriticalSection(&cs);
499
500
		p->manicura(MANICURA_VUELVE);
501
502
503
		for (int i = 0 ; i< MAX_CLIENTES_ESPERANDO; i++){
504
			
505
			if(clientes_wait[i]!=0x00000000 && clientes_wait[i]->id == ID_MANICURA){
506
						clientes_wait[i] = 0x00000000;
507
			}
508
		}
509
		
510
511
		LeaveCriticalSection(&cs);
512
513
514
}
410
void Barberia::terminarManicuria(){
515
void Barberia::terminarManicuria(){
411
		if(asiento != 0x00000000 && asiento->requierePeluquero==1)
516
	
412
			WaitForSingleObject(asiento->semAtendidoP,INFINITE);
517
	if(asiento != 0x00000000 && asiento->requierePeluquero==1){
518
		asiento->requiereManicura = 0;
519
		
520
		WaitForSingleObject(asiento->semAtendidoP,INFINITE);
413
521
414
		if(asiento != 0x00000000)
522
	}
415
			p->cliente(asiento->id,MANICURA_TERMINA);
523
	
524
	if(asiento != 0x00000000){
525
		asiento->requiereManicura = 0;
526
		
527
		p->cliente(asiento->id,MANICURA_TERMINA);
528
529
	}
416
}
530
}
417
531

Updated Barberia.h Download diff

67
39
	void sacarCliente(Lobby* cli);
39
	void sacarCliente(Lobby* cli);
40
	int comenzarManicuria();
40
	int comenzarManicuria();
41
	void terminarManicuria();
41
	void terminarManicuria();
42
	void manicuraEspera();
43
	void manicuraVuelve();
42
44
45
43
	~Barberia(void);
46
	~Barberia(void);
44
};
47
};
45
48

Updated Cliente.cpp Download diff

67
19
	int result = CLIENTE_CANSADO_ESPERA;
19
	int result = CLIENTE_CANSADO_ESPERA;
20
	
20
	
21
21
22
	while( i < MAX_INTENTOS_CLIENTES && result == CLIENTE_CANSADO_ESPERA && result != CLIENTE_ENOJADISIMO && result != CLIENTE_PATALETA && result != CLIENTE_ABANDONA_FELIZ){
22
	while((id==-1 && result!=CLIENTE_ABANDONA_FELIZ) || ( i < MAX_INTENTOS_CLIENTES && result == CLIENTE_CANSADO_ESPERA && result != CLIENTE_ENOJADISIMO && result != CLIENTE_PATALETA && result != CLIENTE_ABANDONA_FELIZ)){
23
		result=pelu->entrarPelu(id) ;
23
		result=pelu->entrarPelu(id) ;
24
		if(result == CLIENTE_ABANDONA_FELIZ ){
24
		if(result == CLIENTE_ABANDONA_FELIZ ){
25
			p->cliente(id, CLIENTE_ABANDONA_FELIZ);
25
			p->cliente(id, CLIENTE_ABANDONA_FELIZ);

Updated Constantes.h Download diff

67
1
#ifndef CONSTANTES_H_
1
#ifndef CONSTANTES_H_
2
#define CONSTANTES_H_
2
#define CONSTANTES_H_
3
3
4
const int MAX_CLIENTES_ESPERANDO = 4;
4
const int MAX_CLIENTES_ESPERANDO = 4;//ASIENTOS DE RECEPCION
5
const int MAX_INTENTOS_CLIENTES = 5;
5
const int MAX_INTENTOS_CLIENTES = 5;//CANTIDAD DE INTENTOS QUE HACE EL CLIENTE CUANDO LA PELU ESTA LLENA
6
const int WAIT_REINTENTO = 5;
6
const int WAIT_REINTENTO = 8;//CANTIDAD DE TIEMPO QUE ESPERA EL CLIENTE EN VOLVER A INTENTAR REINGRESAR
7
const int DEMORA_PATALETA = 8;
7
const int DEMORA_PATALETA = 5;//LO QUE TARDA EL PELUQUERO EN ATENDERSE
8
const int DEMORA_MANICURA = 2;
8
const int DEMORA_MANICURA = 2;//LO QUE TARDA LA MANICURA EN ATENDER
9
const int TIEMPO_DE_CHARLA = 5;
9
const int TIEMPO_DE_CHARLA = 10;//CON AMIGOS
10
const int NUMERO_CLIENTES = 10; //LOS CLIENTES QUE VAN A CAER (DE 1 A NUMERO_CLIENTES)
10
const int NUMERO_CLIENTES = 15; //LOS CLIENTES QUE VAN A CAER (DE 0 A NUMERO_CLIENTES -1) Y SIEMPRE EL ULTIMO ES -1
11
const int DEMORA_CORTE = 5; //LO QUE TARDA EL PELUQUERO EN CORTAR, SI TARDA MUCHO SE VA A ARMAR COLA
11
const int DEMORA_CORTE = 10; //LO QUE TARDA EL PELUQUERO EN CORTAR, SI TARDA MUCHO SE VA A ARMAR COLA
12
const int DEMORA_CLIENTE = 20; //CUANTO MAS CHICO LOS CLIENTES VAN A VENIR MAS RAPIDO (SI ES GRANDE EL PELUQUERO DUERME MAS)
12
const int DEMORA_CLIENTE = 15; //CUANTO MAS CHICO LOS CLIENTES VAN A VENIR MAS RAPIDO (SI ES GRANDE EL PELUQUERO DUERME MAS)
13
const int PACIENCIA = 2;
13
const int PACIENCIA = 30;//PACIENCIA DEL CLIENTE
14
const char MANICURA_VUELVE = ')';
14
const char PELUQUERO_LLEGADA = 'L';
15
const char PELUQUERO_LLEGADA = 'L';
15
const char PELUQUERO_HACE_PASAR_A_ESPERA = 'A';
16
const char PELUQUERO_HACE_PASAR_A_ESPERA = 'A';
16
const char PELUQUERO_IRSE_A_DORMIR = 'D';
17
const char PELUQUERO_IRSE_A_DORMIR = 'D';
...
...
38
const char MANICURA_VE_TV = 'Ñ';
39
const char MANICURA_VE_TV = 'Ñ';
39
const char MANICURA_ATIENDE = '-';
40
const char MANICURA_ATIENDE = '-';
40
const char MANICURA_TERMINA = '|';
41
const char MANICURA_TERMINA = '|';
41
		
42
const int NO_HAY_NADIE = -2; //SUCEDE CUANDO EL BARBERO VA A VER SI HAY ALGUEIN Y NO HAY
43
42
43
const int POS_FAVORITA_MANICURA = 1;//LA MANICURA PREFIERE SENTARSE EN EL ASIENTO 1 SIEMPRE!	
44
const int ID_MANICURA = -2; //ID DE MANICURA CUANDO SE SIENTA EN LOBBY
44
45
45
46
47
46
#endif
48
#endif

Updated Lobby.cpp Download diff

67
1
#include "Lobby.h"
1
#include "Lobby.h"
2
#include "Constantes.h"
2
#include <stdio.h>
3
#include <stdio.h>
3
#include <time.h>
4
#include <time.h>
4
#include <stdlib.h>
5
#include <stdlib.h>
...
...
7
{
8
{
8
	id = idCliente;
9
	id = idCliente;
9
10
10
	amigo=((idCliente % 3)==0); //LOS MULTIPLOS DE 3 SON AMIGOS DEL PELUQUERO
11
11
12
	for (int i = 0; i < idCliente+idCliente*2;i++) { 
12
	
13
		requierePeluquero = rand() % 8 > 4; // genero un numero totalmente al azar entre 0 y 1 para ver si quiere peluquero
13
	if(idCliente!=-1 && idCliente!=ID_MANICURA){
14
	} 
14
		for (int i = 0; i < idCliente+idCliente*2;i++) { 
15
			requierePeluquero = rand() % 8 > 4; // genero un numero totalmente al azar entre 0 y 1 para ver si quiere peluquero
16
		} 
15
17
16
	for (int i = 0; i < idCliente+idCliente*2;i++) {
18
		for (int i = 0; i < idCliente+idCliente*2;i++) {
17
			requiereManicura = rand() % 8 > 4;// genero un numero totalmente al azar entre 0 y 1 para ver si quiere manicura
19
				requiereManicura = rand() % 8 > 4;// genero un numero totalmente al azar entre 0 y 1 para ver si quiere manicura
18
	} 
20
		} 
19
21
20
	if(requierePeluquero==0 && requiereManicura == 0){
22
		if(requierePeluquero==0 && requiereManicura == 0){
21
		requierePeluquero = 1;
23
			requierePeluquero = 1;
24
		}
25
26
	}else{
27
		requierePeluquero =1 ;
28
		requiereManicura =1;
29
		
22
	}
30
	}
23
31
24
	printf("cliente %i requiere peluquero: %i,requiere manicura: %i",idCliente,requierePeluquero,requiereManicura);
32
	if(idCliente != ID_MANICURA)
33
	printf("\ncliente %i requiere peluquero: %i,requiere manicura: %i",idCliente,requierePeluquero,requiereManicura);
25
34
26
35
27
	atendido = 0;
36
	atendido = 0;
28
37
29
	comenzoCorte = 0;
38
	comenzoCorte = 0;
30
39
40
	comenzoManicura = 0;
41
42
	rajadoPorManicura = 0;
43
31
	enEspera = 0;
44
	enEspera = 0;
45
	
46
	esCliente = 1;
47
	
48
	amigo=((idCliente % 3)==0); //LOS MULTIPLOS DE 3 SON AMIGOS DEL PELUQUERO
32
49
50
33
	semAtendidoM = CreateSemaphore(NULL,0,1,NULL);
51
	semAtendidoM = CreateSemaphore(NULL,0,1,NULL);
34
52
35
	semAtendidoP = CreateSemaphore(NULL,0,1,NULL);
53
	semAtendidoP = CreateSemaphore(NULL,0,1,NULL);

Updated Lobby.h Download diff

67
12
	int enEspera;
12
	int enEspera;
13
	int requierePeluquero;
13
	int requierePeluquero;
14
	int requiereManicura;
14
	int requiereManicura;
15
	int esCliente;
16
	int rajadoPorManicura;
17
	int comenzoManicura;
18
	
15
19
16
	HANDLE semSilla;
20
	HANDLE semSilla;
17
	HANDLE semAtendidoM;
21
	HANDLE semAtendidoM;

Updated Main.cpp Download diff

67
142
	ente->mostrarEstadistica();
142
	ente->mostrarEstadistica();
143
143
144
144
145
145
	Sleep(10000);
146
	free(ente);
146
	free(ente);
147
147
148
	free(printer);
148
	free(printer);
149
		
149
		
150
	free(barberia);
150
	free(barberia);
151
151
152
	free(barbero);
152
	//free(barbero);
153
153
154
	free(manicura);
154
	free(manicura);
155
155

Updated Printer.cpp Download diff

67
17
17
18
void Printer::peluquero(char status){
18
void Printer::peluquero(char status){
19
	//EnterCriticalSection(&semPrinter);
19
	//EnterCriticalSection(&semPrinter);
20
	printf("\nEl peluquero tiene estado %s",getStatusName(status));
20
	char buffer[200];
21
	sprintf( buffer, "\nEl peluquero tiene estado %s", getStatusName(status));
22
	//
23
	FILE *fp;
24
    fp = fopen("unDiaDeLaburo.txt", "a");   /* Abrir archivo para apend */
25
    fprintf(fp, buffer);
26
	printf(buffer);
27
    fclose(fp);    /* Cerrar el archivo antes de terminar el programa */
28
21
	//LeaveCriticalSection(&semPrinter);
29
	//LeaveCriticalSection(&semPrinter);
22
}
30
}
23
31
24
32
25
void Printer::manicura(char status){
33
void Printer::manicura(char status){
26
	//EnterCriticalSection(&semPrinter);
34
	//EnterCriticalSection(&semPrinter);
27
	printf("\nLa manicura tiene estado %s",getStatusName(status));
35
	char buffer[200];
36
	sprintf( buffer, "\nLa manicura tiene estado %s",getStatusName(status));
37
	//
38
	FILE *fp;
39
    fp = fopen("unDiaDeLaburo.txt", "a");   /* Abrir archivo para apend */
40
    fprintf(fp, buffer);
41
	printf(buffer);
42
    fclose(fp);    /* Cerrar el archivo antes de terminar el programa */
28
	//LeaveCriticalSection(&semPrinter);
43
	//LeaveCriticalSection(&semPrinter);
29
}
44
}
30
void Printer::comenazarCorte(int id){
45
void Printer::comenazarCorte(int id){
31
	EnterCriticalSection(&semPrinter);
46
	EnterCriticalSection(&semPrinter);
32
	printf("\nEl cliente %i comienza corte",id);
47
48
	char buffer[200];
49
	sprintf( buffer, "\nEl cliente %i comienza corte",id);
50
	//
51
	FILE *fp;
52
    fp = fopen("unDiaDeLaburo.txt", "a");   /* Abrir archivo para apend */
53
    fprintf(fp, buffer);
54
	printf(buffer);
55
    fclose(fp);    /* Cerrar el archivo antes de terminar el programa */
56
33
	LeaveCriticalSection(&semPrinter);
57
	LeaveCriticalSection(&semPrinter);
34
}
58
}
35
	
59
	
36
void Printer::cliente(int id,char status){
60
void Printer::cliente(int id,char status){
37
	EnterCriticalSection(&semPrinter);
61
	EnterCriticalSection(&semPrinter);
38
	printf("\nEl cliente %i tiene estado %s",id,getStatusName(status));
62
	char buffer[200];
63
	sprintf( buffer, "\nEl cliente %i tiene estado %s",id,getStatusName(status));
64
	//
65
	FILE *fp;
66
    fp = fopen("unDiaDeLaburo.txt", "a");   /* Abrir archivo para apend */
67
    fprintf(fp, buffer);
68
	printf(buffer);
69
    fclose(fp);    /* Cerrar el archivo antes de terminar el programa */
39
	LeaveCriticalSection(&semPrinter);
70
	LeaveCriticalSection(&semPrinter);
71
}
40
72
41
73
42
}
43
44
char* Printer::getStatusName(char status){
74
char* Printer::getStatusName(char status){
45
75
46
	switch(status){
76
	switch(status){
...
...
70
		case MANICURA_VE_TV: return "MANICURA_VE_TV"; break;
100
		case MANICURA_VE_TV: return "MANICURA_VE_TV"; break;
71
		case MANICURA_ATIENDE: return "MANICURA_ATIENDE"; break;
101
		case MANICURA_ATIENDE: return "MANICURA_ATIENDE"; break;
72
		case MANICURA_TERMINA: return "MANICURA_TERMINA"; break;
102
		case MANICURA_TERMINA: return "MANICURA_TERMINA"; break;
73
		
103
		case MANICURA_VUELVE: return "MANICURA_VUELVE";break;
74
			
104
			
75
	
105
	
76
		default: return "no interpretado";
106
		default: return "no interpretado";