コード例 #1
0
ファイル: mapio.c プロジェクト: GI-Santana/mapserver
int msIO_installHandlers( msIOContext *stdin_context,
                          msIOContext *stdout_context,
                          msIOContext *stderr_context )

{
  msIOContextGroup *group;

  msIO_Initialize();

  group = msIO_GetContextGroup();

  if( stdin_context == NULL )
    group->stdin_context = default_contexts.stdin_context;
  else if( stdin_context != &group->stdin_context )
    group->stdin_context = *stdin_context;

  if( stdout_context == NULL )
    group->stdout_context = default_contexts.stdout_context;
  else if( stdout_context != &group->stdout_context )
    group->stdout_context = *stdout_context;

  if( stderr_context == NULL )
    group->stderr_context = default_contexts.stderr_context;
  else if( stderr_context != &group->stderr_context )
    group->stderr_context = *stderr_context;

  return MS_TRUE;
}
コード例 #2
0
ファイル: mapio.c プロジェクト: codeforeurope/gim
static msIOContextGroup *msIO_GetContextGroup()

{
    int nThreadId = msGetThreadId();
    msIOContextGroup *prev = NULL, *group = io_context_list;

    if( group != NULL && group->thread_id == nThreadId )
        return group;

/* -------------------------------------------------------------------- */
/*      Search for group for this thread                                */
/* -------------------------------------------------------------------- */
    msAcquireLock( TLOCK_IOCONTEXT );
    msIO_Initialize();

    group = io_context_list;
    while( group != NULL && group->thread_id != nThreadId )
    {
        prev = group;
        group = group->next;
    }

/* -------------------------------------------------------------------- */
/*      If we found it, make sure it is pushed to the front of the      */
/*      link for faster finding next time, and return it.               */
/* -------------------------------------------------------------------- */
    if( group != NULL )
    {
        if( prev != NULL )
        {
            prev->next = group->next;
            group->next = io_context_list;
            io_context_list = group;
        }

        msReleaseLock( TLOCK_IOCONTEXT );
        return group;
    }

/* -------------------------------------------------------------------- */
/*      Create a new context group for this thread.                     */
/* -------------------------------------------------------------------- */
    group = (msIOContextGroup *) calloc(sizeof(msIOContextGroup),1);
    
    group->stdin_context = default_contexts.stdin_context;
    group->stdout_context = default_contexts.stdout_context;
    group->stderr_context = default_contexts.stderr_context;
    group->thread_id = nThreadId;

    group->next = io_context_list;
    io_context_list = group;
    
    msReleaseLock( TLOCK_IOCONTEXT );

    return group;
}
コード例 #3
0
ファイル: mapio.c プロジェクト: GI-Santana/mapserver
msIOContext *msIO_getHandler( FILE * fp )

{
  int nThreadId = msGetThreadId();
  msIOContextGroup *group = io_context_list;

  msIO_Initialize();

  if( group == NULL || group->thread_id != nThreadId ) {
    group = msIO_GetContextGroup();
    if( group == NULL )
      return NULL;
  }

  if( fp == stdin || fp == NULL || strcmp((const char *)fp,"stdin") == 0 )
    return &(group->stdin_context);
  else if( fp == stdout || strcmp((const char *)fp,"stdout") == 0 )
    return &(group->stdout_context);
  else if( fp == stderr || strcmp((const char *)fp,"stderr") == 0 )
    return &(group->stderr_context);
  else
    return NULL;
}