Esempio n. 1
0
void CommandTester::start()
{
    if (m_action)
        m_restart = true;
    else
        startNext();
}
Esempio n. 2
0
void SequentialTask::startNext()
{
	if (m_currentIndex != -1)
	{
		std::shared_ptr<ProgressProvider> previous = m_queue[m_currentIndex];
		disconnect(previous.get(), 0, this, 0);
	}
	m_currentIndex++;
	if (m_queue.isEmpty() || m_currentIndex >= m_queue.size())
	{
		emitSucceeded();
		return;
	}
	std::shared_ptr<ProgressProvider> next = m_queue[m_currentIndex];
	connect(next.get(), SIGNAL(failed(QString)), this, SLOT(subTaskFailed(QString)));
	connect(next.get(), SIGNAL(status(QString)), this, SLOT(subTaskStatus(QString)));
	connect(next.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(subTaskProgress()));
	connect(next.get(), SIGNAL(succeeded()), this, SLOT(startNext()));
	next->start();
	emit status(getStatus());
}
void hEscritura(void * dato) 
{
		
	struct struct_idSockCliente sCliente;
	struct struct_idSockCliente * sAuxCliente;
	
	sAuxCliente = (struct struct_idSockCliente*)dato;
	sCliente.idSockCliente = (*sAuxCliente).idSockCliente;
	
	int id = sCliente.idSockCliente;

	char buffer[100];
	int finBuffer;
	
	mensaje * m =  (struct mensaje *) shmat(idshm,0,0);
	
	/////////////////////////////////////////////////////////
	//	HANDSHAKE CON EL CLIENTE		       //
	/////////////////////////////////////////////////////////
        
	tCliente Cliente;
	
	//RECIVO APODO DEL CLIENTE
	bzero(buffer,100);	
	finBuffer = read(id,&Cliente.Apodo,100);//buffer,100);
	//}while(finBuffer > 0 );
	//	Cliente.Apodo[finBuffer]='\0';
		
	int idLectura;
	Cliente.lugar = (*lClientes).length;//LUGAR ES IGUAL A ID,LUGAR EN LA LISTA
        
	//ENVIAR COD IDENTIFICADOR DEL CLIENTE  	
	snprintf(buffer,100,"%d",Cliente.lugar);
	write(id,buffer,100);

	push_back(lClientes,(void*)&Cliente);
	
	mensaje * mRecivido,maux;
	
	for(;;){
		mRecivido = (struct mensaje*) malloc(sizeof(mensaje));
		//RECIVO ID DEL DESTINATARIO		
		bzero(buffer,100);
		finBuffer = read(id,buffer,100);

		if(finBuffer > 0 )//SI NO HAY ERROR
		{
			//CASTING DE BUFFER A idLectura
			buffer[finBuffer]='\0';				
			idLectura = atoi(buffer);
				
			bzero(buffer,100);
			finBuffer = read(id,(*mRecivido).msn,80 );
			mRecivido->msn[finBuffer] ='\0';			
			
			(*mRecivido).estado = OCUPADO;
			strcpy(mRecivido->apodoDestinatario,Cliente.Apodo);
			(*mRecivido).destinatario = Cliente.lugar;
			(*mRecivido).destino = idLectura;
			
			///***///
			startNext(lClientes);
		 	punt r = NULL;
			r = next( lClientes);
			while( r != NULL )
			{	
				tCliente * aux = (struct tCliente *)r->data;
				if (aux->lugar == idLectura)			
					strcpy( mRecivido->apodoDestino , aux->Apodo);
				r = next(lClientes);
			}	

			/////////
			
			printf(" LOS VALORES SON %d %d \n",(*mRecivido).destino ,(*mRecivido).destinatario);fflush(stdout);
			imprimirMensaje(mRecivido);
			push_back(cMensajes,mRecivido);
			
		
			
		}
		usleep(100000);	
	}	
			
		
}
void hLectura(void * dato)
{
	struct struct_idSockCliente sCliente;
	struct struct_idSockCliente * sAuxCliente;
	sAuxCliente = (struct struct_idSockCliente*)dato;
	sCliente.idSockCliente = (*sAuxCliente).idSockCliente;
	fflush(stdout);	

	int id = sCliente.idSockCliente;
	int posicionEnLista = 0;
	
	char buffer[100];
	int finBuffer;
	
	mensaje * m =  (struct mensaje *) shmat(idshm,0,0) ;

	////////////////////////////////////////////////////
	//INICIO UN HANDSHAKE PARA IDENTIFICAR AL CLIENTE //
	////////////////////////////////////////////////////
	//RECIVO LA ID DEL CLIENTE
	bzero(buffer,100);	
	finBuffer = read(id,buffer,100);
	buffer[finBuffer]='\0';
	posicionEnLista = atoi(buffer); //ID DEL CLIENTE
	//printf("LA POSICION EN LISTA ES %d\n",posicionEnLista);fflush(stdout);
	
	////ENVIO EL APODO DEL CLIENTE
	write(id,m->apodoDestino,20);
	
	for(;;)
	{
		if( IDLECTOR == 0 && lClientes->length > 1 && lIDClientesLectores->length+1>= lClientes->length ) 
		{
			m->estado = DISPONIBLE;	
			clear(lIDClientesLectores);
		}

		

		if( ( m->destino == 0  || m->destino == posicionEnLista) && m->estado == OCUPADO && flagLectura == TRUE ) 		
		{			
		     if(IDLECTOR == 0)
		     {
			
			startNext(lIDClientesLectores);
		 	punt r = NULL;
			r = next( lIDClientesLectores);
			while( r!=NULL && (*(int*)r->data)!= m->destino)
			{	
				r = next(lClientes);
			}
			if(r ==NULL)
			{
				write(id,m->msn,100);		
				write(id,m->apodoDestinatario,20);	
				push_back(lIDClientesLectores,(void*)&m->apodoDestinatario);			
			}
					 
		     }
		     else				
		     {	
			write(id,m->msn,100);		
			write(id,m->apodoDestinatario,20);		
			m->estado = DISPONIBLE;		
		     }
		     imprimirMensaje(m);			
		}
		
		
		usleep(100000);
	}	
//	while( strcmp(buffer,"exit()") );
	
	close(id);
	pthread_exit(NULL);		
}
Esempio n. 5
0
void SequentialTask::executeTask()
{
	m_currentIndex = -1;
	startNext();
}