void BluetoothMultiplexer::_processInHeader()
{
    QDataStream stream(&m_buffer_in_data, QIODevice::ReadOnly);
    stream.setByteOrder(QDataStream::BigEndian);
    stream.setVersion(QDataStream::Qt_5_6);

    stream >> m_buffer_in_version >> m_buffer_in_type;

    switch( m_buffer_in_type ) {
        case TYPE_DATA:
            //qDebug() << this << "Receiving data";
            processNext(5, &BluetoothMultiplexer::_processInDataHeader);
            break;
        case TYPE_QCOMPRESS:
            //qDebug() << this << "Receiving compressed data";
            processNext(5, &BluetoothMultiplexer::_processInDataHeader);
            break;
        case TYPE_GETSERVICES:
            qDebug() << this << "Receiving services list";
            processNext(4, &BluetoothMultiplexer::_processInServiceHeader);
            break;
        case TYPE_GETSERVICE:
            qDebug() << this << "Receiving service name";
            processNext(1, &BluetoothMultiplexer::_processInServiceHeader);
            break;
        case TYPE_SOCKET_CLOSE:
            qDebug() << this << "Received close connection";
            processNext(1, &BluetoothMultiplexer::_processSocket);
            break;
    }
}
Example #2
0
Token* RegxParser::processStar(Token* const tok) {

    processNext();

    if (fState == REGX_T_QUESTION) {
        processNext();
        return fTokenFactory->createClosure(tok, true);
    }

    return fTokenFactory->createClosure(tok);
}
Example #3
0
Token* RegxParser::processParen() {

    processNext();
    int num = fNoGroups++;
    Token* tok = fTokenFactory->createParenthesis(parseRegx(true),num);

    if (fState != REGX_T_RPAREN)
        ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Factor1, fMemoryManager);

    processNext();
    return tok;
}
Token* ParserForXMLSchema::processParen() {

    // XML Schema doesn't support back references
    processNext();
    Token* retTok = getTokenFactory()->createParenthesis(parseRegx(true), 0);

    if (getState() != REGX_T_RPAREN) {
        ThrowXMLwithMemMgr(ParseException, XMLExcepts::Parser_Factor1, getMemoryManager());
    }

    processNext();
    return retTok;
}
BluetoothMultiplexer::BluetoothMultiplexer(const QString &address, const QString &service_uuid, QObject *parent)
    : QObject(parent)
    , m_socket(NULL)
    , m_connections()
    , m_connections_nextid(1)
    , m_buffer_in_required(0)
    , m_buffer_in_data()
    , m_buffer_in_version(0)
    , m_buffer_in_type(0)
    , m_buffer_out_data()
{
    qDebug() << this << "Creating";

    m_buffer_out_data.clear();

    m_socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol, this);

    connect(m_socket, &QBluetoothSocket::connected, this, &BluetoothMultiplexer::_connected);
    connect(m_socket, &QBluetoothSocket::disconnected, this, &BluetoothMultiplexer::_disconnected);
    connect(m_socket, &QBluetoothSocket::readyRead, this, &BluetoothMultiplexer::_read);
    connect(m_socket, &QBluetoothSocket::stateChanged, this, &BluetoothMultiplexer::_stateChanged);
    connect(m_socket, static_cast<void(QBluetoothSocket::*)(QBluetoothSocket::SocketError)>(&QBluetoothSocket::error),
            this, &BluetoothMultiplexer::_error);

    processNext(2, &BluetoothMultiplexer::_processInHeader);

    m_socket->connectToService(QBluetoothAddress(address), QBluetoothUuid(service_uuid));
}
Example #6
0
Token* RegxParser::processBackReference() {

    XMLSize_t position = fOffset - 2;

    // Handle multi digit back references
    int refNo = fCharData - chDigit_0;
    while(true) {
        processNext();
        if(fState != REGX_T_CHAR || fCharData < chDigit_0 || fCharData > chDigit_9)
            break;

        int nextRefNo = (refNo * 10) + fCharData - chDigit_0;
        if(nextRefNo >= fNoGroups)
            break;

        refNo = nextRefNo;
    }

    Token* tok = fTokenFactory->createBackReference(refNo);

    fHasBackReferences = true;
    if (fReferences == 0) {
        fReferences = new (fMemoryManager) RefVectorOf<ReferencePosition>(8, true, fMemoryManager);
    }

    fReferences->addElement(new (fMemoryManager) ReferencePosition(refNo, position));
    return tok;
}
Token* ParserForXMLSchema::processPlus(Token* const tok) {

    // XML Schema doesn't support reluctant quantifiers
    processNext();
    return getTokenFactory()->createConcat(tok,
                               getTokenFactory()->createClosure(tok));
}
Example #8
0
void CommandParser::readLine() {
  char buffer[128];
  qint64 lineLength = m_device->readLine(buffer, 128);
  if (lineLength != -1) {
    buffer[lineLength - 1] = 0;
    processNext(buffer);
  }
}
Example #9
0
void CommandParser::readDataBlock() {
  char *buffer = new char[m_expectingDataSize + 1];
  m_device->read(buffer, m_expectingDataSize);
  buffer[m_expectingDataSize] = 0;
  processNext(buffer);
  m_expectingDataSize = -1;
  delete[] buffer;
}
void Connection::readLine() {
  char buffer[128];
  qint64 lineLength = m_socket->readLine(buffer, 128);
  if (lineLength != -1) {
    buffer[lineLength - 1] = 0;
    processNext(buffer);
  }
}
void Connection::readDataBlock() {
  char *buffer = new char[m_expectingDataSize + 1];
  m_socket->read(buffer, m_expectingDataSize);
  buffer[m_expectingDataSize] = 0;
  processNext(buffer);
  m_expectingDataSize = -1;
  delete buffer;
}
void ClientStream::close()
{
	if( d->socket->isOpen() )
	{
		processNext();
		d->socket->disconnectFromHost();
	}
}
Example #13
0
Token* RegxParser::processQuestion(Token* const tok) {

    processNext();

    Token* parentTok = fTokenFactory->createUnion();

    if (fState == REGX_T_QUESTION) {
        processNext();
        parentTok->addChild(fTokenFactory->createToken(Token::T_EMPTY), fTokenFactory);
        parentTok->addChild(tok, fTokenFactory);
    }
    else {
        parentTok->addChild(tok, fTokenFactory);
        parentTok->addChild(fTokenFactory->createToken(Token::T_EMPTY), fTokenFactory);
    }

    return parentTok;
}
void UniformCostSearch::search(const int init, const int goal)
{
	// put initial node in the frontier, with cost:0 and status:frontier
	initialNodePtr = graph.nodeAt(init);
	initialNodePtr->setStatus(Node::FRONTIER);
	initialNodePtr->setPathCost(0.0f);
	frontier.push(initialNodePtr);

	// set the goal node
	goalNodePtr = graph.nodeAt(goal);

	// output a message of what we're searching for
	cout << "Searching for route from " << initialNodePtr->getNodeID() << " to " << goalNodePtr->getNodeID();

	// this loop keeps searching until a solution is found
	int nodeCount = 0;
	SearchStatus status = processNext();

	while( status == SearchStatus::SEARCHING )
	{
		++nodeCount;
		cout << " .";
		status = processNext();
	}

	// If FAIL, output a message
	if( status == SearchStatus::FAILURE )
	{
		cout << "\n\nNo solution found.\n\n";
	}
	// If SUCCESS, output the solution
	else if( status == SearchStatus::SUCCESS )
	{
		cout << "\n\nSearch Efficiency\n-----------------\nExpanded " << nodeCount << " nodes\n";

		// print out the solution if found
		printSolution();
	}

	// once the search has completed we clear the graph state 
	// (each node cost, state, parent, action) so we can search again
	graph.clearSearchState();
}
void LinkLocal::Stream::ready()
{
	while(!waiting.isEmpty()) {
		inUse = true;
		Stanza s = waiting.first();
		proto->sendStanza(s.element());
		processNext();
		waiting.removeFirst();
	}
}
void LinkLocal::Stream::write(const Stanza &s)
{
	inUse = true;
	if(state == Active && !waiting.isEmpty()) {
		proto->sendStanza(s.element());
		processNext();
	} else {
		waiting.append(s);
	}
}
Token* ParserForXMLSchema::processQuestion(Token* const tok) {

    // XML Schema doesn't support reluctant quantifiers
    processNext();

    TokenFactory* tokFactory = getTokenFactory();
    Token* retTok = tokFactory->createUnion();
    retTok->addChild(tok, tokFactory);
    retTok->addChild(tokFactory->createToken(Token::T_EMPTY), tokFactory);
    return retTok;
}
void ClientStream::close()
{
	if(d->state == Active) {
		d->state = Closing;
//		d->client.shutdown();
		processNext();
	}
	else if(d->state != Idle && d->state != Closing) {
		reset();
	}
}
void BluetoothMultiplexer::_processInDataHeader()
{
    QDataStream stream(&m_buffer_in_data, QIODevice::ReadOnly);
    stream.setByteOrder(QDataStream::BigEndian);
    stream.setVersion(QDataStream::Qt_5_6);

    qint32 length;
    stream >> m_buffer_in_data_id >> length;

    processNext(length, &BluetoothMultiplexer::_processInData);
}
void LinkLocal::Stream::close() {
	if(state == Active) {
		state = Closing;
		proto->shutdown();
		processNext();
		emit cleanUp(this);
		deleteLater();
	}
	else if(state != Idle && state != Closing) {
//		reset();
	}
}
Example #21
0
// ---------------------------------------------------------------------------
//  RegxParser: Parsing methods
// ---------------------------------------------------------------------------
Token* RegxParser::parse(const XMLCh* const regxStr, const int options) {

    // if TokenFactory is not set do nothing.
    // REVISIT - should we throw an exception
    if (fTokenFactory == 0) {
        return 0;
    }

    fOptions = options;
    fOffset = 0;
    fNoGroups = 1;
    fHasBackReferences = false;
    setParseContext(regexParserStateNormal);
    if (fString)
        fMemoryManager->deallocate(fString);//delete [] fString;
    fString = XMLString::replicate(regxStr, fMemoryManager);

    if (isSet(RegularExpression::EXTENDED_COMMENT)) {

        if (fString)
            fMemoryManager->deallocate(fString);//delete [] fString;
        fString = RegxUtil::stripExtendedComment(regxStr, fMemoryManager);
    }

    fStringLen = XMLString::stringLen(fString);
    processNext();

    Token* retTok = parseRegx();

    if (fOffset != fStringLen) {
        XMLCh value1[65];
        XMLString::sizeToText(fOffset, value1, 64, 10, fMemoryManager);
        ThrowXMLwithMemMgr2(ParseException,XMLExcepts::Parser_Parse1, value1, fString, fMemoryManager);
    }

    if (fReferences != 0) {

        XMLSize_t refSize = fReferences->size();
        for (XMLSize_t i = 0; i < refSize; i++) {

            if (fNoGroups <= fReferences->elementAt(i)->fReferenceNo) {
                ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Parse2, fMemoryManager);
            }
        }

        fReferences->removeAllElements();
    }

    return retTok;
}
Example #22
0
void Message::update(updateSpeed speed)
{
    if(stream.atEnd()) // Might happen if given an empty message
        return;
    
    if(speed==spd_normal && timer>0)
    {
        timer--;
        if(timer>0)
            return;
    }
    
    processNext(speed);
    timer=textSpeed;
}
void BluetoothMultiplexer::_processInData()
{
    QByteArray out;
    if( m_buffer_in_type == TYPE_QCOMPRESS )
        out = qUncompress(m_buffer_in_data.left(m_buffer_in_required));
    else
        out = m_buffer_in_data.left(m_buffer_in_required);

    if( m_connections.contains(m_buffer_in_data_id) )
        m_connections[m_buffer_in_data_id]->clientWrite(out);
    else {
        qWarning() << this << "Unable to find connection id:" << m_buffer_in_data_id << m_connections.keys();
        writeSocketClose(m_buffer_in_data_id);
    }

    processNext(2, &BluetoothMultiplexer::_processInHeader);
}
Example #24
0
Token* RegxParser::parseRegx(const bool matchingRParen) {

    Token* tok = parseTerm(matchingRParen);
    Token* parentTok = 0;

    while (fState == REGX_T_OR) {

        processNext();
        if (parentTok == 0) {

            parentTok = fTokenFactory->createUnion();
            parentTok->addChild(tok, fTokenFactory);
            tok = parentTok;
        }

        tok->addChild(parseTerm(matchingRParen), fTokenFactory);
    }

    return tok;
}
Example #25
0
RangeToken* RegxParser::processBacksolidus_pP(const XMLInt32 ch) {

    processNext();

    if (fState != REGX_T_CHAR || fCharData != chOpenCurly)
        ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom2, fMemoryManager);

    XMLSize_t nameStart = fOffset;
    int nameEnd = XMLString::indexOf(fString,chCloseCurly,nameStart, fMemoryManager);

    if (nameEnd < 0)
        ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom3, fMemoryManager);
    
    fOffset = nameEnd + 1;
    XMLCh* rangeName = (XMLCh*) fMemoryManager->allocate
    (
        (nameEnd - nameStart + 1) * sizeof(XMLCh)
    );//new XMLCh[(nameEnd - nameStart) + 1];
    ArrayJanitor<XMLCh> janRangeName(rangeName, fMemoryManager);
    XMLString::subString(rangeName, fString, nameStart, nameEnd, fMemoryManager);

    return  fTokenFactory->getRange(rangeName, !(ch == chLatin_p));
}
void LinkLocal::Stream::bs_readyRead() {
	QByteArray ba = bs_->read(1024);
//	printf("incoming: %s\n", QString(ba).ascii());
	proto->addIncomingData(ba);
	processNext();
}
Example #27
0
RangeToken* RegxParser::parseCharacterClass(const bool useNRange) {

    setParseContext(regexParserStateInBrackets);
    processNext();

    RangeToken* tok = 0;
    bool isNRange = false;

    if (getState() == REGX_T_CHAR && getCharData() == chCaret) {
        isNRange = true;
        processNext();
    }
    tok = fTokenFactory->createRange();

    parserState type;
    bool firstLoop = true;
    bool wasDecoded;

    while ( (type = getState()) != REGX_T_EOF) {

        wasDecoded = false;

        // single range | from-to-range | subtraction
        if (type == REGX_T_CHAR && getCharData() == chCloseSquare && !firstLoop)
            break;

        XMLInt32 ch = getCharData();
        bool     end = false;

        if (type == REGX_T_BACKSOLIDUS) {

            switch(ch) {
            case chLatin_d:
            case chLatin_D:
            case chLatin_w:
            case chLatin_W:
            case chLatin_s:
            case chLatin_S:
            case chLatin_i:
            case chLatin_I:
            case chLatin_c:
            case chLatin_C:
                {
                    tok->mergeRanges(getTokenForShorthand(ch));
                    end = true;
                }
                break;
            case chLatin_p:
            case chLatin_P:
                {                    
                    RangeToken* tok2 = processBacksolidus_pP(ch);

                    if (tok2 == 0) {
                        ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom5, getMemoryManager());
                    }

                    tok->mergeRanges(tok2);
                    end = true;
                }
                break;
            case chDash:
                wasDecoded = true;
                // fall thru to default.
            default:
                ch = decodeEscaped();
            }
        } // end if REGX_T_BACKSOLIDUS
        else if (type == REGX_T_XMLSCHEMA_CC_SUBTRACTION && !firstLoop) {

            if (isNRange)
            {
                tok = RangeToken::complementRanges(tok, fTokenFactory, fMemoryManager);
                isNRange=false;
            }
            RangeToken* rangeTok = parseCharacterClass(false);
            tok->subtractRanges(rangeTok);

            if (getState() != REGX_T_CHAR || getCharData() != chCloseSquare) {
                ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_CC5, getMemoryManager());
            }
            break;
        } // end if REGX_T_XMLSCHEMA...

        processNext();

        if (!end) {

            if (type == REGX_T_CHAR
                && (ch == chOpenSquare
                    || ch == chCloseSquare
                    || (ch == chDash && getCharData() == chCloseSquare && firstLoop))) {
                // if regex = [-] then invalid...
                // '[', ']', '-' not allowed and should be escaped
                XMLCh chStr[] = { ch, chNull };
                ThrowXMLwithMemMgr2(ParseException,XMLExcepts::Parser_CC6, chStr, chStr, getMemoryManager());
            }
            if (ch == chDash && getCharData() == chDash && getState() != REGX_T_BACKSOLIDUS && !wasDecoded) {
                XMLCh chStr[] = { ch, chNull };
                ThrowXMLwithMemMgr2(ParseException,XMLExcepts::Parser_CC6, chStr, chStr, getMemoryManager());
            }

            if (getState() != REGX_T_CHAR || getCharData() != chDash) {
                tok->addRange(ch, ch);
            }
            else {

                processNext();
                if ((type = getState()) == REGX_T_EOF)
                    ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_CC2, getMemoryManager());

                if (type == REGX_T_CHAR && getCharData() == chCloseSquare) {
                    tok->addRange(ch, ch);
                    tok->addRange(chDash, chDash);
                }
                else if (type == REGX_T_XMLSCHEMA_CC_SUBTRACTION) {

                    static const XMLCh dashStr[] = { chDash, chNull};
                    ThrowXMLwithMemMgr2(ParseException, XMLExcepts::Parser_CC6, dashStr, dashStr, getMemoryManager());
                }
                else {

                    XMLInt32 rangeEnd = getCharData();
                    XMLCh rangeEndStr[] = { rangeEnd, chNull };

                    if (type == REGX_T_CHAR) {

                        if (rangeEnd == chOpenSquare
                            || rangeEnd == chCloseSquare
                            || rangeEnd == chDash)
                            // '[', ']', '-' not allowed and should be escaped
                            ThrowXMLwithMemMgr2(ParseException, XMLExcepts::Parser_CC6, rangeEndStr, rangeEndStr, getMemoryManager());
                    }
                    else if (type == REGX_T_BACKSOLIDUS) {
                        rangeEnd = decodeEscaped();
                    }

                    processNext();

                    if (ch > rangeEnd) {
                        XMLCh chStr[] = { ch, chNull };
                        ThrowXMLwithMemMgr2(ParseException,XMLExcepts::Parser_Ope3, rangeEndStr, chStr, getMemoryManager());
                    }

                    tok->addRange(ch, rangeEnd);
                }
            }
        }
        firstLoop = false;
    }

    if (getState() == REGX_T_EOF)
        ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_CC2, getMemoryManager());

    if (isNRange)
    {
        if(useNRange)
            tok->setTokenType(Token::T_NRANGE);
        else
            tok = RangeToken::complementRanges(tok, fTokenFactory, fMemoryManager);
    }

    tok->sortRanges();
    tok->compactRanges();

    // If the case-insensitive option is enabled, we need to
    // have the new RangeToken instance build its internal
    // case-insensitive RangeToken.
    if (RegularExpression::isSet(fOptions, RegularExpression::IGNORE_CASE))
    {
        tok->getCaseInsensitiveToken(fTokenFactory);
    }

    setParseContext(regexParserStateNormal);
    processNext();

    return tok;
}
// ---------------------------------------------------------------------------
//  ParserForXMLSchema: Parsing/Processing methods
// ---------------------------------------------------------------------------
Token* ParserForXMLSchema::processCaret() {

    // XML Schema treats "^" like any other char
    processNext();
    return getTokenFactory()->createChar(chCaret);
}
Token* ParserForXMLSchema::processDollar() {

    // XML Schema treats "$" like any other char
    processNext();
    return getTokenFactory()->createChar(chDollarSign);
}
void LinkLocal::Stream::connected() {
	QByteArray spare = bs_->read();
	proto->startClientOut(jidLocal_, false, false, false, false, true);
	connect(bs_, SIGNAL(readyRead()), SLOT(bs_readyRead()));
	processNext();
}