Beispiel #1
0
/* Initialize the cache mechanism. */
TA_RetCode TA_StringCacheAlloc( TA_StringCache **newStringCache )
{
   TA_StringCachePriv *stringCachePriv;
   #if !defined( TA_SINGLE_THREAD )
   TA_RetCode retCode;
   #endif

   if( !newStringCache )
      return TA_BAD_PARAM;

   *newStringCache = NULL;

   stringCachePriv = (TA_StringCachePriv *)TA_Malloc( sizeof( TA_StringCachePriv ) );

   if( !stringCachePriv )
      return TA_ALLOC_ERR;

   memset( stringCachePriv, 0, sizeof( TA_StringCachePriv ) );

   #if !defined( TA_SINGLE_THREAD )
   retCode = TA_SemaInit( &stringCachePriv->sema, 1 );
   if( retCode != TA_SUCCESS )
   {
      TA_Free(  stringCachePriv );
      return retCode;
   }
   #endif

   /* Success, return the cache to the caller. */
   *newStringCache = (TA_StringCache *)stringCachePriv;

   return TA_SUCCESS;
}
Beispiel #2
0
/**** Local functions definitions.     ****/
static TA_RetCode TA_NetworkGlobalInit( void **globalToAlloc )
{
   #if !defined( TA_SINGLE_THREAD )
   TA_RetCode retCode;
   #endif
   TA_NetworkGlobal *global;

   if( !globalToAlloc )
      return TA_BAD_PARAM;

   *globalToAlloc = NULL;

   #if defined( USE_LIBCURL )
      #if defined(WIN32)
         if( curl_global_init(CURL_GLOBAL_WIN32) != CURLE_OK )
            return TA_LIBCURL_GLOBAL_INIT_FAILED;
      #else
         if( curl_global_init(CURL_GLOBAL_NOTHING) != CURLE_OK )
            return TA_LIBCURL_GLOBAL_INIT_FAILED;
      #endif
   #endif

   global = (TA_NetworkGlobal *)TA_Malloc( sizeof( TA_NetworkGlobal ) );
   if( !global )
      return TA_ALLOC_ERR;

   memset( global, 0, sizeof( TA_NetworkGlobal ) );

   #if defined( USE_LIBCURL )
      global->curlHandle = curl_easy_init();
      if( global->curlHandle == NULL )
      {
         TA_Free(  global );
         return TA_LIBCURL_INIT_FAILED;
      }
   #endif

   #if !defined( TA_SINGLE_THREAD )
      /* Initialize the mutex in a non-block state. */
      retCode = TA_SemaInit( &global->mutexSema, 1 );
      if( retCode != TA_SUCCESS )
      {
         TA_Free(  global );
         return retCode;
      }
   #endif

   global->initialized = 1;

   /* Success, return the allocated memory to the caller. */
   *globalToAlloc = global;
   return TA_SUCCESS;
}
Beispiel #3
0
static TA_RetCode TA_TraceGlobalInit( void **globalToAlloc )
{
   TA_TraceGlobal *global;
   #if !defined( TA_SINGLE_THREAD )
   TA_RetCode retCode;
   #endif

   if( !globalToAlloc )
      return TA_BAD_PARAM;

   *globalToAlloc = NULL;

   global = TA_Malloc( sizeof( TA_TraceGlobal ) );
   if( !global )
      return TA_ALLOC_ERR;

   memset( global, 0, sizeof( TA_TraceGlobal ) );

   #if !defined( TA_SINGLE_THREAD )
      /* Initialize the mutexes in a non-block state. */
      retCode = TA_SemaInit( &global->callSema, 1 );
      if( retCode != TA_SUCCESS )
      {
         TA_Free(  global );
         return retCode;
      }
      retCode = TA_SemaInit( &global->fatalSema, 1 );
      if( retCode != TA_SUCCESS )
      {
         TA_SemaDestroy( &global->callSema );
         TA_Free(  global );
         return retCode;
      }
   #endif

   #ifdef TA_DEBUG   
      #if defined( TA_SINGLE_THREAD )
         /* When single threaded, maintain a calling stack. */      

         global->callStack = TA_ListAlloc();
         if( !global->callStack )
         {
            TA_Free(  global );
            return TA_ALLOC_ERR;
         }
      #endif

      /* All function call and checkpoint are maintained in a dictionary. */
      global->functionCalled = TA_DictAlloc( TA_DICT_KEY_ONE_STRING, freeTracePosition );
      if( !global->functionCalled )
      {
         #if !defined( TA_SINGLE_THREAD )
            TA_SemaDestroy( &global->callSema );
            TA_SemaDestroy( &global->fatalSema );      
         #else
            TA_ListFree( global->callStack );
         #endif      
         TA_Free(  global );
         return TA_ALLOC_ERR;
      }
   #endif

   /* Success, return the allocated memory to the caller. */
   *globalToAlloc = global;

   return TA_SUCCESS;
}
Beispiel #4
0
TA_RetCode TA_Initialize( const TA_InitializeParam *param )
{
    /* Note: Keep that function simple.
     *       No tracing, no stdio and no assert.
     */
    TA_RetCode retCode;
#if !defined( TA_SINGLE_THREAD )
    unsigned int again; /* Boolean */
    unsigned int i;
#endif

    /* Allocate the "global variable" used to manage the global
     * variables of all other modules...
     */
    memset( TA_Globals, 0, sizeof( TA_LibcPriv ) );
    TA_Globals->magicNb = TA_LIBC_PRIV_MAGIC_NB;

    if( param )
    {
        if( param->logOutput )
        {
            /* Override someone intention to use stdin!? */
            if( param->logOutput == stdin )
                TA_Globals->stdioFile = stdout;
            else
                TA_Globals->stdioFile = param->logOutput;

            TA_Globals->stdioEnabled = 1;
        }

        if( param->userLocalDrive )
            TA_Globals->localCachePath = param->userLocalDrive;
    }

#if !defined( TA_SINGLE_THREAD )
    /* For multithread, allocate all semaphores
     * protecting the module's globals.
     */
    again = 1;
    for( i=0; i < TA_NB_GLOBAL_ID && again; i++ )
    {
        retCode = TA_SemaInit( &(TA_Globals->moduleControl[i].sema), 1 );
        if( retCode != TA_SUCCESS )
            again = 0;
    }

    if( again == 0 )
    {
        /* Clean-up and exit. */
        for( i=0; i < TA_NB_GLOBAL_ID; i++ )
            TA_SemaDestroy( &(TA_Globals->moduleControl[i].sema) );

        memset( TA_Globals, 0, sizeof( TA_LibcPriv ) );

        return TA_INTERNAL_ERROR(4);
    }

#endif

    /* Force immediatly the initialization of the memory module.
     * Note: No call to the tracing capability are allowed in TA_MemInit.
     */
    retCode = TA_MemInit( sizeof( TA_LibcPriv ) );

    /* Force immediatly the initialization of the tracing module. */
    if( retCode == TA_SUCCESS )
        retCode = TA_TraceInit();

    if( retCode != TA_SUCCESS )
    {
        /* Clean-up and exit. */
#if !defined( TA_SINGLE_THREAD )
        for( i=0; i < TA_NB_GLOBAL_ID; i++ )
            TA_SemaDestroy( &(TA_Globals->moduleControl[i].sema) );
#endif
        memset( TA_Globals, 0, sizeof( TA_LibcPriv ) );

        return TA_INTERNAL_ERROR(5);
    }

    /* Tracing can now be safely used by the memory module until
     * shutdown in TA_Shutdown.
     */
    TA_Globals->traceEnabled = 1;


    /*** At this point, TA_Shutdown can be called to clean-up. ***/


    /* Allocate the default string cache used throughout the library. */
    retCode = TA_StringCacheAlloc( &(TA_Globals->dfltCache) );

    if( retCode != TA_SUCCESS )
    {
        TA_Shutdown();
        return retCode;
    }

    return TA_SUCCESS;
}