Ejemplo n.º 1
0
void testEnterAndRetrieve(){

    // INT 32
    int32_t value32 = 1, retval32;
    std::string key = "one";

    ContentValue cv;
    cv.put(key, value32);

    cv.getAsInt32(key, retval32);
    CHECK(value32 == retval32);

    // INT 64
    int64_t value64 = 423425242, retval64;
    key = "int64";
    cv.put(key, value64);
    cv.getAsInt64(key, retval64);
    CHECK(value64 == retval64);


    // Double
    double dvalue = 3.5, retvaldbl;
    key = "double";
    cv.put(key, dvalue);
    cv.getAsDouble(key, retvaldbl);
    CHECK(dvalue == retvaldbl );

    // BLOB
    uint32_t data_len = 45, get_len = 0;

    char* src = new char[data_len];
    char* get_src = NULL;
    memset(src, '$', data_len);
    key = "data";
    cv.put(key, data_len, src);

     cv.getAsData(key, get_len, get_src);

    bool fine = true;

    CHECK(get_len = data_len);

    if(data_len == get_len){

        for(int i=0; i < data_len; i++){

            if(src[i] != get_src[i])
                fine &= false;

        }
    }

    delete[] src;
    CHECK(fine);

    // STRING
    std::string strVal = "whoo", getVal("");
    key = "string";
    cv.put(key, strVal);
    cv.getAsString(key, getVal);

    CHECK(getVal == strVal);


    // BOOL
    bool mefalse = false, retvalBool;
    key = "bool";
    cv.put(key, mefalse);
    cv.getAsBool(key, retvalBool);
    CHECK(mefalse == retvalBool);

    cv.clear();

    REPORT("testEnterAndRetrieve()");
}
Ejemplo n.º 2
0
void testSameKey(){


    ContentValue cv;

    // test data

    std::string src = "adalkjalfalfalfkal";
    const char* data = src.data();
    uint32_t data_len = src.length();
    std::string data_key = "private_key";
    cv.put(data_key, data_len, data);

    std::string other_src = "daldko5202402224";
    data_len = other_src.length();
    data = other_src.data();

    cv.put(data_key, data_len, data);

    uint32_t val_len;
    char* val;
    cv.getAsData(data_key, val_len, val);
    std::string str_val(val, val_len);


    CHECK(str_val == other_src);

    // now check string

    std::string key = "peer";
    cv.put(key, std::string("sexy_girl"));
    cv.put(key, std::string("manly man"));

    std::string val_str;
    cv.getAsString(key, val_str);

    CHECK(val_str == "manly man");

    // and double

    cv.put(key, 4.);
    cv.put(key, 32.);
    double val_d;
    cv.getAsDouble(key, val_d);
    CHECK(val_d == 32.);

    // and int64
    int64_t large(20420492040123);
    cv.put(key, large);
    cv.put(key, large+34);
    int64_t val_i64;
    cv.getAsInt64(key, val_i64);

    CHECK(val_i64 == large+34);

    // and bool

    cv.put(key, false);
    cv.put(key, true);
    bool bool_val = false;
    cv.getAsBool(key, bool_val);

    CHECK(bool_val == true);

    // and int32

    int32_t medium = 20432123;
    cv.put(key, medium);
    cv.put(key, medium+34);
    int32_t val_i32;
    cv.getAsInt32(key, val_i32);

    CHECK(val_i32 == medium+34);

    REPORT("testSameKey()");
}
Ejemplo n.º 3
0
void sphinx_snippet_options(sphinx_config *config,
                            const PString *index,
                            const PString *match,
                            const PString *data,
                            const PString *options,
                            return_data_callback callback,
                            void *user_data,
                            char **error)
{
  StringBuilder *sb;
  MYSQL_RES *query_result;
  MYSQL_ROW row;
  unsigned long *lengths;

  if (!callback)
    return;

  if (!ensure_sphinx_is_connected(config, error))
    return;

  sb = string_builder_new();
  string_builder_append(sb, "CALL SNIPPETS('");
  string_builder_append_quoted(sb, data);
  string_builder_append(sb, "', '");
  string_builder_append(sb, config->prefix);
  string_builder_append_pstr(sb, index);
  string_builder_append(sb, "', '");
  string_builder_append_quoted(sb, match);
  string_builder_append(sb, "'");

  if (PSTR_NOT_EMPTY(options)) {
    string_builder_append(sb, ",");
    string_builder_append_pstr(sb, options);
  }
  string_builder_append(sb, ")");

  if (mysql_query(connection, sb->str))
    {
      REPORT(error, "Can't execute snippet query: ", sb->str, "; ", mysql_error(connection));
      string_builder_free(sb);
      return;
    }

  query_result = mysql_store_result(connection);
  if (!query_result)
    {
      REPORT(error, "Can't store result of snippet query: ", sb->str, "; ", mysql_error(connection));
      string_builder_free(sb);
      return;
    }

  row = mysql_fetch_row(query_result);
  if (!row)
    {
      REPORT(error, "Can't fetch result of snippet query: ", sb->str, "; ", mysql_error(connection));
      string_builder_free(sb);
      mysql_free_result(query_result);
      return;
    }

  lengths = mysql_fetch_lengths(query_result);
  callback(row[0], lengths[0], user_data);

  string_builder_free(sb);
  mysql_free_result(query_result);
}
Ejemplo n.º 4
0
HARNESS_EXPORT
int main(int argc, char *argv[] ) {
    char psBuffer[512];
/* We first introduced runtime version identification in 3014 */
#if TBB_INTERFACE_VERSION>=3014
    // For now, just test that run-time TBB version matches the compile-time version,
    // since otherwise the subsequent test of "TBB: INTERFACE VERSION" string will fail anyway.
    // We need something more clever in future.
    if ( tbb::TBB_runtime_interface_version()!=TBB_INTERFACE_VERSION ){
        snprintf( psBuffer,
                  512,
                  "%s %s %d %s %d.",
                  "Running with the library of different version than the test was compiled against.",
                  "Expected",
                  TBB_INTERFACE_VERSION,
                  "- got",
                  tbb::TBB_runtime_interface_version()
                  );
        ASSERT( tbb::TBB_runtime_interface_version()==TBB_INTERFACE_VERSION, psBuffer );
    }
#endif
#if __TBB_MIC
    // Skip the test in offload mode.
    // Run the test in 'true' native mode (because 'system()' works in 'true' native mode).
    (argc, argv);
    REPORT("skip\n");
#else //__TBB_MIC
#if __TBB_MPI_INTEROP
    REPORT("skip\n");
#else
    __TBB_TRY {
        FILE *stream_out;
        FILE *stream_err;

        if(argc>1 && argv[1][0] == '@' ) {
            stream_err = freopen( stderr_stream, "w", stderr );
            if( stream_err == NULL ){
                REPORT( "Internal test error (freopen)\n" );
                exit( 1 );
            }
            stream_out = freopen( stdout_stream, "w", stdout );
            if( stream_out == NULL ){
                REPORT( "Internal test error (freopen)\n" );
                exit( 1 );
            }
            {
                tbb::task_scheduler_init init(1);
            }
            fclose( stream_out );
            fclose( stream_err );
            exit(0);
        }
        //1st step check that output is empty if TBB_VERSION is not defined.
        if ( getenv("TBB_VERSION") ){
            REPORT( "TBB_VERSION defined, skipping step 1 (empty output check)\n" );
        }else{
            if( ( system(TEST_SYSTEM_COMMAND) ) != 0 ){
                REPORT( "Error (step 1): Internal test error\n" );
                exit( 1 );
            }
            //Checking output streams - they should be empty
            stream_err = fopen( stderr_stream, "r" );
            if( stream_err == NULL ){
                REPORT( "Error (step 1):Internal test error (stderr open)\n" );
                exit( 1 );
            }
            while( !feof( stream_err ) ) {
                if( fgets( psBuffer, 512, stream_err ) != NULL ){
                    REPORT( "Error (step 1): stderr should be empty\n" );
                    exit( 1 );
                }
            }
            fclose( stream_err );
            stream_out = fopen( stdout_stream, "r" );
            if( stream_out == NULL ){
                REPORT( "Error (step 1):Internal test error (stdout open)\n" );
                exit( 1 );
            }
            while( !feof( stream_out ) ) {
                if( fgets( psBuffer, 512, stream_out ) != NULL ){
                    REPORT( "Error (step 1): stdout should be empty\n" );
                    exit( 1 );
                }
            }
            fclose( stream_out );
        }

        //Setting TBB_VERSION in case it is not set
        if ( !getenv("TBB_VERSION") ){
            putenv(const_cast<char*>("TBB_VERSION=1"));
        }

        if( ( system(TEST_SYSTEM_COMMAND) ) != 0 ){
            REPORT( "Error (step 2):Internal test error\n" );
            exit( 1 );
        }
        //Checking pipe - it should contain version data
        std::vector <string_pair> strings_vector;
        std::vector <string_pair>::iterator strings_iterator;

        initialize_strings_vector( &strings_vector );
        strings_iterator = strings_vector.begin();

        stream_out = fopen( stdout_stream, "r" );
        if( stream_out == NULL ){
            REPORT( "Error (step 2):Internal test error (stdout open)\n" );
            exit( 1 );
        }
        while( !feof( stream_out ) ) {
            if( fgets( psBuffer, 512, stream_out ) != NULL ){
                REPORT( "Error (step 2): stdout should be empty\n" );
                exit( 1 );
            }
        }
        fclose( stream_out );

        stream_err = fopen( stderr_stream, "r" );
        if( stream_err == NULL ){
            REPORT( "Error (step 1):Internal test error (stderr open)\n" );
            exit( 1 );
        }
        
        while( !feof( stream_err ) ) {
            if( fgets( psBuffer, 512, stream_err ) != NULL ){
                if (strstr( psBuffer, "TBBmalloc: " )) {
                    // TBB allocator might or might not be here, ignore it
                    continue;
                }
                bool match_found = false;
                do{
                    if ( strings_iterator == strings_vector.end() ){
                        REPORT( "Error: version string dictionary ended prematurely.\n" );
                        REPORT( "No match for: \t%s", psBuffer );
                        exit( 1 );
                    }
                    if ( strstr( psBuffer, strings_iterator->first.c_str() ) == NULL ){ // mismatch
                        if( strings_iterator->second == required ){
                            REPORT( "Error: version strings do not match.\n" );
                            REPORT( "Expected \"%s\" not found in:\n\t%s", strings_iterator->first.c_str(), psBuffer );
                            exit( 1 );
                        }
                        ++strings_iterator;
                    }else{
                        match_found = true;
                        if( strings_iterator->second != optional_multiple )
                            ++strings_iterator;
                    }
                }while( !match_found );
            }
        }
        fclose( stream_err );
    } __TBB_CATCH(...) {
        ASSERT( 0,"unexpected exception" );
    }
Ejemplo n.º 5
0
PlayerLogic::PlayerLogic(xy::MessageBus& mb, const sf::Vector2f& spawnPosition)
    : xy::Component     (mb, this),
    m_entity            (nullptr),
    m_spawnPosition     (spawnPosition),
    m_clientID          (-1),
    m_currentDirection  (Direction::Right),
    m_transportStatus   (TransportStatus::Stopped),
    m_programCounter    (0),
    m_loopDestination   (0),
    m_loopCounter       (0),
    m_currentParameter  (0)
{
    instructions.insert(std::make_pair(Instruction::NOP, 
        [this](xy::Entity&, float)
    {return true; }));
    
    instructions.insert(std::make_pair(Instruction::EngineOn,
        [this](xy::Entity& entity, float dt)
    {
        return true;
    }));

    instructions.insert(std::make_pair(Instruction::EngineOff,
        [this](xy::Entity& entity, float dt)
    {
        return true;
    }));

    instructions.insert(std::make_pair(Instruction::Forward,
        [this](xy::Entity& entity, float dt)
    {
        auto path = m_target - entity.getPosition();
        if (xy::Util::Vector::lengthSquared(path) > 2)
        {
            entity.move(xy::Util::Vector::normalise(path) * movespeed * dt);
            return false;
        }
        return true;
    }));

    instructions.insert(std::make_pair(Instruction::Right,
        [this](xy::Entity& entity, float dt)
    {
        if (m_rotationTimer.getElapsedTime().asSeconds() > rotationTime)
        {
            m_rotationTimer.restart();
            m_currentDirection = static_cast<Direction>((static_cast<sf::Uint8>(m_currentDirection) + 1) % static_cast<sf::Uint8>(Direction::Count));
            m_currentParameter--;           
        }
        return (m_currentParameter == 0);
    }));

    instructions.insert(std::make_pair(Instruction::Left,
        [this](xy::Entity& entity, float dt)
    {
        if (m_rotationTimer.getElapsedTime().asSeconds() > rotationTime)
        {
            m_rotationTimer.restart();
            m_currentDirection = static_cast<Direction>((static_cast<sf::Uint8>(m_currentDirection) + static_cast<sf::Uint8>(Direction::Count) - 1) % static_cast<sf::Uint8>(Direction::Count));
            m_currentParameter--;
        }
        return (m_currentParameter == 0);
    }));

    instructions.insert(std::make_pair(Instruction::Loop,
        [this](xy::Entity& entity, float dt)
    { 
        REPORT("Loop count", std::to_string(m_loopCounter));
                
        m_loopCounter--;
        if (m_loopCounter > 0)
        {
            m_programCounter = m_loopDestination;
        }
        return true;
    }));

    m_currentAction = instructions[Instruction::NOP];
}
Ejemplo n.º 6
0
LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window
							UINT	uMsg,			// Message For This Window
							WPARAM	wParam,			// Additional Message Information
							LPARAM	lParam)			// Additional Message Information
{
	switch (uMsg)									// Check For Windows Messages
	{
		case WM_ACTIVATE:							// Watch For Window Activate Message
		{
			if (!HIWORD(wParam))					// Check Minimization State
			{
				gActive=TRUE;						// Program Is Active
			}
			else
			{
				gActive=FALSE;						// Program Is No Longer Active
			}

			return 0;								// Return To The Message Loop
		}

        case WM_POWERBROADCAST:
            REPORT(cDebugSystem::General,">>>>>>> WM_POWERBROADCAST <<<<<<<");
            if(wParam == PBT_APMSUSPEND)
            {
                REPORT(cDebugSystem::General,"--> System is suspending <--");
                CameraLibrary::CameraManager::X().PrepareForSuspend();
            }
            if(wParam == PBT_APMRESUMEAUTOMATIC)
            {
                REPORT(cDebugSystem::General,"--> System is resuming <--");
                CameraLibrary::CameraManager::X().ResumeFromSuspend();
            }
            break;

		case WM_SYSCOMMAND:							// Intercept System Commands
		{
			switch (wParam)							// Check System Calls
			{
				case SC_SCREENSAVE:					// Screensaver Trying To Start?
				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
				return 0;							// Prevent From Happening
			}
			break;									// Exit
		}

		case WM_CLOSE:								// Did We Receive A Close Message?
		{
			PostQuitMessage(0);						// Send A Quit Message
			return 0;								// Jump Back
		}

		case WM_KEYDOWN:							// Is A Key Being Held Down?
		{
			keys[wParam] = TRUE;					// If So, Mark It As TRUE
			return 0;								// Jump Back
		}

		case WM_KEYUP:								// Has A Key Been Released?
		{
			keys[wParam] = FALSE;					// If So, Mark It As FALSE
			return 0;								// Jump Back
		}
        case WM_MOVE:
            DrawGLScene(0);
            SwapBuffers(hDC);
			return 0;								// Jump Back
        case WM_PAINT:
            return 0;
		case WM_SIZE:								// Resize The OpenGL Window
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
            DrawGLScene(0);
            SwapBuffers(hDC);
			return 0;								// Jump Back
		}
	}

	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
Ejemplo n.º 7
0
/*!
******************************************************************************

 @Function              VXDIO_VLRReadWords

******************************************************************************/
IMG_RESULT
VXDIO_VLRReadWords(
    const IMG_HANDLE    hVxdCtx,
    IMG_UINT32          ui32MemRegion,
    IMG_UINT32          ui32Addr,
    IMG_UINT32          ui32NumWords,
    IMG_UINT32        * pui32Values,
    IMG_BOOL            bValidate
)
{
    VXDIO_sContext    * psVxdCtx  = (VXDIO_sContext *)hVxdCtx;
    IMG_UINT32          ui32WordCnt = 0;
    IMG_UINT32          ui32Result = IMG_SUCCESS;

    if (hVxdCtx == IMG_NULL)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "An video decoder device context handle must be provided (%d)", __LINE__);
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }

#if 0
    if (ui32MemRegion != REGION_VLR_REGSPACE &&
        ui32MemRegion != REGION_VLRFE_REGSPACE &&
        ui32MemRegion != REGION_VLRBE_REGSPACE)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "A valid VLR memory space must be provided");
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }
#endif

    if ((ui32Addr & 0x3) != 0 ||
        ui32NumWords == 0 ||
        pui32Values == IMG_NULL)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "A valid VLR location (offset word aligned) must be provided");
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }

    // Repeat for all words.
    for (ui32WordCnt = 0; ui32WordCnt < ui32NumWords; ui32WordCnt++)
    {
#ifdef SECURE_CPU_REG_ACCESS
        {
            IMG_ASSERT(psVxdCtx->sCoreFuncs.pfnSecRegAccess != IMG_NULL);
            psVxdCtx->sCoreFuncs.pfnSecRegAccess(psVxdCtx->hCoreCtx);
        }
#endif

        ui32Result = TALREG_ReadWord32(psVxdCtx->pahMemSpace[ui32MemRegion],
                                       ui32Addr,
                                       pui32Values);
        if (ui32Result != IMG_SUCCESS)
        {
            goto error;
        }

#if !defined(SECURE_MEDIA_SUPPORT) && !defined(VXD_BRIDGING)
        if (bValidate)
        {
            IMG_UINT32 ui32Mask = 0xFFFFFFFF;
            /* Disable DEVA_FW flags: DETECTED_RENDEC_FULL (0x00200000)
             * and DETECTED_RENDEC_EMPTY (0x00400000) because CSIM does not
             * support RENDEC_OVERFLOW and RENDEC_UNDERFLOW flags */
            ui32Mask &= ~(0x00200000 | 0x00400000);
            ui32Result = VXDIO_PDUMPVerifPoll(psVxdCtx,
                                              ui32MemRegion,
                                              ui32Addr,
                                              *pui32Values,
                                              ui32Mask);
            if (ui32Result != IMG_SUCCESS)
            {
                goto error;
            }
        }
#endif

        pui32Values++;
        ui32Addr += 4;
    }

error:

    return ui32Result;
}
Ejemplo n.º 8
0
int Msmpot_compute(Msmpot *msm,
    float *epotmap,               /* electrostatic potential map
                                     assumed to be length mx*my*mz,
                                     stored flat in row-major order, i.e.,
                                     &ep[i,j,k] == ep + ((k*my+j)*mx+i) */
    int mx, int my, int mz,       /* map lattice dimensions */
    float lx, float ly, float lz, /* map lattice lengths */
    float x0, float y0, float z0, /* map origin (lower-left corner) */
    float vx, float vy, float vz, /* periodic cell lengths along x, y, z;
                                     set to 0 for non-periodic direction */
    const float *atom,            /* atoms stored x/y/z/q (length 4*natoms) */
    int natoms                    /* number of atoms */
    ) {
  int err;

  REPORT("Performing MSM calculation of electrostatic potential map.");

  err = Msmpot_check_params(msm, epotmap, mx, my, mz, lx, ly, lz,
      vx, vy, vz, atom, natoms);
  if (err != MSMPOT_SUCCESS) return ERROR(err);

  /* store user parameters */
  msm->atom = atom;
  msm->natoms = natoms;
  msm->epotmap = epotmap;
  msm->mx = mx;
  msm->my = my;
  msm->mz = mz;
  msm->lx = lx;
  msm->ly = ly;
  msm->lz = lz;
  msm->lx0 = x0;
  msm->ly0 = y0;
  msm->lz0 = z0;
  msm->dx = lx / mx;
  msm->dy = ly / my;
  msm->dz = lz / mz;
  msm->px = vx;
  msm->py = vy;
  msm->pz = vz;
  msm->isperiodic = 0;  /* reset flags for periodicity */
  /* zero length indicates nonperiodic direction */
  if (vx > 0) SET_X(msm->isperiodic);
  if (vy > 0) SET_Y(msm->isperiodic);
  if (vz > 0) SET_Z(msm->isperiodic);

  err = Msmpot_setup(msm);
  if (err != MSMPOT_SUCCESS) return ERROR(err);

  memset(epotmap, 0, mx*my*mz*sizeof(float));  /* clear epotmap */


#if !defined(MSMPOT_LONGRANGE_ONLY)
#ifdef MSMPOT_CUDA
  if (msm->use_cuda_shortrng) {
    err = Msmpot_cuda_compute_shortrng(msm->msmcuda);
    if (err && msm->cuda_optional) {  /* fall back on CPU */
#ifdef USE_BIN_HASHING
      err = Msmpot_compute_shortrng_bins(msm);
#else
      err = Msmpot_compute_shortrng_linklist(msm, msm->atom, msm->natoms);
#endif
      if (err) return ERROR(err);
    }
    else if (err) return ERROR(err);
  }
  else {
#ifdef USE_BIN_HASHING
    err = Msmpot_compute_shortrng_bins(msm);
#else
    err = Msmpot_compute_shortrng_linklist(msm, msm->atom, msm->natoms);
#endif /* USE_BIN_HASHING */
    if (err) return ERROR(err);
  }
#else
#ifdef USE_BIN_HASHING
  err = Msmpot_compute_shortrng_bins(msm);
#else
  err = Msmpot_compute_shortrng_linklist(msm, msm->atom, msm->natoms);
#endif /* USE_BIN_HASHING */
  if (err) return ERROR(err);
#endif
#endif

#if !defined(MSMPOT_SHORTRANGE_ONLY)
  err = Msmpot_compute_longrng(msm);
  if (err) return ERROR(err);
#endif

#ifdef MSMPOT_VERBOSE
#ifdef MSMPOT_CHECKMAPINDEX
  printf("epotmap[%d]=%g\n", MAPINDEX, epotmap[MAPINDEX]);
#endif
#endif

  return MSMPOT_SUCCESS;
}
Ejemplo n.º 9
0
/*!
******************************************************************************

 @Function              VXDIO_WriteRegister

******************************************************************************/
IMG_RESULT
VXDIO_WriteRegister(
    const IMG_HANDLE    hVxdCtx,
    IMG_UINT32          ui32MemRegion,
    IMG_UINT32          ui32Offset,
    IMG_UINT32          ui32Value,
    IMG_UINT32          ui32Mask,
    IMG_UINT8           ui8Pipe
)
{
    VXDIO_sContext    * psVxdCtx  = (VXDIO_sContext *)hVxdCtx;
    IMG_UINT32          ui32Result;

    if (hVxdCtx == IMG_NULL)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "An video decoder device context handle must be provided (%d)", __LINE__);
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }

    IMG_ASSERT(psVxdCtx->ui32MemSpaceCount != 0);
    if (ui32MemRegion >= psVxdCtx->ui32MemSpaceCount)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "A valid VXD memory region must be provided");
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }

    IMG_ASSERT(psVxdCtx->bInitialised);

    if (psVxdCtx->bClocks)
    {
        IMG_UINT32 ui32RegValue;

        if (psVxdCtx->sCoreFuncs.pfnSelectPipe != IMG_NULL)
        {
            psVxdCtx->sCoreFuncs.pfnSelectPipe(psVxdCtx->hCoreCtx, ui8Pipe);
        }

        if (ui32Mask != -1)
        {
            TALREG_ReadWord32(psVxdCtx->pahMemSpace[ui32MemRegion], ui32Offset, &ui32RegValue);
            ui32RegValue &= ~ui32Mask;
            ui32RegValue |= ui32Value;
        }
        else
        {
            ui32RegValue = ui32Value;
        }
#ifdef SECURE_CPU_REG_ACCESS
        {
        IMG_ASSERT(psVxdCtx->sCoreFuncs.pfnSecRegAccess != IMG_NULL);
        psVxdCtx->sCoreFuncs.pfnSecRegAccess(psVxdCtx->hCoreCtx);
        }
#endif
        TALREG_WriteWord32(psVxdCtx->pahMemSpace[ui32MemRegion], ui32Offset, ui32RegValue);
    }
    else
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_NOTICE,
            "Didn't WRITE register while clocks are turned off");
        ui32Result = IMG_ERROR_NOT_INITIALISED;
        goto error;
    }

    return IMG_SUCCESS;

error:
    return ui32Result;
}
Ejemplo n.º 10
0
/*!
******************************************************************************

 @Function              VXDIO_VLRWriteWords

******************************************************************************/
IMG_RESULT
VXDIO_VLRWriteWords(
    const IMG_HANDLE    hVxdCtx,
    IMG_UINT32          ui32MemRegion,
    IMG_UINT32          ui32Addr,
    IMG_UINT32          ui32NumWords,
    const IMG_UINT32  * pui32Values
)
{
    VXDIO_sContext    * psVxdCtx = (VXDIO_sContext *)hVxdCtx;
    IMG_UINT32          ui32WordCnt;
    IMG_UINT32          ui32Result;

    if (hVxdCtx == IMG_NULL)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "An video decoder device context handle must be provided (%d)", __LINE__);
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }

#if 0
    if (ui32MemRegion != REGION_VLR_REGSPACE &&
        ui32MemRegion != REGION_VLRFE_REGSPACE &&
        ui32MemRegion != REGION_VLRBE_REGSPACE)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "A valid VLR memory space must be provided");
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }
#endif

    if ((ui32Addr & 0x3) != 0 ||
        ui32NumWords == 0 ||
        pui32Values == IMG_NULL)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "A valid VLR location (offset word aligned) must be provided");
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }

    // Repeat for all words.
    for (ui32WordCnt = 0; ui32WordCnt < ui32NumWords; ui32WordCnt++)
    {
#ifdef SECURE_CPU_REG_ACCESS
        {
            IMG_ASSERT(psVxdCtx->sCoreFuncs.pfnSecRegAccess != IMG_NULL);
            psVxdCtx->sCoreFuncs.pfnSecRegAccess(psVxdCtx->hCoreCtx);
        }
#endif
        ui32Result = TALREG_WriteWord32(psVxdCtx->pahMemSpace[ui32MemRegion],
                                        ui32Addr,
                                        *pui32Values);
        if (ui32Result != IMG_SUCCESS)
        {
            goto error;
        }

        pui32Values++;
        ui32Addr += 4;
    }

    return IMG_SUCCESS;

error:
    return ui32Result;
}
Ejemplo n.º 11
0
//=============================================================================
//      parse3DSChunk : recursively parses the file.
//-----------------------------------------------------------------------------
static TQ3Boolean
parse3DSChunk (TQ3FileObject theFile, TQ3Uns32 endPos, TparamData *paramData)
{
	char buffer[128];

	TQ3Uns32 curPos;

	TQ3Int16 chunkID;
	TQ3Int32 chunkLength;
	TQ3Boolean continueParsing = kQ3True;
	TQ3FileFormatObject format 		= Q3File_GetFileFormat (theFile);
	TQ3XObjectClass theFormatClass = Q3XObject_GetClass (format);
	TE3FFormat_3ds_Data		*instanceData = (TE3FFormat_3ds_Data *) Q3XObjectClass_GetPrivate(theFormatClass, format);
	
	while (continueParsing && ((curPos = instanceData->baseData.currentStoragePosition) < endPos)) {
		if (Q3Int16_Read (&chunkID, theFile) != kQ3Success) {
			return (kQ3False);
		}
		if (Q3Int32_Read (&chunkLength, theFile) != kQ3Success) {
			return (kQ3False);
		}
		switch (chunkID) {
		case kChunkModelData:
			REPORT ((sLogFile, "kChunkModelData\n"));
			continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
			break;
#ifdef DEBUG_3DS
		case kChunkMainVersion:
			{
				TQ3Int32 mainVersion;
				continueParsing = (TQ3Boolean)(Q3Int32_Read (&mainVersion, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkMainVersion %ld\n", mainVersion));
				instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			}
			break;
#endif
#ifdef DEBUG_3DS
		case kChunkModelVersion:
			{
				TQ3Int32 modelVersion;
				continueParsing = (TQ3Boolean)(Q3Int32_Read (&modelVersion, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkModelVersion %ld\n", modelVersion));
				instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			}
			break;
#endif
#ifdef LATER
		// Materials
		//
		case kChunkMaterial:
			REPORT ((sLogFile, "kChunkMaterial\n"));
			// Create a new material to hold onto the parsed information
			//
			paramData->material = newMaterialData ();

			continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
			if (continueParsing) {
				(*(paramData->cmd))(kNewMaterial, paramData->material, paramData->userData);
			}
			deleteMaterialData (paramData->material);
			paramData->material = NULL;
			break;
		case kChunkMaterialName:
			if (paramData->material != NULL) {
				TQ3Uns32 length;
				continueParsing = (TQ3Boolean)(Q3String_Read (buffer, &length, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkMaterialName %s\n", buffer));
				if (continueParsing) {
					if (paramData->material->id != NULL)
						free (paramData->material->id);
					paramData->material->id = strdup(buffer);	
				}
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
		case kChunkByteRGB:
			{
				TQ3Int8 colorComponent;

				continueParsing = (TQ3Boolean)(Q3Int8_Read (&colorComponent, theFile) == kQ3Success);
				if(continueParsing)
					paramData->colorData.r = (colorComponent / 255.0);
				continueParsing = (TQ3Boolean)(Q3Int8_Read (&colorComponent, theFile) == kQ3Success);
				if(continueParsing)
					paramData->colorData.g = (colorComponent / 255.0);
				continueParsing = (TQ3Boolean)(Q3Int8_Read (&colorComponent, theFile) == kQ3Success);
				if(continueParsing)
					paramData->colorData.b = (colorComponent / 255.0);

				REPORT ((sLogFile, "kChunkByteRGB (%g, %g, %g)\n",
											 paramData->colorData.r,
											 paramData->colorData.g,
											 paramData->colorData.b));
				instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			}
			break;
		case kChunkIntData:
			{
				TQ3Int16 intData;
				continueParsing = (TQ3Boolean)(Q3Int16_Read (&intData, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkIntData %d\n", intData));
				if (continueParsing) {
					paramData->floatData = intData;
				}
				instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			}
			break;
		case kChunkFloatData:
			{
				TQ3Float32 floatData;
				continueParsing = (TQ3Boolean)(Q3Float32_Read (&floatData, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkFloatData %g\n", floatData));
				if (continueParsing) {
					paramData->floatData = floatData;
				}
				instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			}
			break;
		case kChunkAmbient:
			REPORT ((sLogFile, "kChunkAmbient\n"));
			continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
			break;
		case kChunkDiffuse:
			REPORT ((sLogFile, "kChunkDiffuse\n"));
			// Parse the diffuse parameters
			//
			continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
			if (continueParsing && (paramData->material != NULL)) {
				paramData->material->Cs = paramData->colorData;
			}
			break;
		case kChunkSpecular:
			REPORT ((sLogFile, "kChunkSpecular\n"));
			// Parse the specular parameters
			//
			continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
			if (continueParsing && (paramData->material != NULL)) {
				paramData->material->specularcolor = paramData->colorData;
			}
			break;
#ifdef DEBUG_3DS
		case kChunkShininess:
			REPORT ((sLogFile, "Unknown chunk: kChunkShininess\n"));
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
#endif
#ifdef DEBUG_3DS
		case kChunkShineStrength:
			REPORT ((sLogFile, "Unknown chunk: kChunkShineStrength\n"));
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
#endif
		case kChunkTransparency:
			// Parse the opacity parameters
			//
			continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
			if (continueParsing && (paramData->material != NULL)) {
				TQ3Float32 opacity = 1.0 - (paramData->floatData / 100.0);
				paramData->material->Os.r = opacity;
				paramData->material->Os.g = opacity;
				paramData->material->Os.b = opacity;
				REPORT ((sLogFile, "kChunkTransparency: %g\n", paramData->floatData));
			}
			break;
		case kChunkTextureMap:
			REPORT ((sLogFile, "kChunkTextureMap\n"));
			continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
			break;
		case kChunkTextureFile:
			if (paramData->material != NULL) {
				TQ3Uns32 length;
				continueParsing = (TQ3Boolean)(Q3String_Read (buffer, &length, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkTextureFile %s\n", buffer));
				if (continueParsing) {
					if (paramData->material->texturename != NULL)
						free (paramData->material->texturename);
					paramData->material->texturename = strdup (buffer);
				}
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
#endif
		// Meshes
		//
		case kChunkObjBlock:
			{
				TQ3Uns32 length;
				continueParsing = (TQ3Boolean)(Q3String_Read (buffer, &length, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkObjBlock %s\n", buffer));
				paramData->pointsPolygons = newPointsPolygonData ();
				paramData->pointsPolygons->name = strdup (buffer);
				continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
				if (continueParsing && (paramData->pointsPolygons->npolys > 0)) {
					(*(paramData->cmd))(kNewPointsPolygon, paramData->pointsPolygons, paramData->userData);
				}
				else if (paramData->pointsPolygons->npolys < 0) {
					switch (paramData->pointsPolygons->npolys) {
					case kLightHint:
						(*(paramData->cmd))(kNewLight, paramData->pointsPolygons, paramData->userData);
						break;
					case kCameraHint:
						(*(paramData->cmd))(kNewCamera, paramData->pointsPolygons, paramData->userData);
						if (paramData->pointsPolygons->hanger != NULL) {
							free (paramData->pointsPolygons->hanger);
							paramData->pointsPolygons->hanger = NULL;
						}
						break;
					}
				}
				deletePointsPolygonData (paramData->pointsPolygons);
				paramData->pointsPolygons = NULL;
			}
			break;
		case kChunkObjHidden:
			REPORT ((sLogFile, "kChunkObjHidden\n"));
			if (paramData->pointsPolygons != NULL) {
				paramData->pointsPolygons->hidden = kQ3True;
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
		case kChunkTriMesh:
			REPORT ((sLogFile, "kChunkTriMesh\n"));
			continueParsing = parse3DSChunk (theFile, curPos + chunkLength, paramData);
			break;
		case kChunkVertList:
			if (paramData->pointsPolygons != NULL) {
				TQ3Int16 n;
				TQ3Point3D *pointList = NULL;
				TQ3Uns16 numVerts;
				continueParsing = (TQ3Boolean)(Q3Uns16_Read(&numVerts, theFile) == kQ3Success);
				if (numVerts > 0) {
					if (paramData->pointsPolygons->Ppointer != NULL)
						free (paramData->pointsPolygons->Ppointer);
					paramData->pointsPolygons->Ppointer = (TQ3Point3D *)malloc (sizeof(TQ3Point3D) * numVerts);
				}
				REPORT ((sLogFile, "kChunkVertList %d\n", numVerts));
				pointList = (TQ3Point3D *)(paramData->pointsPolygons->Ppointer);
				for (n = 0; (n < numVerts) && continueParsing; n++) {
					TQ3Point3D vertex;
					continueParsing = (TQ3Boolean)(Q3Point3D_Read (&vertex, theFile) == kQ3Success);
					pointList[n].x = vertex.x;
					pointList[n].y = vertex.z;
					pointList[n].z = -vertex.y;
					REPORT ((sLogFile, "  (%g, %g, %g)\n", vertex.x, vertex.y, vertex.z));
				}
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
		case kChunkMapList:
			REPORT ((sLogFile, "Unknown chunk: kChunkMapList\n"));
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
		case kChunkFaceList:
			if (paramData->pointsPolygons != NULL) {
				TQ3Int32 vert = 0;
				TQ3Int16 n = 0;
				TQ3Int16 numFaces;
				continueParsing = (TQ3Boolean)(Q3Int16_Read(&numFaces, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkFaceList %d\n", numFaces));
				paramData->pointsPolygons->npolys = numFaces;
				if (numFaces > 0) {
					if (paramData->pointsPolygons->nverts != NULL)
						free (paramData->pointsPolygons->nverts);
					paramData->pointsPolygons->nverts = (TQ3Int32 *)malloc (sizeof(TQ3Int32) * numFaces);
					if (paramData->pointsPolygons->verts != NULL)
						free (paramData->pointsPolygons->verts);
					paramData->pointsPolygons->verts = (TQ3Int32 *)malloc (sizeof(TQ3Int32) * numFaces * 3);
				}
				for (n = 0; (n < numFaces) && continueParsing; n++) {
					TQ3Int16 p0, p1, p2, flags;
					continueParsing = (TQ3Boolean)(Q3Int16_Read (&p0, theFile) == kQ3Success);
					if (!continueParsing) break;
					continueParsing = (TQ3Boolean)(Q3Int16_Read (&p1, theFile) == kQ3Success);
					if (!continueParsing) break;
					continueParsing = (TQ3Boolean)(Q3Int16_Read (&p2, theFile) == kQ3Success);
					if (!continueParsing) break;
					continueParsing = (TQ3Boolean)(Q3Int16_Read (&flags, theFile) == kQ3Success);
					if (!continueParsing) break;
					paramData->pointsPolygons->nverts[n] = 3;
					paramData->pointsPolygons->verts[vert++] = p0;
					paramData->pointsPolygons->verts[vert++] = (flags == 7 ? p2 : p1);
					paramData->pointsPolygons->verts[vert++] = (flags == 7 ? p1 : p2);
//					REPORT ((sLogFile, " (" << p0 << ", " << p1 << ", " << p2 << ") " << (void *)(int)flags << "\n";
				}
			}
			else {
				instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			}
			break;
#ifdef LATER
		case kChunkFaceMaterial:
			if (paramData->pointsPolygons != NULL) {
				TmaterialGroupData *materialGroup;
				TQ3Uns32 length;
				continueParsing = (TQ3Boolean)(Q3String_Read (buffer, &length, theFile) == kQ3Success);
				REPORT ((sLogFile, "kChunkFaceMaterial %s\n", buffer));
				materialGroup = &(paramData->pointsPolygons->materialGroup);
				if (paramData->pointsPolygons->numMaterials != 0) {
					TmaterialGroupData *last = materialGroup;
					while (last->next != NULL) {
						last = last->next;
					}
					materialGroup = (TmaterialGroupData *)malloc (sizeof(TmaterialGroupData));
					materialGroup->faces = NULL;
					materialGroup->next = NULL;
					last->next = materialGroup;
				}
				materialGroup->material = strdup (buffer);
				paramData->pointsPolygons->numMaterials++;
				continueParsing = (TQ3Boolean)(Q3Int16_Read  (&(materialGroup->nfaces), theFile) == kQ3Success);
				if (continueParsing && (materialGroup->nfaces != 0)) {
					TQ3Int16 n;
					materialGroup->faces = (TQ3Int16 *)malloc (sizeof(TQ3Int16) * materialGroup->nfaces);
					for (n = 0; (n < materialGroup->nfaces) && continueParsing; n++) {
						continueParsing = (TQ3Boolean)(Q3Int16_Read  (&(materialGroup->faces[n]), theFile) == kQ3Success);
					}
				}
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
		case kChunkSmoothList:
			REPORT ((sLogFile, "kChunkSmoothList\n"));
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
#endif
		case kChunkTransformMatrix:
			if (paramData->pointsPolygons != NULL) {
				TQ3Int16 row, col;
				TQ3Matrix4x4 matrix;
				for (row = 0; (row < 4) && continueParsing; row++) {
					for (col = 0; (col < 3) && continueParsing; col++) {
						TQ3Float32 element;
						continueParsing = (TQ3Boolean)(Q3Float32_Read (&element, theFile) == kQ3Success);
						if (continueParsing) {
							matrix.value[row][col] = element;
						}
					}
					matrix.value[row][3] = 0.0;
				}
				matrix.value[3][3] = 1.0;
#ifdef DEBUG_3DS
				REPORT ((sLogFile, "kChunkTransformMatrix\n"));
				REPORT ((sLogFile, "Transform ["));
				for (row = 0; row < 4; row++) {
					for (col = 0; col < 4; col++) {
						if ((row > 0) || (col > 0)) {
							REPORT ((sLogFile, " "));
						}
						REPORT ((sLogFile, "%g", matrix.value[row][col]));
					}
				}
				REPORT ((sLogFile, "]\n"));
#endif
				if (continueParsing) {
					paramData->pointsPolygons->pivot.x = -matrix.value[3][0];
					paramData->pointsPolygons->pivot.y = matrix.value[3][2];
					paramData->pointsPolygons->pivot.z = -matrix.value[3][1];
					matrix.value[3][0] = 0.0;
					matrix.value[3][1] = 0.0;
					matrix.value[3][2] = 0.0;
					for (col = 0; col < 3; col++) {
						TQ3Float32 swap = matrix.value[1][col];
						matrix.value[1][col] = matrix.value[2][col];
						matrix.value[2][col] = swap;
					}
					for (row = 0; row < 4; row++) {
						TQ3Float32 swap = matrix.value[row][1];
						matrix.value[row][1] = matrix.value[row][2];
						matrix.value[row][2] = swap;
					}
					Q3Matrix4x4_Invert (&matrix, &paramData->pointsPolygons->matrix);
#ifdef DEBUG_3DS
					REPORT ((sLogFile, "  pivot (%g, %g, %g)\n", paramData->pointsPolygons.pivot[0], paramData->pointsPolygons.pivot[1], paramData->pointsPolygons.pivot[2]));
					REPORT ((sLogFile, "Transform ["));
					for (row = 0; row < 4; row++) {
						for (col = 0; col < 4; col++) {
							if ((row > 0) || (col > 0)) {
								REPORT ((sLogFile, " "));
							}
							REPORT ((sLogFile, "%g", paramData->pointsPolygons.matrix.value[row][col]));
						}
					}
					REPORT ((sLogFile, "]\n"));
#endif
				}
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
#ifdef LATER
		case kChunkDirectionalLight:
			REPORT ((sLogFile, "kChunkDirectionalLight\n"));
			// Tell kChunkObjBlock we found a light
			//
			if (paramData->pointsPolygons != NULL) {
				paramData->pointsPolygons->npolys = kLightHint;
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
		case kChunkAmbientLight:
			REPORT ((sLogFile, "kChunkAmbientLight\n"));
			// Tell kChunkObjBlock we found a light
			//
			if (paramData->pointsPolygons != NULL) {
				paramData->pointsPolygons->npolys = kLightHint;
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
		case kChunkCamera:
			REPORT ((sLogFile, "kChunkCamera\n"));
			if (paramData->pointsPolygons != NULL) {
				TcameraData *cameraData = (TcameraData *)malloc (sizeof(TcameraData));
				TQ3Point3D fltPoint;
				TQ3Float32 twist;
				TQ3Float32 angle;

				// Tell kChunkObjBlock we found a camera
				//
				paramData->pointsPolygons->npolys = kCameraHint;

				continueParsing = (TQ3Boolean)(Q3Point3D_Read (&fltPoint, theFile) == kQ3Success);
				cameraData->eyePt.x = -fltPoint.x;
				cameraData->eyePt.y = fltPoint.y;
				cameraData->eyePt.z = -fltPoint.z;

				continueParsing = (TQ3Boolean)(Q3Point3D_Read (&fltPoint, theFile) == kQ3Success);
				cameraData->viewPt.x = -fltPoint.x;
				cameraData->viewPt.y = fltPoint.z;
				cameraData->viewPt.z = -fltPoint.y;

				continueParsing = (TQ3Boolean)(Q3Float32_Read (&twist, theFile) == kQ3Success);
				cameraData->twist = twist;

				continueParsing = (TQ3Boolean)(Q3Float32_Read (&angle, theFile) == kQ3Success);
				cameraData->viewAngle = angle;

				paramData->pointsPolygons->hanger = cameraData;
			}
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
#endif
		default:
			REPORT ((sLogFile, "Unknown chunk: 0x%x\n", (void *)(int)chunkID));
			instanceData->baseData.currentStoragePosition = curPos + chunkLength;
			break;
		};
	};
	instanceData->baseData.currentStoragePosition = endPos;

	return (TQ3Boolean)((endPos <=instanceData->baseData.logicalEOF) && continueParsing);
}
Ejemplo n.º 12
0
    } __TBB_CATCH( std::runtime_error& error ) {
#if TBB_USE_EXCEPTIONS
        REPORT("ERROR: %s\n", error.what() );
#endif /* TBB_USE_EXCEPTIONS */
    }
Ejemplo n.º 13
0
/**
  * @brief  response for get version request.
  *         parse answer, save online version to flash.
  * @param  arg: contain the ip link information
  *         pusrdata: data
  *         len: len of data (strlen)
  * @retval None
  */
LOCAL void ICACHE_FLASH_ATTR
get_version_recv(void *arg, char *pusrdata, unsigned short len)
{
  struct espconn *pespconn = arg;
  fota_client_t *fota_client = (fota_client_t *)pespconn->reverse;

  /* get body */
  char *body = (char*)os_strstr(pusrdata, "\r\n\r\n");
  if (body == NULL) {
    INFO("Invalide response\n");
    return;
  }
  INFO("Body: %s\n", body+4);
  uint32_t bodylen = os_strlen(body);

  /* parse json, get version */  
  char *n_host,
       *n_url,
       *n_version,
       *n_protocol;

  if (parse_fota(body, bodylen, &n_version, &n_host, &n_url, &n_protocol) < 0) {
    INFO("FOTA Client: Invalid response\n");
    goto CLEAN_MEM;
  }
  INFO("\tVersion %s\n", n_version);
  INFO("\tHost %s\n", n_host);
  INFO("\tURL %s\n", n_url);
  INFO("\tProtocol %s\n", n_protocol);

  /* then, we have valide JSON response */  
  // disable data receiving timeout handing
  // and close connection 
  os_timer_disarm(&fota_client->request_timeout);
#if (FOTA_SECURE)
  espconn_secure_disconnect(pespconn);
#else
  espconn_disconnect(pespconn);
#endif

  uint32_t version;
  if (convert_version(n_version, os_strlen(n_version), &version) < 0) {
    REPORT("FOTA Client: Invalide version return %s\n", n_version);
    goto CLEAN_MEM;
  }

  /* if we still have lastest version */
  if (version <= version_fwr) {
    INFO("FOTA Client: We have lastest firmware (current %u.%u.%u vs online %u.%u.%u)\n", 
      (version_fwr/256/256)%256, (version_fwr/256)%256, version_fwr%256,
      (version/256/256)%256, (version/256)%256, version%256);
    goto CLEAN_MEM;
  }

  INFO("FOTA Client: Preparing to get firmware\n");

  start_cdn(&fota_client->fw_server, n_version, n_host, n_url, n_protocol);

CLEAN_MEM:
  FREE(n_host);
  FREE(n_url);
  FREE(n_version);
  FREE(n_protocol);
}
void Invariant<M,N>::flog_once( size_t mode )
{
    //! Every 8th access is a write access
    bool write = (mode%8)==7;
    bool okay = true;
    bool lock_kept = true;
    if( (mode/8)&1 ) {
        // Try implicit acquire and explicit release
        typename mutex_type::scoped_lock lock(mutex,write);
        if( write ) {
            long my_value = value[0];
            update();
            if( mode%16==7 ) {
                lock_kept = lock.downgrade_to_reader();
                if( !lock_kept )
                    my_value = value[0] - 1;
                okay = value_is(my_value+1);
            }
        } else {
            okay = is_okay();
            if( mode%8==3 ) {
                long my_value = value[0];
                lock_kept = lock.upgrade_to_writer();
                if( !lock_kept )
                    my_value = value[0];
                update();
                okay = value_is(my_value+1);
            }
        }
        lock.release();
    } else {
        // Try explicit acquire and implicit release
        typename mutex_type::scoped_lock lock;
        lock.acquire(mutex,write);
        if( write ) {
            long my_value = value[0];
            update();
            if( mode%16==7 ) {
                lock_kept = lock.downgrade_to_reader();
                if( !lock_kept )
                    my_value = value[0] - 1;
                okay = value_is(my_value+1);
            }
        } else {
            okay = is_okay();
            if( mode%8==3 ) {
                long my_value = value[0];
                lock_kept = lock.upgrade_to_writer();
                if( !lock_kept )
                    my_value = value[0];
                update();
                okay = value_is(my_value+1);
            }
        }
    }
    if( !okay ) {
        REPORT( "ERROR for %s at %ld: %s %s %s %s\n",mutex_name, long(mode),
                write?"write,":"read,", write?(mode%16==7?"downgrade,":""):(mode%8==3?"upgrade,":""),
                lock_kept?"lock kept,":"lock not kept,", (mode/8)&1?"imp/exp":"exp/imp" );
    }
}
Ejemplo n.º 15
0
/*
******************************************************************************

 @Function              VXDIO_Initialise

******************************************************************************/
IMG_RESULT
VXDIO_DeInitialise(
    IMG_UINT32          ui32CoreNum,
    IMG_HANDLE          hVxdCtx
)
{
    VXDIO_sContext    * psVxdCtx  = (VXDIO_sContext *)hVxdCtx;
    IMG_UINT32          ui32Result;

    if (hVxdCtx == IMG_NULL)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "An video decoder device context handle must be provided (%d)", __LINE__);
        return IMG_ERROR_INVALID_PARAMETERS;
    }

    IMG_ASSERT(psVxdCtx->sCoreFuncs.pfnDeInitialise != IMG_NULL);
    ui32Result = psVxdCtx->sCoreFuncs.pfnDeInitialise(ui32CoreNum,
                                                      psVxdCtx->hCoreCtx);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error;
    }

    ui32NumOfCoresInit = ui32NumOfCoresInit > 0 ? ui32NumOfCoresInit-1 : 0;
    if (ui32NumOfCoresInit == 0)
    {
#ifdef SECURE_TAL
        ui32Result = TAL_DeviceUnRegister("VDEC");
        IMG_ASSERT(ui32Result == IMG_SUCCESS);
        if (ui32Result != IMG_SUCCESS)
        {
            goto error;
        }
#else
        ui32Result = TALSETUP_Deinitialise();
        IMG_ASSERT(ui32Result == IMG_SUCCESS);
        if (ui32Result != IMG_SUCCESS)
        {
            goto error;
        }
#endif

#ifdef SECURE_TAL
        ui32Result = TARGET_Deinitialise(&gsTargetConfig);
        SECDEV_DeInitialise(SECDEV_MAPAREA_REGISTER);
#else
        ui32Result = TARGET_Deinitialise(IMG_NULL);
#endif
        IMG_ASSERT(ui32Result == IMG_SUCCESS);
        if (ui32Result != IMG_SUCCESS)
        {
            goto error;
        }
    }

    IMG_FREE(psVxdCtx);

    return IMG_SUCCESS;

error:
    return ui32Result;
}
static void
CollectWindowReports(nsGlobalWindow *aWindow,
                     nsWindowSizes *aWindowTotalSizes,
                     nsIMemoryMultiReporterCallback *aCb,
                     nsISupports *aClosure)
{
  // DOM window objects fall into one of three categories:
  // - "active" windows are currently either displayed in an active
  //   tab, or a child of such a window.
  // - "cached" windows are in the fastback cache.
  // - "other" windows are closed (or navigated away from w/o being
  //   cached) yet held alive by either a website or our code. The
  //   latter case may be a memory leak, but not necessarily.
  //
  // For inner windows we show how much memory the window and its
  // document etc use, and we report those per URI, where the URI is
  // the document URI, if available, or the codebase of the principal
  // in the window. In the case where we're unable to find a URI we're
  // dealing with a chrome window with no document in it (or
  // somesuch), and for that we make the URI be the string "[system]".
  //
  // For outer windows we simply group them all together and just show
  // the combined count and amount of memory used, which is generally
  // a constant amount per window (since all the actual data lives in
  // the inner window).
  //
  // The path we give to the reporter callback for inner windows are
  // as follows:
  //
  //   explicit/window-objects/<category>/top=<top-outer-id> (inner=<top-inner-id>)/inner-window(id=<id>, uri=<uri>)
  //
  // Where:
  // - <category> is active, cached, or other, as described above.
  // - <top-outer-id> is the window id (nsPIDOMWindow::WindowID()) of
  //   the top outer window (i.e. tab, or top level chrome window).
  // - <top-inner-id> is the window id of the top window's inner
  //   window.
  // - <id> is the window id of the inner window in question.
  // - <uri> is the URI per above description.
  //
  // Exposing the window ids is done to get logical grouping in
  // about:memory, and also for debuggability since one can get to the
  // nsGlobalWindow for a window id by calling the static method
  // nsGlobalWindow::GetInnerWindowWithId(id) (or
  // GetOuterWindowWithId(id) in a debugger.
  //
  // For outer windows we simply use:
  // 
  //   explicit/window-objects/<category>/outer-windows
  //
  // Which gives us simple counts of how many outer windows (and their
  // combined sizes) per category.

  nsCAutoString windowPath("explicit/window-objects/");

  nsIDocShell *docShell = aWindow->GetDocShell();

  nsGlobalWindow *top = aWindow->GetTop();
  nsWindowSizes windowSizes(DOMStyleMallocSizeOf);
  aWindow->SizeOfIncludingThis(&windowSizes);

  if (docShell && aWindow->IsFrozen()) {
    windowPath += NS_LITERAL_CSTRING("cached/");
  } else if (docShell) {
    windowPath += NS_LITERAL_CSTRING("active/");
  } else {
    windowPath += NS_LITERAL_CSTRING("other/");
  }

  if (aWindow->IsInnerWindow()) {
    windowPath += NS_LITERAL_CSTRING("top=");

    if (top) {
      windowPath.AppendInt(top->WindowID());

      nsGlobalWindow *topInner = top->GetCurrentInnerWindowInternal();
      if (topInner) {
        windowPath += NS_LITERAL_CSTRING(" (inner=");
        windowPath.AppendInt(topInner->WindowID());
        windowPath += NS_LITERAL_CSTRING(")");
      }
    } else {
      windowPath += NS_LITERAL_CSTRING("none");
    }

    windowPath += NS_LITERAL_CSTRING("/inner-window(id=");
    windowPath.AppendInt(aWindow->WindowID());
    windowPath += NS_LITERAL_CSTRING(", uri=");

    if (!AppendWindowURI(aWindow, windowPath)) {
      windowPath += NS_LITERAL_CSTRING("[system]");
    }

    windowPath += NS_LITERAL_CSTRING(")");
  } else {
    // Combine all outer windows per section (active/cached/other) as
    // they basically never contain anything of interest, and are
    // always pretty much the same size.

    windowPath += NS_LITERAL_CSTRING("outer-windows");
  }

#define REPORT(_path1, _path2, _amount, _desc)                                \
  do {                                                                        \
    if (_amount > 0) {                                                        \
        nsCAutoString path(_path1);                                           \
        path += _path2;                                                       \
        aCb->Callback(EmptyCString(), path, nsIMemoryReporter::KIND_HEAP,     \
                      nsIMemoryReporter::UNITS_BYTES, _amount,                \
                      NS_LITERAL_CSTRING(_desc), aClosure);                   \
    }                                                                         \
  } while (0)

  REPORT(windowPath, "/dom", windowSizes.mDOM,
         "Memory used by a window and the DOM within it.");
  aWindowTotalSizes->mDOM += windowSizes.mDOM;

  REPORT(windowPath, "/style-sheets", windowSizes.mStyleSheets,
         "Memory used by style sheets within a window.");
  aWindowTotalSizes->mStyleSheets += windowSizes.mStyleSheets;

  REPORT(windowPath, "/layout/arenas", windowSizes.mLayoutArenas,
         "Memory used by layout PresShell, PresContext, and other related "
         "areas within a window.");
  aWindowTotalSizes->mLayoutArenas += windowSizes.mLayoutArenas;

  REPORT(windowPath, "/layout/style-sets", windowSizes.mLayoutStyleSets,
         "Memory used by style sets within a window.");
  aWindowTotalSizes->mLayoutStyleSets += windowSizes.mLayoutStyleSets;

  REPORT(windowPath, "/layout/text-runs", windowSizes.mLayoutTextRuns,
         "Memory used for text-runs (glyph layout) in the PresShell's frame "
         "tree, within a window.");
  aWindowTotalSizes->mLayoutTextRuns += windowSizes.mLayoutTextRuns;

#undef REPORT
}
Ejemplo n.º 17
0
/*
******************************************************************************

 @Function              VXDIO_Initialise

******************************************************************************/
IMG_RESULT
VXDIO_Initialise(
    IMG_BOOL            bFakeMtx,
    IMG_BOOL            bPost,
    IMG_BOOL            bStackUsageTest,
    IMG_UINT32          ui32CoreNum,
    VXD_eDevType        eDeviceType,
    IMG_HANDLE        * phVxdCtx
)
{
    IMG_RESULT          ui32Result;
    VXDIO_sContext    * psVxdCtx;
#ifdef SECURE_TAL
    SECURE_sDev			sDevInfo;
#endif

    if (phVxdCtx == IMG_NULL)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
               "An video decoder device context handle must be provided (%d)", __LINE__);
        return IMG_ERROR_INVALID_PARAMETERS;
    }

    psVxdCtx = IMG_MALLOC(sizeof(*psVxdCtx));
    IMG_ASSERT(psVxdCtx);
    if (psVxdCtx == IMG_NULL)
    {
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR,
            "Failed to allocate memory for VXDIO context");
        return IMG_ERROR_OUT_OF_MEMORY;
    }
    IMG_MEMSET(psVxdCtx, 0, sizeof(*psVxdCtx));
    *phVxdCtx = psVxdCtx;


    if (ui32NumOfCoresInit == 0)
    {
#ifdef SECURE_TAL
        IMG_UINT32 i;
        for(i = 0; i < gsTargetConfig.ui32DevNum; i++)
        {
            sDevInfo.pszDeviceName = gsTargetConfig.pasDevices[i].pszDeviceName;

            ui32Result = SECDEV_Initialise();
            if(ui32Result != IMG_SUCCESS)
            {
                goto error;
            }
            ui32Result = SECDEV_LocateDevice(&sDevInfo, SECDEV_MAPAREA_REGISTER);
            if (ui32Result != IMG_SUCCESS)
            {
                goto error;
            }
            gsTargetConfig.pasDevices[i].pvKmRegBase = sDevInfo.pvKmRegBase;
            gsTargetConfig.pasDevices[i].ui32RegSize = sDevInfo.ui32RegSize;
        }

        TARGET_Initialise(&gsTargetConfig);
#else
        TARGET_Initialise(IMG_NULL);
#endif
    }

    switch (eDeviceType)
    {
    case VXD_DEV_MSVDX:
#ifdef POST_TEST
#ifdef STACK_USAGE_TEST
        ui32Result = MSVDXIO_Initialise(bFakeMtx,
                                        bPost,
                                        bStackUsageTest,
                                        ui32CoreNum,
                                        (IMG_HANDLE)psVxdCtx,
                                        &psVxdCtx->hCoreCtx);
#else
        /* POST required only */
        ui32Result = MSVDXIO_Initialise(bFakeMtx,
                                        bPost,
                                        IMG_FALSE,
                                        ui32CoreNum,
                                        (IMG_HANDLE)psVxdCtx,
                                        &psVxdCtx->hCoreCtx);
#endif
#else
#ifdef STACK_USAGE_TEST
        /* STACK USAGE TEST required only */
        ui32Result = MSVDXIO_Initialise(bFakeMtx,
                                        IMG_FALSE,
                                        bStackUsageTest,
                                        ui32CoreNum,
                                        (IMG_HANDLE)psVxdCtx,
                                        &psVxdCtx->hCoreCtx);
#else
        /* POST and STACK USAGE TEST not required */
        ui32Result = MSVDXIO_Initialise(bFakeMtx,
                                        IMG_FALSE,
                                        IMG_FALSE,
                                        ui32CoreNum,
                                        (IMG_HANDLE)psVxdCtx,
                                        &psVxdCtx->hCoreCtx);
#endif
#endif
        break;
#ifdef VDEC_USE_PVDEC
    case VXD_DEV_PVDEC:
        ui32Result = PVDECIO_Initialise(bFakeMtx,
                                        ui32CoreNum,
                                        (IMG_HANDLE)psVxdCtx,
                                        &psVxdCtx->hCoreCtx);
        break;
#endif /* VDEC_USE_PVDEC */
    default:
        REPORT(REPORT_MODULE_VXDIO, REPORT_ERR, "Wrong device type selected");
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error;
    }

    return ui32Result;

error:
    IMG_FREE(psVxdCtx);
    *phVxdCtx = IMG_NULL;
    return ui32Result;
}
Ejemplo n.º 18
0
/*!
******************************************************************************

 @Function              MMU_DeviceCreate

******************************************************************************/
IMG_RESULT  MMU_DeviceCreate(
    MMU_eMmuType                    eMmuType,
    VDEC_eTileScheme                eTileScheme,
    VDECDDMMU_pfnDeviceCallback     pfnDeviceCallback,
    MSVDXIO_sMemPool                sMemPool,
    IMG_VOID                      * pvCallbackParameter,
    IMG_UINT32                      ui32PtdAlignment,
    IMG_HANDLE                    * phMmuDevHandle
)
{
    IMG_RESULT          ui32Result = IMG_SUCCESS;
    IMG_BOOL            bTiling = IMG_TRUE;
    TALMMU_eMMUType     eTalMmuType = TALMMU_MMUTYPE_4K_PAGES_32BIT_ADDR;
    IMG_UINT32          i;
    MMU_sDevContext *   psDevContext;
    TALMMU_sDevMemInfo  sDevMemInfo;

    // Set the TAL MMU type.
    switch (eMmuType)
    {
    case MMU_TYPE_32BIT:
        eTalMmuType = TALMMU_MMUTYPE_4K_PAGES_32BIT_ADDR;
        break;

    case MMU_TYPE_36BIT:
        eTalMmuType = TALMMU_MMUTYPE_4K_PAGES_36BIT_ADDR;
        break;

    case MMU_TYPE_40BIT:
        eTalMmuType = TALMMU_MMUTYPE_4K_PAGES_40BIT_ADDR;
        break;

    default:
        return IMG_ERROR_INVALID_PARAMETERS;
    }

    /* Allocate a device context structure...*/
    VDEC_MALLOC(psDevContext);
    IMG_ASSERT(psDevContext != IMG_NULL);
    if (psDevContext == IMG_NULL)
    {
        REPORT(REPORT_MODULE_MMU, REPORT_ERR,
               "Failed to allocate memory for MMU device context");
        return IMG_ERROR_OUT_OF_MEMORY;
    }
    VDEC_BZERO(psDevContext);

    /* Initialise stream list. */
    LST_init(&psDevContext->sStrList);

    psDevContext->pfnDeviceCallback = pfnDeviceCallback;
    psDevContext->pvCallbackParameter = pvCallbackParameter;

    /* Initialise TALMMU. */
    ui32Result = TALMMU_Initialise();
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_tal_init;
    }

    /* Create an MMU template */
    sDevMemInfo.pszDeviceName = "VDEC";
    sDevMemInfo.ui32DeviceId = 0;
    sDevMemInfo.eMMUType = eTalMmuType;
    sDevMemInfo.eDevFlags = TALMMU_DEVFLAGS_NONE;
    sDevMemInfo.pszPageDirMemSpaceName = "MEM";
    sDevMemInfo.pszPageTableMemSpaceName = IMG_NULL;
    sDevMemInfo.ui32PageSize = DEV_MMU_PAGE_SIZE;
    sDevMemInfo.ui32PageTableDirAlignment = ui32PtdAlignment;
    sDevMemInfo.eMemAttrib = (SYS_MEMATTRIB_UNCACHED | SYS_MEMATTRIB_WRITECOMBINE);
    sDevMemInfo.eMemPool = sMemPool.eMemPoolId;
    sDevMemInfo.eTilingScheme = (eTileScheme == VDEC_TS1_512x8) ? TALMMU_MMUTILING_SCHEME_1 : TALMMU_MMUTILING_SCHEME_0;

    ui32Result = TALMMU_DevMemTemplateCreate(&sDevMemInfo, &psDevContext->hDevMemTemplate);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_tal_template;
    }

    TALMMU_AddCallback(psDevContext->hDevMemTemplate,
                       mmu_Callback,
                       (IMG_PVOID)psDevContext);

    /* Add heaps to template */
    for (i = 0; i < MMU_HEAP_MAX; i++)
    {
        sHeapInfo.ui32HeapId = asMmuHeaps[i].eHeapId;
        sHeapInfo.eHeapType = asMmuHeaps[i].eHeapType;
        sHeapInfo.pszMemSpaceName = asMmuHeaps[i].pszMemSpace;
        sHeapInfo.bTiled = (bTiling && asMmuHeaps[i].ui32TileStride) ? IMG_TRUE : IMG_FALSE;
        sHeapInfo.ui32BaseDevVirtAddr = asMmuHeaps[i].ui32StartOffset;
        sHeapInfo.ui32Size = asMmuHeaps[i].ui32Size;
        sHeapInfo.ui32XTileStride = 0;

        if (asMmuHeaps[i].ui32TileStride)
        {
            IMG_UINT32  ui32HwTileStride;
            IMG_UINT32  ui32Log2HwTileStride = 0;

            ui32HwTileStride = asMmuHeaps[i].ui32TileStride;
            // Calculate HW tile stride.
            // HW tile stride = log2((tile_stride / tile_width)/ 2)
            ui32HwTileStride >>= 1;
            switch (eTileScheme)
            {
            case VDEC_TS0_256x16:
                ui32HwTileStride >>= 8;
                break;
            case VDEC_TS1_512x8:
                ui32HwTileStride >>= 9;
                break;
            default:
                IMG_ASSERT(0);
                break;
            }

            ui32HwTileStride >>= 1;
            while (ui32HwTileStride)
            {
                ui32HwTileStride >>= 1;
                ui32Log2HwTileStride++;
            }
            // Calculated hardware coded stride value.
            ui32HwTileStride = ui32Log2HwTileStride;

            sHeapInfo.ui32XTileStride = ui32HwTileStride;
        }

        ui32Result = TALMMU_DevMemHeapAdd(psDevContext->hDevMemTemplate, &sHeapInfo);
        IMG_ASSERT(ui32Result == IMG_SUCCESS);
        if (ui32Result != IMG_SUCCESS)
        {
            goto error_tal_heap;
        }
    }
Ejemplo n.º 19
0
//public
void PlayerLogic::entityUpdate(xy::Entity& entity, float dt)
{
    if (m_transportStatus == TransportStatus::Playing)
    {       
        REPORT("Current Parameter", std::to_string(m_currentParameter));
        Direction direction = m_currentDirection;
        if(m_currentAction(entity, dt))
        {
            //quit if we finished
            if (m_programCounter == m_program.size())
            {
                stop();
                //LOG("Finished running program", xy::Logger::Type::Info);
                return;
            }            
            
            //action completed get next instruction and its parameter
            Instruction instruction = static_cast<Instruction>(m_program[m_programCounter++]);
            m_currentParameter = m_program[m_programCounter++];
            
            REPORT("Current Instruction", std::to_string(sf::Uint8(instruction)));
            
            //set up inital action values
            switch (instruction)
            {
            default: break;
            case Instruction::EngineOn: break;
            case Instruction::EngineOff: break;
            case Instruction::Forward:
            {
                //calc the target from the current direction and entity position
                m_target = entity.getPosition();
                switch (m_currentDirection)
                {
                default: break;
                case Direction::Left:
                    m_target.x -= tileSize.x * static_cast<float>(m_currentParameter);
                    break;
                case Direction::Right:
                    m_target.x += tileSize.x * static_cast<float>(m_currentParameter);
                    break;
                case Direction::Up:
                    m_target.y -= tileSize.y * static_cast<float>(m_currentParameter);
                    break;
                case Direction::Down:
                    m_target.y += tileSize.y * static_cast<float>(m_currentParameter);
                    break;
                }
            }
                break;
            case Instruction::Right:
            case Instruction::Left:
                m_rotationTimer.restart();
                break;
            case Instruction::Loop:
                m_loopDestination = m_program[m_programCounter++];
                if(m_loopCounter == 0) m_loopCounter = m_currentParameter;
                break;
            }
            //update the current action
            m_currentAction = instructions[instruction];

            REPORT("Program Counter", std::to_string(m_programCounter));
        }

        //check if action changed our direction and message if so
        if (direction != m_currentDirection)
        {
            auto msg = sendMessage<DirectionEvent>(DirectionMessage);
            msg->id = m_clientID;
            msg->direction = m_currentDirection;
        }
    }
}