示例#1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    mMsg = new CMsg(this);  // instanciation de la file de messages
    int res = mMsg->initialiser(NOMFIC, (int)LETTRE);
    if (res==-1) {
        qDebug("Erreur init file de message !");
    } // if res

    // création du segment de mémoire partagé contenant la description des capteurs et les valeurs instantanées
    mShm = new QSharedMemory(KEY, this);
    mShm->attach();   // tentative de s'attacher
    if (!mShm->isAttached()) {   // si existe pas alors création
        res = mShm->create(9*sizeof(T_Mes));   // on réserve pour 9 capteurs max
        if (res == false)
            qDebug(mShm->errorString().toStdString().c_str());
    } // if isattached

    mCCom = new CCommuniquer(this, mMsg);
    connect(mMsg, SIGNAL(mailReady(long)), mCCom, SLOT(onMessReady(long)));
    connect(mCCom, SIGNAL(afficherTexte(QString)), this, SLOT(onAfficherTexte(QString)));
    connect(mCCom, SIGNAL(lancerThreads()), this, SLOT(onLancerThreads()));
/*
    // lecture du fichier de configuration config.ini qui identifie les capteurs présents sur le drone
    QList<T_Mes> mesures;
    T_Mes mes;
    QList<QByteArray> parties;
    QFile file("./config.ini");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
         qDebug("Erreur ouverture du fichier config.ini !");
    } // if fichier pas bon
    int nbLigne=0;
    while (!file.atEnd()) {         // lecture des lignes du fichier
         QByteArray line = file.readLine();
         if (isdigit(line[0])) {    // si le premier car de la ligne est 0-9
             qDebug() << "CONFIG.INI: " << line;
             parties = line.split(';'); // extrait chaque partie de la ligne
             mes.noMes = parties.at(0).toInt();
             strncpy(mes.adrCapteur, parties.at(1).toStdString().c_str(), sizeof(mes.adrCapteur));
             strncpy(mes.nomClasse, parties.at(2).toStdString().c_str(), sizeof(mes.nomClasse));
             strncpy(mes.nomMes, parties.at(3).toStdString().c_str(), sizeof(mes.nomMes));
             strncpy(mes.symbUnit, parties.at(4).toStdString().c_str(), sizeof(mes.symbUnit));
             strncpy(mes.textUnit, parties.at(5).toStdString().c_str(), sizeof(mes.textUnit));
             mesures.append(mes);       // ajout dans la QList
             nbLigne++;
         } // if
    } // while

    qDebug() << "Main:" << nbLigne << "capteurs vus";
*/

    // création des objets et connexions à la file des messages
    connect(mMsg, SIGNAL(mailReady(long)), this, SLOT(onMessReady(long)));
    mCCam = new CControlerCamera(this, mMsg);
    connect(mMsg, SIGNAL(mailReady(long)), mCCam, SLOT(onMessReady(long)));

    ui->setupUi(this);

} // constructeur
示例#2
0
/**
 * Permet de simuler une iteration de propagation de chaleur
 *
 * @author   Lucas Martinez
 */
void initSimulation(int taille, int etape, int nbIter, int nbThread, caseDansMat * mat){
	vraieTaille = taille + 2; //bords

	nbCaseParThread = sqrt(taille * taille / nbThread); //nbCaseParThread par ligne en fait
	if(nbCaseParThread < 1){
		nbCaseParThread = 1;
		nbThread = taille * taille;
	}

	pthread_t* threads = malloc(nbThread * sizeof(pthread_t));
	if (!threads){
		perror("Erreur d'allocation mémoire, arret du programme.");
		exit(1);
	}

	wrappedMatrice* wrappedMat = malloc(nbThread * sizeof(wrappedMatrice));
	if (!wrappedMat){
		perror("Erreur d'allocation mémoire, arret du programme.");
		exit(1);
	}

	switch (etape){
		case 0:
			lancerThread(taille, nbIter, mat, wrappedMat); //un seul thread, comportement different
			break;
		case 1: ;
			pthread_barrier_t* barriereHori = malloc(sizeof(pthread_barrier_t));
			if (!barriereHori){
				perror("Erreur d'allocation mémoire, arret du programme.");
				exit(1);
			}

			pthread_barrier_t* barriereVerti = malloc(sizeof(pthread_barrier_t));
			if (!barriereVerti){
				perror("Erreur d'allocation mémoire, arret du programme.");
				exit(1);
			}

			initBarrieres(nbThread, barriereHori, barriereVerti);
			lancerThreads(taille, etape, nbIter, mat, threads, wrappedMat, barriereHori, barriereVerti);
			rendreBarrieres(barriereHori, barriereVerti);
			break;
		case 2: ;
			maBarriere* maBarriereHori = malloc(sizeof(maBarriere));
			if (!maBarriereHori){
				perror("Erreur d'allocation mémoire, arret du programme.");
				exit(1);
			}

			maBarriere* maBarriereVerti = malloc(sizeof(maBarriere));
			if (!maBarriereVerti){
				perror("Erreur d'allocation mémoire, arret du programme.");
				exit(1);
			}

			barrier_init(maBarriereHori, nbThread);
			barrier_init(maBarriereVerti, nbThread);

			lancerThreads(taille, etape, nbIter, mat, threads, wrappedMat, maBarriereHori, maBarriereVerti);

			barrier_destroy(maBarriereHori);
			barrier_destroy(maBarriereVerti);
			free(maBarriereHori);
			free(maBarriereVerti);

			break;
		case 3: ;
			maBarriereSem* maBarriereSemHori = malloc(sizeof(maBarriereSem));
			if (!maBarriereSemHori){
				perror("Erreur d'allocation mémoire, arret du programme.");
				exit(1);
			}

			maBarriereSem* maBarriereSemVerti = malloc(sizeof(maBarriereSem));
			if (!maBarriereSemVerti){
				perror("Erreur d'allocation mémoire, arret du programme.");
				exit(1);
			}

			barrier_sem_init(maBarriereSemHori, nbThread);
			barrier_sem_init(maBarriereSemVerti, nbThread);

			lancerThreads(taille, etape, nbIter, mat, threads, wrappedMat, maBarriereSemHori, maBarriereSemVerti);

			barrier_sem_destroy(maBarriereSemHori);
			barrier_sem_destroy(maBarriereSemVerti);
			free(maBarriereSemHori);
			free(maBarriereSemVerti);

			break;
	}

	free(wrappedMat);
	free(threads);

}