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

  // lock global mutex
  ThGlobalLock();

  //
  // Device thread already exists. 
  //
  if( (pThCtl = ThHashGetCtl(sDevUri)) != NULL )
  {
    pThCtl->m_uRefCnt++;
    LOGDIAG1("Service Thread \"%s\" attached (refcnt=%u).",
        pThCtl->m_sDevUri, pThCtl->m_uRefCnt);
  }

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

    pThCtl->m_fnRequest = ThDevRequest;       // device 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 thread mutex
  ThGlobalUnlock();

  return pThCtl;
}
/*!
 * \brief Create a device service thread.
 *
 * The actual thread is only created if it does not already exists. The internal
 * reference count is incremented to keep track of the users of this thread.
 *
 * \par Execution Context:
 * Calling thread.
 *
 * \param sDevUri   Device URI.
 *
 * \return On success, returns the service thread control block.
 * On failure, NULL is returned.
 */
\brief Create a device service thread.
The actual thread is only created if it does not already exists. The internal
reference count is incremented to keep track of the users of this thread.

\par Execution Context:
Calling thread.

\param sDevUri   Device URI.

\return On success, returns the service thread control block.
On failure, NULL is returned.
\ brief Create a device service thread . The actual thread is only created if it does not already exists . The internal reference count is incremented to keep track of the users of this thread . \ par Execution Context : Calling thread . \ param sDevUri Device URI . \ return On success returns the service thread control block . On failure NULL is returned .
BsProxyThCtl_T *ThCreateDevThread(const char *sDevUri)
{
  BsProxyThCtl_T *pThCtl;
  int             rc;
  ThGlobalLock();
   Device thread already exists. 
  if( (pThCtl = ThHashGetCtl(sDevUri)) != NULL )
  {
    pThCtl->m_uRefCnt++;
    LOGDIAG1("Service Thread \"%s\" attached (refcnt=%u).",
        pThCtl->m_sDevUri, pThCtl->m_uRefCnt);
  }
   Create new device thread.
  else
  {
     Create a new thread control block.
    pThCtl = ThCtlBlkNew(sDevUri);
    pThCtl->m_fnRequest = ThDevRequest;        device 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 thread mutex
  ThGlobalUnlock();
  return pThCtl;
}
BsProxyThCtl_T * ThCreateDevThread ( const char * sDevUri ) { BsProxyThCtl_T * pThCtl ; int rc ; ThGlobalLock ( ) ; if ( ( pThCtl = ThHashGetCtl ( sDevUri ) ) != NULL ) { pThCtl -> m_uRefCnt ++ ; LOGDIAG1 ( " \" \" " , pThCtl -> m_sDevUri , pThCtl -> m_uRefCnt ) ; } else { pThCtl = ThCtlBlkNew ( sDevUri ) ; pThCtl -> m_fnRequest = ThDevRequest ; 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 a device service thread.
\ brief Create a device service thread .
// lock global mutex // // Device thread already exists.  // // // Create new device thread. // // // Create a new thread control block. // // device 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 thread mutex