示例#1
0
文件: getLines.hpp 项目: xaizek/dit
 /**
  * @brief Advances to the next line in the stream.
  */
 void increment()
 {
     if (!std::getline(*s, *str, delim) || s->eof()) {
         *this = linesIterator();
     }
 }
void AstManager::processAstData(QString str) {
  //qDebug () << "AstData: " << str;

    QStringList lines = str.split("\n");
    //qDebug() << lines;

    QHash<QString, QString> strHash;
    QStringListIterator linesIterator(lines);
    while (linesIterator.hasNext()) {
       QStringList fields = linesIterator.next().split(": ");
       if (fields.size() == 2) {
	 strHash[fields.at(0).toLower()]= fields.at(1).toLower();
       }
    }
      
     qDebug() << "Hash: " << strHash;

    if (strHash.contains("event")) {
      if (strHash.value("event") == "newchannel") {
	Channel *channel = new Channel();
	channel->setName(strHash.value("channel"));
	channel->setUniqueID(strHash.value("uniqueid"));
	channel->setCallerID(strHash.value("callerid"));
	channel->setCallerIDName(strHash.value("calleridname"));
	channel->setState(convertToChannelState(strHash.value("state")));
	channelsHash.insert(strHash.value("uniqueid"), channel);
	emit somethingChanged();
      } else if (strHash.value("event") == "newstate") {
	Channel *channel = channelsHash.value(strHash.value("uniqueid"));
	if (channel != 0) {
	  channel->setState(convertToChannelState(strHash.value("state")));
	  emit somethingChanged();
	}	
      } else if (strHash.value("event") == "newcallerid") {
	Channel *channel = channelsHash.value(strHash.value("uniqueid"));
	if (channel != 0) {
	  channel->setCallerID(strHash.value("callerid"));
	  channel->setCallerIDName(strHash.value("calleridname"));
	  emit somethingChanged();
	}	
      } else if (strHash.value("event") == "newexten") {
	//emit newextension();
	qDebug() << "Newextension : " <<  strHash.value("newexten");
      } else if (strHash.value("event") == "dial") {
	// dest channel holds the connection
	Channel *destchannel = channelsHash.value(strHash.value("destuniqueid"));
	destchannel->newConnection(channelsHash.value(strHash.value("srcuniqueid")), ConnectionNsp::dail);
	emit somethingChanged();

      } else if (strHash.value("event") == "link") {
	// guess uniqueid2 is destuniqueid
	Channel *destchannel = channelsHash.value(strHash.value("uniqueid2"));
	if (destchannel != 0) {
	  Connection *connection = destchannel->getConnectionPtr();
	  
	  if (connection != 0) {
	    connection->setState(ConnectionNsp::link);
	    emit somethingChanged();
	  } else {
	    qWarning() << "Internal error ... conection == NULL";
	  }
	} else {
	  qWarning() << "Internal error ... destchannel == NULL";
	}

      } else if (strHash.value("event") == "hangup") {
	Channel *channel = channelsHash.value(strHash.value("uniqueid"));
	channel->setState(down);
	emit somethingChanged();
	channelsHash.remove(strHash.value("uniqueid"));
	delete channel;
	emit somethingChanged();
      }
    }
}
示例#3
0
文件: getLines.hpp 项目: xaizek/dit
 /**
  * @brief Constructs range iterator.
  *
  * @param s Stream to read lines from.
  * @param delim Lines separator.
  */
 explicit linesRange(std::istream &s, char delim = '\n')
     : linesRangeBase(linesIterator(&s, &str, delim), linesIterator())
 {
 }