Пример #1
0
void CardReaderThread::run() {
    stopped = false;
    reader->connect();

    if (0 == reader->errorCode) {
        handleInfo(Constants::CODE_READ_READY, Constants::INFO_READ_READY);
    } else {
        handleInfo(reader->errorCode, reader->errorString);
    }

    while (reader->connected && !stopped) {
        Person p = reader->read();

        if (0 == reader->errorCode) {
            emit personReady(p);
        } else {
            handleInfo(reader->errorCode, reader->errorString);
        }

        QThread::msleep(1000);
    }

    stopped = true;
    reader->disconnect();
    handleInfo(reader->errorCode, reader->errorString);
}
Пример #2
0
/*
	read info from buffer received from server
	wrapped by protocolBegin and protocolEnd
	example: seat/ eol ...(info we want)... /seat eol
*/
int getInfoFromBuffer(){
	//find the protocolBegin and the protocolEnd
	int j;
	int copyLen, moveLen;
	char *pBegin, *pEnd;
	int isFound = 0;
	for(j=0; j<protocolNum; j++){
		pBegin = strstr(totalBuf, protocolBegin[j]);
		if(NULL == pBegin) continue;
		pEnd = strstr(pBegin, protocolEnd[j]);
		if(NULL != pEnd){// protocal found
			copyLen = strlen(pBegin)-strlen(pEnd)-strlen(protocolBegin[j]);
			memset(tmpInfo, '\0', BUFFER_LENGTH);
			memcpy(tmpInfo, pBegin+strlen(protocolBegin[j]), copyLen);

			moveLen = strlen(pEnd)-strlen(protocolEnd[j]);
			memmove(totalBuf, pEnd+strlen(protocolEnd[j]), moveLen); //remove the info got from totalBuf
			memset(totalBuf+moveLen, '\0', BUFFER_LENGTH-moveLen);
			totalBufLen = moveLen;
			isFound = 1;
			handleInfo(j);
			break;
		}
	}
	if(NULL != (pBegin = strstr(totalBuf, "game-over \n"))){
		return GAMEOVER;
	}
	return 1==isFound? PROTOCOL_FOUND: PROTOCOL_NOTFOUND;
}
bool TestCaseSandboxResultDecoderImpl::decode()
{
    switch(channel->readByte())
    {
    case startCmd:
        handleStartCase();
        break;
    case endCmd:
        handleEndCase();
        return true;
    case errorCmd:
        handleError();
        break;
    case failureCmd:
        handleAssertionFailure();
        break;
    case infoCmd:
        handleInfo();
        break;
    case warningCmd:
        handleWarning();
        break;
    default:
        handleInternalError();
    }
    return false;
}
Пример #4
0
void Keyboard::handlePPSMessage(PPSObject const& message)
{
#ifdef PPS_KEYBOARD_DEBUG
    qDebug() << "Handling pps message with attributes: " << message.attributes();
#endif

    if (message.objectStatus() != PPSObject::Undefined &&
        message.objectStatus() != PPSObject::Created) {
        // In all other cases the keyboard service is probably gone.
        handleHide();
        return;
    }

    QVariantHash attributes = message.attributes().toHash();

    QString msg = attributes[QString::fromLatin1("msg")].toString();
    // We don't care if it's a response or message right now.
    if(msg.isEmpty())
        msg = attributes[QString::fromLatin1("res")].toString();

    if (msg.compare(QString::fromLatin1("show"), Qt::CaseInsensitive) == 0)
        handleShow();
    else if (msg.compare(QString::fromLatin1("hide"), Qt::CaseInsensitive) == 0)
        handleHide();
    else if (msg.compare(QString::fromLatin1("info"), Qt::CaseInsensitive) == 0)
        handleInfo(attributes[QString::fromLatin1("dat")]);
    else if (msg.compare(QString::fromLatin1("connect"), Qt::CaseInsensitive) == 0)
        return; // We don't care, but no need to log a warning.
    else
        qWarning() << "Unsupported message type from keyboard: " << msg;
}
Пример #5
0
bool disruptorPublish( disruptor* d, char* ptr )
{
    int64_t claim;
    sendBuffer* buf;
    volatile sharedSlot* slot;

    (void)d;
    (void)ptr;
    buf = &d->buffers[ d->id ];

    /* increment the claim cursor. */
    claim = xadd64( &d->ringbuffer->claimCursor.v, 1 );

    /* block until the slot is ready. */
    if ( !waitUntilAvailable( d, claim ) )
        return false;

    /* fill out the slot. */
    {
        slot = getSlot( d, claim );
        assert( slot );
        if ( !slot )
            return false;

        slot->sender = d->id;
        slot->size = (buf->tail - ptr);
        slot->offset = (ptr - buf->start);
        slot->timestamp = rdtsc();

        /*
        handleInfo( d, "slot %lld sender=%lld size=%lld offset=%lld timestamp=%lld",
                claim,
                slot->sender,
                slot->size,
                slot->offset,
                slot->timestamp );
                */
    }


    /* wait until any other producers have published. */
    {
        int64_t expectedCursor = ( claim - 1 );
        while ( d->ringbuffer->publishCursor.v < expectedCursor )
        {
            atomicYield();
        }
    }

    /* increment the publish cursor. */
    d->ringbuffer->publishCursor.v = claim;

    handleInfo( d, "publish %d", (int)claim );

    return true;
}
TVerdict CTestStepUnitMMFVidClient::DoControllerCalled(TInt aFunction, const TDesC8& aText, TBool aExpected)
	{
	// Get the controller
	TInt err = KErrNone;
	RMMFController* controller = NULL;
	err = GetPlayerController(controller);
	if (err != KErrNone)
		{
		INFO_PRINTF2(_L("Error getting controller %d"), err);
		return EInconclusive;
		}

	// Check that the correct functions were called in the controller
	TBuf8<64> functionText;
	TUid uid = { KMmfVideoTestControllerUid };
	TMMFMessageDestination handleInfo(uid);
	TMMFMessageDestinationPckg message(handleInfo);

	TBuf<64> functionText16;
	err = controller->CustomCommandSync(message, aFunction, KNullDesC8, KNullDesC8, functionText);
	if (err == KErrNone ) 
		{
		functionText16.Copy(aText);
		
		if (aExpected)
			{
			INFO_PRINTF2(_L("Expect %S"), &functionText16);
			}
		else
			{
			INFO_PRINTF2(_L("Should not have %S"), &functionText16);
			}
			
		if ((functionText.Compare(aText) == 0 && aExpected) ||
			(functionText.Compare(aText) != 0 && !aExpected))
			{
			iTestStepResult = EPass;
			}
		else 
			{
			iTestStepResult = EFail;
			return iTestStepResult;
			}
		}
	return iTestStepResult;
	}
Пример #7
0
static bool mapClient( disruptor* d, unsigned int id )
{
    assert( id < MAX_CONNECTIONS );
    if ( id >= MAX_CONNECTIONS )
        return false;

    unmapClient( d, id );

    {
        shmem* s;
        int64_t size;

        s = shmemOpen( 0, SHMEM_MUST_NOT_CREATE, "disruptor:%s:%d", d->address, id );
        if ( !s )
            return false;

        size = shmemGetSize( s );
        d->buffers[ id ].shmem = s;
        d->buffers[ id ].start = shmemGetPtr( s );
        d->buffers[ id ].end = ( d->buffers[ id ].start + size );
        d->buffers[ id ].tail = d->buffers[ id ].start;
        handleInfo( d, "for #%d: size=%u", id, (unsigned int)size );

        {
            redisContext* r = d->redis;
            redisReply* reply;

            reply = redisCommand( r, "GET disruptor:%s:%d:username", d->address, id );
            if ( reply->type == REDIS_REPLY_STRING )
                d->names[ id ] = strclone( reply->str );
            freeReplyObject( reply );
        }

        if ( !d->names[ id ] )
            return false;

        return true;
    }
}
Пример #8
0
static bool startup( disruptor* d )
{
    bool wasCreated = false;
    redisContext* r;
    redisReply* reply;

    /* validate inputs. */
    {
        if ( !isStringValid( d->address, 1, MAX_ADDRESS_LENGTH ) )
        {
            handleError( d, "invalid length for string '%s'", d->address );
            return false;
        }

        if ( !isStringValid( d->username, 1, MAX_USERNAME_LENGTH ) )
        {
            handleError( d, "invalid length for string '%s'", d->username );
            return false;
        }
    }

    /* connect to redis. */
    r = d->redis = connectToRedis();
    if ( !r )
    {
        handleError( d, "could not connect to redis" );
        return false;
    }

    /* determine a mapping for this connection. */
    {
        int id = -1;

        /* try to fetch an existing mapping. */
        {
            reply = redisCommand( r, "GET disruptor:%s:connections:%s:id", d->address, d->username );
            if ( reply->type == REDIS_REPLY_STRING )
            {
                id = atoi( reply->str );
            }
            freeReplyObject( reply );
        }

        /* if no mapping exists, then assign a new one. */
        if ( id < 0 )
        {
            {
                reply = redisCommand( r, "INCR disruptor:%s:connectionsCount", d->address );
                if ( reply->type == REDIS_REPLY_INTEGER )
                    id = ( reply->integer - 1 );
                freeReplyObject( reply );
            }

            assert( id >= 0 );
            if ( id < 0 )
            {
                handleError( d, "could not determine mapping for username '%s'", d->username );
                return false;
            }

            wasCreated = true;

            {
                reply = redisCommand( r, "SET disruptor:%s:connections:%s:id %d", d->address, d->username, id );
                freeReplyObject( reply );
            }

            {
                reply = redisCommand( r, "SET disruptor:%s:%d:username %s", d->address, id, d->username );
                freeReplyObject( reply );
            }
        }

        d->id = id;
    }

    /* determine the connection count. */
    {
        d->connectionsCount = 0;

        reply = redisCommand( r, "GET disruptor:%s:connectionsCount", d->address, d->username );
        if ( reply->type == REDIS_REPLY_STRING )
            d->connectionsCount = atoi( reply->str );
        freeReplyObject( reply );

        if ( d->connectionsCount <= 0 )
        {
            handleError( d, "could not determine the connection count." );
            return false;
        }
    }

    handleInfo( d, "id=%d total=%d", d->id, d->connectionsCount );

    /* open the shared header. */
    {
        d->shHeader = shmemOpen( sizeof(sharedHeader), SHMEM_DEFAULT, "disruptor:%s", d->address );
        d->header = shmemGetPtr( d->shHeader );
    }

    /* open the shared ringbuffer. */
    {
        d->shRingbuffer = shmemOpen( sizeof(sharedRingbuffer), SHMEM_DEFAULT, "disruptor:%s:rb", d->address );
        d->ringbuffer = shmemGetPtr( d->shRingbuffer );
    }

    {
        int i;

        /* create the shared memory sendBuffer. */
        if ( wasCreated )
        {
            shmem* s;
            handleInfo( d, "creating %d", d->id );
            s = shmemOpen( d->sendBufferSize, SHMEM_MUST_CREATE, "disruptor:%s:%d", d->address, d->id );
            shmemClose( s );
        }

        /* map each connection. */
        for ( i = 0; i < d->connectionsCount; ++i )
        {
            if ( !mapClient( d, i ) )
            {
                handleError( d, "could not map client %d", i );
                return false;
            }
        }
    }

    return true;
}
Пример #9
0
FontFace * FontImporter::loadFont(const std::string & filename)
{
    std::ifstream in(filename, std::ios::in | std::ios::binary);

    if (!in)
    {
        return nullptr;
    }

    FontFace * font = new FontFace();

    std::string line;
    std::string identifier;
    while (std::getline(in, line))
    {
        std::stringstream ss(line);

        if (std::getline(ss, identifier, ' '))
        {
            if (identifier == "info")
            {
                handleInfo(ss, font);
            }
            else if (identifier == "common")
            {
                handleCommon(ss, font);
            }
            else if (identifier == "page")
            {
                handlePage(ss, font, filename);
            }
            else if (identifier == "chars")
            {
                handleChars(ss, font);
            }
            else if (identifier == "char")
            {
                handleChar(ss, font);
            }
            else if (identifier == "kernings")
            {
                handleKernings(ss, font);
            }
            else if (identifier == "kerning")
            {
                handleKerning(ss, font);
            }
            else
            {
                assert(false);
            }
        }
        else
        {
            assert(false);
        }
    }

    if (!font->glyphTexture())
    {
        delete font;

        return nullptr;
    }

    return font;
}