This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nodo *proceso; | |
int i=0, tiempoEjecucion=0,tiempo=0; | |
//Mientras las colas no esten vacias. | |
//Si hay al menos un proceso en alguna cola el ciclo continuara | |
while(AdministradorColas.getVacio != 0){ | |
if (AdministradorColas.getProcesador){ //Si hay un proceso en el cpu | |
switch (AdministradorColas.getProcesador.getPrioridad()){ //Obtenemos su prioridad | |
case 1: //Si ya estuvo en cpu el t asignado. ALGORITMO FIFS | |
if (AdministradorColas.getCola1.getTEjecutado== tiempoEjecucion){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Si hay un proceso en CPU | |
if (AdministradorColas.getProcesador().getId() != LIBRE){ | |
//Obtenemos la cola a la que pertenece, esta refleja su prioridad. | |
//Control del tiempo del proceso en el cpu | |
switch (AdministradorColas.getProcesador().getCola() ){ | |
case 1: case 2: case 3: case 4: | |
//Si el tiempo que ha estado ejecutandose es igual al t asignado en un inicio | |
if (AdministradorColas.getProcesador().getTEjecucion() == tiempoEjecucion){ | |
tiempoEjecucion=0; | |
//Ese proceso saldra del procesador |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Si el procesador se ha desocupado | |
if (AdministradorColas.getProcesador().getEstado() == "Terminado" || AdministradorColas.getProcesador().getId() == LIBRE){ | |
//Cola 1 es la de mayor prioridad. Si hay procesos se atendera primero esta | |
if ( ! AdministradorColas.cola1.empty()) | |
pthread_create(&threads[i], NULL, gestionarCola1, (void*)&AdministradorColas); | |
else{ | |
//Si la cola 1 esta vacia, procedemos a tomar procesos de la cola 2 | |
if (! AdministradorColas.cola2.empty()) | |
pthread_create(&threads[i], NULL, gestionarCola2, (void*)&AdministradorColas); | |
else{ //Si cola 1 y 2 están vacias |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Cambios de cola | |
for(int i = 0; i < NUM_QUEUES ; i++){ | |
//Si el tiempo de Quantum de la cola es igual al tiempo en ejecucion por el proceso en cpu | |
//Y si el T que ha estado ejecutandose es distinto al tiempo de ejecución asignado en un inicio | |
if ( AdministradorColas.getProcesador().getCola() == (i+1) && | |
tiempoEjecucion == queues[i] && AdministradorColas.getProcesador().getTEjecucion() != tiempoEjecucion){ | |
tiempoEjecucion=0; | |
AdministradorColas.gestionarEvento(); //Pasara a la cola inferior | |
AdministradorColas.setIdProcesador(); | |
continue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void *gestionarCola1(void* threadid) { | |
struct Planificador &value = *((struct Planificador *)threadid); | |
Proceso n = value.getPopCola1(); //El proceso pasa al procesador | |
cout<<" ATENDIENDO NUEVO PROCESO EN CPU. ID: "<<value.getPopCola1().getId() <<endl; | |
n.setEstado("Ejecutandose"); //Cambia su estado | |
n.imprimirDatos(); //Imprimimis datos del proceso en CPU | |
cout<<endl; | |
value.cola1.pop(); //Ya no esta en cola | |
value.setProceso(n); | |
pthread_exit(NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//El proceso sale del cpu | |
void *gestionarPlanificador(void* threadid) { | |
struct Planificador value = *((struct Planificador *)threadid); | |
value.Procesador.setEstado("Terminado"); | |
cout << "Proceso ID (" << value.Procesador.getId()<< ") ESTADO: "<< value.Procesador.getEstado() << endl; | |
cout << "Proceso ID (" << value.Procesador.getId()<< ") HA TERMINADO SU EJECUCION TOTAL. LIBERADO RECURSOS" << endl; | |
value.getProcesador().setEstado("Terminado"); | |
value.getProcesador().setId(); | |
pthread_exit(NULL); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Dialog::sendTextToServer(QString text){ | |
QByteArray block; | |
QDataStream out(&block,QIODevice::WriteOnly); | |
out.setVersion(QDataStream::Qt_5_3); | |
qDebug() << "texto: " + text; | |
out << (quint32)0 << text; | |
out.device()->seek(0); | |
out << (quint32)(block.size() - sizeof(quint32)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Server::sendTextToAll(QString text,ClientThread* except){ | |
QByteArray block; | |
QDataStream out(&block,QIODevice::WriteOnly); | |
out.setVersion(QDataStream::Qt_5_8); | |
out << (quint32)0 << text; | |
out.device()->seek(0); | |
out << (quint32)(block.size() - sizeof(quint32)); | |
qDebug() << "block.size() = " << block.size(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Server::on_client_textSend(QString uname,QString text){ | |
//client that send the signal to this slot | |
ClientThread* sender_client = (ClientThread*)sender(); | |
QString currentTime = QTime::currentTime().toString("H:m A/"); | |
QString message = "/text:"+currentTime + uname + " : " + text + "\n"; | |
sendTextToAll(message,sender_client); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Server::on_client_privateTextSend(QString uname,QString receiverName,QString text){ | |
QString currentTime = QTime::currentTime().toString("H:mm A/"); | |
QString messagePm = "/pm:"+currentTime+uname+" : "+text+"\n"; | |
foreach(ClientThread* client,clientThreadList){ | |
if(client->getUsername() == receiverName){ | |
sendTextToOne(messagePm,client); | |
return; | |
} | |
} | |
} |