Пример #1
0
int main( int argc, char** argv )
{
  /* loop variables */
  int x,y;

  /* Create matrixes */
  unsigned int * input_array;
  unsigned int * serial_array;
  unsigned int * output_array;
  unsigned int * filter_list;

  /* Initialize the data. Values don't matter much. */
  posix_memalign ( (void**)&input_array, 4096,  DATA_LEN * sizeof(unsigned int));
  //  input_array = (unsigned int*) posix_memalign ( DATA_LEN * sizeof(unsigned int), 4096);
  for (x=0; x<DATA_LEN; x++)
    {
      input_array[x] = x % 2048;
    }

  /* start with an empty *all zeros* output array */
  posix_memalign ( (void**)&output_array, 4096, DATA_LEN * sizeof(unsigned int));
  memset ( output_array, 0, DATA_LEN );
  posix_memalign ( (void**)&serial_array, 4096, DATA_LEN * sizeof(unsigned int));
  memset ( serial_array, 0, DATA_LEN );

  /* Initialize the filter. Values don't matter much. */
  filter_list = (unsigned int*) malloc ( FILTER_LEN * sizeof(unsigned int));
  for (y=0; y<FILTER_LEN; y++)
    {
      filter_list[y] = y;
    }

  /* Execute at a variety of filter lengths */
  for ( int filter_len =16; filter_len<=FILTER_LEN; filter_len*=2) 
    {
      serialDataFirst ( DATA_LEN, input_array, serial_array, filter_len, filter_list );
      memset ( output_array, 0, DATA_LEN );

      serialFilterFirst ( DATA_LEN, input_array, output_array, filter_len, filter_list );
      checkData ( serial_array, output_array );
      memset ( output_array, 0, DATA_LEN );

      //omp_set_num_threads(16);
      parallelFilterFirst ( DATA_LEN, input_array, output_array, filter_len, filter_list );
      checkData ( serial_array, output_array );
      memset ( output_array, 0, DATA_LEN );

      parallelDataFirst ( DATA_LEN, input_array, output_array, filter_len, filter_list );
      checkData ( serial_array, output_array );
      memset ( output_array, 0, DATA_LEN );
    }
}
PlaceInformationDialog::PlaceInformationDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PlaceInformationDialog)
{
    ui->setupUi(this);

    ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

    connect(ui->lineEditNumber, SIGNAL(editingFinished()), this, SLOT(checkData()));
    connect(ui->lineEditPLZ, SIGNAL(editingFinished()), this, SLOT(checkData()));
    connect(ui->lineEditStreet, SIGNAL(editingFinished()), this, SLOT(checkData()));
    connect(ui->lineEditTown, SIGNAL(editingFinished()), this, SLOT(checkData()));
}
Пример #3
0
bool SudokuBox::checkResult() {
	bool ret = true;
	//XXX optimization: only check the error index and changed index.
	m_setErrors.clear();

	std::vector<int> index_array;
	//1.check each row
	for (int row = 0; row < m_iRows; row++) {
		index_array.clear();
		for (int col = 0; col < m_iCols; col++) {
			index_array.push_back(m_iCols * row + col);
		}
		ret &= checkData(index_array);
	}

	//2.check each column
	for (int col = 0; col < m_iCols; col++) {
		index_array.clear();
		for (int row = 0; row < m_iRows; row++) {
			index_array.push_back(m_iCols * row + col);
		}

		ret &= checkData(index_array);
	}

	//3.check each grid
	if (m_stagedata.cols_per_grid > 1 && m_stagedata.rows_per_grid > 1) {
		int count = m_stagedata.grids_in_col * m_stagedata.grids_in_row;
//		int cell_count = m_stagedata.rows_per_grid * m_stagedata.cols_per_grid;
		for (int grid = 0; grid < count; grid++) {
			index_array.clear();
			int start_col = (grid % m_stagedata.grids_in_col) * m_stagedata.cols_per_grid;
			int start_row = (grid / m_stagedata.grids_in_col) * m_stagedata.rows_per_grid;
			int start = start_row * m_iCols + start_col;
			for (int row = 0; row < m_stagedata.rows_per_grid; row++) {
				for (int col = 0; col < m_stagedata.cols_per_grid; col++) {
					index_array.push_back(start + row * m_iCols + col);
				}
			}
			ret &= checkData(index_array);
		}
	}

	//4.check if each cell filled with valid number
	for (int index = 0; index < m_iRows*m_iCols; index++) {
		if (m_pData[index] <= 0)
			return false;
	}

	return ret;
}
Пример #4
0
MainWindow::MainWindow(QIODevice *ioDev, QWidget *parent) :
        QMainWindow(parent),
        ioDev(ioDev),
        ui(new Ui::MainWindow)
{
    this->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    ui->setupUi(this);
    connect(ioDev, SIGNAL(readyRead()), this, SLOT(onReadyRead()));

    //edited
    AbstractSerial *tempDev = (AbstractSerial *) ioDev;
    tempDev->setDtr(false);
    tempDev->setRts(true);

    save="";
    readFormatedTimer = new QTimer(this);
    readFormatedTimer->start(1000);
    connect(readFormatedTimer,SIGNAL(timeout()),this,SLOT(checkData()));
    ///

    readWaitTimer = new QTimer(this);
    connect(readWaitTimer, SIGNAL(timeout()), this, SLOT(onReadyRead()));

    onReadyRead();
}
Пример #5
0
// Build a PPM from given attributes
//-------------------------------------------------------------------------------------------------
bool PPM::build(const std::string &format, unsigned int width, unsigned int height, unsigned int maxrgb, 
		const std::vector<unsigned char> &r, 
		const std::vector<unsigned char> &g, 
		const std::vector<unsigned char> &b)
{
	// Copy the header values
	m_format = format;
	m_width = width;
	m_height = height;
	m_maxrgb = maxrgb;

	// Check that the values are valid
	if(!checkHeader())
	{
		std::cerr << "Error in build: invalid header values" << std::endl;
		close(); // Prevent inconsistant state
		return false;
	}

	// Copy each of the vectors
	m_pR = new std::vector<unsigned char>(r);
	m_pG = new std::vector<unsigned char>(g);
	m_pB = new std::vector<unsigned char>(b);

	// Check that the data is valid
	if(!checkData())
	{
		std::cerr << "Error in build: invalid data" << std::endl;
		close(); // Prevent inconsistant state
		return false;
	}

	return true;
}
Пример #6
0
void AddClientDialog::loadQuery()
{
    ThreadControl *tc = qobject_cast<ThreadControl *>( sender() );
    if( !tc )
        return;

    int i = tc->getIndexOfLastQuery( qList );
    if( i < 0 )
        return;

    QStringList list = tc->getDataList();
    switch(i)
    {
        case 0:
        {
            checkData( list );
            break;
        }
        case 1:
        {
            if( list.count() > 0 )
                insertData( list.first() );
            break;
        }
    }
}
Пример #7
0
void QXmppTransferIncomingJob::_q_disconnected()
{
    if (d->state == QXmppTransferJob::FinishedState)
        return;

    checkData();
}
Пример #8
0
void BytesTrieTest::TestShortestBranch() {
    static const StringAndValue data[]={
        { "a", 1000 },
        { "b", 2000 }
    };
    checkData(data, UPRV_LENGTHOF(data));
}
Пример #9
0
void BytesTrieTest::Test_a_ab() {
    static const StringAndValue data[]={
        { "a", 1 },
        { "ab", 100 }
    };
    checkData(data, UPRV_LENGTHOF(data));
}
Пример #10
0
Foam::actuationDiskSource::actuationDiskSource
(
    const word& name,
    const dictionary& dict,
    const fvMesh& mesh
)
:
    basicSource(name, dict, mesh),
    cellZoneID_(mesh.cellZones().findZoneID(this->cellSetName())),
    dict_(dict.subDict(typeName + "Coeffs")),
    diskDir_(dict_.lookup("diskDir")),
    Cp_(readScalar(dict_.lookup("Cp"))),
    Ct_(readScalar(dict_.lookup("Ct"))),
    diskArea_(readScalar(dict_.lookup("diskArea")))
{
    Info<< "    - creating actuation disk zone: "
        << this->name() << endl;

    bool foundZone = (cellZoneID_ != -1);

    reduce(foundZone, orOp<bool>());

    if (!foundZone && Pstream::master())
    {
        FatalErrorIn
        (
            "Foam::actuationDiskSource::actuationDiskSource"
            "(const word&, const dictionary&, const fvMesh&)"
        )   << "cannot find porous cellZone " << this->name()
            << exit(FatalError);
    }

    checkData();
}
Пример #11
0
void BytesTrieTest::TestCompact() {
    // Duplicate trailing strings and values provide opportunities for compacting.
    static const StringAndValue data[]={
        { "+", 0 },
        { "+august", 8 },
        { "+december", 12 },
        { "+july", 7 },
        { "+june", 6 },
        { "+november", 11 },
        { "+october", 10 },
        { "+september", 9 },
        { "-", 0 },
        { "-august", 8 },
        { "-december", 12 },
        { "-july", 7 },
        { "-june", 6 },
        { "-november", 11 },
        { "-october", 10 },
        { "-september", 9 },
        // The l+n branch (with its sub-nodes) is a duplicate but will be written
        // both times because each time it follows a different linear-match node.
        { "xjuly", 7 },
        { "xjune", 6 }
    };
    checkData(data, UPRV_LENGTHOF(data));
}
Пример #12
0
void BytesTrieTest::TestLongBranch() {
    // Split-branch and interesting compact-integer values.
    static const StringAndValue data[]={
        { "a", -2 },
        { "b", -1 },
        { "c", 0 },
        { "d2", 1 },
        { "f", 0x3f },
        { "g", 0x40 },
        { "h", 0x41 },
        { "j23", 0x1900 },
        { "j24", 0x19ff },
        { "j25", 0x1a00 },
        { "k2", 0x1a80 },
        { "k3", 0x1aff },
        { "l234567890", 0x1b00 },
        { "l234567890123", 0x1b01 },
        { "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn", 0x10ffff },
        { "oooooooooooooooooooooooooooooooooooooooooooooooooooooo", 0x110000 },
        { "pppppppppppppppppppppppppppppppppppppppppppppppppppppp", 0x120000 },
        { "r", 0x333333 },
        { "s2345", 0x4444444 },
        { "t234567890", 0x77777777 },
        { "z", (int32_t)0x80000001 }
    };
    checkData(data, UPRV_LENGTHOF(data));
}
Пример #13
0
	//文件切割逻辑
	void doIncise()
	{
		checkData();
		checkSize();
		if (mChang) {
			createFile();
		}
	}
Пример #14
0
void ZipCountryCompleters::filterCountry(const int index)
{
    if (!m_Country)
        return;
    if (!m_Model)
        return;
    m_Model->filterCountry(m_Country->itemData(index).toInt());
    checkData();
}
Пример #15
0
Palapeli::PuzzleCreatorDialog::PuzzleCreatorDialog()
	: m_result(0)
	, m_imageSelector(new KUrlRequester)
	, m_nameEdit(new KLineEdit)
	, m_commentEdit(new KLineEdit)
	, m_authorEdit(new KLineEdit)
	, m_slicerSelector(new Palapeli::SlicerSelector)
	, m_slicerConfigMasterWidget(new QStackedWidget)
{
	//setup dialog
	setCaption(i18nc("@title:window", "Create new puzzle"));
	showButton(KDialog::Help, false);
	//setup image selector
	m_imageSelector->setMode(KFile::File | KFile::LocalOnly | KFile::ExistingOnly);
	//build sublayouts
	QFormLayout* sourceLayout = new QFormLayout;
	sourceLayout->addRow(i18nc("@label:chooser", "Image file:"), m_imageSelector);
	sourceLayout->addRow(new QLabel(i18nc("@info", "Please describe below the image which you have chosen.")));
	sourceLayout->addRow(i18nc("@label:textbox", "Image name:"), m_nameEdit);
	sourceLayout->addRow(i18nc("@label:textbox (like in: This comment is optional.)", "Optional comment:"), m_commentEdit);
	sourceLayout->addRow(i18nc("@label:textbox", "Name of image author:"), m_authorEdit);
	foreach (const Pala::Slicer* slicer, m_slicerSelector->slicers())
	{
		m_slicerConfigWidgets[slicer] = new Palapeli::SlicerConfigWidget(slicer);
		m_slicerConfigMasterWidget->addWidget(m_slicerConfigWidgets[slicer]);
	}
	//build page widget items
	m_sourcePage = addPage(new QWidget, i18nc("@item:inlistbox (page name in an assistant dialog)", "Choose image"));
	m_sourcePage->setHeader(i18nc("@title:tab (page header in an assistant dialog)", "Specify the source image to be sliced into pieces"));
	m_sourcePage->widget()->setLayout(sourceLayout);
	m_slicerPage = addPage(m_slicerSelector, i18nc("@item:inlistbox (page name in an assistant dialog)", "Choose slicer"));
	m_slicerPage->setHeader(i18nc("@title:tab (page header in an assistant dialog)", "Choose a slicing method"));
	m_slicerConfigPage = addPage(m_slicerConfigMasterWidget, i18nc("@item:inlistbox (page name in an assistant dialog)", "Configure slicer"));
	m_slicerConfigPage->setHeader(i18nc("@title:tab (page header in an assistant dialog)", "Tweak the parameters of the chosen slicing method"));
	//wire up stuff
	connect(this, SIGNAL(accepted()), this, SLOT(createPuzzle()));
	connect(m_imageSelector, SIGNAL(urlSelected(KUrl)), this, SLOT(checkData()));
	connect(m_nameEdit, SIGNAL(textChanged(QString)), this, SLOT(checkData()));
	connect(m_authorEdit, SIGNAL(textChanged(QString)), this, SLOT(checkData()));
	checkData(); //to invalidate first page
	connect(m_slicerSelector, SIGNAL(currentSelectionChanged(Palapeli::SlicerSelection)), this, SLOT(updateSlicerSelection(Palapeli::SlicerSelection)));
}
void PlaceInformationDialog::setPlace(QSharedPointer<Place> place)
{
    m_place = place;

    ui->lineEditNumber->setText(QString::number(place->houseNumber()));
    ui->lineEditPLZ->setText(QString::number(place->postalCode()));
    ui->lineEditStreet->setText(place->street());
    ui->lineEditTown->setText(place->city());
    ui->imageWellIcon->setPixmap(place->cityEmblem());

    checkData();
}
Пример #17
0
void Connection::connect(const SocketClient::SharedPtr &client)
{
    assert(!mSocketClient);
    mSocketClient = client;
    mIsConnected = true;
    assert(client->isConnected());
    mSocketClient->disconnected().connect(std::bind(&Connection::onClientDisconnected, this, std::placeholders::_1));
    mSocketClient->readyRead().connect(std::bind(&Connection::onDataAvailable, this, std::placeholders::_1, std::placeholders::_2));
    mSocketClient->bytesWritten().connect(std::bind(&Connection::onDataWritten, this, std::placeholders::_1, std::placeholders::_2));
    mSocketClient->error().connect(std::bind(&Connection::onSocketError, this, std::placeholders::_1, std::placeholders::_2));
    mCheckTimer = EventLoop::eventLoop()->registerTimer([this](int) { checkData(); }, 0, Timer::SingleShot);
}
Пример #18
0
// Write current contents to file
//-------------------------------------------------------------------------------------------------
bool PPM::writeTo(const std::string &filename)
{
	// Cheak the header values are valid
	if(!checkHeader())
	{
		std::cerr << "Error in writeTo: invalid header values" << std::endl;
		return false;
	}

	// Check the data is valid
	if(!checkData())
	{
		std::cerr << "Error in writeTo: invalid data" << std::endl;
		return false;
	}

	std::ofstream outFile;
	// Open output file in binary mode
	outFile.open(filename.c_str(), std::ios::binary);
	
	// Check file open ok
	if(!outFile)
	{
		std::cerr << "Error in writeTo: could not open or create file '" << filename << "'" << std::endl;
		return false;
	}

	// Write header values
	outFile << m_format << std::endl;
	outFile << "# Created by PPM.cpp" << std::endl;
	outFile << m_width << " " << m_height << std::endl;
	outFile << m_maxrgb << std::endl;


	// Iterate through vectors and write data
	char c;
	unsigned int size = m_width * m_height;
	for(unsigned int i = 0; i < size; ++i)
	{
		c = (*m_pR)[i];
		outFile.write(&c, 1);
		c = (*m_pG)[i];
		outFile.write(&c, 1);
		c = (*m_pB)[i];
		outFile.write(&c, 1);		
	}

	// Close the file
	outFile.close();

	return true;
}
Пример #19
0
void BytesTrieTest::TestValuesForState() {
    // Check that saveState() and resetToState() interact properly
    // with next() and current().
    static const StringAndValue data[]={
        { "a", -1 },
        { "ab", -2 },
        { "abc", -3 },
        { "abcd", -4 },
        { "abcde", -5 },
        { "abcdef", -6 }
    };
    checkData(data, UPRV_LENGTHOF(data));
}
Пример #20
0
// Read the data
//-------------------------------------------------------------------------------------------------
bool PPM::readData(std::ifstream &inFile)
{
	// Read data into r, g and b vectors
	// Note: if << is used data that looks like a white space will be skipped
	char c;
	int length = m_width * m_height;
	for(int i = 0; i < length; ++i)
	{
		// Red
		inFile.read(&c, 1); // read a byte
		// Check for eof
		if(inFile.eof())
		{
			std::cerr << "Error in readData: unexpected end of file" << std::endl;
			return false;
		}
		// Set value
		(*m_pR)[i] = (unsigned char)c;

		// Green
		inFile.read(&c, 1); // read a byte
		// Check for eof
		if(inFile.eof())
		{
			std::cerr << "Error in readData: unexpected end of file" << std::endl;
			return false;
		}
		// Set value
		(*m_pG)[i] = (unsigned char)c;

		// Blue
		inFile.read(&c, 1); // read a byte
		// Check for eof
		if(inFile.eof())
		{
			std::cerr << "Error in readData: unexpected end of file" << std::endl;
			return false;
		}
		// Set value
		(*m_pB)[i] = (unsigned char)c;
	}

	// Check the data is valid
	if(!checkData())
	{
		std::cerr << "Error in readData: invalid data" << std::cout;
		return false;
	}

	return true;
}
Пример #21
0
/** When user select a zip or a city this private slot s activated. It causes the line edit
    to be populated with the selected values.
*/
void ZipCountryCompleters::indexActivated(const QModelIndex &index)
{
    QString zip = m_Model->index(index.row(), ZipCountryModel::Zip).data().toString();
    QString city = m_Model->index(index.row(), ZipCountryModel::City).data().toString();
    if (m_Zip) {
        m_Zip->clearFocus();
        m_Zip->setText(zip);
    }
    if (m_City) {
        m_City->clearFocus();
        m_City->setText(city);
    }
    checkData();
}
Пример #22
0
void UCharsTrieTest::TestFirstForCodePoint() {
    static const StringAndValue data[]={
        { "a", 1 },
        { "a\\ud800", 2 },
        { "a\\U00010000", 3 },
        { "\\ud840", 4 },
        { "\\U00020000\\udbff", 5 },
        { "\\U00020000\\U0010ffff", 6 },
        { "\\U00020000\\U0010ffffz", 7 },
        { "\\U00050000xy", 8 },
        { "\\U00050000xyz", 9 }
    };
    checkData(data, UPRV_LENGTHOF(data));
}
Пример #23
0
QAction *BtMenuView::newAction(QMenu *parentMenu, const QModelIndex &itemIndex) {
    QVariant displayData(m_model->data(itemIndex, Qt::DisplayRole));
    QVariant iconData(m_model->data(itemIndex, Qt::DecorationRole));
    QVariant toolTipData(m_model->data(itemIndex, Qt::ToolTipRole));
    QVariant statusTipData(m_model->data(itemIndex, Qt::StatusTipRole));
    QVariant whatsThisData(m_model->data(itemIndex, Qt::WhatsThisRole));

    QAction *childAction = new QAction(parentMenu);

    // Set text:
    if (displayData.canConvert(QVariant::String)) {
        childAction->setText(displayData.toString());
    }

    // Set icon:
    if (iconData.canConvert(QVariant::Icon)) {
        childAction->setIcon(iconData.value<QIcon>());
    }

    // Set tooltip:
    if (toolTipData.canConvert(QVariant::String)) {
        childAction->setToolTip(toolTipData.toString());
    }

    // Set status tip:
    if (statusTipData.canConvert(QVariant::String)) {
        childAction->setStatusTip(statusTipData.toString());
    }

    // Set whatsthis:
    if (whatsThisData.canConvert(QVariant::String)) {
        childAction->setWhatsThis(whatsThisData.toString());
    }

    // Set checkable:
    if (m_model->flags(itemIndex).testFlag(Qt::ItemIsUserCheckable)) {
        childAction->setCheckable(true);
    }

    // Set checked:
    QVariant checkData(m_model->data(itemIndex, Qt::CheckStateRole));
    bool ok;
    Qt::CheckState state = (Qt::CheckState) checkData.toInt(&ok);
    if (ok) {
        childAction->setChecked(state == Qt::Checked);
    }

    return childAction;
}
Пример #24
0
void QXmppTransferIncomingJob::_q_receiveData()
{
    if (d->state != QXmppTransferJob::TransferState)
        return;

    // receive data block
    if (d->direction == QXmppTransferJob::IncomingDirection)
    {
        writeData(d->socksSocket->readAll());

        // if we have received all the data, stop here
        if (fileSize() && d->done >= fileSize())
            checkData();
    }
}
Пример #25
0
void BytesTrieTest::TestLongSequence() {
    static const StringAndValue data[]={
        { "a", -1 },
        // sequence of linear-match nodes
        { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", -2 },
        // more than 256 bytes
        { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", -3 }
    };
    checkData(data, UPRV_LENGTHOF(data));
}
Пример #26
0
void QXmppTransferJob::disconnected()
{
    if (m_state == QXmppTransferJob::FinishedState)
        return;

    // terminate transfer
    if (m_direction == QXmppTransferJob::IncomingDirection)
    {
        checkData();
    } else {
        if (fileSize() && m_done != fileSize())
            terminate(QXmppTransferJob::ProtocolError);
        else
            terminate(QXmppTransferJob::NoError);
    }
}
Пример #27
0
//Verifica se o I foi bem recebido
int checkI(char* buffer,int cns){
	int res,i;
	char data[15000];
	if(	 buffer[0]!=FLAG
	  || buffer[1]!=A
	  || buffer[2]!=cns
	  || buffer[3]!=(A^cns))
	{
		return FALSE;
	}
	else
	{
		res = getData(buffer,data);
		res = checkData(data,res);
		return res;
	}
}
int peakDetection(int input){
    currentTime = sampleCounter/250;
    sampleCounter++;
    if(init<2){
        buffer[loopCheck(init,4)] = input;
        init++;
        counter = init;
    }else{
        bufferData(input);
        checkData(input);
        counter++;
        if(misscounter==5){
            printf("Missed 5 times in a row.\n");
            misscounter = 0;
        }
    }
	return 0;
}
Пример #29
0
void
execute(void* callbackObj, 
	SignalHeader * const header, Uint8 prio, Uint32 * const theData, 
	LinearSectionPtr ptr[3]){
  const NodeId nodeId = refToNode(header->theSendersBlockRef);
  
  ndbout << "Recieved prio " << (int)prio << " signal from node: " 
	 << nodeId
	 << " gsn = " << header->theVerId_signalNumber << endl;
  checkData(header, prio, theData, ptr);
  ndbout << " Data is ok!\n" << endl;
  
  signalReceived[nodeId]++;
  
  if(prio == 0)
    sendSignalTo(nodeId, 1);
  else
    tReg->setPerformState(nodeId, PerformDisconnect);
}
Пример #30
0
bool ServerNetObject::initGame( QString& serror)
{
	for (int i=1; i<=nb_pl; i++) {	
		writeSelect(1);
		if ( writeIsset(pl[i]->sock) ) {
			/* send PLAY_MSG to clients */
			write( pl[i]->sock, PLAY_MSG, (int)strlen(PLAY_MSG) );
			
			/* send opponents' names */
			strncpy(names_msg.prev, (const char *)pl[i-1]->name, NAME_LENGTH);
			if ( i!=nb_pl )
				strncpy( names_msg.next, (const char *)pl[i+1]->name,
						NAME_LENGTH );
			 else
				strncpy( names_msg.next, (const char *)pl[0]->name,
						NAME_LENGTH );
			write( pl[i]->sock, &names_msg, sizeof(names_msg) );
		}
	 }

	/* receive READY_MSG from clients */
	for (int i=1; i<=nb_pl; i++) {
		readSelect(1);
		if ( readIsset(pl[i]->sock) ) {
			nb_b = read( pl[i]->sock, buff, MAX_BUFF );
			 if ( !checkData(i18n("Client has died"),
							 i18n("Cancel from client"), serror) )
				return FALSE;
			if ( !hasReceivedMsg(READY_MSG) ) {
				serror = i18n("Unknown message from client");
				return FALSE;
			}
		} else {
			serror = i18n("Timeout");
			return FALSE;        
		}
	}
	
	/* set the "first time" bool */
	firstTime = TRUE;
	
	return TRUE;
}