Skip to content

Instantly share code, notes, and snippets.

View oppahero's full-sized avatar
🎯
Focusing

María López oppahero

🎯
Focusing
View GitHub Profile
int public static Operaciones.factorial (int n)
int factorial = 1;
if (n < 1) return 0;  //El número debe ser positivo mayor a cero.
for (int i=1; i <= n ; i++)
factorial = factorial *1 ;
return factorial;
}
@oppahero
oppahero / .cpp
Last active March 21, 2019 00:52
int factorial (int n) {
if (n < 0) return 0;
else if(n > 1) return n*factorial(n-1);
  return 1;
}
void Server::on_client_fileSend(QString uname,QString filename,QByteArray dataOfFile){
ClientThread* client = (ClientThread*)sender();
QString currentTime = QTime::currentTime().toString("H:mm A/");
QString command = "/fileAll:"+currentTime + uname + " : " + filename + "\n";
QString filePath;
//Si no esta la carpeta creada, la crea.
if(!QDir("Documentos_Servidor").exists()){
qDebug() << "No esta creada la carpeta";
void Dialog::on_pushButton_ChooseFile_clicked()
{
//configurar el directorio de inicio a la ruta de inicio del usuario
QString homePath = QDir::homePath();
//Abre el dialogo y escoge el archivo. Obtenemos el path del archivo.
QString filePath = QFileDialog::getOpenFileName(this,tr("Open a file"),
homePath,tr("All files (*.*)"),NULL,QFileDialog::DontResolveSymlinks);
//Se obtiene el nombre del archivo
QString filename = filePath.section("/",-1);
void Server::sendTextToOne(QString text,ClientThread* target){
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();
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;
}
}
}
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);
}
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();
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));
//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);
}