Пример #1
0
void MultiPageLayout::goForward()
{
    /*
        if(nFirstPage == secondPage)
        {
    //	secondPage = firstPage + 2;
    //	firstPage = firstPage + 1;
            secondPage = nFirstPage + 1;
       }
        else
        {
    	nFirstPage = nFirstPage + 2;
    	secondPage = secondPage + 2;
        }

        nFirstPage = qMin(nFirstPage,book->pages()->count()-1);
        secondPage = qMin(secondPage,book->pages()->count()-1);
    */
    if(nFirstPage == 0)
    {
        nFirstPage++;
    }
    else
    {
        nFirstPage += 2;
    }
//    qDebug() << "MultiPageLayout::goForward" << nFirstPage << qMin(nFirstPage+1,book->pages()->count()-1);
    setPages(nFirstPage,qMin(nFirstPage+1,book->pages()->count()-1));
}
Пример #2
0
void MultiPageLayout::removeSecondPage()
{
    if( QMessageBox::question(this->parentWidget(), tr("Bas"), tr("Are you sure you want to delete this page?\n\nYou cannot undo this."),QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes )
        if( book->removePage( nFirstPage + 1 ) )
        {
            qDebug() << "MultiPageLayout::removeSecondPage()";
            setPages( qMin(nFirstPage, book->pages()->count()-1), qMin(nFirstPage+1, book->pages()->count()-1) );
        }
}
Пример #3
0
MultiPageLayout::MultiPageLayout(Book *book, QWidget *parent)
{
    this->book = book;

    // Qt automatically sets the layout to be RTL or LTR, based on the application's QLocale
    // this works, unless a person working in an LTR interface is working on an RTL-text book
    // or unless a person working in an RTL interface is working on an LTR-text book
    // in either of those cases we need to switch the layout interface back, manually
    bSwapDirection = false;
    if( (parent->layoutDirection() == Qt::LeftToRight && book->textDirection() == LanguageTemplate::RTL) ||
            (parent->layoutDirection() == Qt::RightToLeft && book->textDirection() == LanguageTemplate::LTR) )
        bSwapDirection = true;

    nFirstPage = 0;

    if( book->textDirection() == LanguageTemplate::LTR )
    {
        backward = new ImagePushButton(new QImage(":/resources/left-active.png"), new QImage(":/resources/left-pressed.png"), new QImage(":/resources/left-inactive.png"));
        forward = new ImagePushButton(new QImage(":/resources/right-active.png"), new QImage(":/resources/right-pressed.png"), new QImage(":/resources/right-inactive.png"));
    }
    else
    {
        forward = new ImagePushButton(new QImage(":/resources/left-active.png"), new QImage(":/resources/left-pressed.png"), new QImage(":/resources/left-inactive.png"));
        backward = new ImagePushButton(new QImage(":/resources/right-active.png"), new QImage(":/resources/right-pressed.png"), new QImage(":/resources/right-inactive.png"));
    }

    if( bSwapDirection )
    {
        addWidget(backward,1,4,1,1,Qt::AlignRight);
        addWidget(forward,1,1,1,1,Qt::AlignLeft);
    }
    else
    {
        addWidget(backward,1,1,1,1,Qt::AlignRight);
        addWidget(forward,1,4,1,1,Qt::AlignLeft);
    }

    backward->setToolTip(tr("Backward"));
    forward->setToolTip(tr("Forward"));

    connect(this,SIGNAL(backwardEnabled(bool)),backward,SLOT(setEnabled(bool)));
    connect(this,SIGNAL(forwardEnabled(bool)),forward,SLOT(setEnabled(bool)));

    connect(backward,SIGNAL(clicked()),this,SLOT(goBackward()));
    connect(forward,SIGNAL(clicked()),this,SLOT(goForward()));

    if(book->pages()->count() > 0)
    {
        setPages(0,0);
    }
    else
    {
        backward->setEnabled(false);
        forward->setEnabled(false);
    }
}
Пример #4
0
void MultiPageLayout::addPageAfterFirst()
{
    // in this case the second page should be new, so it will be refreshed
    if( book->addPage(nFirstPage) )
    {
        if( nFirstPage == 0 )
            goForward();
        else
            setPages(nFirstPage,nFirstPage+1);
    }
}
Пример #5
0
void MultiPageLayout::addPageAfterFirst(LayoutTemplate *lt)
{
    // in this case the second page should be new, so it will be refreshed
//    qDebug() << "MultiPageLayout::addPageAfterFirst(LayoutTemplate *lt)";
    if( book->addPage(nFirstPage,lt) )
    {
        if( nFirstPage == 0 )
            goForward();
        else
            setPages(nFirstPage,nFirstPage+1);
    }
}
Пример #6
0
void MultiPageLayout::goBackward()
{
    /*
        if(nFirstPage == secondPage)
        {
    	secondPage = nFirstPage - 1;
    	nFirstPage = secondPage - 1;
        }
        else
        {
    	nFirstPage = nFirstPage - 2;
    	secondPage = secondPage - 2;
        }

        nFirstPage = qMax(nFirstPage,0);
        secondPage = qMax(secondPage,0);
    */
    nFirstPage = qMax(nFirstPage-2,0);
//    qDebug() << "goBackward" << nFirstPage << qMin(nFirstPage+1,book->pages()->count()-1 );
    setPages(nFirstPage, qMin(nFirstPage+1,book->pages()->count()-1 ) );
}
Пример #7
0
void MultiPageLayout::updatePages()
{
    setPages(nFirstPage,qMin(nFirstPage+1,book->pages()->count()-1));
}
Пример #8
0
int main(int argc, char **argv) {

	remove("/tp-2015-2c-signiorcodigo/swap/log_swap");

	swapConfig = config_create("/tp-2015-2c-signiorcodigo/swap/swapConfig");

	setupSwap();

	setPages();

	int socketEscucha, socketMemoria;

	char * puerto = getPort();

	socketEscucha = setup_listen("localhost", puerto);

	socketMemoria = esperarConexionEntrante(socketEscucha, 1024, log_swap);

	t_data * paqueteInicio = leer_paquete(socketMemoria);

	if (paqueteInicio->header->codigo_operacion == 1) {

		int datonulo = 0;

		paqueteInicio = pedirPaquete(2, sizeof(int), &datonulo);

		common_send(socketMemoria, paqueteInicio);

		log_info(log_swap, "Conectado con la memoria en el socket: %d",
				socketMemoria);

	} else {

		log_info(log_swap, "Falla en la conexion con la memoria");

		exit(EXIT_FAILURE);
	}

	t_data * paquete;

	while (1) {

		paquete = leer_paquete(socketMemoria);

		switch (paquete->header->codigo_operacion) {

		case LEER: {

			int pid, page;

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&page, paquete->data + sizeof(int), sizeof(int));

			char * content = readProcessPage(pid, page);

			paquete = pedirPaquete(LEER, getSwapPagesSize(), content);

			common_send(socketMemoria, paquete);

			break;
		}

		case ESCRIBIR: {

			int pid, page;
			char * content = malloc(getSwapPagesSize());

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&page, paquete->data + sizeof(int), sizeof(int));
			memcpy(content, paquete->data + 2 * sizeof(int),
					getSwapPagesSize());

			writeProcessPage(pid, page, content);

			break;
		}

		case INICIAR: {

			int pid, pagesAmount;

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&pagesAmount, paquete->data + sizeof(int), sizeof(int));

			int blank_pages = getBlankPages();
			int success;

			if (blank_pages >= pagesAmount) {
				success = reserve(pid, pagesAmount);

				if (success == -1) {
					compact();
					success = reserve(pid, pagesAmount);
				}
			}else{
				success = -1;
			}


			if (success == -1) {

				paquete = pedirPaquete(0, sizeof(int), &pid);
				log_info(log_swap,
						"No se pudo reservar las paginas solicitadas para el proceso con pid: %d",
						pid);

			} else {

				paquete = pedirPaquete(1, sizeof(int), &pid);
				int absolutePage = getProcessFirstPage(pid);

				int byteInicial = absolutePage * getSwapPagesSize();

				int size = pagesAmount * getSwapPagesSize();

				log_info(log_swap,
						"Se inicia el proceso %d en el byte %d con tamanio %d",
						pid, byteInicial, size);

			}

			common_send(socketMemoria, paquete);

			break;
		}

		case FINALIZAR: {

			int pid;

			memcpy(&pid, paquete->data, sizeof(int));

			int processSpace = getProcessReservedSpace(pid)
					* getSwapPagesSize();

			int byteInicial = getProcessFirstPage(pid) * getSwapPagesSize();

			freeSpace(pid);

			log_info(log_swap,
					"Proceso %d liberado. N° de byte inicial: %d, y tamaño en bytes: %d",
					pid, byteInicial, processSpace);

			break;
		}

		default: {

			break;
		}

		}

	}

	return 0;
}