botsense/bsProxy/bsProxyThread.c
BsProxyThCtl_T *ThCreateServerThread()
{
  char           *sDevUri;
  BsProxyThCtl_T *pThCtl;
  int             rc;

  // Server URI
  sDevUri = new_strdup(BSPROXY_TH_SERVER_URI);

  // lock global mutex
  ThGlobalLock();

  //
  // There should only be one server thread.
  //
  if( (pThCtl = ThHashGetCtl(sDevUri)) != NULL )
  {
    BSPROXY_TH_LOG_ERROR(sDevUri, BS_ECODE_INTERNAL,
        "Server service thread already exists.");
  }

  //
  // Create new device thread.
  //
  else
  {
    //
    // Create a new thread control block.
    //
    pThCtl = ThCtlBlkNew(sDevUri);

    pThCtl->m_fnRequest = ServerRequest;      // server request handler
    pThCtl->m_uRefCnt   = 1;                  // thread reference count
    pThCtl->m_eState    = BsProxyThStateInit; // control is (mostly) initialized

    //
    // Add thread control to thread hash table
    //
    if( (rc = ThHashAdd(sDevUri, pThCtl)) < 0 )
    {
      LOGERROR("\"%s\": Failed to add thread control to hash table.", sDevUri);
      ThCtlBlkDelete(pThCtl);
      pThCtl = NULL;
    }

    //
    // Start the device service thread. The thread will block until the run
    // state is set this context.
    //
    else if( pthread_create(&pThCtl->m_thread, NULL, ThServiceThread,
                            (void *)pThCtl) )
    {
      LOGSYSERROR("pthread_create(\"%s\")", sDevUri);
      ThHashDelete(pThCtl);
      pThCtl = NULL;
    }

    //
    // Signal the thread to run.
    //
    else
    {
      ThSyncRun(pThCtl);
    }
  }

  // unlock global mutex
  ThGlobalUnlock();

  return pThCtl;
}
/*!
 * \brief Create the special server service thread.
 *
 * There is only one server service thread per server. The server thread processes
 * all server terminated requests.
 *
 * \par Execution Context:
 * Calling thread.
 *
 * \return On success, returns the service thread control block.
 * On failure, NULL is returned.
 */
\brief Create the special server service thread.
There is only one server service thread per server. The server thread processes
all server terminated requests.

\par Execution Context:
Calling thread.

\return On success, returns the service thread control block.
On failure, NULL is returned.
\ brief Create the special server service thread . There is only one server service thread per server . The server thread processes all server terminated requests . \ par Execution Context : Calling thread . \ return On success returns the service thread control block . On failure NULL is returned .
BsProxyThCtl_T *ThCreateServerThread()
{
  char           *sDevUri;
  BsProxyThCtl_T *pThCtl;
  int             rc;
  sDevUri = new_strdup(BSPROXY_TH_SERVER_URI);
  ThGlobalLock();
   There should only be one server thread.
  if( (pThCtl = ThHashGetCtl(sDevUri)) != NULL )
  {
    BSPROXY_TH_LOG_ERROR(sDevUri, BS_ECODE_INTERNAL,
        "Server service thread already exists.");
  }
   Create new device thread.
  else
  {
     Create a new thread control block.
    pThCtl = ThCtlBlkNew(sDevUri);
    pThCtl->m_fnRequest = ServerRequest;       server request handler
    pThCtl->m_uRefCnt   = 1;                   thread reference count
    pThCtl->m_eState    = BsProxyThStateInit;  control is (mostly) initialized
     Add thread control to thread hash table
    if( (rc = ThHashAdd(sDevUri, pThCtl)) < 0 )
    {
      LOGERROR("\"%s\": Failed to add thread control to hash table.", sDevUri);
      ThCtlBlkDelete(pThCtl);
      pThCtl = NULL;
    }
     Start the device service thread. The thread will block until the run
     state is set this context.
    else if( pthread_create(&pThCtl->m_thread, NULL, ThServiceThread,
                            (void *)pThCtl) )
    {
      LOGSYSERROR("pthread_create(\"%s\")", sDevUri);
      ThHashDelete(pThCtl);
      pThCtl = NULL;
    }
     Signal the thread to run.
    else
    {
      ThSyncRun(pThCtl);
    }
  }
   unlock global mutex
  ThGlobalUnlock();
  return pThCtl;
}
BsProxyThCtl_T * ThCreateServerThread ( ) { char * sDevUri ; BsProxyThCtl_T * pThCtl ; int rc ; sDevUri = new_strdup ( BSPROXY_TH_SERVER_URI ) ; ThGlobalLock ( ) ; if ( ( pThCtl = ThHashGetCtl ( sDevUri ) ) != NULL ) { BSPROXY_TH_LOG_ERROR ( sDevUri , BS_ECODE_INTERNAL , " " ) ; } else { pThCtl = ThCtlBlkNew ( sDevUri ) ; pThCtl -> m_fnRequest = ServerRequest ; pThCtl -> m_uRefCnt = 1 ; pThCtl -> m_eState = BsProxyThStateInit ; if ( ( rc = ThHashAdd ( sDevUri , pThCtl ) ) < 0 ) { LOGERROR ( " \" \" " , sDevUri ) ; ThCtlBlkDelete ( pThCtl ) ; pThCtl = NULL ; } else if ( pthread_create ( & pThCtl -> m_thread , NULL , ThServiceThread , ( void * ) pThCtl ) ) { LOGSYSERROR ( " \" \" " , sDevUri ) ; ThHashDelete ( pThCtl ) ; pThCtl = NULL ; } else { ThSyncRun ( pThCtl ) ; } } ThGlobalUnlock ( ) ; return pThCtl ; }
\brief Create the special server service thread.
\ brief Create the special server service thread .
// Server URI // lock global mutex // // There should only be one server thread. // // // Create new device thread. // // // Create a new thread control block. // // server request handler // thread reference count // control is (mostly) initialized // // Add thread control to thread hash table // // // Start the device service thread. The thread will block until the run // state is set this context. // // // Signal the thread to run. // // unlock global mutex