Пример #1
0
void MyProcess::genericRead(const QByteArray & output) {
	QByteArray totalOutput = _remainingOutput + output;
	int start = 0;
	int from = 0;
        int pos = canReadLine(totalOutput, from);

	while (pos > -1) {
		//Readline
		//QString line = totalOutput.mid(start, pos - start);
		//cp1252
		//Windows-1252
		//QTextCodec::setCodecForCStrings(QTextCodec::codecForName("Windows-1252"));
		QString line = QString::fromLocal8Bit(totalOutput.mid(start, pos - start));
		from = pos + 1;


		start = from;

		//QString::trimmed() is used for removing leading and trailing whitespaces
		//Some .mp3 files contain tags with starting and ending whitespaces
		//Unfortunately MPlayer gives us leading and trailing whitespaces,
		//Winamp for example doesn't show them
		line = line.trimmed();
		if (!line.isEmpty()) {
			emit lineAvailable(line);
		}

                pos = canReadLine(totalOutput, from);
	}

	_remainingOutput = totalOutput.mid(from);
}
Пример #2
0
void MyProcess::genericRead(QByteArray buffer) {
	QByteArray ba = remaining_output + buffer;
	int start = 0;
	int from_pos = 0;
	int pos = canReadLine(ba, from_pos);

	//qDebug("MyProcess::read: pos: %d", pos);
	while ( pos > -1 ) {
		// Readline
		//QByteArray line = ba.left(pos);
		QByteArray line = ba.mid(start, pos-start);
		//ba = ba.mid(pos+1);
		from_pos = pos + 1;
#ifdef Q_OS_WIN
		if ((from_pos < ba.size()) && (ba.at(from_pos)=='\n')) from_pos++;
#endif
		start = from_pos;

		emit lineAvailable(line);

		pos = canReadLine(ba, from_pos);
	}

	remaining_output = ba.mid(from_pos);
}
Пример #3
0
void AsteriskManager::onReadyRead()
{
	QRegExp keyValue("^([A-Za-z0-9\\-]+):\\s(.+)$");
	QByteArray line;

    qDebug("<ami>");

	while (canReadLine()) {
		line = readLine();

        qDebug() << line.trimmed();

		if (line != "\r\n") {
            if (keyValue.indexIn(line) > -1) {
				packetBuffer[keyValue.cap(1)] = stringValue(keyValue.cap(2).trimmed());
            } else if (line.startsWith("Asterisk Call Manager")) {
                version_ = line.replace("Asterisk Call Manager/", QByteArray()).trimmed();

                emit connected(version_);
            }
		} else if (!packetBuffer.isEmpty()) {
			dispatchPacket();
		}
	}

    qDebug("</ami>");
}
Пример #4
0
void ClientSocket::readClient()
{
    QTextStream stream( this );
    QStringList answer;
    while ( canReadLine() ) {
	stream << processCommand( stream.readLine() );
    }
}
Пример #5
0
bool  QLocalSocket_QtDShell::__override_canReadLine(bool static_call) const
{
    if (static_call) {
        return QLocalSocket::canReadLine();
    } else {
        return canReadLine();
    }
}
Пример #6
0
bool  QTemporaryFile_QtDShell::__override_canReadLine(bool static_call) const
{
    if (static_call) {
        return QIODevice::canReadLine();
    } else {
        return canReadLine();
    }
}
Пример #7
0
void HttpServer :: readSocket()
{
  auto socket = qobject_cast<QTcpSocket*>(sender());
  Q_CHECK_PTR(socket);
  if (socket->canReadLine()) {
    auto tokens = QString (socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
    if (tokens[0] == "GET") replyGet(socket, tokens[1]);
  }
}
Пример #8
0
bool ImapTransport::imapCanReadLine()
{
    if (!compress()) {
        return canReadLine();
    } else {
        _decompressor->consume(&socket());
        return _decompressor->canReadLine();
    }
}
Пример #9
0
void
UpdateProcess::readStandardOutput()
{
  QString line;

  setReadChannel(QProcess::StandardOutput);
  while (canReadLine()) {
    line = readLine().trimmed();
    vInfo("updater (stdout): %1").arg(line);
  }
}
Пример #10
0
void QgsHelpContextSocket::readClient()
{
  // Read context numbers (one per line) and pass upwards
  QString contextId;
  while ( canReadLine() )
  {
    contextId = readLine();
    contextId.remove( '\n' );
    emit setContext( contextId );
  }
}
Пример #11
0
void MyProcess::genericRead(QByteArray buffer) {
	QByteArray ba = remaining_output + buffer;
	int start = 0;
	int from_pos = 0;
	int pos = canReadLine(ba, from_pos);

	while ( pos > -1 ) {
		QByteArray line = ba.mid(start, pos-start);
		from_pos = pos + 1;
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
		if ((from_pos < ba.size()) && (ba.at(from_pos)=='\n')) from_pos++;
#endif
		start = from_pos;

		emit lineAvailable(line);

		pos = canReadLine(ba, from_pos);
	}

	remaining_output = ba.mid(from_pos);
}
void AsteriskManager::onReadyRead()
{
  QRegExp keyValue("^([A-Za-z0-9\\-]+):\\s(.+)$");
  QByteArray line;


  while (canReadLine()) {
    line = readLine();

    if (line != "\r\n") {
      if (keyValue.indexIn(line) > -1)
        packetBuffer[keyValue.cap(1)] = stringValue(keyValue.cap(2).trimmed());
      else if (line.startsWith("ChanVariable"))
      {
        if(!packetBuffer.contains("ChanVars"))
        {
          QMap<QString, QVariant> chanvars;
          packetBuffer.insert("ChanVars",chanvars);
        }
        QMap<QString, QVariant> chanvars = packetBuffer.value("ChanVars").toMap();
        //Get the Channel Name
        QRegExp re ("^ChanVariable\\(([^)]+)\\):\\ (.*)$");
        if(re.exactMatch(line))
        {
          if(!chanvars.contains(re.cap(1)))
          {
            QMap<QString, QVariant> chanvarvals;
            chanvars.insert(re.cap(1),chanvarvals);
          }
          QMap<QString, QVariant> chanvarvals = chanvars.value(re.cap(1)).toMap();
          QRegExp re2 ("^([^=]+)=(.*)$");
          if(re2.exactMatch(re.cap(2).trimmed()))
          {
            if(re2.captureCount() == 2)
            {
              chanvarvals.insert(re2.cap(1), re2.cap(2));
            }
          }
          chanvars.insert(re.cap(1),chanvarvals);
        }
        packetBuffer.insert("ChanVars",chanvars);
      }
      else if (line.startsWith("Asterisk Call Manager"))
        emit connected(line.replace("Asterisk Call Manager/", QByteArray()).trimmed());
    } else if (!packetBuffer.isEmpty()) {
      dispatchPacket();
    }
  }
}
Пример #13
0
void AtlantikNetwork::slotRead()
{
	if ( socketStatus() != KExtendedSocket::connected )
		return;

	if (canReadLine())
	{
		processMsg(m_textStream->readLine());
		// There might be more data
		QTimer::singleShot(0, this, SLOT(slotRead()));
	}
	else
	{
		// Maximum message size. Messages won't get bigger than 32k anyway, so
		// if we didn't receive a newline by now, we probably won't anyway.
		if (bytesAvailable() > (1024 * 32))
			flush();
	}
}
Пример #14
0
void ExtPlaneConnection::readClient() {
    while(canReadLine()) {
        QByteArray lineBA = readLine();
        QString line = QString(lineBA).trimmed();
        //DEBUG << "Server says: " << line;
        if(!server_ok) { // Waiting for handshake..
            if(line=="EXTPLANE 1") {
                server_ok = true;
                emit connectionMessage("");
                setUpdateInterval(updateInterval);
                // Sub all refs
                foreach(ClientDataRef *ref, dataRefs)
                    subRef(ref);
            }
            return;
        } else { // Handle updates
            QStringList cmd = line.split(" ", QString::SkipEmptyParts);
            if(cmd.size()==3) {
                ClientDataRef *ref = dataRefs.value(cmd.value(1));
                if(ref) {
                    if (cmd.value(0)=="ufa" || cmd.value(0)=="uia"){
                        // Array dataref
                        QString arrayString = cmd.value(2);
                        Q_ASSERT(arrayString[0]=='[' && arrayString[arrayString.length()-1]==']');
                        arrayString = arrayString.mid(1, arrayString.length()-2);
                        QStringList arrayValues = arrayString.split(',');
                        ref->updateValue(arrayValues);
                    } else if ((cmd.value(0)=="uf")||(cmd.value(0)=="ui")||(cmd.value(0)=="ud")) {
                        // Single value dataref
                        ref->updateValue(cmd.value(2));
                    } else if (cmd.value(0)=="ub") {
                        // Data dataref
                        ref->updateValue(QByteArray::fromBase64(cmd.value(2).toUtf8()));
                    } else {
                        INFO << "Unsupported ref type " << cmd.value(0);
                    }
                } else {
                    INFO << "Ref not subscribed " << cmd.value(2);
                }
            }
        }
    }
}
Пример #15
0
bool DhQAbstractSocket::DvhcanReadLine() const {
  return canReadLine();
}
Пример #16
0
/*!
  This is the main routine for parsing input on the clientSocket.
  There should be one command for each line of input.  This reads one
  line, and looks at the first word (up to the first space character) to
  determine the command.   Then if there are body or robot indices to read,
  it calls a support routine to read those and return a vector of bodies or
  robots.  These are then passed to the appropriate routine to carry out the
  action and write out any necessary results.
*/
void
ClientSocket::readClient()
{
  int i, numData, numBodies, numRobots;
  double time;
  std::vector<Body *> bodyVec;
  std::vector<Robot *> robVec;

  bool ok;

  while (canReadLine()) {
    line = readLine();
    line.truncate(line.length() - 1); //strip newline character
    lineStrList =
      QStringList::split(' ', line);
    strPtr = lineStrList.begin();

#ifdef GRASPITDBG
    std::cout << "Command parser line: " << line.toStdString().c_str() << std::endl;
#endif

    if (*strPtr == "getContacts") {
      strPtr++; if (strPtr == lineStrList.end()) { continue; }
      numData = (*strPtr).toInt(&ok); strPtr++;
      if (!ok) { continue; }

#ifdef GRASPITDBG
      std::cout << "Num data: " << numData << std::endl;
#endif

      if (readBodyIndList(bodyVec)) { continue; }
      numBodies = bodyVec.size();
      for (i = 0; i < numBodies; i++) {
        sendContacts(bodyVec[i], numData);
      }
    }

    else if (*strPtr == "getAverageContacts") {
      strPtr++;
      if (readBodyIndList(bodyVec)) { continue; }
      numBodies = bodyVec.size();
      for (i = 0; i < numBodies; i++) {
        sendAverageContacts(bodyVec[i]);
      }
    }

    else if (*strPtr == "getBodyName") {
      strPtr++;
      if (readBodyIndList(bodyVec)) { continue; }
      numBodies = bodyVec.size();
      for (i = 0; i < numBodies; i++) {
        sendBodyName(bodyVec[i]);
      }
    }

    else if (*strPtr == "getRobotName") {
      strPtr++;
      if (readRobotIndList(robVec)) { continue; }
      numRobots = robVec.size();
      for (i = 0; i < numRobots; i++) {
        sendRobotName(robVec[i]);
      }
    }

    else if (*strPtr == "getDOFVals") {
      strPtr++;
      if (readRobotIndList(robVec)) { continue; }
      numRobots = robVec.size();
      for (i = 0; i < numRobots; i++) {
        sendDOFVals(robVec[i]);
      }
    }

    else if (*strPtr == "moveDOFs") {
      strPtr++;
      readDOFVals();
    }

    else if (*strPtr == "render") {
      graspitCore->getIVmgr()->getViewer()->render();
    }

    else if (*strPtr == "setDOFForces") {
      strPtr++;
      if (readRobotIndList(robVec)) { continue; }
      numRobots = robVec.size();
      for (i = 0; i < numRobots; i++)
        if (readDOFForces(robVec[i]) == FAILURE) { continue; }
    }
    else if (*strPtr == "moveToContacts") {
      graspitCore->getWorld()->getCurrentHand()->approachToContact(30, true);
    }

    else if ((*strPtr) == "moveDynamicBodies") {
      strPtr++;
      if (strPtr == lineStrList.end()) { ok = FALSE; }
      else {
        time = (*strPtr).toDouble(&ok); strPtr++;
      }
      if (!ok) {
        moveDynamicBodies(-1);
      }
      else {
        moveDynamicBodies(time);
      }
    }

    else if (*strPtr == "computeNewVelocities") {

#ifdef GRASPITDBG
      std::cout << "cnv" << std::endl;
#endif

      strPtr++; if (strPtr == lineStrList.end()) { continue; }
      time = (*strPtr).toDouble(&ok); strPtr++;
      if (!ok) { continue; }

#ifdef GRASPITDBG
      std::cout << time << std::endl;
#endif
      computeNewVelocities(time);
    }

  }
}
Пример #17
0
void
UpdateProcess::readStandardError()
{
  int idx;
  bool ok;
  QString line, type;
  QHash<QString,QString> args;

  setReadChannel(QProcess::StandardError);
  while (canReadLine()) {
    line = readLine().trimmed();
    vInfo("updater (stderr): %1").arg(line);

    idx = line.indexOf(" ");
    if (idx < 0 || idx == line.length()-1)
      continue;
    type = line.mid(0, idx);
    line = line.mid(idx + 1);

    args = string_parse_keyvals(line, &ok);
    if (! ok)
      continue;
    else if (line.startsWith("thandy.InstallFailed: ", Qt::CaseInsensitive)) {
      /** XXX: This is a f*****g kludge. If installation fails, Thandy just
       *       dumps a Python traceback that (for obvious reasons) doesn't
       *       follow the expected format. There isn't a defined control
       *       message type for this yet we'd really like the error, so treat
       *       this one specially.
       */
      emit installUpdatesFailed(line);
      continue;
    }

    if (! type.compare("CAN_INSTALL", Qt::CaseInsensitive)) {
      QString package = args.value("PKG");
      if (! package.isEmpty()) {
        PackageInfo pkgInfo = packageInfo(package);
        if (pkgInfo.isValid())
          _packageList << pkgInfo;
      }
    } else if (_currentCommand == CheckForUpdates
                 && ! type.compare("DEBUG")
                 && args.value("msg").startsWith("Got ")) {
      /* XXX: This is an even worse f*****g kludge. Thandy only reports
       *      download progress in a not-so-parser-friendly log message,
       *      though, so we must kludge again.
       *
       *      Here's an example of what we're parsing:
       *        "Got 1666048/1666560 bytes from http://updates.torproject.org/thandy/data/win32/tor-0.2.1.9-alpha.msi"
       *
       *      (Note that the kludge above would even match on "Got milk?".)
       */
      QStringList parts = args.value("msg").split(" ");
      if (parts.size() == 5) {
        QStringList progress = parts.at(1).split("/");
        if (progress.size() == 2) {
          int bytesReceived = progress.at(0).toUInt();
          int bytesTotal = progress.at(1).toUInt();
          vInfo("updater: Downloaded %1 of %2 bytes of file %3").arg(bytesReceived)
                                                                .arg(bytesTotal)
                                                                .arg(parts.at(4));
          emit downloadProgress(parts.at(4), bytesReceived, bytesTotal);
        }
      }
    }
  }
}
Пример #18
0
bool DhQIODevice::DvhcanReadLine() const {
  return canReadLine();
}
Пример #19
0
/*!
  This is the main routine for parsing input on the clientSocket.
  There should be one command for each line of input.  This reads one
  line, and looks at the first word (up to the first space character) to
  determine the command.   Then if there are body or robot indices to read,
  it calls a support routine to read those and return a vector of bodies or
  robots.  These are then passed to the appropriate routine to carry out the
  action and write out any necessary results.
*/
void
ClientSocket::readClient()
{
  int i,numData,numBodies,numRobots;
  double time;
  std::vector<Body *> bodyVec;
  std::vector<Robot *> robVec;

  bool ok;

  while ( canReadLine() ) {
    line = readLine();
    line.truncate(line.length()-1); //strip newline character
    lineStrList =
      QStringList::split(' ',line);
    strPtr = lineStrList.begin();

#ifdef GRASPITDBG
    std::cout <<"Command parser line: "<<line << std::endl;
#endif
    
    if (*strPtr == "getContacts") {
      strPtr++; if (strPtr == lineStrList.end()) continue;
      numData = (*strPtr).toInt(&ok); strPtr++;
      if (!ok) continue;

#ifdef GRASPITDBG
      std::cout << "Num data: "<<numData<<std::endl;
#endif

      if (readBodyIndList(bodyVec)) continue;
      numBodies = bodyVec.size();
      for (i=0;i<numBodies;i++)
        sendContacts(bodyVec[i],numData);
    }
    
    else if (*strPtr == "getAverageContacts") {
      strPtr++;
      if (readBodyIndList(bodyVec)) continue;
      numBodies = bodyVec.size();
      for (i=0;i<numBodies;i++)
	sendAverageContacts(bodyVec[i]);
    }
    
    else if (*strPtr == "getBodyName") {
      strPtr++;
      if (readBodyIndList(bodyVec)) continue;
      numBodies = bodyVec.size();
      for (i=0;i<numBodies;i++)
	sendBodyName(bodyVec[i]);
    }
    else if(*strPtr == "setBodyName") {
      strPtr++;
      int body_index;
      if(strPtr != lineStrList.end()){
        body_index = strPtr->toInt(&ok);
        strPtr++;
        if(strPtr == lineStrList.end())
          return;
        if (body_index == -1 || body_index >= graspItGUI->getIVmgr()->getWorld()->getNumBodies())
        {
          body_index = graspItGUI->getIVmgr()->getWorld()->getNumBodies() - 1;          
        }
        graspItGUI->getIVmgr()->getWorld()->getBody(body_index)->setName(*strPtr);
      }
    }
    
    else if (*strPtr == "getRobotName") {
      strPtr++;
      if (readRobotIndList(robVec)) continue;
      numRobots = robVec.size();
      for (i=0;i<numRobots;i++)
	sendRobotName(robVec[i]);
    }
    
    else if (*strPtr == "getDOFVals") {
      strPtr++;
      if (readRobotIndList(robVec)) continue;
      numRobots = robVec.size();
      for (i=0;i<numRobots;i++)
	sendDOFVals(robVec[i]);
    }
    
    else if (*strPtr == "moveDOFs") {
      strPtr++;
      readDOFVals();
    }
    
    else if (*strPtr == "render")
      graspItGUI->getIVmgr()->getViewer()->render();
    
    else if (*strPtr == "setDOFForces") {
      strPtr++;
      if (readRobotIndList(robVec)) continue;
      numRobots = robVec.size();
      for (i=0;i<numRobots;i++)
	if (readDOFForces(robVec[i])==FAILURE) continue;
    }
    
    else if ((*strPtr) == "moveDynamicBodies") {
      strPtr++;
      if (strPtr == lineStrList.end()) ok = FALSE;
      else {
	time = (*strPtr).toDouble(&ok); strPtr++;
      }
      if (!ok)
	moveDynamicBodies(-1);
      else
	moveDynamicBodies(time);
    }
    
    else if (*strPtr == "computeNewVelocities") {

#ifdef GRASPITDBG
      std::cout << "cnv" << std::endl;
#endif

      strPtr++; if (strPtr == lineStrList.end()) continue;
      time = (*strPtr).toDouble(&ok); strPtr++;
      if (!ok) continue;

#ifdef GRASPITDBG
      std::cout << time <<std::endl;
#endif
      computeNewVelocities(time);
    }    
    else if ((*strPtr) == "outputPlannerResults"){      
      strPtr++;
      outputPlannerResults(0);      
    }
    else if ((*strPtr) == "outputCurrentGrasp"){      
      strPtr++;
      outputCurrentGrasp();
    }    
    else if ((*strPtr) == "sendBodyTransf"){            
      strPtr++;
      verifyInput(1);
      sendBodyTransf();
    }
    else if ((*strPtr) == "setBodyTransf"){            
      strPtr++;
      verifyInput(7);
      setBodyTransf();
    }
    else if ((*strPtr) == "addObstacle"){            
      strPtr++;
      verifyInput(1);
      addObstacle(*(strPtr+1));
      strPtr+=2;
    }
    else if ((*strPtr) == "addObject"){
      verifyInput(2);
      addGraspableBody(*(strPtr+1), *(strPtr+2));
      strPtr+=3;
      verifyInput(7);
      transf object_pose;
      readTransf(&object_pose);
      World * w = graspItGUI->getIVmgr()->getWorld();
      w->getGB(w->getNumGB() - 1)->setTran(object_pose);
    }
    
    else if ((*strPtr) == "getCurrentHandTran"){
      strPtr++;
      getCurrentHandTran();
    }
    else if ((*strPtr) == "signalGraspUnreachable"){
      strPtr+=4;
      std::cout << line.toStdString() << std::endl;
      graspItGUI->getIVmgr()->blinkBackground();
    }
    else if ((*strPtr) == "getPlannerTarget"){
      strPtr+=1;
      QTextStream os (this) ;
      os << graspItGUI->getIVmgr()->getWorld()->getCurrentHand()->getGrasp()->getObject()->getName() << "\n";
    } 
    else if ((*strPtr) == "setPlannerTarget"){
      QTextStream os(this);
      os << setPlannerTarget(*(strPtr+1)) << "\n";
      strPtr+=2;

    }    

    else if ((*strPtr) == "rotateHandLat"){
      strPtr+=1;
      rotateHandLat();
    }
    else if ((*strPtr) == "rotateHandLong"){
      strPtr+=1;
      rotateHandLong();
    }    
    else if ((*strPtr) == "exec"){
      strPtr+=1;
      exec();
    } 
    else if ((*strPtr) == "next"){
      strPtr+=1;
      next();
    }
    else if ((*strPtr) == "addPointCloud")
    {
      strPtr += 1;
      addPointCloud();
      //QTextStream os(this);  
      //os << addPointCloud() <<" \n";

    }
    else if ((*strPtr) == "setCameraOrigin")
      {
	strPtr += 1;
	setCameraOrigin();
      }
    else if ((*strPtr) == "removeBodies"){
      strPtr += 1;
      removeBodies();
    }
    else if ((*strPtr) == "clearGraspableBodies"){
      strPtr += 1;
      removeBodies(true);
            
    }
  }
}